fix(console): single feature patch (#10476)

# Which Problems Are Solved

This PR fixes an issue where all features where patched, instead of a
single one. This led to instance overrides which were not intended.
With this change, an update is executed whenever a toggle is hit, only
containing the respective feature, not all.

# How the Problems Are Solved

The console application was overriding the feature settings as an entire
request. A toggle change is now only changing the desired and targeted
feature using partial patches.

# Additional Context

Closes #10459

---------

Co-authored-by: Elio Bischof <[email protected]>
This commit is contained in:
Max Peintner
2025-08-22 09:55:31 +02:00
committed by GitHub
co-authored by Elio Bischof
parent ac3a4037a7
commit d8518d48f2
7 changed files with 251 additions and 21 deletions
@@ -13,7 +13,7 @@
<p class="events-desc cnsl-secondary-text">{{ 'DESCRIPTIONS.SETTINGS.FEATURES.DESCRIPTION' | translate }}</p>
<ng-template cnslHasRole [hasRole]="['iam.restrictions.write']">
<button color="warn" (click)="resetFeatures()" mat-stroked-button>
<button color="warn" (click)="resetFeatures()" mat-stroked-button data-e2e="reset-features-button">
{{ 'SETTING.FEATURES.RESET' | translate }}
</button>
</ng-template>
@@ -24,9 +24,9 @@
*ngFor="let key of FEATURE_KEYS"
[toggleStateKey]="key"
[toggleState]="toggleStates[key]"
(toggleChange)="saveFeatures(key, $event)"
(toggleChange)="saveFeature(key, $event)"
></cnsl-feature-toggle>
<cnsl-login-v2-feature-toggle [toggleState]="toggleStates.loginV2" (toggleChanged)="saveFeatures('loginV2', $event)" />
<cnsl-login-v2-feature-toggle [toggleState]="toggleStates.loginV2" (toggleChanged)="saveFeature('loginV2', $event)" />
</div>
</cnsl-card>
</div>
@@ -129,19 +129,18 @@ export class FeaturesComponent {
);
}
public async saveFeatures<TKey extends ToggleStateKeys, TValue extends ToggleStates[TKey]>(key: TKey, value: TValue) {
const toggleStates = { ...(await firstValueFrom(this.toggleStates$)), [key]: value };
public async saveFeature<TKey extends ToggleStateKeys, TValue extends ToggleStates[TKey]>(key: TKey, value: TValue) {
const req: MessageInitShape<typeof SetInstanceFeaturesRequestSchema> = {};
const req = FEATURE_KEYS.reduce<MessageInitShape<typeof SetInstanceFeaturesRequestSchema>>((acc, key) => {
acc[key] = toggleStates[key].enabled;
return acc;
}, {});
// to save special flags they have to be handled here
req['loginV2'] = {
required: toggleStates.loginV2.enabled,
baseUri: toggleStates.loginV2.baseUri,
};
// Set only the specific feature being updated
if (key === 'loginV2') {
req['loginV2'] = {
required: value.enabled,
baseUri: (value as ToggleStates['loginV2']).baseUri,
};
} else if (FEATURE_KEYS.includes(key)) {
req[key] = value.enabled;
}
try {
await this.featureService.setInstanceFeatures(req);