Merge pull request #3380 from fosrl/resource-launcher

improve pagination
This commit is contained in:
Owen Schwartz
2026-07-01 21:47:14 -04:00
committed by GitHub
4 changed files with 12 additions and 72 deletions

View File

@@ -87,7 +87,6 @@ export default async function OrgPage(props: OrgPageProps) {
savedConfig={launcherData.savedConfig} savedConfig={launcherData.savedConfig}
groups={launcherData.groups} groups={launcherData.groups}
groupsPagination={launcherData.groupsPagination} groupsPagination={launcherData.groupsPagination}
resourcesByGroupKey={launcherData.resourcesByGroupKey}
/> />
) : null} ) : null}
</Layout> </Layout>

View File

@@ -1,7 +1,6 @@
"use client"; "use client";
import type { LauncherActiveViewId } from "@app/lib/launcherLocalStorage"; import type { LauncherActiveViewId } from "@app/lib/launcherLocalStorage";
import type { LauncherGroupResources } from "@app/lib/launcherServerData";
import { launcherQueries } from "@app/lib/queries"; import { launcherQueries } from "@app/lib/queries";
import type { import type {
LauncherGroup, LauncherGroup,
@@ -24,7 +23,6 @@ type LauncherGroupListProps = {
page: number; page: number;
pageSize: number; pageSize: number;
}; };
resourcesByGroupKey: Record<string, LauncherGroupResources>;
onClearFilters?: () => void; onClearFilters?: () => void;
onResourceSelect?: (resource: LauncherResource) => void; onResourceSelect?: (resource: LauncherResource) => void;
}; };
@@ -43,7 +41,6 @@ export function LauncherGroupList({
config, config,
initialGroups, initialGroups,
groupsPagination, groupsPagination,
resourcesByGroupKey,
onClearFilters, onClearFilters,
onResourceSelect onResourceSelect
}: LauncherGroupListProps) { }: LauncherGroupListProps) {
@@ -128,22 +125,16 @@ export function LauncherGroupList({
return ( return (
<div className="flex flex-col gap-2.5"> <div className="flex flex-col gap-2.5">
{groups.map((group) => { {groups.map((group) => (
const groupResources = resourcesByGroupKey[group.groupKey]; <LauncherGroupSection
key={group.groupKey}
return ( orgId={orgId}
<LauncherGroupSection activeViewId={activeViewId}
key={group.groupKey} group={group}
orgId={orgId} config={config}
activeViewId={activeViewId} onResourceSelect={onResourceSelect}
group={group} />
config={config} ))}
initialResources={groupResources?.resources}
initialResourcesPagination={groupResources?.pagination}
onResourceSelect={onResourceSelect}
/>
);
})}
<div ref={loadMoreRef} className="h-4" /> <div ref={loadMoreRef} className="h-4" />
{isFetchingNextPage ? ( {isFetchingNextPage ? (
<div className="flex justify-center py-2"> <div className="flex justify-center py-2">

View File

@@ -20,7 +20,6 @@ import {
writeLauncherLastView, writeLauncherLastView,
type LauncherActiveViewId type LauncherActiveViewId
} from "@app/lib/launcherLocalStorage"; } from "@app/lib/launcherLocalStorage";
import type { LauncherGroupResources } from "@app/lib/launcherServerData";
import { import {
buildLauncherPath, buildLauncherPath,
getLauncherUrlBaseConfig, getLauncherUrlBaseConfig,
@@ -73,7 +72,6 @@ type ResourceLauncherProps = {
page: number; page: number;
pageSize: number; pageSize: number;
}; };
resourcesByGroupKey: Record<string, LauncherGroupResources>;
}; };
export default function ResourceLauncher({ export default function ResourceLauncher({
@@ -84,8 +82,7 @@ export default function ResourceLauncher({
config, config,
savedConfig, savedConfig,
groups, groups,
groupsPagination, groupsPagination
resourcesByGroupKey
}: ResourceLauncherProps) { }: ResourceLauncherProps) {
const t = useTranslations(); const t = useTranslations();
const { toast } = useToast(); const { toast } = useToast();
@@ -511,7 +508,6 @@ export default function ResourceLauncher({
config={config} config={config}
initialGroups={groups} initialGroups={groups}
groupsPagination={groupsPagination} groupsPagination={groupsPagination}
resourcesByGroupKey={resourcesByGroupKey}
onClearFilters={handleClearFilters} onClearFilters={handleClearFilters}
/> />

View File

@@ -4,24 +4,13 @@ import { resolveLauncherStateFromUrl } from "@app/lib/launcherUrlState";
import { buildLauncherSearchParams } from "@app/lib/launcherSearchParams"; import { buildLauncherSearchParams } from "@app/lib/launcherSearchParams";
import type { import type {
LauncherGroup, LauncherGroup,
LauncherResource,
LauncherViewConfig, LauncherViewConfig,
LauncherViewRecord, LauncherViewRecord,
ListLauncherGroupsResponse, ListLauncherGroupsResponse,
ListLauncherResourcesResponse,
ListLauncherViewsResponse ListLauncherViewsResponse
} from "@server/routers/launcher/types"; } from "@server/routers/launcher/types";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
export type LauncherGroupResources = {
resources: LauncherResource[];
pagination: {
total: number;
page: number;
pageSize: number;
};
};
export type LauncherPageData = { export type LauncherPageData = {
views: LauncherViewRecord[]; views: LauncherViewRecord[];
activeViewId: LauncherActiveViewId; activeViewId: LauncherActiveViewId;
@@ -33,12 +22,6 @@ export type LauncherPageData = {
page: number; page: number;
pageSize: number; pageSize: number;
}; };
resourcesByGroupKey: Record<string, LauncherGroupResources>;
};
const emptyResources: LauncherGroupResources = {
resources: [],
pagination: { total: 0, page: 1, pageSize: 20 }
}; };
export async function fetchLauncherPageData( export async function fetchLauncherPageData(
@@ -88,41 +71,12 @@ export async function fetchLauncherPageData(
groupsPagination = groupsRes.data.data.pagination; groupsPagination = groupsRes.data.data.pagination;
} catch (e) {} } 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 { return {
views, views,
activeViewId, activeViewId,
config, config,
savedConfig, savedConfig,
groups, groups,
groupsPagination, groupsPagination
resourcesByGroupKey
}; };
} }