Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort functionality for feature flag root table #1711

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
selectFeatureFlagInclusions,
selectFeatureFlagExclusions,
selectIsLoadingSelectedFeatureFlag,
selectSortKey,
selectSortAs,
} from './store/feature-flags.selectors';
import * as FeatureFlagsActions from './store/feature-flags.actions';
import { actionFetchContextMetaData } from '../experiments/store/experiments.actions';
Expand All @@ -39,6 +41,8 @@ export class FeatureFlagsService {
isAllFlagsFetched$ = this.store$.pipe(select(selectIsAllFlagsFetched));
searchString$ = this.store$.pipe(select(selectSearchString));
searchKey$ = this.store$.pipe(select(selectSearchKey));
sortKey$ = this.store$.pipe(select(selectSortKey));
sortAs$ = this.store$.pipe(select(selectSortAs));
isLoadingUpsertFeatureFlag$ = this.store$.pipe(select(selectIsLoadingUpsertFeatureFlag));
IsLoadingFeatureFlagDelete$ = this.store$.pipe(select(selectIsLoadingFeatureFlagDelete));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ export enum FLAG_SEARCH_KEY {
}

export const FLAG_ROOT_COLUMN_NAMES = {
NAME: 'Name',
STATUS: 'Status',
UPDATED_AT: 'Updated at',
APP_CONTEXT: 'App Context',
TAGS: 'Tags',
EXPOSURES: 'Exposures',
NAME: 'name',
STATUS: 'status',
UPDATED_AT: 'updatedAt',
APP_CONTEXT: 'appContext',
TAGS: 'tags',
EXPOSURES: 'exposures',
};

export const FLAG_TRANSLATION_KEYS = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<div class="flags-list-container">
<div scroll (scrolled)="fetchFlagsOnScroll()" class="flags-list-table-container" #tableContainer>
<mat-progress-bar class="spinner" mode="indeterminate" *ngIf="isLoading$ | async"></mat-progress-bar>
<table class="flags-list" mat-table [dataSource]="dataSource$" matSort (matSortChange)="changeSorting($event)">
<table
class="flags-list"
mat-table
[dataSource]="dataSource$"
matSort
(matSortChange)="changeSorting($event)"
[matSortActive]="flagSortKey$ | async"
[matSortDirection]="flagSortAs$ | async | lowercase"
>
<ng-container [matColumnDef]="FLAG_ROOT_COLUMN_NAMES.NAME">
<th class="ft-12-700" mat-header-cell *matHeaderCellDef mat-sort-header>
<span [matTooltip]="FLAG_TRANSLATION_KEYS.NAME | translate" matTooltipPosition="above">
Expand All @@ -19,7 +27,7 @@
<ng-template #flagNameEllipsis>
<span
[matTooltip]="flag.name"
class="flag-name",
class="flag-name"
matTooltipPosition="above"
>
{{ flag.name | truncate: 30 }}
Expand All @@ -39,7 +47,9 @@

<ng-container [matColumnDef]="FLAG_ROOT_COLUMN_NAMES.STATUS">
<th class="ft-12-700" mat-header-cell *matHeaderCellDef mat-sort-header>
<span [matTooltip]="FLAG_TRANSLATION_KEYS.STATUS | translate" matTooltipPosition="above">{{ FLAG_TRANSLATION_KEYS.STATUS | translate | uppercase }}</span>
<span [matTooltip]="FLAG_TRANSLATION_KEYS.STATUS | translate" matTooltipPosition="above">
{{ FLAG_TRANSLATION_KEYS.STATUS | translate | uppercase }}
</span>
</th>
<td class="ft-12-600" mat-cell *matCellDef="let flag">
<app-common-status-indicator-chip [chipClass]="flag.status"></app-common-status-indicator-chip>
Expand All @@ -58,7 +68,7 @@
</ng-container>

<ng-container [matColumnDef]="FLAG_ROOT_COLUMN_NAMES.APP_CONTEXT">
<th class="ft-12-700" mat-header-cell *matHeaderCellDef mat-sort-header>
<th class="ft-12-700" mat-header-cell *matHeaderCellDef>
<span [matTooltip]="FLAG_TRANSLATION_KEYS.APP_CONTEXT | translate" matTooltipPosition="above">
{{ FLAG_TRANSLATION_KEYS.APP_CONTEXT | translate | uppercase }}
</span>
Expand All @@ -69,16 +79,18 @@
</ng-container>

<ng-container [matColumnDef]="FLAG_ROOT_COLUMN_NAMES.TAGS">
<th class="ft-12-700" mat-header-cell *matHeaderCellDef mat-sort-header>
<span [matTooltip]="FLAG_TRANSLATION_KEYS.TAGS | translate" matTooltipPosition="above">{{ FLAG_TRANSLATION_KEYS.TAGS | translate | uppercase }}</span>
<th class="ft-12-700" mat-header-cell *matHeaderCellDef>
<span [matTooltip]="FLAG_TRANSLATION_KEYS.TAGS | translate" matTooltipPosition="above">
{{ FLAG_TRANSLATION_KEYS.TAGS | translate | uppercase }}
</span>
</th>
<td class="ft-12-600" mat-cell *matCellDef="let flag">
<mat-chip *ngFor="let tag of flag.tags" class="tag">{{ tag }}</mat-chip>
</td>
</ng-container>

<ng-container [matColumnDef]="FLAG_ROOT_COLUMN_NAMES.EXPOSURES">
<th class="ft-12-700" mat-header-cell *matHeaderCellDef mat-sort-header>
<th class="ft-12-700" mat-header-cell *matHeaderCellDef>
<span [matTooltip]="FLAG_TRANSLATION_KEYS.EXPOSURES | translate" matTooltipPosition="above">
{{ FLAG_TRANSLATION_KEYS.EXPOSURES | translate | uppercase }}
</span>
Expand All @@ -97,4 +109,4 @@
</tr>
</table>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnInit, ViewChild } from '@angular/core';
import { Observable } from 'rxjs';
import {
FLAG_ROOT_COLUMN_NAMES,
Expand All @@ -7,12 +7,14 @@ import {
FeatureFlag,
} from '../../../../../../../../core/feature-flags/store/feature-flags.model';
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
import { AsyncPipe, NgIf, NgFor, UpperCasePipe, DatePipe } from '@angular/common';
import { AsyncPipe, NgIf, NgFor, UpperCasePipe, DatePipe, CommonModule } from '@angular/common';
import { MatTooltipModule } from '@angular/material/tooltip';
import { TranslateModule } from '@ngx-translate/core';
import { MatChipsModule } from '@angular/material/chips';
import { RouterModule } from '@angular/router';
import { MatSort, MatSortModule } from '@angular/material/sort';
import { CommonStatusIndicatorChipComponent } from '../../../../../../../../shared-standalone-component-lib/components';
import { FeatureFlagsService } from '../../../../../../../../core/feature-flags/feature-flags.service';

@Component({
selector: 'app-feature-flag-root-section-card-table',
Expand All @@ -22,7 +24,9 @@ import { CommonStatusIndicatorChipComponent } from '../../../../../../../../shar
AsyncPipe,
NgIf,
NgFor,
MatSortModule,
MatTooltipModule,
CommonModule,
TranslateModule,
UpperCasePipe,
MatChipsModule,
Expand All @@ -34,9 +38,21 @@ import { CommonStatusIndicatorChipComponent } from '../../../../../../../../shar
styleUrl: './feature-flag-root-section-card-table.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FeatureFlagRootSectionCardTableComponent {
@Input() dataSource$: MatTableDataSource<FeatureFlag[]>;
export class FeatureFlagRootSectionCardTableComponent implements OnInit {
@Input() dataSource$: MatTableDataSource<FeatureFlag>;
@Input() isLoading$: Observable<boolean>;
flagSortKey$ = this.featureFlagsService.sortKey$;
flagSortAs$ = this.featureFlagsService.sortAs$;

@ViewChild(MatSort, { static: true }) sort: MatSort;

constructor(private featureFlagsService: FeatureFlagsService) {}

ngOnInit() {
if (this.dataSource$?.data) {
this.dataSource$.sort = this.sort;
}
}

get displayedColumns(): string[] {
return FLAG_ROOT_DISPLAYED_COLUMNS;
Expand All @@ -54,7 +70,8 @@ export class FeatureFlagRootSectionCardTableComponent {
console.log('fetchFlagsOnScroll');
}

changeSorting($event) {
console.log('onSearch:', $event);
changeSorting(event) {
this.featureFlagsService.setSortingType(event.direction ? event.direction.toUpperCase() : null);
this.featureFlagsService.setSortKey(event.direction ? event.active : null);
}
}
1 change: 0 additions & 1 deletion types/src/Experiment/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export enum METRIC_SEARCH_KEY {

export enum FLAG_SORT_KEY {
NAME = 'name',
KEY = 'key',
STATUS = 'status',
UPDATED_AT = 'updatedAt',
}
Expand Down
Loading