Skip to content

Commit

Permalink
Composite kind type violation
Browse files Browse the repository at this point in the history
The composite component shall not deal with single `kind` values.

Update components documentation
  • Loading branch information
widoz committed Feb 24, 2024
1 parent ca48137 commit e8397c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export function MyComponent(props) {
/>
<ToggleControl
value={entities.value}
options={entities.options}
onChange={entities.onChange}
/>
</>
Expand Down Expand Up @@ -206,8 +207,8 @@ export function MyComponent(props) {
<>
<RadioControl
value={kind.value.first()}
options={Array.from(kind.options)}
onChange={kind.onChange}
options={kind.options}
onChange={(value) => kind.onChange(new Set([value]))}
/>
/* ... */
</>
Expand Down
11 changes: 5 additions & 6 deletions sources/client/src/components/composite-entities-by-kind.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,28 @@ export function CompositeEntitiesByKind< E, K >(
};

const onChangeKind = ( kind: EntitiesSearch.Kind< K > ) => {
const _kind = kind instanceof Set ? kind : new Set( [ kind ] );
const emptySet = new Set< any >();

props.kind.onChange( _kind );
props.kind.onChange( kind );
props.entities.onChange( emptySet );

if ( _kind.length() <= 0 ) {
if ( kind.length() <= 0 ) {
dispatch( {
type: 'CLEAN_ENTITIES_OPTIONS',
} );
dispatch( { type: 'UPDATE_KIND', kind: _kind } );
dispatch( { type: 'UPDATE_KIND', kind } );
return;
}

props
.searchEntities( state.searchPhrase, _kind, {
.searchEntities( state.searchPhrase, kind, {
exclude: state.entities,
} )
.then( ( entitiesOptions ) => {
dispatch( {
type: 'UPDATE_ENTITIES_OPTIONS_FOR_NEW_KIND',
entitiesOptions,
kind: _kind,
kind,
} );
} )
.catch( ( error ) => {
Expand Down

0 comments on commit e8397c1

Please sign in to comment.