@dative-gpi/foundation-core-components 0.0.129 → 0.0.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,16 @@
1
1
  <template>
2
2
  <FSLoadDataTable
3
- v-if="gettingUserOrganisationTable"
3
+ v-if="!initialized || gettingUserOrganisationTable"
4
4
  />
5
5
  <FSDataTableUI
6
6
  v-else
7
- :headers="headers"
8
- :mode="table.mode"
9
- :sortBy="table.sortBy"
10
- :rowsPerPage="table.rowsPerPage"
11
- :filters="table.filters"
12
- :page="table.page"
13
- @update:headers="updateHeaders"
14
- @update:mode="updateMode"
15
- @update:sortBy="updateSortBy"
16
- @update:rowsPerPage="updateRowsPerPage"
17
- @update:filters="updateFilters"
18
- @update:page="updatePage"
19
- v-bind="$attrs"
7
+ @update:rowsPerPage="table.rowsPerPage = $event"
8
+ @update:filters="table.filters = $event"
9
+ @update:headers="table.headers = $event"
10
+ @update:sortBy="table.sortBy = $event"
11
+ @update:mode="table.mode = $event"
12
+ @update:page="table.page = $event"
13
+ v-bind="{ ...computedTable, ...$attrs }"
20
14
  >
21
15
  <template
22
16
  v-for="(_, name) in $slots"
@@ -33,9 +27,9 @@
33
27
  <script lang="ts">
34
28
  import { PropType, computed, defineComponent, onUnmounted, ref, watch } from "vue";
35
29
 
36
- import { FSDataTable, FSDataTableColumn, FSDataTableFilter, FSDataTableOrder } from "@dative-gpi/foundation-shared-components/models";
37
30
  import { useUserOrganisationTable, useUpdateUserOrganisationTable } from "@dative-gpi/foundation-core-services/composables";
38
31
  import { useDebounce, useTables } from "@dative-gpi/foundation-shared-components/composables";
32
+ import { FSDataTable } from "@dative-gpi/foundation-shared-components/models";
39
33
 
40
34
  import FSLoadDataTable from "@dative-gpi/foundation-shared-components/components/lists/FSLoadDataTable.vue";
41
35
  import FSDataTableUI from "@dative-gpi/foundation-shared-components/components/lists/FSDataTableUI.vue";
@@ -73,7 +67,9 @@ export default defineComponent({
73
67
  const { getTable, setTable } = useTables();
74
68
  const { debounce, cancel } = useDebounce();
75
69
 
76
- const table = ref<FSDataTable | null>({
70
+ const initialized = ref(false);
71
+
72
+ const table = ref<FSDataTable>({
77
73
  headers: [],
78
74
  mode: "table",
79
75
  sortBy: null,
@@ -82,83 +78,14 @@ export default defineComponent({
82
78
  page: 1
83
79
  });
84
80
 
85
- const headers = computed((): FSDataTableColumn[] => {
86
- if(!table.value) {
87
- return [];
88
- }
89
- return table.value.headers.map(header => {
90
- return {
91
- ...header,
92
- sort: header.value && props.customSorts[header.value] || null,
93
- sortRaw: header.value && props.customSortRaws[header.value] || null
94
- }
95
- })
96
- });
97
-
98
- const reset = async (): Promise<void> => {
99
- const composableTable = getTable(props.tableCode);
100
- if (composableTable) {
101
- table.value = composableTable;
102
- }
103
- else {
104
- await getUserOrganisationTable(props.tableCode);
105
- if (userOrganisationTable.value) {
106
- table.value = {
107
- headers: userOrganisationTable.value.columns,
108
- sortBy: {
109
- key: userOrganisationTable.value.sortByKey,
110
- order: userOrganisationTable.value.sortByOrder
111
- },
112
- mode: userOrganisationTable.value.mode,
113
- rowsPerPage: userOrganisationTable.value.rowsPerPage,
114
- filters: {},
115
- page: 1
116
- };
117
- }
118
- }
119
- };
120
-
121
- const updateHeaders = (value: FSDataTableColumn[]): void => {
122
- if (table.value) {
123
- table.value.headers = value;
124
- debounce(updateTable, props.debounceTime);
125
- }
126
- };
127
-
128
- const updateMode = (value: "table" | "iterator"): void => {
129
- if (table.value) {
130
- table.value.mode = value;
131
- debounce(updateTable, props.debounceTime);
132
- }
133
- };
134
-
135
- const updateSortBy = (value: FSDataTableOrder | null): void => {
136
- if (table.value) {
137
- table.value.sortBy = value;
138
- debounce(updateTable, props.debounceTime);
139
- }
140
- };
141
-
142
- const updateRowsPerPage = (value: -1 | 10 | 30): void => {
143
- if (table.value) {
144
- table.value.rowsPerPage = value;
145
- debounce(updateTable, props.debounceTime);
146
- }
147
- };
148
-
149
- const updateFilters = (value: { [key: string]: FSDataTableFilter[] }): void => {
150
- if (table.value) {
151
- table.value.filters = value;
152
- setTable(props.tableCode, table.value);
153
- }
154
- };
155
-
156
- const updatePage = (value: number): void => {
157
- if (table.value) {
158
- table.value.page = value;
159
- setTable(props.tableCode, table.value);
160
- }
161
- };
81
+ const computedTable = computed(() => ({
82
+ ...table.value,
83
+ headers: table.value.headers.map(header => ({
84
+ ...header,
85
+ sort: header.value && props.customSorts[header.value] || null,
86
+ sortRaw: header.value && props.customSortRaws[header.value] || null
87
+ }))
88
+ }));
162
89
 
163
90
  const updateTable = (): void => {
164
91
  if (table.value) {
@@ -182,22 +109,43 @@ export default defineComponent({
182
109
  updateTable();
183
110
  });
184
111
 
185
- watch(() => props.tableCode, () => {
112
+ watch(() => props.tableCode, async (): Promise<void> => {
186
113
  if (props.tableCode) {
187
- reset();
114
+ const composableTable = getTable(props.tableCode);
115
+ if (composableTable) {
116
+ table.value = composableTable;
117
+ }
118
+ else {
119
+ await getUserOrganisationTable(props.tableCode);
120
+ if (userOrganisationTable.value) {
121
+ table.value = {
122
+ headers: userOrganisationTable.value.columns,
123
+ sortBy: {
124
+ key: userOrganisationTable.value.sortByKey,
125
+ order: userOrganisationTable.value.sortByOrder
126
+ },
127
+ mode: userOrganisationTable.value.mode,
128
+ rowsPerPage: userOrganisationTable.value.rowsPerPage,
129
+ filters: {},
130
+ page: 1
131
+ }
132
+ }
133
+ }
188
134
  }
135
+ initialized.value = true;
189
136
  }, { immediate: true });
190
137
 
138
+ watch(() => table.value, () => {
139
+ if (table.value && initialized.value) {
140
+ debounce(updateTable, props.debounceTime);
141
+ }
142
+ }, { deep: true });
143
+
191
144
  return {
192
145
  gettingUserOrganisationTable,
193
- headers,
194
- table,
195
- updateRowsPerPage,
196
- updateFilters,
197
- updateHeaders,
198
- updateSortBy,
199
- updateMode,
200
- updatePage
146
+ computedTable,
147
+ initialized,
148
+ table
201
149
  };
202
150
  },
203
151
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-core-components",
3
3
  "sideEffects": false,
4
- "version": "0.0.129",
4
+ "version": "0.0.131",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,11 +10,11 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dative-gpi/foundation-core-domain": "0.0.129",
14
- "@dative-gpi/foundation-core-services": "0.0.129",
15
- "@dative-gpi/foundation-shared-components": "0.0.129",
16
- "@dative-gpi/foundation-shared-domain": "0.0.129",
17
- "@dative-gpi/foundation-shared-services": "0.0.129",
13
+ "@dative-gpi/foundation-core-domain": "0.0.131",
14
+ "@dative-gpi/foundation-core-services": "0.0.131",
15
+ "@dative-gpi/foundation-shared-components": "0.0.131",
16
+ "@dative-gpi/foundation-shared-domain": "0.0.131",
17
+ "@dative-gpi/foundation-shared-services": "0.0.131",
18
18
  "color": "^4.2.3",
19
19
  "vue": "^3.4.23",
20
20
  "vuedraggable": "^4.1.0"
@@ -24,5 +24,5 @@
24
24
  "sass": "^1.69.5",
25
25
  "sass-loader": "^13.3.2"
26
26
  },
27
- "gitHead": "9de5285c5772c30e67c5b32dbaf1a6a571297c8b"
27
+ "gitHead": "11ac39c098085a049744234e279ca4a71bfaf75a"
28
28
  }