From 2ed6da0ff9642e01655ed4a669c4972e9d372e8b Mon Sep 17 00:00:00 2001 From: daedalus <44623501+ComfortablyCoding@users.noreply.github.com> Date: Fri, 29 Dec 2023 05:56:28 -0500 Subject: [PATCH] Do not load sidebar details until they are opened (#20848) Co-authored-by: ian Co-authored-by: Pascal Jufer --- .changeset/thick-spiders-share.md | 5 + app/src/composables/use-revisions.ts | 75 +++- app/src/modules/content/routes/item.vue | 27 +- .../flows/components/logs-sidebar-detail.vue | 35 +- .../components/comments-sidebar-detail.vue | 93 ++++- .../components/revisions-drawer-detail.vue | 32 +- .../components/shares-sidebar-detail.vue | 334 ++++++++++++------ .../private/components/sidebar-detail.vue | 11 +- 8 files changed, 453 insertions(+), 159 deletions(-) create mode 100644 .changeset/thick-spiders-share.md diff --git a/.changeset/thick-spiders-share.md b/.changeset/thick-spiders-share.md new file mode 100644 index 0000000000..7e0bcdf048 --- /dev/null +++ b/.changeset/thick-spiders-share.md @@ -0,0 +1,5 @@ +--- +'@directus/app': minor +--- + +Prevented loading of sidebar details (revisions, comments, shares etc) until they are opened diff --git a/app/src/composables/use-revisions.ts b/app/src/composables/use-revisions.ts index c5a541803c..ad73aa5a61 100644 --- a/app/src/composables/use-revisions.ts +++ b/app/src/composables/use-revisions.ts @@ -27,13 +27,25 @@ export function useRevisions( const revisions = ref(null); const revisionsByDate = ref(null); const loading = ref(false); + const loadingCount = ref(false); const revisionsCount = ref(0); const created = ref(); const pagesCount = ref(0); - watch([collection, primaryKey, version], () => getRevisions(), { immediate: true }); + watch([collection, primaryKey, version], () => refresh()); - return { created, revisions, revisionsByDate, loading, refresh, revisionsCount, pagesCount }; + return { + created, + revisions, + revisionsByDate, + getRevisions, + loading, + refresh, + loadingCount, + revisionsCount, + getRevisionsCount, + pagesCount, + }; async function getRevisions(page = 0) { if (typeof unref(primaryKey) === 'undefined') return; @@ -98,7 +110,6 @@ export function useRevisions( 'activity.user_agent', 'activity.origin', ], - meta: ['filter_count'], }, }); @@ -137,7 +148,6 @@ export function useRevisions( 'activity.user_agent', 'activity.origin', ], - meta: ['filter_count'], }, }); @@ -193,7 +203,6 @@ export function useRevisions( revisionsByDate.value = orderBy(revisionsGrouped, ['date'], ['desc']); revisions.value = orderBy(response.data.data, ['activity.timestamp'], ['desc']); - revisionsCount.value = response.data.meta.filter_count; pagesCount.value = Math.ceil(revisionsCount.value / pageSize); } catch (error) { unexpectedError(error); @@ -202,7 +211,63 @@ export function useRevisions( } } + async function getRevisionsCount() { + if (typeof unref(primaryKey) === 'undefined') return; + + loadingCount.value = true; + + try { + const filter: Filter = { + _and: [ + { + collection: { + _eq: unref(collection), + }, + }, + { + item: { + _eq: unref(primaryKey), + }, + }, + { + version: version?.value + ? { + _eq: version.value.id, + } + : { _null: true }, + }, + ], + }; + + if (options?.action) { + filter._and.push({ + activity: { + action: { + _eq: options?.action, + }, + }, + }); + } + + const response = await api.get(`/revisions`, { + params: { + filter, + aggregate: { + count: 'id', + }, + }, + }); + + revisionsCount.value = Number(response.data.data[0].count.id); + } catch (error) { + unexpectedError(error); + } finally { + loadingCount.value = false; + } + } + async function refresh(page = 0) { + await getRevisionsCount(); await getRevisions(page); } diff --git a/app/src/modules/content/routes/item.vue b/app/src/modules/content/routes/item.vue index 5a80f29e42..2d756b4d49 100644 --- a/app/src/modules/content/routes/item.vue +++ b/app/src/modules/content/routes/item.vue @@ -19,6 +19,7 @@ import RevisionsDrawerDetail from '@/views/private/components/revisions-drawer-d import SaveOptions from '@/views/private/components/save-options.vue'; import SharesSidebarDetail from '@/views/private/components/shares-sidebar-detail.vue'; import { useCollection } from '@directus/composables'; +import type { PrimaryKey } from '@directus/types'; import { useHead } from '@unhead/vue'; import { useRouter } from 'vue-router'; import LivePreview from '../components/live-preview.vue'; @@ -184,11 +185,25 @@ const isFormDisabled = computed(() => { return true; }); +const actualPrimaryKey = computed(() => { + if (unref(isSingleton)) { + const singleton = unref(item); + const pkField = unref(primaryKeyField)?.field; + return (singleton && pkField ? singleton[pkField] ?? null : null) as PrimaryKey | null; + } + + return props.primaryKey; +}); + const internalPrimaryKey = computed(() => { if (unref(loading)) return '+'; if (unref(isNew)) return '+'; - if (unref(isSingleton)) return unref(item)?.[unref(primaryKeyField)?.field] ?? '+'; + if (unref(isSingleton)) { + const singleton = unref(item); + const pkField = unref(primaryKeyField)?.field; + return (singleton && pkField ? singleton[pkField] ?? '+' : '+') as PrimaryKey; + } return props.primaryKey; }); @@ -706,12 +721,12 @@ function revert(values: Record) {
-