forked from verdnatura/salix-front
Merge pull request 'perf_redirectTransition' (!1178) from perf_redirectTransition into test
Reviewed-on: verdnatura/salix-front#1178 Reviewed-by: Javier Segarra <jsegarra@verdnatura.es> Reviewed-by: Carlos Satorres <carlossa@verdnatura.es>
This commit is contained in:
commit
f45612f058
|
@ -124,12 +124,14 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
const { limit } = filter;
|
||||
store.hasMoreData = limit && response.data.length >= limit;
|
||||
|
||||
processData(response.data, { map: !!store.mapKey, append });
|
||||
if (!append && !isDialogOpened()) updateRouter && updateStateParams();
|
||||
|
||||
if (!append && !isDialogOpened() && updateRouter) {
|
||||
if (updateStateParams(response.data)?.redirect) return;
|
||||
}
|
||||
store.isLoading = false;
|
||||
canceller = null;
|
||||
|
||||
processData(response.data, { map: !!store.mapKey, append });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -259,7 +261,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
if (Object.values(store.userParams).length) await fetch({});
|
||||
}
|
||||
|
||||
function updateStateParams() {
|
||||
function updateStateParams(data) {
|
||||
if (!route?.path) return;
|
||||
const newUrl = { path: route.path, query: { ...(route.query ?? {}) } };
|
||||
if (store?.searchUrl)
|
||||
|
@ -276,15 +278,15 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
const { path } = matches.at(-1);
|
||||
|
||||
const to =
|
||||
store?.data?.length === 1
|
||||
? path.replace(/\/(list|:id)|-list/, `/${store.data[0].id}`)
|
||||
data?.length === 1
|
||||
? path.replace(/\/(list|:id)|-list/, `/${data[0].id}`)
|
||||
: path.replace(/:id.*/, '');
|
||||
|
||||
if (route.path != to) {
|
||||
const pushUrl = { path: to };
|
||||
if (to.endsWith('/list') || to.endsWith('/'))
|
||||
pushUrl.query = newUrl.query;
|
||||
return router.push(pushUrl);
|
||||
return router.push(pushUrl) && { redirect: true };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue