Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad committed Nov 29, 2023
1 parent a284ad3 commit 110b3ec
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
13 changes: 9 additions & 4 deletions src/components/Table/LGFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ type TreeSelectFilterProps = {
tData: TreeDataEntry[];
};

/*
* @deprecated Use react-table's onColumnFiltersChange prop.
*/
export const getColumnTreeSelectFilterProps = ({
"data-cy": dataCy,
onConfirm = () => {},
Expand Down Expand Up @@ -52,13 +55,14 @@ export const getColumnTreeSelectFilterProps = ({
type InputFilterProps = {
"data-cy"?: string;
onConfirm?: ({ id, value }: { id: string; value: string }) => void;
placeholder?: string;
};

/*
* @deprecated Use react-table's onColumnFiltersChange prop.
*/
export const getColumnInputFilterProps = ({
"data-cy": dataCy,
onConfirm = () => {},
placeholder,
}: InputFilterProps) => ({
enableColumnFilter: false,
meta: {
Expand All @@ -69,7 +73,6 @@ export const getColumnInputFilterProps = ({
column.setFilterValue(newValue);
onConfirm({ id: column.id, value: newValue });
}}
placeholder={placeholder}
value={column?.getFilterValue() ?? ""}
/>
),
Expand All @@ -94,6 +97,9 @@ type SortProps = {
onToggle?: ({ id, value }: { id: string; value: string }) => void;
};

/*
* @deprecated Use react-table's onSortingChange prop.
*/
export const getColumnSortProps = ({
"data-cy": dataCy,
onToggle = () => {},
Expand All @@ -102,7 +108,6 @@ export const getColumnSortProps = ({
sortComponent: ({ column }) => (
<TableSortIcon
data-cy={dataCy}
key={column.id}
onToggle={(newValue) => {
column.toggleSorting();
onToggle({ id: column.id, value: newValue });
Expand Down
16 changes: 8 additions & 8 deletions src/components/Table/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { OnChangeFn } from "@tanstack/react-table";

export enum TableQueryParams {
Limit = "limit",
Page = "page",
SortBy = "sortBy",
SortDir = "sortDir",
Sorts = "sorts",
}

/**
* `onChangeHandler` simplifies applying a side effect with one of react-table's callback functions (e.g. onColumnFiltersChange, onSortingChange).
* @param setState - state updater as returned by a React useState hook.
Expand All @@ -18,11 +26,3 @@ export const onChangeHandler = <T>(
return updatedState;
});
}) satisfies OnChangeFn<T>;

export enum TableQueryParams {
Limit = "limit",
Page = "page",
SortBy = "sortBy",
SortDir = "sortDir",
Sorts = "sorts",
}
1 change: 0 additions & 1 deletion src/components/TablePopover/TableSortIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const TableSortIcon: React.FC<TableSortIconProps> = ({
} else {
update = undefined;
}
console.log(value, update);
onToggle(update);
};

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useTableSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useTableSort = ({
nextQueryParams[TableQueryParams.SortDir] = undefined;
nextQueryParams[TableQueryParams.SortBy] = undefined;
} else {
// TODO: For other tables that support multi-sort, we should be able to update this to handle a sorter array with more than one entry.
// TODO: For tables that support multi-sort, we should be able to update this to handle a sorter array with more than one entry.
const { desc, id } = Array.isArray(sorter) ? sorter[0] : sorter;
nextQueryParams[TableQueryParams.SortDir] = desc
? SortDirection.Desc
Expand Down
21 changes: 9 additions & 12 deletions src/types/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,18 @@ export enum HostsTableFilterParams {
Statuses = "statuses",
}

export const mapQueryParamToId: Record<HostsTableFilterParams, HostSortBy> = {
[HostsTableFilterParams.HostId]: HostSortBy.Id,
[HostsTableFilterParams.DistroId]: HostSortBy.Distro,
[HostsTableFilterParams.Statuses]: HostSortBy.Status,
[HostsTableFilterParams.CurrentTaskId]: HostSortBy.CurrentTask,
[HostsTableFilterParams.StartedBy]: HostSortBy.Owner,
} as const;

export const mapIdToFilterParam: PartialRecord<
HostSortBy,
keyof HostsQueryVariables
> = {
[HostSortBy.Id]: HostsTableFilterParams.HostId,
[HostSortBy.Distro]: HostsTableFilterParams.DistroId,
[HostSortBy.Status]: HostsTableFilterParams.Statuses,
[HostSortBy.CurrentTask]: HostsTableFilterParams.CurrentTaskId,
[HostSortBy.Owner]: HostsTableFilterParams.StartedBy,
} as const;

export const mapQueryParamToId: PartialRecord<
keyof HostsQueryVariables,
HostSortBy
> = Object.entries(mapIdToFilterParam).reduce(
> = Object.entries(mapQueryParamToId).reduce(
(obj, [id, param]) => ({
...obj,
[param]: id,
Expand Down

0 comments on commit 110b3ec

Please sign in to comment.