Skip to content

Commit 0aafd6f

Browse files
committed
fixup! geturl
1 parent 5891000 commit 0aafd6f

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

src/components/JobList/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ type JobListProps = {
225225
}
226226

227227
export default function JobList({ sortMode }: JobListProps) {
228-
const run: Run = useData();
228+
const data_: Run = useData();
229229
const options = useDefaultTableOptions<Job>();
230230
const data = useMemo(() => {
231-
return (run?.jobs || []).filter(item => {
231+
return (data_?.jobs || []).filter(item => {
232232
item.id = String(item.job_id);
233233
return !! item.id;
234234
});
235-
}, [run, sortMode]);
235+
}, [data_, sortMode]);
236236
const table = useMaterialReactTable({
237237
...options,
238238
columns,

src/components/RunList/index.tsx

+9-24
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import {
1616
import { type Theme } from "@mui/material/styles";
1717
import { parse } from "date-fns";
1818

19-
import { formatDate, formatDay, formatDuration } from "../../lib/utils";
19+
import {
20+
formatDate,
21+
formatDuration,
22+
getUrl,
23+
} from "../../lib/utils";
2024
import IconLink from "../../components/IconLink";
2125
import type {
2226
Run,
@@ -27,15 +31,12 @@ import {
2731
RunResultKeys,
2832
RunStatuses,
2933
} from "../../lib/paddles.d";
34+
import {
35+
DEFAULT_PAGE_SIZE
36+
} from "#src/lib/paddles";
3037
import useDefaultTableOptions from "../../lib/table";
3138

3239

33-
const DEFAULT_PAGE_SIZE = 25;
34-
const NON_FILTER_PARAMS = [
35-
"page",
36-
"pageSize",
37-
];
38-
3940
const _columns: MRT_ColumnDef<Run>[] = [
4041
{
4142
accessorKey: "name",
@@ -191,22 +192,6 @@ type RunListProps = {
191192
tableOptions?: Partial<MRT_TableOptions<Run>>;
192193
}
193194

194-
function getUrl(path: string, filters: MRT_ColumnFiltersState, pagination: MRT_PaginationState) {
195-
const newUrl = new URL(path, window.location.origin);
196-
filters.forEach(item => {
197-
if ( ! item.id ) return;
198-
if ( item.value instanceof Function ) return;
199-
if ( item.value instanceof Date ) {
200-
newUrl.searchParams.set("date", formatDay(item.value));
201-
} else {
202-
newUrl.searchParams.set(String(item.id), String(item.value));
203-
}
204-
});
205-
if ( pagination.pageIndex ) newUrl.searchParams.set("page", String(pagination.pageIndex));
206-
if ( pagination.pageSize != DEFAULT_PAGE_SIZE ) newUrl.searchParams.set("pageSize", String(pagination.pageSize));
207-
return newUrl;
208-
}
209-
210195
export default function RunList(props: RunListProps) {
211196
const context = usePageContext();
212197
const { params, tableOptions } = props;
@@ -215,7 +200,7 @@ export default function RunList(props: RunListProps) {
215200
const columnFilters: MRT_ColumnFiltersState = [];
216201
Object.entries(debouncedParams).forEach(param => {
217202
const [id, value] = param;
218-
if ( NON_FILTER_PARAMS.includes(id) ) return;
203+
if ( ["page", "pageSize"].includes(id) ) return;
219204
if ( id === "date" && !!value ) {
220205
columnFilters.push({
221206
id: "scheduled",

src/lib/paddles.ts

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import type {
1313
const PADDLES_SERVER =
1414
import.meta.env.VITE_PADDLES_SERVER || "https://paddles.front.sepia.ceph.com";
1515

16+
// for queries which mention 'page', use this default page size if another is not specified.
17+
const DEFAULT_PAGE_SIZE = 25;
18+
1619
async function queryFn (params: QueryOptions) {
1720
const queryKey = params.queryKey as [string, { url: string}];
1821
return axios.get(queryKey[1].url).then((resp) => resp.data);
@@ -42,6 +45,9 @@ function getURL(endpoint: string, params?: Record<string, string>) {
4245
url.pathname += `/${key}/${value}/`;
4346
}
4447
});
48+
if ( ! url.searchParams.get("pageSize") ) {
49+
url.searchParams.set("count", String(DEFAULT_PAGE_SIZE));
50+
};
4551
return url;
4652
}
4753

@@ -232,6 +238,7 @@ function useStatuses() {
232238
}
233239

234240
export {
241+
DEFAULT_PAGE_SIZE,
235242
getURL,
236243
queryFn,
237244
useBranches,

0 commit comments

Comments
 (0)