mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-09 07:30:40 +02:00
add compact mode for large orgs
This commit is contained in:
@@ -10,7 +10,7 @@ function lastViewKey(orgId: string) {
|
||||
function groupOpenKey(
|
||||
orgId: string,
|
||||
viewId: LauncherActiveViewId,
|
||||
groupBy: "site" | "label"
|
||||
groupBy: "site" | "label" | "none"
|
||||
) {
|
||||
return `${GROUP_OPEN_PREFIX}${orgId}:${viewId}:${groupBy}`;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export function writeLauncherLastView(
|
||||
export function readLauncherGroupOpenState(
|
||||
orgId: string,
|
||||
viewId: LauncherActiveViewId,
|
||||
groupBy: "site" | "label"
|
||||
groupBy: "site" | "label" | "none"
|
||||
): Record<string, boolean> {
|
||||
return readJson<Record<string, boolean>>(
|
||||
groupOpenKey(orgId, viewId, groupBy),
|
||||
@@ -75,7 +75,7 @@ export function readLauncherGroupOpenState(
|
||||
export function readLauncherGroupOpen(
|
||||
orgId: string,
|
||||
viewId: LauncherActiveViewId,
|
||||
groupBy: "site" | "label",
|
||||
groupBy: "site" | "label" | "none",
|
||||
groupKey: string,
|
||||
defaultOpen: boolean
|
||||
): boolean {
|
||||
@@ -86,7 +86,7 @@ export function readLauncherGroupOpen(
|
||||
export function writeLauncherGroupOpen(
|
||||
orgId: string,
|
||||
viewId: LauncherActiveViewId,
|
||||
groupBy: "site" | "label",
|
||||
groupBy: "site" | "label" | "none",
|
||||
groupKey: string,
|
||||
isOpen: boolean
|
||||
) {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import type {
|
||||
LauncherScaleInfo,
|
||||
LauncherViewConfig
|
||||
} from "@server/routers/launcher/types";
|
||||
|
||||
export function hasActiveLauncherFilters(config: LauncherViewConfig): boolean {
|
||||
return (
|
||||
config.query.trim().length > 0 ||
|
||||
config.siteIds.length > 0 ||
|
||||
config.labelIds.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
export function getEffectiveGroupBy(
|
||||
scale: LauncherScaleInfo,
|
||||
config: LauncherViewConfig
|
||||
): LauncherViewConfig["groupBy"] {
|
||||
if (scale.mode === "compact") {
|
||||
return "none";
|
||||
}
|
||||
|
||||
return config.groupBy;
|
||||
}
|
||||
|
||||
export function getEffectiveLauncherConfig(
|
||||
scale: LauncherScaleInfo,
|
||||
config: LauncherViewConfig
|
||||
): LauncherViewConfig {
|
||||
const groupBy = getEffectiveGroupBy(scale, config);
|
||||
if (groupBy === config.groupBy) {
|
||||
return config;
|
||||
}
|
||||
|
||||
return { ...config, groupBy };
|
||||
}
|
||||
|
||||
export function shouldFetchLauncherGroups(
|
||||
scale: LauncherScaleInfo,
|
||||
config: LauncherViewConfig
|
||||
): boolean {
|
||||
const groupBy = getEffectiveGroupBy(scale, config);
|
||||
|
||||
if (groupBy === "none") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (scale.mode === "full") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (
|
||||
scale.capabilities.allowSiteGrouping &&
|
||||
groupBy === "site" &&
|
||||
config.siteIds.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
export function shouldShowLauncherGroupList(
|
||||
scale: LauncherScaleInfo,
|
||||
config: LauncherViewConfig
|
||||
): boolean {
|
||||
return shouldFetchLauncherGroups(scale, config);
|
||||
}
|
||||
|
||||
export function shouldShowSearchFirstGate(
|
||||
scale: LauncherScaleInfo,
|
||||
config: LauncherViewConfig
|
||||
): boolean {
|
||||
return (
|
||||
scale.mode === "compact" &&
|
||||
scale.capabilities.requireSearchOrFilter &&
|
||||
!hasActiveLauncherFilters(config)
|
||||
);
|
||||
}
|
||||
|
||||
export function shouldShowFlatResourceList(
|
||||
scale: LauncherScaleInfo,
|
||||
config: LauncherViewConfig
|
||||
): boolean {
|
||||
if (shouldShowSearchFirstGate(scale, config)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const groupBy = getEffectiveGroupBy(scale, config);
|
||||
|
||||
if (groupBy === "none") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (scale.mode === "full") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !shouldShowLauncherGroupList(scale, config);
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
import { internal } from "@app/lib/api";
|
||||
import type { LauncherActiveViewId } from "@app/lib/launcherLocalStorage";
|
||||
import { shouldFetchLauncherGroups } from "@app/lib/launcherScale";
|
||||
import { resolveLauncherStateFromUrl } from "@app/lib/launcherUrlState";
|
||||
import { buildLauncherSearchParams } from "@app/lib/launcherSearchParams";
|
||||
import type {
|
||||
LauncherGroup,
|
||||
LauncherScaleInfo,
|
||||
LauncherViewConfig,
|
||||
LauncherViewRecord,
|
||||
ListLauncherGroupsResponse,
|
||||
ListLauncherScaleResponse,
|
||||
ListLauncherViewsResponse
|
||||
} from "@server/routers/launcher/types";
|
||||
import { AxiosResponse } from "axios";
|
||||
@@ -16,6 +19,7 @@ export type LauncherPageData = {
|
||||
activeViewId: LauncherActiveViewId;
|
||||
config: LauncherViewConfig;
|
||||
savedConfig: LauncherViewConfig;
|
||||
scale: LauncherScaleInfo;
|
||||
groups: LauncherGroup[];
|
||||
groupsPagination: {
|
||||
total: number;
|
||||
@@ -45,6 +49,37 @@ export async function fetchLauncherPageData(
|
||||
null
|
||||
);
|
||||
|
||||
const scaleFilters = {
|
||||
query: config.query,
|
||||
groupBy: config.groupBy,
|
||||
siteIds: config.siteIds,
|
||||
labelIds: config.labelIds,
|
||||
sort_by: config.sortBy,
|
||||
order: config.order
|
||||
};
|
||||
|
||||
let scale: LauncherScaleInfo = {
|
||||
mode: "full",
|
||||
resourceCount: 0,
|
||||
siteGroupCount: 0,
|
||||
labelGroupCount: 0,
|
||||
capabilities: {
|
||||
allowSiteGrouping: true,
|
||||
allowLabelGrouping: true,
|
||||
requireSearchOrFilter: false
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const sp = buildLauncherSearchParams(scaleFilters, 1);
|
||||
sp.delete("page");
|
||||
sp.delete("pageSize");
|
||||
const scaleRes = await internal.get<
|
||||
AxiosResponse<ListLauncherScaleResponse>
|
||||
>(`/org/${orgId}/launcher/scale?${sp.toString()}`, cookieHeader);
|
||||
scale = scaleRes.data.data.scale;
|
||||
} catch (e) {}
|
||||
|
||||
const groupFilters = {
|
||||
query: config.query,
|
||||
groupBy: config.groupBy,
|
||||
@@ -62,20 +97,23 @@ export async function fetchLauncherPageData(
|
||||
pageSize: 20
|
||||
};
|
||||
|
||||
try {
|
||||
const sp = buildLauncherSearchParams(groupFilters, 1);
|
||||
const groupsRes = await internal.get<
|
||||
AxiosResponse<ListLauncherGroupsResponse>
|
||||
>(`/org/${orgId}/launcher/groups?${sp.toString()}`, cookieHeader);
|
||||
groups = groupsRes.data.data.groups;
|
||||
groupsPagination = groupsRes.data.data.pagination;
|
||||
} catch (e) {}
|
||||
if (shouldFetchLauncherGroups(scale, config)) {
|
||||
try {
|
||||
const sp = buildLauncherSearchParams(groupFilters, 1);
|
||||
const groupsRes = await internal.get<
|
||||
AxiosResponse<ListLauncherGroupsResponse>
|
||||
>(`/org/${orgId}/launcher/groups?${sp.toString()}`, cookieHeader);
|
||||
groups = groupsRes.data.data.groups;
|
||||
groupsPagination = groupsRes.data.data.pagination;
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
return {
|
||||
views,
|
||||
activeViewId,
|
||||
config,
|
||||
savedConfig,
|
||||
scale,
|
||||
groups,
|
||||
groupsPagination
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ function parseConfigOverrides(
|
||||
}
|
||||
|
||||
const groupBy = searchParams.get("groupBy");
|
||||
if (groupBy === "site" || groupBy === "label") {
|
||||
if (groupBy === "site" || groupBy === "label" || groupBy === "none") {
|
||||
overrides.groupBy = groupBy;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import type {
|
||||
ListLauncherGroupsResponse,
|
||||
ListLauncherLabelsResponse,
|
||||
ListLauncherResourcesResponse,
|
||||
ListLauncherScaleResponse,
|
||||
ListLauncherSitesResponse,
|
||||
ListLauncherViewsResponse,
|
||||
LauncherListQuery,
|
||||
@@ -1298,5 +1299,19 @@ export const launcherQueries = {
|
||||
const nextPage = page + 1;
|
||||
return page * pageSize < total ? nextPage : undefined;
|
||||
}
|
||||
}),
|
||||
scale: (orgId: string, filters: LauncherQueryFilters) =>
|
||||
queryOptions({
|
||||
queryKey: ["ORG", orgId, "LAUNCHER", "SCALE", filters] as const,
|
||||
queryFn: async ({ signal, meta }) => {
|
||||
const sp = buildLauncherSearchParams(filters, 1);
|
||||
sp.delete("page");
|
||||
sp.delete("pageSize");
|
||||
sp.delete("groupKey");
|
||||
const res = await meta!.api.get<
|
||||
AxiosResponse<ListLauncherScaleResponse>
|
||||
>(`/org/${orgId}/launcher/scale?${sp.toString()}`, { signal });
|
||||
return res.data.data.scale;
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user