Skip to content

Commit

Permalink
feat(admin-ui): Implement filter preset renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Aug 28, 2023
1 parent 0c5ce7d commit 8b52e6f
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 34 deletions.
66 changes: 33 additions & 33 deletions packages/admin-ui/i18n-coverage.json
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
{
"generatedOn": "2023-08-25T13:17:19.387Z",
"lastCommit": "8deb17927b4fc69c2602c82ed722a0980026e698",
"generatedOn": "2023-08-28T07:56:15.924Z",
"lastCommit": "0c5ce7d43ecbaf67da4254c25fe3562626072844",
"translationStatus": {
"ar": {
"tokenCount": 745,
"translatedCount": 743,
"tokenCount": 746,
"translatedCount": 745,
"percentage": 100
},
"cs": {
"tokenCount": 745,
"translatedCount": 548,
"tokenCount": 746,
"translatedCount": 550,
"percentage": 74
},
"de": {
"tokenCount": 745,
"translatedCount": 743,
"tokenCount": 746,
"translatedCount": 745,
"percentage": 100
},
"en": {
"tokenCount": 745,
"translatedCount": 743,
"tokenCount": 746,
"translatedCount": 745,
"percentage": 100
},
"es": {
"tokenCount": 745,
"translatedCount": 743,
"tokenCount": 746,
"translatedCount": 745,
"percentage": 100
},
"fr": {
"tokenCount": 745,
"translatedCount": 739,
"tokenCount": 746,
"translatedCount": 741,
"percentage": 99
},
"he": {
"tokenCount": 745,
"translatedCount": 743,
"tokenCount": 746,
"translatedCount": 745,
"percentage": 100
},
"it": {
"tokenCount": 745,
"translatedCount": 573,
"tokenCount": 746,
"translatedCount": 575,
"percentage": 77
},
"pl": {
"tokenCount": 745,
"translatedCount": 383,
"percentage": 51
"tokenCount": 746,
"translatedCount": 385,
"percentage": 52
},
"pt_BR": {
"tokenCount": 745,
"translatedCount": 742,
"tokenCount": 746,
"translatedCount": 744,
"percentage": 100
},
"pt_PT": {
"tokenCount": 745,
"translatedCount": 582,
"tokenCount": 746,
"translatedCount": 584,
"percentage": 78
},
"ru": {
"tokenCount": 745,
"translatedCount": 743,
"tokenCount": 746,
"translatedCount": 745,
"percentage": 100
},
"uk": {
"tokenCount": 745,
"translatedCount": 572,
"tokenCount": 746,
"translatedCount": 574,
"percentage": 77
},
"zh_Hans": {
"tokenCount": 745,
"translatedCount": 518,
"tokenCount": 746,
"translatedCount": 520,
"percentage": 70
},
"zh_Hant": {
"tokenCount": 745,
"translatedCount": 363,
"tokenCount": 746,
"translatedCount": 365,
"percentage": 49
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<clr-icon shape="ellipsis-vertical" size="12"/>
</button>
<vdr-dropdown-menu vdrPosition="bottom-left">
<button vdrDropdownItem (click)="renameFilterPreset(preset.name)">
<clr-icon shape="edit"></clr-icon>
{{ 'common.rename-filter-preset' | translate }}
</button>
<button vdrDropdownItem (click)="deleteFilterPreset(preset.name)">
<clr-icon shape="trash" class="is-danger"></clr-icon>
{{ 'common.delete' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { ActivatedRoute } from '@angular/router';
import { Observable, Subject } from 'rxjs';
import { distinctUntilChanged, map, startWith, takeUntil } from 'rxjs/operators';
import { DataTableFilterCollection } from '../../../providers/data-table/data-table-filter-collection';
import { ModalService } from '../../../providers/modal/modal.service';
import { FilterPresetService } from './filter-preset.service';
import { RenameFilterPresetDialogComponent } from './rename-filter-preset-dialog.component';

@Component({
selector: 'vdr-data-table-filter-presets',
Expand All @@ -20,7 +22,11 @@ export class DataTableFilterPresetsComponent implements OnInit, OnDestroy {

private destroy$ = new Subject<void>();

constructor(private route: ActivatedRoute, private filterPresetService: FilterPresetService) {}
constructor(
private route: ActivatedRoute,
private filterPresetService: FilterPresetService,
private modalService: ModalService,
) {}
ngOnInit() {
this.route.queryParamMap
.pipe(
Expand Down Expand Up @@ -51,6 +57,25 @@ export class DataTableFilterPresetsComponent implements OnInit, OnDestroy {
this.serializedActiveFilters = this.filters.serialize();
}

renameFilterPreset(name: string) {
this.modalService
.fromComponent(RenameFilterPresetDialogComponent, {
closable: true,
locals: {
name,
},
})
.subscribe(result => {
if (result) {
this.filterPresetService.renameFilterPreset({
dataTableId: this.dataTableId,
oldName: name,
newName: result,
});
}
});
}

drop(event: CdkDragDrop<any>) {
this.filterPresetService.reorderPresets(this.dataTableId, event.previousIndex, event.currentIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ export class FilterPresetService {
this.localStorageService.set('dataTableConfig', dataTableConfig);
this._presetChanges.next(presets);
}

renameFilterPreset(config: { dataTableId: string; oldName: string; newName: string }) {
const dataTableConfig = this.getDataTableConfig(config.dataTableId);
const filterPresets = dataTableConfig[config.dataTableId].filterPresets ?? [];
const existingName = filterPresets.find(p => p.name === config.oldName);
if (existingName) {
existingName.name = config.newName;
dataTableConfig[config.dataTableId].filterPresets = filterPresets;
this.localStorageService.set('dataTableConfig', dataTableConfig);
this._presetChanges.next(filterPresets);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<ng-template vdrDialogTitle>
{{ 'common.rename-filter-preset' | translate }}
</ng-template>
<vdr-form-field>
<input type="text" [(ngModel)]="name">
</vdr-form-field>
<ng-template vdrDialogButtons>
<button type="submit" (click)="rename()" [disabled]="!name" class="button primary">
{{ 'common.update' | translate }}
</button>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { FilterPresetService } from '@vendure/admin-ui/core';
import { Dialog } from '../../../providers/modal/modal.types';

@Component({
selector: 'vdr-rename-filter-preset-dialog',
templateUrl: './rename-filter-preset-dialog.component.html',
styleUrls: ['./rename-filter-preset-dialog.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RenameFilterPresetDialogComponent implements Dialog<string> {
name: string;
resolveWith: (result?: string) => void;

rename() {
this.resolveWith(this.name);
}
}
2 changes: 2 additions & 0 deletions packages/admin-ui/src/lib/core/src/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ import { CurrencyCodeSelectorComponent } from './components/currency-code-select
import { LanguageCodeSelectorComponent } from './components/language-code-selector/language-code-selector.component';
import { DataTableFilterPresetsComponent } from './components/data-table-filter-presets/data-table-filter-presets.component';
import { AddFilterPresetButtonComponent } from './components/data-table-filter-presets/add-filter-preset-button.component';
import { RenameFilterPresetDialogComponent } from './components/data-table-filter-presets/rename-filter-preset-dialog.component';

const IMPORTS = [
ClarityModule,
Expand Down Expand Up @@ -353,6 +354,7 @@ const DYNAMIC_FORM_INPUTS = [
...DYNAMIC_FORM_INPUTS,
DataTableFilterPresetsComponent,
AddFilterPresetButtonComponent,
RenameFilterPresetDialogComponent,
],
providers: [
// This needs to be shared, since lazy-loaded
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "إزالة",
"remove-from-channel": "إزالة من القناة الحالية",
"remove-item-from-list": "إزالة العنصر من القائمة",
"rename-filter-preset": "إعادة تسمية الضبط",
"reset-columns": "إعادة تعيين الأعمدة",
"results-count": "{ count } {count, plural, one {نتيجة واحدة} other {من النتائج}}",
"sample-formatting": "تنسيق العينة",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Smazat",
"remove-from-channel": "",
"remove-item-from-list": "Odebrat položku ze seznamu",
"rename-filter-preset": "Přejmenovat předvolbu",
"reset-columns": "",
"results-count": "{ count } {count, plural, one {výsledek} other {výsledků/y}}",
"sample-formatting": "",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Entfernen",
"remove-from-channel": "Aus dem Kanal entfernen",
"remove-item-from-list": "Artikel von Liste entfernen",
"rename-filter-preset": "Voreinstellung umbenennen",
"reset-columns": "Spalten zurücksetzen",
"results-count": "{ count } {count, plural, one {Ergebnis} other {Ergebnisse}}",
"sample-formatting": "Beispiel Formatierung",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Remove",
"remove-from-channel": "Remove from current channel",
"remove-item-from-list": "Remove item from list",
"rename-filter-preset": "Rename preset",
"reset-columns": "Reset columns",
"results-count": "{ count } {count, plural, one {result} other {results}}",
"sample-formatting": "Sample formatting",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Borrar",
"remove-from-channel": "Borrar del canal",
"remove-item-from-list": "Eliminar elemento de la lista",
"rename-filter-preset": "Renombrar preestablecido",
"reset-columns": "Reajustar las columnas al estado inicial",
"results-count": "{ count } {count, plural, one {resultado} other {resultados}}",
"sample-formatting": "Formato de ejemplo",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Retirer",
"remove-from-channel": "Retirer du canal",
"remove-item-from-list": "Retirer l'article de la liste",
"rename-filter-preset": "Renommer le préréglage",
"reset-columns": "RAZ colonnes",
"results-count": "{ count } {count, plural, one {result} other {results}}",
"sample-formatting": "Exemple de mise en forme",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "הסר",
"remove-from-channel": "הסר מהערוץ הנוכחי",
"remove-item-from-list": "הסר פריט מהרשימה",
"rename-filter-preset": "שינוי שם להגדרה",
"reset-columns": "אפס עמודות",
"results-count": "{ count } {count, plural, one {תוצאה} other {תוצאות}}",
"sample-formatting": "פורמט דוגמא",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Rimuovi",
"remove-from-channel": "",
"remove-item-from-list": "Rimuovi elemento dalla lista",
"rename-filter-preset": "Rinomina preimpostazione",
"reset-columns": "",
"results-count": "{ count } {count, plural, one {risultato} other {risultati}}",
"sample-formatting": "",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Usuń",
"remove-from-channel": "",
"remove-item-from-list": "",
"rename-filter-preset": "Zmień nazwę preselekcji",
"reset-columns": "",
"results-count": "{ count } {count, plural, one {wynik} other {wyników}}",
"sample-formatting": "",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Exclui",
"remove-from-channel": "Remover do canal atual",
"remove-item-from-list": "Remover item da lista",
"rename-filter-preset": "Renomear predefinição",
"reset-columns": "Redefinir colunas",
"results-count": "{ count } {count, plural, one {resultado} other {resultados}}",
"sample-formatting": "Formataçāo simples",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/pt_PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Eliminar",
"remove-from-channel": "",
"remove-item-from-list": "Remover item da lista",
"rename-filter-preset": "Renomear predefinição",
"reset-columns": "",
"results-count": "{ count } {count, plural, one {resultado} other {resultados}}",
"sample-formatting": "Formatação de amostra",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Удалить",
"remove-from-channel": "Удалить из канала",
"remove-item-from-list": "Удалить позицию из списка",
"rename-filter-preset": "Переименовать пресет",
"reset-columns": "Сброс колонок",
"results-count": "{ count } {count, plural, one {результат} other {результатов}}",
"sample-formatting": "Пример форматирования",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "Видалити",
"remove-from-channel": "",
"remove-item-from-list": "Видалити позицію зі списку",
"rename-filter-preset": "Перейменувати пресет",
"reset-columns": "",
"results-count": "{ count } {count, plural, one {результат} other {результатів}}",
"sample-formatting": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "删除",
"remove-from-channel": "",
"remove-item-from-list": "从列表中移除",
"rename-filter-preset": "重命名预设",
"reset-columns": "",
"results-count": "{count, plural, =0{无} other {{count}个过滤结果}}",
"sample-formatting": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"remove": "移除",
"remove-from-channel": "",
"remove-item-from-list": "",
"rename-filter-preset": "重新命名預設",
"reset-columns": "",
"results-count": "{count, plural, =0{無} other {{count}個篩選結果}}",
"sample-formatting": "",
Expand Down

0 comments on commit 8b52e6f

Please sign in to comment.