Skip to content

Commit

Permalink
Docs: SonarCloud Regulation Changes on Table Component
Browse files Browse the repository at this point in the history
  • Loading branch information
FAUSTMANNSTEF committed Nov 29, 2024
1 parent 5b3e37e commit b34a587
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
8 changes: 6 additions & 2 deletions src/app/utils/formatLocale.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const locale = "en-US";

export function formatLocale(value: number | bigint): string {
if (!value) return "";
if (!value) {
return "";
}
return `US$ ${Number(value)
.toLocaleString(locale, {
style: "currency",
Expand All @@ -13,6 +15,8 @@ export function formatLocale(value: number | bigint): string {
}

export function formatLocaleN(value: number | bigint): string {
if (!value) return "0";
if (!value) {
return "0";
}
return Number(value).toLocaleString(locale);
}
30 changes: 18 additions & 12 deletions src/components/tables/mui-datagrid/datagrid.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import myDataGrid from "./datagrid";
import { GridToolbarContainer, GridToolbarQuickFilter } from "@mui/x-data-grid";
import { columns, rows } from "./data";

// Add at the top of datagrid.stories.tsx
const BORDER_STYLES = {
RED: "2px solid red",
BLUE: "2px solid blue",
} as const;

// Custom toolbar component for the DataGrid
const CustomToolbar = () => (
<GridToolbarContainer>
Expand Down Expand Up @@ -60,8 +66,8 @@ export const DefaultDataGrid: Story = {
columnHeaderTitleColor: "#333",
rowHoverBackground: "#f0f0f0",
cellFontSize: "14px",
cellFocusOutline: "2px solid blue",
cellActiveOutline: "2px solid red",
cellFocusOutline: BORDER_STYLES.BLUE,
cellActiveOutline: BORDER_STYLES.RED,
},
sx: {
backgroundColor: "#f0f0f0",
Expand All @@ -84,8 +90,8 @@ export const DataGridWithCustomToolbar: Story = {
columnHeaderTitleColor: "#333",
rowHoverBackground: "#f0f0f0",
cellFontSize: "14px",
cellFocusOutline: "2px solid blue",
cellActiveOutline: "2px solid red",
cellFocusOutline: BORDER_STYLES.BLUE,
cellActiveOutline: BORDER_STYLES.RED,
},
sx: {
backgroundColor: "#f0f0f0",
Expand Down Expand Up @@ -122,8 +128,8 @@ export const DataGridWithCheckboxSelection: Story = {
columnHeaderTitleColor: "#333",
rowHoverBackground: "#f0f0f0",
cellFontSize: "14px",
cellFocusOutline: "2px solid blue",
cellActiveOutline: "2px solid red",
cellFocusOutline: BORDER_STYLES.BLUE,
cellActiveOutline: BORDER_STYLES.RED,
},
sx: {
backgroundColor: "#f0f0f0",
Expand All @@ -147,8 +153,8 @@ export const DataGridWithPagination: Story = {
columnHeaderTitleColor: "#333",
rowHoverBackground: "#f0f0f0",
cellFontSize: "14px",
cellFocusOutline: "2px solid blue",
cellActiveOutline: "2px solid red",
cellFocusOutline: BORDER_STYLES.BLUE,
cellActiveOutline: BORDER_STYLES.RED,
},
sx: {
backgroundColor: "#f0f0f0",
Expand All @@ -173,8 +179,8 @@ export const DataGridWithSorting: Story = {
columnHeaderTitleColor: "#333",
rowHoverBackground: "#f0f0f0",
cellFontSize: "14px",
cellFocusOutline: "2px solid blue",
cellActiveOutline: "2px solid red",
cellFocusOutline: BORDER_STYLES.BLUE,
cellActiveOutline: BORDER_STYLES.RED,
},
sx: {
backgroundColor: "#f0f0f0",
Expand All @@ -200,8 +206,8 @@ export const DataGridWithFiltering: Story = {
columnHeaderTitleColor: "#333",
rowHoverBackground: "#f0f0f0",
cellFontSize: "14px",
cellFocusOutline: "2px solid blue",
cellActiveOutline: "2px solid red",
cellFocusOutline: BORDER_STYLES.BLUE,
cellActiveOutline: BORDER_STYLES.RED,
},
sx: {
backgroundColor: "#f0f0f0",
Expand Down
8 changes: 6 additions & 2 deletions src/components/tables/mui-tables/tables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export default function MyTable({
// Handle page change
const handlePageChange = (event: unknown, newPage: number) => {
setCurrentPage(newPage);
if (onPageChange) onPageChange(newPage);
if (onPageChange) {
onPageChange(newPage);
}
};
// Handle rows per page change
const handleRowsPerPageChange = (
Expand All @@ -148,7 +150,9 @@ export default function MyTable({
const direction = isAsc ? "desc" : "asc";
setCurrentSortKey(columnId);
setCurrentSortDirection(direction);
if (onSortChange) onSortChange(columnId, direction);
if (onSortChange) {
onSortChange(columnId, direction);
}
};

const sortedData = React.useMemo(() => {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/formatFinancialValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export function formatFinancialValue(
value: number | bigint,
noCurrency?: boolean
): string {
if (!value) return `${!noCurrency ? "US$ " : ""}0`;
if (!value) {
return `${!noCurrency ? "US$ " : ""}0`;
}
return `${!noCurrency ? "US$ " : ""}${value.toLocaleString("en-US", {
minimumFractionDigits: 0,
maximumFractionDigits: 0,
Expand Down

0 comments on commit b34a587

Please sign in to comment.