Skip to content

Commit b640cf1

Browse files
committed
add composable reactivity + refacto all dashboards lists
1 parent fb53e71 commit b640cf1

File tree

20 files changed

+367
-787
lines changed

20 files changed

+367
-787
lines changed

dev/storybook/src/stories/core/explorers/BaseFoldersExplorer.stories.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

dev/storybook/src/stories/core/lists/baseLists/BaseDashboardsList.stories.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import type { Meta, StoryObj } from '@storybook/vue3';
22

3+
import { addComponentEmits, addSubcomponentsArgTypes } from '@/utils/properties';
4+
35
import FSBaseDashboardsList from "@dative-gpi/foundation-core-components/components/lists/dashboards/FSBaseDashboardsList.vue";
6+
import FSBaseDashboardsExplorer from "@dative-gpi/foundation-core-components/components/explorers/FSBaseDashboardsExplorer.vue";
47
import FSDataTable from '@dative-gpi/foundation-core-components/components/lists/FSDataTable.vue';
8+
import FSDataTableUI from '@dative-gpi/foundation-shared-components/components/lists/FSDataTableUI.vue';
59

610
const meta: Meta<typeof FSBaseDashboardsList> = {
711
title: 'Foundation/Core/Lists/Base Lists/BaseDashboardsList',
812
component: FSBaseDashboardsList,
9-
subcomponents: { FSDataTable },
1013
tags: ['autodocs'],
1114
argTypes: {
15+
...addSubcomponentsArgTypes([FSBaseDashboardsExplorer, FSDataTable, FSDataTableUI], FSBaseDashboardsList),
16+
...addComponentEmits(FSBaseDashboardsList),
17+
tableCode: {
18+
control: "select",
19+
options: ["dashboardsExplorer1"],
20+
}
1221
},
1322
};
1423

@@ -24,12 +33,12 @@ export const Default: Story = {
2433
template: `
2534
<FSBaseDashboardsList
2635
v-model:modelValue="args.modelValue"
27-
v-mode:type="args.type"
2836
v-bind="args"
2937
/>
3038
`,
3139
}),
3240
args: {
33-
tableCode: 'dashboards1'
41+
modelValue: [],
42+
tableCode: 'dashboardsExplorer1'
3443
},
3544
};

dev/storybook/src/stories/core/lists/tileLists/TileDashboardsList.stories.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,5 @@ export const Default: Story = {
3333
}),
3434
args: {
3535
modelValue: [],
36-
dashboardOrganisationFilters: {},
37-
dashboardOrganisationTypeFilters: {},
38-
dashboardShallowFilters: {},
3936
}
4037
};

src/core/foundation-core-components/components/entities/FSEntityField.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { defineComponent, ref, type PropType, computed } from "vue";
4141
4242
import { EntityType } from "@dative-gpi/foundation-shared-domain/enums";
4343
44-
import type { DashboardOrganisationFilters, DashboardOrganisationTypeFilters, DashboardShallowFilters, DeviceOrganisationFilters, FolderFilters, GroupFilters, GroupingFilters, LocationFilters, ModelFilters, SubgroupingFilters, UserOrganisationFilters } from "@dative-gpi/foundation-core-domain/models";
44+
import type { DashboardExplorerElementFilters, DeviceOrganisationFilters, FolderFilters, GroupFilters, GroupingFilters, LocationFilters, ModelFilters, SubgroupingFilters, UserOrganisationFilters } from "@dative-gpi/foundation-core-domain/models";
4545
4646
import FSEntityFieldUI from "@dative-gpi/foundation-shared-components/components/fields/FSEntityFieldUI.vue";
4747
@@ -138,10 +138,8 @@ export default defineComponent({
138138
} satisfies DeviceOrganisationFilters;
139139
case EntityType.Dashboard:
140140
return {
141-
dashboardOrganisationsIds: props.modelValue,
142-
dashboardOrganisationTypesIds: props.modelValue,
143-
dashboardShallowsIds: props.modelValue
144-
} satisfies DashboardOrganisationFilters & DashboardOrganisationTypeFilters & DashboardShallowFilters;
141+
dashboardExplorerElementsIds: props.modelValue,
142+
} satisfies DashboardExplorerElementFilters;
145143
case EntityType.Group:
146144
return {
147145
groupsIds: props.modelValue

src/core/foundation-core-components/components/entities/FSSelectEntitiesList.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
import { defineComponent, type PropType, computed } from "vue";
6666
6767
import { EntityType } from "@dative-gpi/foundation-shared-domain/enums";
68-
import type { DashboardOrganisationFilters, DashboardOrganisationTypeFilters, DashboardShallowFilters, DeviceOrganisationFilters, FolderFilters, GroupFilters, GroupingFilters, LocationFilters, ModelFilters, SubgroupingFilters, UserOrganisationFilters } from "@dative-gpi/foundation-core-domain/models";
68+
import type { DashboardExplorerElementFilters, DeviceOrganisationFilters, FolderFilters, GroupFilters, GroupingFilters, LocationFilters, ModelFilters, SubgroupingFilters, UserOrganisationFilters } from "@dative-gpi/foundation-core-domain/models";
6969
7070
import { TABLES as T } from "../../utils";
7171
@@ -124,10 +124,8 @@ export default defineComponent({
124124
} satisfies DeviceOrganisationFilters;
125125
case EntityType.Dashboard:
126126
return {
127-
dashboardOrganisationsIds: props.modelValue,
128-
dashboardOrganisationTypesIds: props.modelValue,
129-
dashboardShallowsIds: props.modelValue
130-
} satisfies DashboardOrganisationFilters & DashboardOrganisationTypeFilters & DashboardShallowFilters;
127+
dashboardExplorerElementsIds: props.modelValue,
128+
} satisfies DashboardExplorerElementFilters;
131129
case EntityType.Group:
132130
return {
133131
groupsIds: props.modelValue
@@ -191,9 +189,7 @@ export default defineComponent({
191189
};
192190
case EntityType.Dashboard:
193191
return {
194-
dashboardShallowsFilters: props.filters,
195-
dashboardOrganisationsFilters: props.filters,
196-
dashboardOrganisationTypeFetchFilter: props.filters,
192+
dashboardExplorerElementsFilters: props.filters,
197193
...attrs
198194
};
199195
case EntityType.Group:

src/core/foundation-core-components/components/entities/FSSimpleEntitiesList.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ export default defineComponent({
6262
case EntityType.Dashboard:
6363
return {
6464
...attrs,
65-
dashboardOrganisationFilters : props.filters,
66-
dashboardOrganisationTypeFilters : props.filters,
67-
dashboardShallowFilters : props.filters
65+
dashboardExplorerElementsFilters: props.filters
6866
};
6967
case EntityType.Folder:
7068
return {

src/core/foundation-core-components/components/entities/FSTileEntitiesList.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ export default defineComponent({
5555
case EntityType.Dashboard:
5656
return {
5757
...attrs,
58-
dashboardOrganisationFilters : props.filters,
59-
dashboardOrganisationTypeFilters : props.filters,
60-
dashboardShallowFilters : props.filters
58+
dashboardExplorerElementsFilters: props.filters
6159
};
6260
case EntityType.Folder:
6361
return {

src/core/foundation-core-components/components/explorers/FSBaseDashboardsExplorer.vue

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@
6464
{{ item.icon }}
6565
</FSIcon>
6666
</template>
67+
<template
68+
#item.main="{ item }"
69+
>
70+
<FSIcon
71+
v-if="item.id === mainOrganisationDashboardId"
72+
>
73+
mdi-account-group-outline
74+
</FSIcon>
75+
<FSIcon
76+
v-if="item.id === mainUserDashboardId"
77+
>
78+
mdi-home
79+
</FSIcon>
80+
</template>
6781
<template
6882
#item.locked="{ item }"
6983
>
@@ -135,15 +149,16 @@
135149
</template>
136150

137151
<script lang="ts">
138-
import { computed, defineComponent, type PropType, ref, watch } from "vue";
152+
import { computed, defineComponent, onMounted, type PropType, ref, watch } from "vue";
139153
import { type RouteLocation } from "vue-router";
140154
import _ from "lodash";
141155
142156
import { DashboardExplorerElementType } from "@dative-gpi/foundation-shared-domain/enums";
143-
import { useDashboardExplorerElements } from "@dative-gpi/foundation-core-services/composables";
144-
import { type DashboardExplorerElementInfos } from "@dative-gpi/foundation-core-domain/models";
157+
import { useDashboardExplorerElements, useAppOrganisationId, useCurrentUserOrganisation } from "@dative-gpi/foundation-core-services/composables";
158+
import { type DashboardExplorerElementInfos, type DashboardExplorerElementFilters } from "@dative-gpi/foundation-core-domain/models";
145159
import { dashboardExplorerElementTypeLabel } from "@dative-gpi/foundation-core-components/utils";
146160
import { useDebounce } from "@dative-gpi/foundation-shared-components/composables";
161+
import { useOrganisation } from "@dative-gpi/foundation-shared-services/composables";
147162
148163
import FSDashboardOrganisationTypeTileUI from "@dative-gpi/foundation-shared-components/components/tiles/FSDashboardOrganisationTypeTileUI.vue";
149164
import FSDashboardOrganisationTileUI from "@dative-gpi/foundation-shared-components/components/tiles/FSDashboardOrganisationTileUI.vue";
@@ -220,15 +235,26 @@ export default defineComponent({
220235
type: Array as PropType<string[]>,
221236
default: () => [],
222237
required: false
238+
},
239+
dashboardExplorerElementsFilters: {
240+
type: Object as PropType<DashboardExplorerElementFilters>,
241+
required: false,
242+
default: () => ({})
223243
}
224244
},
225245
emits: ["update:modelValue", "update:types"],
226246
setup(props, { emit }) {
227247
const { entities, fetching: fetchingDashboardExplorerElements, getMany: getManyDashboardExplorerElements } = useDashboardExplorerElements();
248+
const { fetch: fetchUserOrganisation, entity: userOrganisation } = useCurrentUserOrganisation();
249+
const { entity: organisation, get: getOrganisation } = useOrganisation();
250+
const { organisationId } = useAppOrganisationId();
228251
const { debounce } = useDebounce();
229252
230253
const search = ref("");
231254
255+
const mainUserDashboardId = computed(() => userOrganisation.value?.mainDashboardId);
256+
const mainOrganisationDashboardId = computed(() => organisation.value?.mainDashboardId);
257+
232258
const dashboardExplorerElements = computed((): DashboardExplorerElementInfos[] => {
233259
return entities.value
234260
.filter(e => props.allowedTypes.includes(e.type))
@@ -264,22 +290,34 @@ export default defineComponent({
264290
getManyDashboardExplorerElements({
265291
parentId: props.parentId,
266292
search: search.value,
267-
types: props.allowedTypes
293+
types: props.allowedTypes,
294+
...props.dashboardExplorerElementsFilters
268295
});
269296
}
270297
else {
271298
getManyDashboardExplorerElements({
272299
parentId: props.parentId,
273300
root: props.root,
274-
types: props.allowedTypes
301+
types: props.allowedTypes,
302+
...props.dashboardExplorerElementsFilters
275303
});
276304
}
277305
}
278306
279307
// Delay to wait before fetching after a search change
280308
const debounceFetch = (): void => debounce(fetch, 1000);
281-
282-
watch([() => props.parentId, () => props.root, () => props.allowedTypes], (next, previous) => {
309+
310+
onMounted(() => {
311+
fetchUserOrganisation();
312+
});
313+
314+
watch(() => organisationId.value, () => {
315+
if (organisationId.value) {
316+
getOrganisation(organisationId.value);
317+
}
318+
}, { immediate: true });
319+
320+
watch([() => props.parentId, () => props.root, () => props.allowedTypes, () => props.dashboardExplorerElementsFilters], (next, previous) => {
283321
if ((!next && !previous) || !_.isEqual(next, previous)) {
284322
fetch();
285323
}
@@ -295,6 +333,8 @@ export default defineComponent({
295333
fetchingDashboardExplorerElements,
296334
DashboardExplorerElementType,
297335
dashboardExplorerElements,
336+
mainOrganisationDashboardId,
337+
mainUserDashboardId,
298338
headersOptions,
299339
search,
300340
isSelected,

0 commit comments

Comments
 (0)