mig-schema-table 2.0.2 → 2.0.3

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.
@@ -1,6 +1,6 @@
1
1
  import { oas31 } from "openapi3-ts";
2
2
  import React, { CSSProperties, Dispatch, SetStateAction } from "react";
3
- import { IColumnConfig } from "../../../types/type";
3
+ import { IColumnConfig } from "../../types";
4
4
  interface IThProps {
5
5
  columnFilters?: {
6
6
  [prop: string]: any;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
- import { uncamel } from "../../../inc/string";
3
+ import { uncamel } from "../../inc/string";
4
4
  import { SELECT_ALL_COLUMN_NAME } from "../constants";
5
5
  const Th = ({ columnFilters, config, isSortable, name, schema, setColumnFilters, setSortAsc, setSortColumn, sortAsc, style, onSelectAllIndexesHandler, isAllChecked, numberOfSelectedRows, }) => {
6
6
  const thDivProps = {
@@ -1 +1,2 @@
1
1
  export declare const SELECT_ALL_COLUMN_NAME = "SELECT_ALL_COLUMN_NAME";
2
+ export declare const SELECT_ALL_COLUMN_WIDTH = 40;
@@ -1 +1,2 @@
1
1
  export const SELECT_ALL_COLUMN_NAME = "SELECT_ALL_COLUMN_NAME";
2
+ export const SELECT_ALL_COLUMN_WIDTH = 40;
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { oas31 } from "openapi3-ts";
3
- import { IColumnConfig, IRenderData } from "../../types/type";
3
+ import { IColumnConfig, IRenderData } from "../types";
4
4
  export interface ISchemaTableComponentProps<T> {
5
5
  config?: {
6
6
  [propName: string]: IColumnConfig<T>;
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import { VariableSizeList, VariableSizeGrid } from "react-window";
4
- import { localeFormat } from "../../inc/date";
5
- import { uncamel } from "../../inc/string";
4
+ import { localeFormat } from "../inc/date";
5
+ import { uncamel } from "../inc/string";
6
6
  import Th from "./Th";
7
- import { SELECT_ALL_COLUMN_NAME } from "./constants";
7
+ import { SELECT_ALL_COLUMN_NAME, SELECT_ALL_COLUMN_WIDTH } from "./constants";
8
8
  export default function SchemaTable(props) {
9
9
  const { config, data, defaultSortColumn, defaultSortAsc = false, Heading = VariableSizeList, isSearchable, isSortable, onRowClick, getRowClassName, getRowSelected, rowHeight = 36, schema, style, customElement, tableTitle, searchPlaceholder, onCheckedIndexesChange, checkedIndexes, } = props;
10
10
  const [sortColumn, setSortColumn] = React.useState(defaultSortColumn);
@@ -105,29 +105,40 @@ export default function SchemaTable(props) {
105
105
  : undefined, [columnNames, config, data, properties]);
106
106
  const gridWidth = props.width;
107
107
  const columnCount = columnNames.length;
108
- const { columnWidths, dynamicWidthColumnCount, fixedWidthColumnsWidth } = React.useMemo(() => {
108
+ const { dynamicWidthColumnCount, fixedWidthColumnsWidth } = React.useMemo(() => {
109
109
  let fixedWidthColumnsWidth = 0;
110
110
  let dynamicWidthColumnCount = 0;
111
111
  columnNames.forEach((propName) => {
112
+ if (propName === SELECT_ALL_COLUMN_NAME) {
113
+ return SELECT_ALL_COLUMN_WIDTH;
114
+ }
112
115
  const propConfig = config ? config[propName] : undefined;
113
116
  if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.width) {
114
- fixedWidthColumnsWidth += propConfig.width;
117
+ fixedWidthColumnsWidth += propConfig.width + 8;
115
118
  }
116
119
  else {
117
120
  dynamicWidthColumnCount += 1;
118
121
  }
119
122
  }, 0);
120
- const dynamicColumnWidth = Math.floor((gridWidth - 16 - fixedWidthColumnsWidth) / dynamicWidthColumnCount);
121
- const columnWidths = columnNames.map((propName) => {
122
- const propConfig = config ? config[propName] : undefined;
123
+ return { dynamicWidthColumnCount, fixedWidthColumnsWidth };
124
+ }, [columnNames, config]);
125
+ const columnWidths = React.useMemo(() => {
126
+ const dynamicColumnWidth = Math.floor((gridWidth - fixedWidthColumnsWidth) / dynamicWidthColumnCount);
127
+ return columnNames.map((propName) => {
123
128
  if (propName === SELECT_ALL_COLUMN_NAME) {
124
- return 50;
129
+ return SELECT_ALL_COLUMN_WIDTH;
125
130
  }
131
+ const propConfig = config ? config[propName] : undefined;
126
132
  return (propConfig === null || propConfig === void 0 ? void 0 : propConfig.width) || dynamicColumnWidth;
127
133
  });
128
- return { columnWidths, dynamicWidthColumnCount, fixedWidthColumnsWidth };
129
- }, [columnNames, config, gridWidth]);
130
- const getColumnWidth = React.useCallback((columnIndex) => columnWidths[columnIndex], [columnWidths]);
134
+ }, [
135
+ columnNames,
136
+ config,
137
+ dynamicWidthColumnCount,
138
+ fixedWidthColumnsWidth,
139
+ gridWidth,
140
+ ]);
141
+ const getColumnWidth = React.useCallback((columnIndex) => (columnWidths ? columnWidths[columnIndex] : 1), [columnWidths]);
131
142
  const filteredRenderData = React.useMemo(() => {
132
143
  let result = renderData;
133
144
  if (!result) {
@@ -295,9 +306,6 @@ export default function SchemaTable(props) {
295
306
  }, []);
296
307
  const getRowHeight = React.useCallback(() => rowHeight, [rowHeight]);
297
308
  const width = dynamicWidthColumnCount ? gridWidth : fixedWidthColumnsWidth;
298
- const totalWidth = React.useMemo(() => columnWidths.reduce((a, b) => {
299
- return a + b;
300
- }, 0), [columnWidths]);
301
309
  const tableBodyHeight = React.useMemo(() => {
302
310
  const defaultHeight = props.height - (isSearchable ? 50 : 0);
303
311
  if (!sortedRenderData) {
@@ -306,5 +314,5 @@ export default function SchemaTable(props) {
306
314
  const dynamicHeight = sortedRenderData.length * rowHeight;
307
315
  return dynamicHeight < defaultHeight ? dynamicHeight : defaultHeight;
308
316
  }, [isSearchable, props.height, rowHeight, sortedRenderData]);
309
- return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: dynamicWidthColumnCount ? gridWidth : fixedWidthColumnsWidth }) }, { children: [_jsx("div", Object.assign({ className: "tableTitle" }, { children: tableTitle })), _jsxs("div", Object.assign({ className: "action-container" }, { children: [_jsx("div", Object.assign({ style: { flex: 1 } }, { children: isSearchable ? (_jsx("input", { id: "input-filter", type: "text", placeholder: searchPlaceholder || "Search...", value: searchQuery, onChange: onSearchChange, autoFocus: true })) : null })), customElement] })), _jsx(Heading, Object.assign({ height: 50, itemCount: columnCount, itemSize: getColumnWidth, layout: "horizontal", width: width, sortAsc: sortAsc, setSortAsc: setSortAsc, setSortColumn: setSortColumn, sortColumn: sortColumn, sortedRenderData: sortedRenderData, className: "schema-table__th-row" }, { children: SchemaTableTh }), `thead_${width}_${sortColumn}_${sortAsc}_${searchQuery}`), _jsx(VariableSizeGrid, Object.assign({ className: "schema-table__tbody", height: tableBodyHeight, width: totalWidth, columnWidth: getColumnWidth, rowHeight: getRowHeight, columnCount: columnCount, rowCount: sortedRenderData ? sortedRenderData.length : 0 }, { children: Td }), `tbody_${width}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`)] })));
317
+ return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: dynamicWidthColumnCount ? gridWidth : fixedWidthColumnsWidth }) }, { children: [_jsx("div", Object.assign({ className: "tableTitle" }, { children: tableTitle })), _jsxs("div", Object.assign({ className: "action-container" }, { children: [_jsx("div", Object.assign({ style: { flex: 1 } }, { children: isSearchable ? (_jsx("input", { id: "input-filter", type: "text", placeholder: searchPlaceholder || "Search...", value: searchQuery, onChange: onSearchChange, autoFocus: true })) : null })), customElement] })), _jsx(Heading, Object.assign({ height: 50, itemCount: columnCount, itemSize: getColumnWidth, layout: "horizontal", width: width, sortAsc: sortAsc, setSortAsc: setSortAsc, setSortColumn: setSortColumn, sortColumn: sortColumn, sortedRenderData: sortedRenderData, className: "schema-table__th-row" }, { children: SchemaTableTh }), `thead_${width}_${sortColumn}_${sortAsc}_${searchQuery}`), _jsx(VariableSizeGrid, Object.assign({ className: "schema-table__tbody", height: tableBodyHeight, width: dynamicWidthColumnCount ? gridWidth : fixedWidthColumnsWidth, columnWidth: getColumnWidth, rowHeight: getRowHeight, columnCount: columnCount, rowCount: sortedRenderData ? sortedRenderData.length : 0 }, { children: Td }), `tbody_${width}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`)] })));
310
318
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import SchemaTable from "./component/SchemaTable";
2
- import { IColumnConfig, IRenderData } from "./types/type";
1
+ import SchemaTable from "./SchemaTable";
2
+ import { IColumnConfig, IRenderData } from "./types.js";
3
3
  export type { IColumnConfig, IRenderData };
4
4
  export { SchemaTable };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import SchemaTable from "./component/SchemaTable";
1
+ import SchemaTable from "./SchemaTable";
2
2
  export { SchemaTable };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/"
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "scripts": {
32
32
  "start": "react-scripts start",
33
- "build": "tsc -p tsconfig.json; sass --no-source-map src/index.scss dist/index.css"
33
+ "build": "tsc -p tsconfig.json; sass --no-source-map src/component/SchemaTable/index.scss dist/index.css"
34
34
  },
35
35
  "eslintConfig": {
36
36
  "extends": [
@@ -1,3 +0,0 @@
1
- import { ReportHandler } from 'web-vitals';
2
- declare const reportWebVitals: (onPerfEntry?: ReportHandler) => void;
3
- export default reportWebVitals;
@@ -1,12 +0,0 @@
1
- const reportWebVitals = (onPerfEntry) => {
2
- if (onPerfEntry && onPerfEntry instanceof Function) {
3
- import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4
- getCLS(onPerfEntry);
5
- getFID(onPerfEntry);
6
- getFCP(onPerfEntry);
7
- getLCP(onPerfEntry);
8
- getTTFB(onPerfEntry);
9
- });
10
- }
11
- };
12
- export default reportWebVitals;
@@ -1 +0,0 @@
1
- import '@testing-library/jest-dom';
@@ -1,5 +0,0 @@
1
- // jest-dom adds custom jest matchers for asserting on DOM nodes.
2
- // allows you to do things like:
3
- // expect(element).toHaveTextContent(/react/i)
4
- // learn more: https://github.com/testing-library/jest-dom
5
- import '@testing-library/jest-dom';
@@ -1,20 +0,0 @@
1
- import React from "react";
2
- export interface IColumnConfig<T> {
3
- align?: "start" | "center" | "end";
4
- defaultSortDesc?: boolean;
5
- hidden?: boolean;
6
- hoverTitle?: string;
7
- isFilterable?: boolean;
8
- renderCell?: (rowData: T, index: number) => React.ReactElement | null;
9
- renderData?: (rowData: T, index: number) => string;
10
- sort?: (a: T, b: T, sortAsc: boolean) => number;
11
- sortByValue?: boolean;
12
- sortable?: boolean;
13
- title?: string | React.ReactElement;
14
- width?: number;
15
- order?: number;
16
- }
17
- export interface IRenderData {
18
- _index: number;
19
- [key: string]: any;
20
- }
@@ -1 +0,0 @@
1
- export {};