@bsol-oss/react-datatable5 9.1.0 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -433,9 +433,10 @@ interface GetColumnsConfigs<K extends RowData> {
433
433
  [key in K as string]?: object;
434
434
  };
435
435
  defaultWidth?: number;
436
+ translate?: UseTranslationResponse<any, any>;
436
437
  }
437
438
  declare const widthSanityCheck: <K extends unknown>(widthList: number[], ignoreList: K[], properties: { [key in K as string]?: object | undefined; }) => void;
438
- declare const getColumns: <TData extends unknown>({ schema, ignore, width, meta, defaultWidth, }: GetColumnsConfigs<TData>) => ColumnDef<TData>[];
439
+ declare const getColumns: <TData extends unknown>({ schema, ignore, width, meta, defaultWidth, translate, }: GetColumnsConfigs<TData>) => ColumnDef<TData>[];
439
440
 
440
441
  interface EmptyStateProps {
441
442
  title?: string;
@@ -537,8 +538,10 @@ interface RangeDatePickerProps extends Props, RangeCalendarProps {
537
538
  interface RecordDisplayProps {
538
539
  object: object | null;
539
540
  boxProps?: BoxProps;
541
+ translate?: UseTranslationResponse<any, any>;
542
+ prefix?: string;
540
543
  }
541
- declare const RecordDisplay: ({ object, boxProps }: RecordDisplayProps) => react_jsx_runtime.JSX.Element;
544
+ declare const RecordDisplay: ({ object, boxProps, translate, prefix, }: RecordDisplayProps) => react_jsx_runtime.JSX.Element;
542
545
 
543
546
  declare module "@tanstack/react-table" {
544
547
  interface ColumnMeta<TData extends RowData, TValue> {
package/dist/index.js CHANGED
@@ -2606,12 +2606,18 @@ const snakeToLabel = (str) => {
2606
2606
  .join(" "); // Join with space
2607
2607
  };
2608
2608
 
2609
- const RecordDisplay = ({ object, boxProps }) => {
2609
+ const RecordDisplay = ({ object, boxProps, translate, prefix = "", }) => {
2610
+ const getColumn = ({ field }) => {
2611
+ if (translate !== undefined) {
2612
+ return translate.t(`${prefix}${field}`);
2613
+ }
2614
+ return snakeToLabel(field);
2615
+ };
2610
2616
  if (object === null) {
2611
2617
  return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "null" });
2612
2618
  }
2613
2619
  return (jsxRuntime.jsx(react.Grid, { rowGap: 1, padding: 1, overflow: "auto", ...boxProps, children: Object.entries(object).map(([field, value]) => {
2614
- return (jsxRuntime.jsxs(react.Grid, { columnGap: 2, gridTemplateColumns: "auto 1fr", children: [jsxRuntime.jsx(react.Text, { color: "gray.400", children: snakeToLabel(field) }), typeof value === "object" ? (jsxRuntime.jsx(RecordDisplay, { object: value })) : (jsxRuntime.jsx(react.Text, { children: JSON.stringify(value) }))] }, field));
2620
+ return (jsxRuntime.jsxs(react.Grid, { columnGap: 2, gridTemplateColumns: "auto 1fr", children: [jsxRuntime.jsx(react.Text, { color: "gray.400", children: getColumn({ field }) }), typeof value === "object" ? (jsxRuntime.jsx(RecordDisplay, { object: value, prefix: `${prefix}${field}.`, translate: translate })) : (jsxRuntime.jsx(react.Text, { children: JSON.stringify(value) }))] }, field));
2615
2621
  }) }));
2616
2622
  };
2617
2623
 
@@ -3481,11 +3487,17 @@ const widthSanityCheck = (widthList, ignoreList, properties) => {
3481
3487
  throw new Error(`The width list is too long given from the number of remaining properties after ignore some.`);
3482
3488
  }
3483
3489
  };
3484
- const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth = 400, }) => {
3490
+ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth = 400, translate, }) => {
3485
3491
  const { properties } = schema;
3486
3492
  idListSanityCheck("ignore", ignore, properties);
3487
3493
  widthSanityCheck(width, ignore, properties);
3488
3494
  idListSanityCheck("meta", Object.keys(meta), properties);
3495
+ const getColumn = ({ column }) => {
3496
+ if (translate !== undefined) {
3497
+ return translate.t(`${column}`);
3498
+ }
3499
+ return snakeToLabel(column);
3500
+ };
3489
3501
  const keys = Object.keys(properties);
3490
3502
  const ignored = keys.filter((key) => {
3491
3503
  return !ignore.some((shouldIgnoreKey) => key === shouldIgnoreKey);
@@ -3499,18 +3511,18 @@ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth =
3499
3511
  // @ts-expect-error find type for unknown
3500
3512
  const value = props.row.original[column];
3501
3513
  if (typeof value === "object") {
3502
- return (jsxRuntime.jsx(react.Grid, { overflow: "auto", children: jsxRuntime.jsx(RecordDisplay, { object: value }) }));
3514
+ return (jsxRuntime.jsx(react.Grid, { overflow: "auto", children: jsxRuntime.jsx(RecordDisplay, { object: value, translate }) }));
3503
3515
  }
3504
3516
  return jsxRuntime.jsx(TextCell, { children: value });
3505
3517
  },
3506
3518
  header: (columnHeader) => {
3507
3519
  const displayName = columnHeader.column.columnDef.meta?.displayName ??
3508
- snakeToLabel(column);
3520
+ getColumn({ column });
3509
3521
  return jsxRuntime.jsx("span", { children: displayName });
3510
3522
  },
3511
3523
  footer: (columnFooter) => {
3512
3524
  const displayName = columnFooter.column.columnDef.meta?.displayName ??
3513
- snakeToLabel(column);
3525
+ getColumn({ column });
3514
3526
  return jsxRuntime.jsx("span", { children: displayName });
3515
3527
  },
3516
3528
  size: width[index] ?? defaultWidth,
package/dist/index.mjs CHANGED
@@ -2586,12 +2586,18 @@ const snakeToLabel = (str) => {
2586
2586
  .join(" "); // Join with space
2587
2587
  };
2588
2588
 
2589
- const RecordDisplay = ({ object, boxProps }) => {
2589
+ const RecordDisplay = ({ object, boxProps, translate, prefix = "", }) => {
2590
+ const getColumn = ({ field }) => {
2591
+ if (translate !== undefined) {
2592
+ return translate.t(`${prefix}${field}`);
2593
+ }
2594
+ return snakeToLabel(field);
2595
+ };
2590
2596
  if (object === null) {
2591
2597
  return jsx(Fragment, { children: "null" });
2592
2598
  }
2593
2599
  return (jsx(Grid, { rowGap: 1, padding: 1, overflow: "auto", ...boxProps, children: Object.entries(object).map(([field, value]) => {
2594
- return (jsxs(Grid, { columnGap: 2, gridTemplateColumns: "auto 1fr", children: [jsx(Text, { color: "gray.400", children: snakeToLabel(field) }), typeof value === "object" ? (jsx(RecordDisplay, { object: value })) : (jsx(Text, { children: JSON.stringify(value) }))] }, field));
2600
+ return (jsxs(Grid, { columnGap: 2, gridTemplateColumns: "auto 1fr", children: [jsx(Text, { color: "gray.400", children: getColumn({ field }) }), typeof value === "object" ? (jsx(RecordDisplay, { object: value, prefix: `${prefix}${field}.`, translate: translate })) : (jsx(Text, { children: JSON.stringify(value) }))] }, field));
2595
2601
  }) }));
2596
2602
  };
2597
2603
 
@@ -3461,11 +3467,17 @@ const widthSanityCheck = (widthList, ignoreList, properties) => {
3461
3467
  throw new Error(`The width list is too long given from the number of remaining properties after ignore some.`);
3462
3468
  }
3463
3469
  };
3464
- const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth = 400, }) => {
3470
+ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth = 400, translate, }) => {
3465
3471
  const { properties } = schema;
3466
3472
  idListSanityCheck("ignore", ignore, properties);
3467
3473
  widthSanityCheck(width, ignore, properties);
3468
3474
  idListSanityCheck("meta", Object.keys(meta), properties);
3475
+ const getColumn = ({ column }) => {
3476
+ if (translate !== undefined) {
3477
+ return translate.t(`${column}`);
3478
+ }
3479
+ return snakeToLabel(column);
3480
+ };
3469
3481
  const keys = Object.keys(properties);
3470
3482
  const ignored = keys.filter((key) => {
3471
3483
  return !ignore.some((shouldIgnoreKey) => key === shouldIgnoreKey);
@@ -3479,18 +3491,18 @@ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth =
3479
3491
  // @ts-expect-error find type for unknown
3480
3492
  const value = props.row.original[column];
3481
3493
  if (typeof value === "object") {
3482
- return (jsx(Grid, { overflow: "auto", children: jsx(RecordDisplay, { object: value }) }));
3494
+ return (jsx(Grid, { overflow: "auto", children: jsx(RecordDisplay, { object: value, translate }) }));
3483
3495
  }
3484
3496
  return jsx(TextCell, { children: value });
3485
3497
  },
3486
3498
  header: (columnHeader) => {
3487
3499
  const displayName = columnHeader.column.columnDef.meta?.displayName ??
3488
- snakeToLabel(column);
3500
+ getColumn({ column });
3489
3501
  return jsx("span", { children: displayName });
3490
3502
  },
3491
3503
  footer: (columnFooter) => {
3492
3504
  const displayName = columnFooter.column.columnDef.meta?.displayName ??
3493
- snakeToLabel(column);
3505
+ getColumn({ column });
3494
3506
  return jsx("span", { children: displayName });
3495
3507
  },
3496
3508
  size: width[index] ?? defaultWidth,
@@ -1,6 +1,9 @@
1
1
  import { BoxProps } from "@chakra-ui/react";
2
+ import { UseTranslationResponse } from "react-i18next";
2
3
  export interface RecordDisplayProps {
3
4
  object: object | null;
4
5
  boxProps?: BoxProps;
6
+ translate?: UseTranslationResponse<any, any>;
7
+ prefix?: string;
5
8
  }
6
- export declare const RecordDisplay: ({ object, boxProps }: RecordDisplayProps) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const RecordDisplay: ({ object, boxProps, translate, prefix, }: RecordDisplayProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,6 @@
1
1
  import { ColumnDef, RowData } from "@tanstack/react-table";
2
2
  import { JSONSchema7 } from "json-schema";
3
+ import { UseTranslationResponse } from "react-i18next";
3
4
  export interface GetColumnsConfigs<K extends RowData> {
4
5
  schema: JSONSchema7;
5
6
  ignore?: K[];
@@ -8,6 +9,7 @@ export interface GetColumnsConfigs<K extends RowData> {
8
9
  [key in K as string]?: object;
9
10
  };
10
11
  defaultWidth?: number;
12
+ translate?: UseTranslationResponse<any, any>;
11
13
  }
12
14
  export declare const widthSanityCheck: <K extends unknown>(widthList: number[], ignoreList: K[], properties: { [key in K as string]?: object | undefined; }) => void;
13
- export declare const getColumns: <TData extends unknown>({ schema, ignore, width, meta, defaultWidth, }: GetColumnsConfigs<TData>) => ColumnDef<TData>[];
15
+ export declare const getColumns: <TData extends unknown>({ schema, ignore, width, meta, defaultWidth, translate, }: GetColumnsConfigs<TData>) => ColumnDef<TData>[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsol-oss/react-datatable5",
3
- "version": "9.1.0",
3
+ "version": "9.2.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",