Skip to content

Commit b2831c7

Browse files
jcabannesZorin95670
authored andcommitted
feat(catalog-ui): override favorite from smart-filter
Related to #197
1 parent d7631c0 commit b2831c7

5 files changed

Lines changed: 100 additions & 11 deletions

File tree

apps/catalog-ui/docs/i18n.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ The `FormDialog` component uses the following keys for internationalization:
379379
| `[INSTANCE_ID].seeButton` | Label for the “see details” action button | Table row action | - |
380380
| `[INSTANCE_ID].ButtonsCard` | Base translation scope for the actions card (e.g. create button label) | Page actions section | - |
381381
| `[INSTANCE_ID].GenericEntityTable` | Base translation scope for the GenericEntityTable | Page table section | - |
382-
| `[INSTANCE_ID].ConfirmationDialog` | Base translation scope for the ConfirmationDialog | Page dialog section | - |
382+
| `[INSTANCE_ID].ConfirmationDialog` | Base translation scope for the delete-favorite ConfirmationDialog | Page dialog section | - |
383+
| `[INSTANCE_ID].FormDialog` | Base translation scope for the override-favorite FormDialog | Page dialog section | - |
383384
| `[INSTANCE_ID].LinidSmartFilter` | Base translation scope for the LinidSmartFilter | Page search section | - |
384385
| `[INSTANCE_ID].[FIELD_LABEL]` | Label displayed for a table column header | Table column header | - |
385386

@@ -410,6 +411,20 @@ The `FormDialog` component uses the following keys for internationalization:
410411
"confirmLoading": "Saving..."
411412
}
412413
},
414+
"FormDialog": {
415+
"overrideTitle": "Override a favorite?",
416+
"overrideContent": "Select the favorite to replace with the current filters.",
417+
"ButtonsCard": {
418+
"cancel": "Cancel",
419+
"confirm": "Override",
420+
"confirmLoading": "Overriding..."
421+
},
422+
"fields": {
423+
"favorite": {
424+
"label": "Favorite"
425+
}
426+
}
427+
},
413428
"LinidSmartFilter": {
414429
//(...) see next section
415430
}
@@ -778,6 +793,20 @@ export default {
778793
confirmLoading: 'Saving...',
779794
},
780795
},
796+
FormDialog: {
797+
overrideTitle: 'Override a favorite?',
798+
overrideContent: 'Select the favorite to replace with the current filters.',
799+
ButtonsCard: {
800+
cancel: 'Cancel',
801+
confirm: 'Override',
802+
confirmLoading: 'Overriding...',
803+
},
804+
fields: {
805+
favorite: {
806+
label: 'Favorite',
807+
},
808+
},
809+
},
781810
LinidSmartFilter: {
782811
label: 'Search',
783812
hint: 'Enter your search criteria',

apps/catalog-ui/docs/pages/GenericTablePage.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ Each active filter is serialized to a query param using `filter.toString()`, key
193193
- `seeButton`
194194
- `error`
195195
- `ButtonsCard.create`
196+
- `ConfirmationDialog.title` — title of the delete-favorite confirmation dialog
197+
- `ConfirmationDialog.content` — body of the delete-favorite confirmation dialog (`{label}` placeholder available)
198+
- `FormDialog.overrideTitle` — title of the override-favorite form dialog
199+
- `FormDialog.overrideContent` — body of the override-favorite form dialog
196200

197201
---
198202

apps/catalog-ui/src/federation/module-page-lifecycle.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class ModulePage extends BasicRemoteModule<ModulePageOptions> {
8787
plugin: 'catalogUI/ConfirmationDialog',
8888
});
8989

90+
linidZoneStore.registerOnce('base-layout.dialogComponent', {
91+
plugin: 'catalogUI/FormDialog',
92+
});
93+
9094
return { success: true };
9195
}
9296
}

apps/catalog-ui/src/pages/GenericTablePage.vue

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
@update:filters="onFiltersChange"
8080
@apply:favorite="onFavoriteApply"
8181
@delete:favorite="openDeleteFavoriteDialog"
82+
@override:favorite="openOverrideFavoriteDialog"
8283
/>
8384

8485
<GenericEntityTable
@@ -123,34 +124,34 @@
123124
</template>
124125

125126
<script setup lang="ts">
126-
import { useRoute, useRouter } from 'vue-router';
127-
import { computed, onMounted, ref } from 'vue';
128127
import type {
129128
LinidFilter,
129+
LinidFilterSetUserPreference,
130130
LinidQBtnProps,
131131
QTableRequestEvent,
132-
QueryFilter,
133132
QuasarPagination,
134-
LinidFilterSetUserPreference,
133+
QueryFilter,
135134
} from '@linagora/linid-im-front-corelib';
136135
import {
137136
getEntities,
138137
getModuleHostConfiguration,
139-
LinidZoneRenderer,
140138
LinidFilterSet,
139+
LinidZoneRenderer,
140+
uiEventSubject,
141141
useLinidFilterUrl,
142+
useLinidUserPreference,
142143
useNotify,
143144
usePagination,
144145
useScopedI18n,
145146
useUiDesign,
146-
useLinidUserPreference,
147-
uiEventSubject,
148147
} from '@linagora/linid-im-front-corelib';
149-
import type { ModuleGenericTablePageOptions } from '../types/ModuleGenericTablePageOptions';
150148
import type { QTableColumn } from 'quasar';
149+
import { computed, onMounted, ref } from 'vue';
150+
import { useRoute, useRouter } from 'vue-router';
151151
import ButtonsCard from '../components/card/ButtonsCard.vue';
152-
import GenericEntityTable from '../components/table/GenericEntityTable.vue';
153152
import LinidSmartFilter from '../components/smart-filter/LinidSmartFilter.vue';
153+
import GenericEntityTable from '../components/table/GenericEntityTable.vue';
154+
import type { ModuleGenericTablePageOptions } from '../types/ModuleGenericTablePageOptions';
154155
155156
const router = useRouter();
156157
const route = useRoute();
@@ -165,7 +166,8 @@ const options = computed(
165166
);
166167
167168
const { t, te } = useScopedI18n(i18nScope.value);
168-
const { userPreferenceStore, deleteUserPreference } = useLinidUserPreference();
169+
const { userPreferenceStore, deleteUserPreference, saveUserPreference } =
170+
useLinidUserPreference();
169171
const items = ref<Record<string, unknown>[]>([]);
170172
const isLoading = ref<boolean>(false);
171173
const { Notify } = useNotify();
@@ -297,6 +299,51 @@ function openDeleteFavoriteDialog(favorite: LinidFilterSet): void {
297299
});
298300
}
299301
302+
/**
303+
* Opens a confirmation dialog to override an existing favorite filter set with the current filters.
304+
*/
305+
function openOverrideFavoriteDialog(): void {
306+
uiEventSubject.next({
307+
key: 'form',
308+
data: {
309+
type: 'open',
310+
title: t('FormDialog.overrideTitle'),
311+
content: t('FormDialog.overrideContent'),
312+
uiNamespace: uiNamespace.value,
313+
i18nScope: `${i18nScope.value}.FormDialog`,
314+
formFields: [
315+
{
316+
name: 'favorite',
317+
type: 'String',
318+
input: 'List',
319+
required: true,
320+
inputSettings: {
321+
values: favorites.value.map((f) => ({
322+
label: f.label,
323+
value: f,
324+
})),
325+
optionLabel: 'label',
326+
},
327+
},
328+
],
329+
// eslint-disable-next-line jsdoc/require-jsdoc
330+
onSubmit: (formData: { favorite: LinidFilterSet }) =>
331+
saveUserPreference(
332+
`${favoritesBaseConfigurationKey.value}${formData.favorite.id}`,
333+
JSON.stringify({
334+
id: formData.favorite.id,
335+
label: formData.favorite.label,
336+
value: new LinidFilterSet(
337+
formData.favorite.id,
338+
formData.favorite.label,
339+
filters.value
340+
).toString(),
341+
})
342+
),
343+
},
344+
});
345+
}
346+
300347
/**
301348
* Parses a serialized favorite filter set from a JSON string and validates its structure.
302349
*

apps/catalog-ui/src/types/field.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ export interface FieldListValue {
210210
* Settings for fields that allow selection from a predefined list of values.
211211
*/
212212
export interface FieldListSettings extends FieldSettings {
213+
/**
214+
* Optional key used to display a label for the field in the UI.
215+
* If omitted, the field's `value` property will be used as the label.
216+
*/
217+
optionLabel?: string;
213218
/**
214219
* List of possible values for the field.
215220
* Use `string[]` for a flat list with no filtering.

0 commit comments

Comments
 (0)