Skip to content

Commit 64779f4

Browse files
committed
Offer configured sources by label when adding accounts
The add-account service picker is now constrained to the game's configured sources (no free text), each offered by its label (falling back to the source key). Source editor tabs show the label too, so an RSS-keyed source labelled e.g. Thursdoid reads as Thursdoid everywhere. queue-users resolves the picked value back to the source by label.
1 parent d8882b4 commit 64779f4

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

src/AddService.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ class AddService extends React.Component {
8989

9090
if ( this.state.isOpen ) {
9191
returnNodes.push(
92+
// Constrained (no freeSolo): an account can only be attached to a
93+
// service the game has a configured source for, so it can't be
94+
// created with a service nothing will index. The value comes from
95+
// onChange (a picked option), not onInputChange (free text).
9296
<Autocomplete
93-
filterOptions = { ( options ) => {
94-
return options;
95-
} }
96-
freeSolo
9797
fullWidth
9898
key = { 'add-account-service' }
99-
onInputChange = { ( event, value ) => {
99+
onChange = { ( event, value ) => {
100100
this.handleServiceChange( value );
101101
} }
102102
openOnFocus
@@ -111,6 +111,7 @@ class AddService extends React.Component {
111111
/>
112112
);
113113
} }
114+
value = { this.state.service || null }
114115
/>
115116
);
116117
returnNodes.push(
@@ -141,6 +142,7 @@ class AddService extends React.Component {
141142
>
142143
<Button
143144
color = { 'primary' }
145+
disabled = { !this.state.service || !this.state.identifier }
144146
key = { 'add-account-save-button' }
145147
onClick = { this.handleSave }
146148
style = { styles.saveAccountButton }

src/GameSources.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,12 +1327,19 @@ class GameSources extends React.Component {
13271327
variant = { 'scrollable' }
13281328
>
13291329
{ services.map( ( service ) => {
1330+
// Show the source's `label` (its human name, e.g.
1331+
// an 'RSS'-keyed source labelled 'Thursdoid') on the
1332+
// tab, falling back to the object key when unlabelled
1333+
// — matching what the "Add account" picker offers and
1334+
// what queue-users resolves accounts against.
1335+
const tabLabel = this.props.sources[ service ].label || service;
1336+
13301337
return (
13311338
<Tab
13321339
icon = { this.renderSourceIcon( service ) }
13331340
iconPosition = { 'start' }
13341341
key = { service }
1335-
label = { service }
1342+
label = { tabLabel }
13361343
sx = { {
13371344
minHeight: 'auto',
13381345
// Disabled sources read at a glance as dimmed tabs.

src/Games.jsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,24 @@ class Games extends React.Component {
195195

196196
api.get( `/${ useId }/developers` )
197197
.then( ( developers ) => {
198-
const services = [];
199198
const groups = [];
200199

201-
for ( let i = 0; i < developers.data.length; i = i + 1 ) {
202-
for ( let accountIndex = 0; accountIndex < developers.data[ i ].accounts.length; accountIndex = accountIndex + 1 ) {
203-
services.push( developers.data[ i ].accounts[ accountIndex ].service );
204-
}
200+
// The "Add account" service picker offers only the game's
201+
// configured sources, so an account can't be attached to a service
202+
// nothing will index. Each source is offered by its `label` (its
203+
// human name, e.g. an 'RSS'-keyed source labelled 'Thursdoid'),
204+
// falling back to the config.sources key when it has no label.
205+
// queue-users resolves this value back to the source (by label,
206+
// then key) when fanning out jobs.
207+
const game = this.state.games.find( ( candidate ) => {
208+
return candidate.identifier === useId;
209+
} );
210+
const sources = ( game && game.config && game.config.sources ) || {};
211+
const services = Object.keys( sources ).map( ( sourceKey ) => {
212+
return ( sources[ sourceKey ] && sources[ sourceKey ].label ) || sourceKey;
213+
} );
205214

215+
for ( let i = 0; i < developers.data.length; i = i + 1 ) {
206216
if ( developers.data[ i ].group ) {
207217
groups.push( developers.data[ i ].group );
208218
}

0 commit comments

Comments
 (0)