-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: table2 refactor + breadcrumb + linting
- Loading branch information
1 parent
9e70782
commit ae967c1
Showing
6 changed files
with
155 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { TextField } from "@mui/material"; | ||
import { Dropdown } from "@/components/design_system/dropdown/Dropdown"; | ||
import { ColumnDefinition, BaseEntity, SelectOption } from "./types"; | ||
|
||
export function renderTableInput<T extends BaseEntity>( | ||
column: ColumnDefinition<T>, | ||
value: T[keyof T] | undefined, | ||
onChange: (value: T[keyof T]) => void | ||
): React.ReactNode { | ||
switch (column.type) { | ||
case "text": | ||
return ( | ||
<TextField | ||
size="small" | ||
label={column.label} | ||
value={(value as string) || ""} | ||
onChange={(e) => onChange(e.target.value as T[keyof T])} | ||
/> | ||
); | ||
case "number": | ||
return ( | ||
<TextField | ||
size="small" | ||
type="number" | ||
label={column.label} | ||
value={(value as number) || ""} | ||
onChange={(e) => onChange(Number(e.target.value) as T[keyof T])} | ||
/> | ||
); | ||
case "select": | ||
return ( | ||
<Dropdown | ||
itemList={column.options as SelectOption[]} | ||
selectedOption={(value as string) || ""} | ||
setSelectedOption={(newValue) => onChange(newValue as T[keyof T])} | ||
label={column.label} | ||
/> | ||
); | ||
default: | ||
return String(value || ""); | ||
} | ||
} | ||
|
||
export function renderTableCell<T extends BaseEntity>( | ||
column: ColumnDefinition<T>, | ||
value: T[keyof T] | ||
): React.ReactNode { | ||
if (column.customRender) { | ||
return column.customRender(value); | ||
} | ||
|
||
switch (column.type) { | ||
case "select": | ||
return ( | ||
column.options?.find((opt) => opt.value === value)?.label || | ||
String(value) | ||
); | ||
case "date": | ||
return value instanceof Date ? value.toLocaleDateString() : String(value); | ||
default: | ||
return String(value || ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export type ColumnType = "text" | "number" | "select" | "date"; | ||
|
||
export interface BaseEntity { | ||
id?: string | number; | ||
first_name: string; | ||
last_name: string; | ||
email: string; | ||
[key: string]: string | number | Date | undefined; | ||
} | ||
|
||
export interface SelectOption { | ||
value: string; | ||
label: string; | ||
} | ||
|
||
export interface ColumnDefinition<T extends BaseEntity> { | ||
id: keyof T; | ||
label: string; | ||
type: ColumnType; | ||
options?: SelectOption[]; | ||
validation?: (value: T[keyof T]) => boolean; | ||
customRender?: (value: T[keyof T]) => React.ReactNode; | ||
} | ||
|
||
export interface TableProps<T extends BaseEntity> { | ||
data: T[]; | ||
columns: ColumnDefinition<T>[]; | ||
type: string; | ||
onRowClick?: (row: T) => void; | ||
page?: number; | ||
totalPages?: number; | ||
onPageChange?: (page: number) => void; | ||
sortBy: keyof T; | ||
sortOrder: "asc" | "desc"; | ||
onSort: (sortBy: keyof T, sortOrder: "asc" | "desc") => void; | ||
onSearch?: (search: string) => void; | ||
searchTerm?: string; | ||
onAdd?: (data: Omit<T, "id">) => Promise<void>; | ||
showAddRow?: boolean; | ||
} |
File renamed without changes.
Oops, something went wrong.