Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Columns and Tag to tsx #1807

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Checkbox as Check } from "./ui/checkbox";

type checkbox = {
toggle: boolean;
text: string;
text?: string;
color?: string;
onClick?: () => void;
};
Expand Down
15 changes: 0 additions & 15 deletions src/components/admin/Tag.jsx

This file was deleted.

31 changes: 31 additions & 0 deletions src/components/admin/Tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { StatusMapping } from "@/data/Statuses";

type color = {
background: string;
text: string;
hover: string;
};

type props = {
color: color;
text: string;
onClick?: () => void;
classes?: string;
statuses?: StatusMapping;
};

const Tag = ({ color, text, onClick, classes, statuses }: props) => {
return (
<div
data-cy={`${text}-tag`}
className={`${classes} ${color.background} ${color.text} ${
onClick && `hover:cursor-pointer ${color.hover}`
} m-0 w-fit whitespace-nowrap rounded px-2 py-0.5 text-xs md:text-sm`}
onClick={onClick}
>
{isNaN(Number(text)) ? text : statuses?.[text as keyof StatusMapping]}
</div>
);
};

export default Tag;
4 changes: 3 additions & 1 deletion src/data/Statuses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
type Code = "1" | "0" | "-1";
type Status = "accepted" | "pending" | "rejected";

export const STATUSES: Record<Code, Status> = {
export type StatusMapping = Record<Code, Status>;

export const STATUSES: StatusMapping = {
1: "accepted",
0: "pending",
"-1": "rejected",
Expand Down
54 changes: 0 additions & 54 deletions src/data/admin/Columns.js

This file was deleted.

67 changes: 67 additions & 0 deletions src/data/admin/Columns.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import Tag from "@/components/admin/Tag";
import { COLORS } from "../Tags";
import Checkbox from "@/components/Checkbox";
import { Table, Row } from "@tanstack/react-table";

export const generateSelect = <TData extends object>() => ({
id: "select",
meta: { width: "w-1/12" },
header: ({ table }: { table: Table<TData> }) => (
<Checkbox
toggle={table.getIsAllRowsSelected()}
onClick={() => table.getToggleAllRowsSelectedHandler()}
/>
),
cell: ({ row }: { row: Row<TData> }) => (
<Checkbox
toggle={row.getIsSelected()}
onClick={() => row.getToggleSelectedHandler()}
/>
),
});

type cellProp = {
DannielK marked this conversation as resolved.
Show resolved Hide resolved
getValue: () => string;
};

type stringRecord = Record<string, string>;

export const generateAffiliation = (affiliations: stringRecord) => ({
accessorKey: "affiliation",
header: "Affiliation",
meta: { width: "w-1/12" },
cell: ({ getValue }: cellProp) => (
<Tag
text={affiliations[getValue().toLowerCase()]}
color={COLORS[getValue().toLowerCase() as keyof typeof COLORS]}
/>
),
});

export const generateStatus = (statuses: stringRecord) => ({
accessorKey: "status",
header: "Status",
meta: { width: "w-[10%]" },
enableColumnFilter: true,
filterFn: (row: any, col: any, filter: string[]) => {
const status = row.getValue(col);
return filter.includes(status);
},
cell: ({ getValue }: cellProp) => (
<Tag
text={statuses[getValue()]}
color={COLORS[getValue() as keyof typeof COLORS]}
/>
),
});
export const generateTiers = (tiers: stringRecord) => ({
accessorKey: "tier",
header: "Tier",
meta: { width: "w-1/12" },
cell: ({ getValue }: cellProp) => (
<Tag
text={tiers[getValue()]}
color={COLORS[getValue() as keyof typeof COLORS]}
/>
),
});
Loading