mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Don't track preview window as user's last page (#19162)
* Pass full router object to UsersStore trackPage method * Don't track /preview pages as part of user's last * Add changeset * Fix tests
This commit is contained in:
6
.changeset/shaggy-moose-stare.md
Normal file
6
.changeset/shaggy-moose-stare.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@directus/app': patch
|
||||
---
|
||||
|
||||
Fixed an issue that would persist the full screen preview URL as an in-app user's last-page, potentially causing issues
|
||||
on login
|
||||
@@ -166,7 +166,7 @@ export const onAfterEach: NavigationHookAfter = (to) => {
|
||||
}
|
||||
|
||||
trackTimeout = window.setTimeout(() => {
|
||||
userStore.trackPage(to.fullPath);
|
||||
userStore.trackPage(to);
|
||||
}, 500);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createTestingPinia } from '@pinia/testing';
|
||||
import { AxiosRequestConfig } from 'axios';
|
||||
import { setActivePinia } from 'pinia';
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
import type { RouteLocationNormalized } from 'vue-router';
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(
|
||||
@@ -149,7 +150,7 @@ describe('actions', () => {
|
||||
vi.spyOn(latencyStore, 'save').mockReturnValue();
|
||||
|
||||
const userStore = useUserStore();
|
||||
await userStore.trackPage(page);
|
||||
await userStore.trackPage({ path: page, fullPath: page } as RouteLocationNormalized);
|
||||
|
||||
expect((userStore.currentUser as User)?.last_page).not.toBe(page);
|
||||
});
|
||||
@@ -160,7 +161,7 @@ describe('actions', () => {
|
||||
|
||||
const userStore = useUserStore();
|
||||
await userStore.hydrate();
|
||||
await userStore.trackPage(page);
|
||||
await userStore.trackPage({ path: page, fullPath: page } as RouteLocationNormalized);
|
||||
|
||||
expect((userStore.currentUser as User).last_page).toBe(page);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import api from '@/api';
|
||||
import { useLatencyStore } from '@/stores/latency';
|
||||
import { User } from '@directus/types';
|
||||
import { userName } from '@/utils/user-name';
|
||||
import { User } from '@directus/types';
|
||||
import { merge } from 'lodash';
|
||||
import { defineStore } from 'pinia';
|
||||
import type { RouteLocationNormalized } from 'vue-router';
|
||||
|
||||
type ShareUser = {
|
||||
share: string;
|
||||
@@ -72,13 +73,22 @@ export const useUserStore = defineStore({
|
||||
// Do nothing
|
||||
}
|
||||
},
|
||||
async trackPage(page: string) {
|
||||
async trackPage(to: RouteLocationNormalized) {
|
||||
/**
|
||||
* We don't want to track the full screen preview from live previews as part of the user's
|
||||
* last page, as that'll cause a fresh login to navigate to the full screen preview where
|
||||
* you can't navigate away from #19160
|
||||
*/
|
||||
if (to.path.endsWith('/preview')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const latencyStore = useLatencyStore();
|
||||
|
||||
const start = performance.now();
|
||||
|
||||
await api.patch(`/users/me/track/page`, {
|
||||
last_page: page,
|
||||
last_page: to.fullPath,
|
||||
});
|
||||
|
||||
const end = performance.now();
|
||||
@@ -89,7 +99,7 @@ export const useUserStore = defineStore({
|
||||
});
|
||||
|
||||
if (this.currentUser && !('share' in this.currentUser)) {
|
||||
this.currentUser.last_page = page;
|
||||
this.currentUser.last_page = to.fullPath;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user