mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-02 02:24:45 +00:00
improve pagination
This commit is contained in:
@@ -87,7 +87,6 @@ export default async function OrgPage(props: OrgPageProps) {
|
||||
savedConfig={launcherData.savedConfig}
|
||||
groups={launcherData.groups}
|
||||
groupsPagination={launcherData.groupsPagination}
|
||||
resourcesByGroupKey={launcherData.resourcesByGroupKey}
|
||||
/>
|
||||
) : null}
|
||||
</Layout>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import type { LauncherActiveViewId } from "@app/lib/launcherLocalStorage";
|
||||
import type { LauncherGroupResources } from "@app/lib/launcherServerData";
|
||||
import { launcherQueries } from "@app/lib/queries";
|
||||
import type {
|
||||
LauncherGroup,
|
||||
@@ -24,7 +23,6 @@ type LauncherGroupListProps = {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
};
|
||||
resourcesByGroupKey: Record<string, LauncherGroupResources>;
|
||||
onClearFilters?: () => void;
|
||||
onResourceSelect?: (resource: LauncherResource) => void;
|
||||
};
|
||||
@@ -43,7 +41,6 @@ export function LauncherGroupList({
|
||||
config,
|
||||
initialGroups,
|
||||
groupsPagination,
|
||||
resourcesByGroupKey,
|
||||
onClearFilters,
|
||||
onResourceSelect
|
||||
}: LauncherGroupListProps) {
|
||||
@@ -128,22 +125,16 @@ export function LauncherGroupList({
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5">
|
||||
{groups.map((group) => {
|
||||
const groupResources = resourcesByGroupKey[group.groupKey];
|
||||
|
||||
return (
|
||||
<LauncherGroupSection
|
||||
key={group.groupKey}
|
||||
orgId={orgId}
|
||||
activeViewId={activeViewId}
|
||||
group={group}
|
||||
config={config}
|
||||
initialResources={groupResources?.resources}
|
||||
initialResourcesPagination={groupResources?.pagination}
|
||||
onResourceSelect={onResourceSelect}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{groups.map((group) => (
|
||||
<LauncherGroupSection
|
||||
key={group.groupKey}
|
||||
orgId={orgId}
|
||||
activeViewId={activeViewId}
|
||||
group={group}
|
||||
config={config}
|
||||
onResourceSelect={onResourceSelect}
|
||||
/>
|
||||
))}
|
||||
<div ref={loadMoreRef} className="h-4" />
|
||||
{isFetchingNextPage ? (
|
||||
<div className="flex justify-center py-2">
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
writeLauncherLastView,
|
||||
type LauncherActiveViewId
|
||||
} from "@app/lib/launcherLocalStorage";
|
||||
import type { LauncherGroupResources } from "@app/lib/launcherServerData";
|
||||
import {
|
||||
buildLauncherPath,
|
||||
getLauncherUrlBaseConfig,
|
||||
@@ -73,7 +72,6 @@ type ResourceLauncherProps = {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
};
|
||||
resourcesByGroupKey: Record<string, LauncherGroupResources>;
|
||||
};
|
||||
|
||||
export default function ResourceLauncher({
|
||||
@@ -84,8 +82,7 @@ export default function ResourceLauncher({
|
||||
config,
|
||||
savedConfig,
|
||||
groups,
|
||||
groupsPagination,
|
||||
resourcesByGroupKey
|
||||
groupsPagination
|
||||
}: ResourceLauncherProps) {
|
||||
const t = useTranslations();
|
||||
const { toast } = useToast();
|
||||
@@ -511,7 +508,6 @@ export default function ResourceLauncher({
|
||||
config={config}
|
||||
initialGroups={groups}
|
||||
groupsPagination={groupsPagination}
|
||||
resourcesByGroupKey={resourcesByGroupKey}
|
||||
onClearFilters={handleClearFilters}
|
||||
/>
|
||||
|
||||
|
||||
@@ -4,24 +4,13 @@ import { resolveLauncherStateFromUrl } from "@app/lib/launcherUrlState";
|
||||
import { buildLauncherSearchParams } from "@app/lib/launcherSearchParams";
|
||||
import type {
|
||||
LauncherGroup,
|
||||
LauncherResource,
|
||||
LauncherViewConfig,
|
||||
LauncherViewRecord,
|
||||
ListLauncherGroupsResponse,
|
||||
ListLauncherResourcesResponse,
|
||||
ListLauncherViewsResponse
|
||||
} from "@server/routers/launcher/types";
|
||||
import { AxiosResponse } from "axios";
|
||||
|
||||
export type LauncherGroupResources = {
|
||||
resources: LauncherResource[];
|
||||
pagination: {
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
};
|
||||
};
|
||||
|
||||
export type LauncherPageData = {
|
||||
views: LauncherViewRecord[];
|
||||
activeViewId: LauncherActiveViewId;
|
||||
@@ -33,12 +22,6 @@ export type LauncherPageData = {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
};
|
||||
resourcesByGroupKey: Record<string, LauncherGroupResources>;
|
||||
};
|
||||
|
||||
const emptyResources: LauncherGroupResources = {
|
||||
resources: [],
|
||||
pagination: { total: 0, page: 1, pageSize: 20 }
|
||||
};
|
||||
|
||||
export async function fetchLauncherPageData(
|
||||
@@ -88,41 +71,12 @@ export async function fetchLauncherPageData(
|
||||
groupsPagination = groupsRes.data.data.pagination;
|
||||
} catch (e) {}
|
||||
|
||||
const resourcesByGroupKey: Record<string, LauncherGroupResources> = {};
|
||||
|
||||
await Promise.all(
|
||||
groups.map(async (group) => {
|
||||
try {
|
||||
const sp = buildLauncherSearchParams(
|
||||
{
|
||||
...groupFilters,
|
||||
groupKey: group.groupKey
|
||||
},
|
||||
1
|
||||
);
|
||||
const res = await internal.get<
|
||||
AxiosResponse<ListLauncherResourcesResponse>
|
||||
>(
|
||||
`/org/${orgId}/launcher/resources?${sp.toString()}`,
|
||||
cookieHeader
|
||||
);
|
||||
resourcesByGroupKey[group.groupKey] = {
|
||||
resources: res.data.data.resources,
|
||||
pagination: res.data.data.pagination
|
||||
};
|
||||
} catch (e) {
|
||||
resourcesByGroupKey[group.groupKey] = emptyResources;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
views,
|
||||
activeViewId,
|
||||
config,
|
||||
savedConfig,
|
||||
groups,
|
||||
groupsPagination,
|
||||
resourcesByGroupKey
|
||||
groupsPagination
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user