♻️ (tableComponent): remove toTitleCase utility function to simplify headerName assignment

💡 (utils.ts): remove unnecessary commas and improve code readability
This commit is contained in:
cristhianzl 2024-06-14 14:30:32 -03:00 • committed by ogabrielluiz
commit bc6304b338
2 changed files with 8 additions and 8 deletions

View file

@ -8,7 +8,7 @@ import {
} from "../../constants/constants"; } from "../../constants/constants";
import { useDarkStore } from "../../stores/darkStore"; import { useDarkStore } from "../../stores/darkStore";
import "../../style/ag-theme-shadcn.css"; // Custom CSS applied to the grid import "../../style/ag-theme-shadcn.css"; // Custom CSS applied to the grid
import { cn, toTitleCase } from "../../utils/utils"; import { cn } from "../../utils/utils";
import ForwardedIconComponent from "../genericIconComponent"; import ForwardedIconComponent from "../genericIconComponent";
import { Alert, AlertDescription, AlertTitle } from "../ui/alert"; import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
import TableOptions from "./components/TableOptions"; import TableOptions from "./components/TableOptions";
@ -35,7 +35,7 @@ const TableComponent = forwardRef<
alertDescription = DEFAULT_TABLE_ALERT_MSG, alertDescription = DEFAULT_TABLE_ALERT_MSG,
...props ...props
}, },
ref, ref
) => { ) => {
let colDef = props.columnDefs.map((col, index) => { let colDef = props.columnDefs.map((col, index) => {
let newCol = { let newCol = {
@ -110,7 +110,7 @@ const TableComponent = forwardRef<
}; };
const onColumnMoved = (params) => { const onColumnMoved = (params) => {
const updatedColumnDefs = makeLastColumnNonResizable( const updatedColumnDefs = makeLastColumnNonResizable(
params.columnApi.getAllGridColumns().map((col) => col.getColDef()), params.columnApi.getAllGridColumns().map((col) => col.getColDef())
); );
params.api.setGridOption("columnDefs", updatedColumnDefs); params.api.setGridOption("columnDefs", updatedColumnDefs);
if (props.onColumnMoved) props.onColumnMoved(params); if (props.onColumnMoved) props.onColumnMoved(params);
@ -134,7 +134,7 @@ const TableComponent = forwardRef<
className={cn( className={cn(
dark ? "ag-theme-quartz-dark" : "ag-theme-quartz", dark ? "ag-theme-quartz-dark" : "ag-theme-quartz",
"ag-theme-shadcn flex h-full flex-col", "ag-theme-shadcn flex h-full flex-col",
"relative", "relative"
)} // applying the grid theme )} // applying the grid theme
> >
<AgGridReact <AgGridReact
@ -152,7 +152,7 @@ const TableComponent = forwardRef<
if (e.sources.some((source) => source.includes("column"))) { if (e.sources.some((source) => source.includes("column"))) {
localStorage.setItem( localStorage.setItem(
storeReference, storeReference,
JSON.stringify(realRef.current?.api?.getColumnState()), JSON.stringify(realRef.current?.api?.getColumnState())
); );
setColumnStateChange(true); setColumnStateChange(true);
} }
@ -175,7 +175,7 @@ const TableComponent = forwardRef<
)} )}
</div> </div>
); );
}, }
); );
export default TableComponent; export default TableComponent;

View file

@ -364,7 +364,7 @@ export function extractColumnsFromRows(
function intersection() { function intersection() {
for (const key in rows[0]) { for (const key in rows[0]) {
columnsKeys[key] = { columnsKeys[key] = {
headerName: toTitleCase(key), headerName: key,
field: key, field: key,
cellRenderer: TableAutoCellRender, cellRenderer: TableAutoCellRender,
filter: true, filter: true,
@ -382,7 +382,7 @@ export function extractColumnsFromRows(
for (const row of rows) { for (const row of rows) {
for (const key in row) { for (const key in row) {
columnsKeys[key] = { columnsKeys[key] = {
headerName: toTitleCase(key), headerName: key,
field: key, field: key,
filter: true, filter: true,
cellRenderer: TableAutoCellRender, cellRenderer: TableAutoCellRender,