mirror of https://github.com/halo-dev/halo
refactor: enable dashboard widgets query cache (#7520)
#### What type of PR is this? /kind improvement /area ui /milestone 2.21.x #### What this PR does / why we need it: Enable query cache for dashboard widgets. #### Does this PR introduce a user-facing change? ```release-note None ```pull/7521/head^2
parent
65d4751509
commit
63d40d4d40
|
@ -6,10 +6,10 @@ import {
|
||||||
VPageHeader,
|
VPageHeader,
|
||||||
} from "@halo-dev/components";
|
} from "@halo-dev/components";
|
||||||
import type { DashboardWidgetDefinition } from "@halo-dev/console-shared";
|
import type { DashboardWidgetDefinition } from "@halo-dev/console-shared";
|
||||||
import { computed, type ComputedRef, provide, ref } from "vue";
|
import { computed, type ComputedRef, provide, ref, toRaw } from "vue";
|
||||||
import WidgetViewItem from "./components/WidgetViewItem.vue";
|
import WidgetViewItem from "./components/WidgetViewItem.vue";
|
||||||
import { useDashboardExtensionPoint } from "./composables/use-dashboard-extension-point";
|
import { useDashboardExtensionPoint } from "./composables/use-dashboard-extension-point";
|
||||||
import { useDashboardWidgetsFetch } from "./composables/use-dashboard-widgets-fetch";
|
import { useDashboardWidgetsViewFetch } from "./composables/use-dashboard-widgets-fetch";
|
||||||
import "./styles/dashboard.css";
|
import "./styles/dashboard.css";
|
||||||
import { internalWidgetDefinitions } from "./widgets";
|
import { internalWidgetDefinitions } from "./widgets";
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ function breakpointChangedEvent(breakpoint: string) {
|
||||||
currentBreakpoint.value = breakpoint;
|
currentBreakpoint.value = breakpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { layouts, layout } = useDashboardWidgetsFetch(currentBreakpoint);
|
const { data } = useDashboardWidgetsViewFetch(currentBreakpoint);
|
||||||
|
|
||||||
const { widgetDefinitions } = useDashboardExtensionPoint();
|
const { widgetDefinitions } = useDashboardExtensionPoint();
|
||||||
|
|
||||||
|
@ -52,8 +52,8 @@ provide<ComputedRef<DashboardWidgetDefinition[]>>(
|
||||||
|
|
||||||
<div class="dashboard m-4">
|
<div class="dashboard m-4">
|
||||||
<grid-layout
|
<grid-layout
|
||||||
v-model:layout="layout"
|
:layout="toRaw(data?.layout || [])"
|
||||||
:responsive-layouts="layouts"
|
:responsive-layouts="data?.layouts"
|
||||||
:col-num="12"
|
:col-num="12"
|
||||||
:is-draggable="false"
|
:is-draggable="false"
|
||||||
:is-resizable="false"
|
:is-resizable="false"
|
||||||
|
@ -66,7 +66,7 @@ provide<ComputedRef<DashboardWidgetDefinition[]>>(
|
||||||
:cols="{ lg: 12, md: 12, sm: 6, xs: 4 }"
|
:cols="{ lg: 12, md: 12, sm: 6, xs: 4 }"
|
||||||
@breakpoint-changed="breakpointChangedEvent"
|
@breakpoint-changed="breakpointChangedEvent"
|
||||||
>
|
>
|
||||||
<WidgetViewItem v-for="item in layout" :key="item.i" :item="item" />
|
<WidgetViewItem v-for="item in data?.layout" :key="item.i" :item="item" />
|
||||||
</grid-layout>
|
</grid-layout>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -254,6 +254,10 @@ async function handleSave() {
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: ["core:dashboard:widgets"],
|
queryKey: ["core:dashboard:widgets"],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: ["core:dashboard:widgets:view"],
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to save dashboard widgets config", error);
|
console.error("Failed to save dashboard widgets config", error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -43,3 +43,23 @@ export function useDashboardWidgetsFetch(breakpoint: Ref<string>) {
|
||||||
isLoading,
|
isLoading,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useDashboardWidgetsViewFetch(breakpoint: Ref<string>) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["core:dashboard:widgets:view", breakpoint],
|
||||||
|
queryFn: async () => {
|
||||||
|
const { data } = await ucApiClient.user.preference.getMyPreference({
|
||||||
|
group: "dashboard-widgets",
|
||||||
|
});
|
||||||
|
|
||||||
|
const layouts = (data ||
|
||||||
|
DefaultResponsiveLayouts) as DashboardResponsiveLayout;
|
||||||
|
|
||||||
|
return {
|
||||||
|
layouts,
|
||||||
|
layout: layouts[breakpoint.value] || layouts.lg || [],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
enabled: computed(() => !!breakpoint.value),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue