Skip to content

Commit

Permalink
Merge branch 'dev' into merge-down-6-0-8-to-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
danoswaltCL authored Dec 2, 2024
2 parents dbf3336 + ad3852d commit e276cff
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<form [formGroup]="featureFlagForm" class="form-standard dense-3">
<mat-form-field appearance="outline">
<mat-label class="ft-14-400">Name</mat-label>
<input matInput formControlName="name" placeholder="e.g., My feature flag" class="ft-14-400"/>
<input matInput formControlName="name" placeholder="e.g., My feature flag" class="ft-14-400" />
<mat-hint class="form-hint ft-12-400">
{{ 'feature-flags.upsert-flag-modal.name-hint.text' | translate }}
</mat-hint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ export class UpsertFeatureFlagModalComponent {
this.listenForPrimaryButtonDisabled();
this.listenForDuplicateKey();
this.listenOnContext();

if (this.isDisabled()) {
this.disableRestrictedFields();
}
}

isDisabled() {
return (
this.config.params.action === UPSERT_FEATURE_FLAG_ACTION.EDIT &&
this.config.params.sourceFlag?.status === FEATURE_FLAG_STATUS.ENABLED
);
}

disableRestrictedFields(): void {
this.featureFlagForm.get('name')?.disable();
this.featureFlagForm.get('key')?.disable();
this.featureFlagForm.get('appContext')?.disable();
}

createFeatureFlagForm(): void {
Expand Down Expand Up @@ -234,10 +251,13 @@ export class UpsertFeatureFlagModalComponent {
this.featureFlagsService.addFeatureFlag(flagRequest);
}

createEditRequest(
{ name, key, description, appContext, tags }: FeatureFlagFormData,
{ id, status, filterMode }: FeatureFlag
): void {
createEditRequest({ name, key, description, appContext, tags }: FeatureFlagFormData, sourceFlag: FeatureFlag): void {
const { id, status, filterMode } = sourceFlag;
if (sourceFlag.status === 'enabled') {
name = sourceFlag.name;
key = sourceFlag.key;
appContext = sourceFlag.context[0];
}
const flagRequest: UpdateFeatureFlagRequest = {
id,
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[slideToggleChecked]="flag.status === FEATURE_FLAG_STATUS.ENABLED"
[slideToggleText]="'feature-flags.enable.text' | translate"
[showMenuButton]="true"
[menuButtonItems]="menuButtonItems"
[menuButtonItems]="menuButtonItems$ | async"
[isSectionCardExpanded]="isSectionCardExpanded"
(slideToggleChange)="onSlideToggleChange($event, flag)"
(menuButtonItemClick)="onMenuButtonItemClick($event, flag)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
FEATURE_FLAG_DETAILS_PAGE_ACTIONS,
FeatureFlag,
} from '../../../../../../../core/feature-flags/store/feature-flags.model';
import { Observable, Subscription } from 'rxjs';
import { combineLatest, map, Observable, Subscription } from 'rxjs';
import { MatDialogRef } from '@angular/material/dialog';
import { CommonSimpleConfirmationModalComponent } from '../../../../../../../shared-standalone-component-lib/components/common-simple-confirmation-modal/common-simple-confirmation-modal.component';
import { Router } from '@angular/router';
Expand All @@ -39,16 +39,21 @@ import { AuthService } from '../../../../../../../core/auth/auth.service';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FeatureFlagOverviewDetailsSectionCardComponent implements OnInit, OnDestroy {
permissions$: Observable<UserPermission>;
isSectionCardExpanded = true;
@Output() sectionCardExpandChange = new EventEmitter<boolean>();
emailId = '';
permissions$: Observable<UserPermission> = this.authService.userPermissions$;
featureFlag$ = this.featureFlagService.selectedFeatureFlag$;
flagAndPermissions$: Observable<{ flag: FeatureFlag; permissions: UserPermission }> = combineLatest([
this.featureFlag$,
this.permissions$,
]).pipe(map(([flag, permissions]) => ({ flag, permissions })));

subscriptions = new Subscription();
flagOverviewDetails$ = this.featureFlagService.selectedFlagOverviewDetails;
shouldShowWarning$ = this.featureFlagService.shouldShowWarningForSelectedFlag$;
subscriptions = new Subscription();
confirmStatusChangeDialogRef: MatDialogRef<CommonSimpleConfirmationModalComponent>;
menuButtonItems: IMenuButtonItem[];
menuButtonItems$: Observable<IMenuButtonItem[]>;
isSectionCardExpanded = true;
emailId = '';

constructor(
private dialogService: DialogService,
Expand All @@ -58,13 +63,20 @@ export class FeatureFlagOverviewDetailsSectionCardComponent implements OnInit, O
) {}

ngOnInit(): void {
this.permissions$ = this.authService.userPermissions$;
this.subscriptions.add(this.featureFlagService.currentUserEmailAddress$.subscribe((id) => (this.emailId = id)));

this.subscriptions.add(
this.permissions$.subscribe((permissions) => {
this.updateMenuItems(permissions);
})
this.menuButtonItems$ = this.flagAndPermissions$.pipe(
map(({ flag, permissions }) => [
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.EDIT, disabled: !permissions.featureFlags.update },
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.DUPLICATE, disabled: !permissions.featureFlags.create },
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.EXPORT_DESIGN, disabled: false },
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.EMAIL_DATA, disabled: true },
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.ARCHIVE, disabled: true },
{
name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.DELETE,
disabled: !permissions?.featureFlags.delete || flag?.status === 'enabled',
},
])
);
}

Expand All @@ -76,17 +88,6 @@ export class FeatureFlagOverviewDetailsSectionCardComponent implements OnInit, O
return FILTER_MODE;
}

private updateMenuItems(permissions: UserPermission): void {
this.menuButtonItems = [
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.EDIT, disabled: !permissions?.featureFlags.update },
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.DUPLICATE, disabled: !permissions?.featureFlags.create },
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.EXPORT_DESIGN, disabled: false },
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.EMAIL_DATA, disabled: true },
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.ARCHIVE, disabled: true },
{ name: FEATURE_FLAG_DETAILS_PAGE_ACTIONS.DELETE, disabled: !permissions?.featureFlags.delete },
];
}

onSlideToggleChange(event: MatSlideToggleChange, flag: FeatureFlag) {
const slideToggleEvent = event.source;
const newStatus = slideToggleEvent.checked ? FEATURE_FLAG_STATUS.ENABLED : FEATURE_FLAG_STATUS.DISABLED;
Expand Down

0 comments on commit e276cff

Please sign in to comment.