atom-nuxt 1.4.9 → 1.4.11
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.
package/dist/module.json
CHANGED
|
@@ -4,7 +4,7 @@ import { useCrudConverters } from "../composables/useCrudConverters";
|
|
|
4
4
|
import { usePreviousRoute } from "../composables/usePreviousRoute";
|
|
5
5
|
import { useRoute, useRouter } from "#app";
|
|
6
6
|
import CrudFilterList from "./CrudFilterList.vue";
|
|
7
|
-
import { computed, ref, watch, onMounted, onBeforeUnmount, toRaw } from "vue";
|
|
7
|
+
import { computed, ref, watch, onMounted, onBeforeUnmount, toRaw, nextTick } from "vue";
|
|
8
8
|
import { useDebounceFn } from "@vueuse/core";
|
|
9
9
|
import { useListenerService } from "../composables/useListenerService";
|
|
10
10
|
import CrudFormDialog from "./CrudFormDialog.vue";
|
|
@@ -245,8 +245,9 @@ const dialogOpen = computed({
|
|
|
245
245
|
}
|
|
246
246
|
});
|
|
247
247
|
const page = computed(() => props.loaderKey ? parseQuery(route.query[props.loaderKey])?.page ?? 1 : route.query.page ?? 1);
|
|
248
|
-
const filterValues = props.loaderKey ? ref({ fromPaginatedLoader: true, ...props.customFilters, ...parseQuery(route.query[props.loaderKey]) }) : ref({ ...props.customFilters, ...route.query });
|
|
248
|
+
const filterValues = props.loaderKey ? ref({ fromPaginatedLoader: true, ...props.customFilters, ...parseQuery(route.query[props.loaderKey]) }) : ref({ fromPaginatedLoader: true, ...props.customFilters, ...route.query });
|
|
249
249
|
const isInitialLoad = ref(true);
|
|
250
|
+
const isSanitizing = ref(false);
|
|
250
251
|
const onQueryChange = (page2) => {
|
|
251
252
|
console.error("QUERY CHANGED");
|
|
252
253
|
const newQuery = {};
|
|
@@ -279,9 +280,32 @@ watch(currentPage, (newVal, oldValue) => {
|
|
|
279
280
|
onQueryChange(currentPage.value);
|
|
280
281
|
});
|
|
281
282
|
watch(filterValues, (newVal, oldValue) => {
|
|
283
|
+
if (isSanitizing.value) return;
|
|
282
284
|
console.error("FILTERS CHANGED");
|
|
283
285
|
onQueryChange(1);
|
|
284
286
|
}, { deep: true });
|
|
287
|
+
watch(filters, (newFilters) => {
|
|
288
|
+
if (!newFilters || newFilters.length === 0) return;
|
|
289
|
+
isSanitizing.value = true;
|
|
290
|
+
newFilters.forEach((filter) => {
|
|
291
|
+
if (filter.type === "option" || filter.type === "multiOption") {
|
|
292
|
+
const currentValue = filterValues.value[filter.key];
|
|
293
|
+
if (!currentValue) return;
|
|
294
|
+
const validValues = filter.options?.map((opt) => opt.value) || [];
|
|
295
|
+
if (filter.type === "multiOption" && Array.isArray(currentValue)) {
|
|
296
|
+
const validatedValue = currentValue.filter((v) => validValues.includes(v));
|
|
297
|
+
if (validatedValue.length !== currentValue.length) {
|
|
298
|
+
filterValues.value[filter.key] = validatedValue.length > 0 ? validatedValue : [];
|
|
299
|
+
}
|
|
300
|
+
} else if (filter.type === "option" && !validValues.includes(currentValue)) {
|
|
301
|
+
filterValues.value[filter.key] = null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
nextTick(() => {
|
|
306
|
+
isSanitizing.value = false;
|
|
307
|
+
});
|
|
308
|
+
});
|
|
285
309
|
watch(() => page, () => {
|
|
286
310
|
console.error("ROUTE CHANGED");
|
|
287
311
|
debouncedGet();
|
|
@@ -20,6 +20,7 @@ export const useCrudApi = (path, watchPage = true, transformItem = null, transfo
|
|
|
20
20
|
const atomNuxtConfig = useRuntimeConfig().public.atomNuxt;
|
|
21
21
|
const { stringifyQuery, flattenQuery, cloneDeep } = useCrudConverters();
|
|
22
22
|
const { setAlertMessage } = useAlertService();
|
|
23
|
+
let currentAbortController = null;
|
|
23
24
|
if (atomNuxtConfig.azureAdB2C) {
|
|
24
25
|
setCrudHeadersGenerator(async () => {
|
|
25
26
|
const { acquireTokensSilent } = useMSAuth();
|
|
@@ -119,6 +120,12 @@ export const useCrudApi = (path, watchPage = true, transformItem = null, transfo
|
|
|
119
120
|
}
|
|
120
121
|
return responseBody;
|
|
121
122
|
} catch (error) {
|
|
123
|
+
if (error.name === "AbortError") {
|
|
124
|
+
if (atomNuxtConfig.debug) {
|
|
125
|
+
console.log("Request aborted:", error);
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
122
129
|
if (error.status === 401 && crudOnUnauthenticated) {
|
|
123
130
|
await crudOnUnauthenticated();
|
|
124
131
|
}
|
|
@@ -130,6 +137,11 @@ export const useCrudApi = (path, watchPage = true, transformItem = null, transfo
|
|
|
130
137
|
}
|
|
131
138
|
};
|
|
132
139
|
const getItems = async (page = null, perPageLimit = null, filterValues = null, headers = {}) => {
|
|
140
|
+
if (currentAbortController) {
|
|
141
|
+
currentAbortController.abort();
|
|
142
|
+
}
|
|
143
|
+
currentAbortController = new AbortController();
|
|
144
|
+
const signal = currentAbortController.signal;
|
|
133
145
|
let pageToFetch = page ? page : currentPage.value;
|
|
134
146
|
let perPageToFetch = perPageLimit ? perPageLimit : perPage.value;
|
|
135
147
|
let parameters = stringifyQuery({ page: pageToFetch, limit: perPageToFetch }, "?");
|
|
@@ -144,9 +156,13 @@ export const useCrudApi = (path, watchPage = true, transformItem = null, transfo
|
|
|
144
156
|
headers: {
|
|
145
157
|
...atomNuxtConfig.additionalHeaders,
|
|
146
158
|
...headers
|
|
147
|
-
}
|
|
159
|
+
},
|
|
160
|
+
signal
|
|
148
161
|
};
|
|
149
162
|
const responseData = await fetchRequest(url, options, listPending, listErrors);
|
|
163
|
+
if (!responseData) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
150
166
|
if (responseData.currentPage) {
|
|
151
167
|
if (transformItems) {
|
|
152
168
|
responseData.items = transformItems(responseData.items);
|