Skip to content

Commit

Permalink
fix(pretty): pretty it
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Oct 27, 2023
1 parent 3df395b commit 4009890
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/components/features/list-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ListEditor: FunctionComponent<ListEditorProps> = (props) => {
const onItemChange = (itemValue: any, itemIndex: number) => {
const newListValue = [...currentValue];
if (typeof itemValue === 'object') {
itemValue = {...currentValue[itemIndex], ...itemValue}
itemValue = { ...currentValue[itemIndex], ...itemValue };
}
newListValue[itemIndex] = itemValue;
replaceList(newListValue);
Expand Down
42 changes: 19 additions & 23 deletions src/components/features/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,32 @@ interface State {
value: any[];
}

type Props = BaseFeatureProps<ListFeature> & { parentFeatures: (CompositeFeature | GenericExposedFeature)[] } & WithTranslation<'list'>;
type Props = BaseFeatureProps<ListFeature> & {
parentFeatures: (CompositeFeature | GenericExposedFeature)[];
} & WithTranslation<'list'>;

class List extends Component<Props, State> {
constructor(props: Props) {
super(props);
const {deviceState, feature} = this.props;
const {property} = feature;
const value = (property ? ((deviceState[property] ?? []) as any[]) : []);;
this.state = {value}
const { deviceState, feature } = this.props;
const { property } = feature;
const value = property ? ((deviceState[property] ?? []) as any[]) : [];
this.state = { value };
}

onChange = (value: any[]): void => {
const {endpoint, property} = this.props.feature;
this.setState({value});
const { endpoint, property } = this.props.feature;
this.setState({ value });
if (!this.isListRoot()) {
this.props.onChange(endpoint as Endpoint, property ? { [property]: value } : value);
}
}
};

onApply = () => {
const {value} = this.state;
const {endpoint, property} = this.props.feature;
const { value } = this.state;
const { endpoint, property } = this.props.feature;
this.props.onChange(endpoint as Endpoint, property ? { [property]: value } : value);
}
};

isListRoot = (): boolean => {
return this.props.parentFeatures?.length === 1;
Expand All @@ -45,34 +47,28 @@ class List extends Component<Props, State> {
const { access = FeatureAccessMode.ACCESS_WRITE, item_type: itemType } = feature;
if (access & FeatureAccessMode.ACCESS_WRITE) {
if (itemType == 'number') {
return (
<RangeListEditor
onChange={this.onChange}
value={this.state.value}
minimal={minimal}
/>
);
return <RangeListEditor onChange={this.onChange} value={this.state.value} minimal={minimal} />;
} else {
const result = [
<ListEditor
key='1'
key="1"
feature={itemType}
parentFeatures={[...parentFeatures, feature]}
onChange={this.onChange}
value={this.state.value}
/>
/>,
];

if (this.isListRoot()) {
result.push(
<div key='2'>
<div key="2">
<Button
className={cx('btn btn-primary float-end', { 'btn-sm': minimal })}
onClick={this.onApply}
>
{t('common:apply')}
</Button>
</div>
</div>,
);
}

Expand All @@ -84,6 +80,6 @@ class List extends Component<Props, State> {
return <NoAccessError {...this.props} />;
}
}
};
}

export default withTranslation(['list', 'common'])(React.memo(List));

0 comments on commit 4009890

Please sign in to comment.