Skip to content

Commit 1c08285

Browse files
author
Koen Kanters
committed
feat(composite): improve composite exposes
1 parent 8414b98 commit 1c08285

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/components/features/composite/Feature.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface FeatureProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onCha
2323
feature: CompositeFeature | GenericExposedFeature;
2424
deviceState: DeviceState;
2525
device: Device;
26+
depth: number;
2627
stepsConfiguration?: Record<string, unknown>;
2728
onChange(endpoint: Endpoint, value: Record<string, unknown>): void;
2829
onRead(endpoint: Endpoint, value: Record<string, unknown>): void;
@@ -32,7 +33,7 @@ interface FeatureProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onCha
3233

3334
export const Feature = (props: FeatureProps): JSX.Element => {
3435

35-
const { feature, device, deviceState, stepsConfiguration, onRead, onChange, featureWrapperClass: FeatureWrapper, minimal } = props;
36+
const { feature, device, deviceState, stepsConfiguration, onRead, onChange, featureWrapperClass: FeatureWrapper, minimal, depth } = props;
3637

3738
const genericParams = { key: JSON.stringify(feature), device, deviceState, onChange, onRead, featureWrapperClass: FeatureWrapper, minimal };
3839
const wrapperParams = { key: JSON.stringify(feature), feature, onRead, deviceState };
@@ -77,7 +78,7 @@ export const Feature = (props: FeatureProps): JSX.Element => {
7778
return <Fan feature={feature} {...genericParams} />
7879
} else if (isCompositeFeature(feature)) {
7980
return <FeatureWrapper {...wrapperParams}>
80-
<Composite type="composite" feature={feature} {...genericParams} deviceState={(deviceState[feature.property] ?? {}) as DeviceState} />
81+
<Composite type="composite" feature={feature} {...genericParams} depth={depth} deviceState={(deviceState[feature.property] ?? {}) as DeviceState} />
8182
</FeatureWrapper>
8283
}
8384
return (<FeatureWrapper {...wrapperParams}>

src/components/features/composite/composite.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type CompositeType = "composite" | "light" | "switch" | "cover" | "lock" | "fan"
1212

1313
interface CompositeProps extends BaseFeatureProps<CompositeFeature> {
1414
type: CompositeType;
15+
depth?: number;
1516
stepsConfiguration?: Record<string, unknown>;
1617
minimal?: boolean;
1718
showEndpointLabels?: boolean;
@@ -68,6 +69,7 @@ export class Composite extends Component<CompositeProps & WithTranslation<"compo
6869
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6970
const { t, showEndpointLabels = false, feature, device, deviceState, onRead: _onRead, onChange: _onChange, featureWrapperClass, minimal } = this.props;
7071
const { features = [] } = feature;
72+
const depth = this.props.depth ?? 0;
7173
const { state } = this;
7274
const isThisACompositeFeature = isCompositeFeature(feature)
7375
const isMoreThanOneFeature = features.length > 1;
@@ -83,6 +85,7 @@ export class Composite extends Component<CompositeProps & WithTranslation<"compo
8385
feature={f}
8486
device={device}
8587
deviceState={combinedState}
88+
depth={depth + 1}
8689
onChange={this.onChange}
8790
onRead={this.onRead}
8891
featureWrapperClass={featureWrapperClass}
@@ -97,6 +100,7 @@ export class Composite extends Component<CompositeProps & WithTranslation<"compo
97100
feature={f}
98101
device={device}
99102
deviceState={combinedState}
103+
depth={depth + 1}
100104
onChange={this.onChange}
101105
onRead={this.onRead}
102106
featureWrapperClass={featureWrapperClass}
@@ -108,6 +112,7 @@ export class Composite extends Component<CompositeProps & WithTranslation<"compo
108112
key={JSON.stringify(f)}
109113
feature={f}
110114
device={device}
115+
depth={depth + 1}
111116
deviceState={combinedState}
112117
onChange={this.onChange}
113118
onRead={this.onRead}
@@ -118,7 +123,7 @@ export class Composite extends Component<CompositeProps & WithTranslation<"compo
118123
}
119124

120125

121-
if (isThisACompositeFeature && isMoreThanOneFeature) {
126+
if (isThisACompositeFeature && isMoreThanOneFeature && depth === 1) {
122127
result.push(<div key={feature.name + 'apply'}>
123128
<Button disabled={!this.allInnerFeaturesHaveValues()} className={cx('btn btn-primary float-end', { 'btn-sm': minimal })} onClick={this.onCompositeFeatureApply}>{t('common:apply')}</Button>
124129
</div>)

0 commit comments

Comments
 (0)