@ctlyst.id/internal-ui 2.0.9 → 2.0.10

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,5 +1,5 @@
1
1
  import type { BoxProps, TableBodyProps, TableCellProps, TableColumnHeaderProps, TableHeadProps, TableProps, TableRowProps } from '@chakra-ui/react';
2
- import type { ColumnDef, ColumnSort, RowSelectionInstance, SortingState } from '@tanstack/react-table';
2
+ import type { ColumnDef, RowSelectionInstance, SortingState } from '@tanstack/react-table';
3
3
  import * as React from 'react';
4
4
  export interface TableStyleProps {
5
5
  table?: TableProps;
@@ -16,7 +16,7 @@ export interface DataTableProps<T = unknown> extends BoxProps {
16
16
  isLoading?: boolean;
17
17
  withSelectedRow?: boolean | undefined;
18
18
  onSelectedRow?: (data: T[]) => void;
19
- onSort?: (data: ColumnSort[] | SortingState | ((prevState: SortingState) => SortingState)) => void;
19
+ onSort?: (data: SortingState) => void;
20
20
  manualSorting?: boolean;
21
21
  sortingState?: SortingState;
22
22
  sortDescFirst?: boolean;
@@ -560,48 +560,6 @@ Chips.defaultProps = {
560
560
  size: 'sm'
561
561
  };
562
562
 
563
- const useCombinedRefs = (...refs) => {
564
- const targetRef = React.useRef();
565
- React.useEffect(() => {
566
- refs.forEach(ref => {
567
- /* eslint-disable no-param-reassign */
568
- if (!ref) return;
569
- if (typeof ref === 'function') {
570
- ref(targetRef.current);
571
- } else {
572
- ref.current = targetRef.current;
573
- }
574
- });
575
- }, [refs]);
576
- return targetRef;
577
- };
578
- const IndeterminateCheckbox = /*#__PURE__*/React.forwardRef(({
579
- isIndeterminate,
580
- isChecked,
581
- ...rest
582
- }, ref) => {
583
- const defaultRef = React.useRef(null);
584
- const combinedRef = useCombinedRefs(ref, defaultRef);
585
- React.useEffect(() => {
586
- if (combinedRef !== null && combinedRef !== void 0 && combinedRef.current) {
587
- combinedRef.current.indeterminate = isIndeterminate !== null && isIndeterminate !== void 0 ? isIndeterminate : false;
588
- }
589
- }, [combinedRef, isIndeterminate]);
590
- return /*#__PURE__*/React__default.createElement(react.Checkbox, Object.assign({
591
- ref: combinedRef,
592
- focusBorderColor: "0",
593
- isIndeterminate: isIndeterminate,
594
- isChecked: isChecked,
595
- inputProps: {
596
- 'data-test-id': `CT_component_indeterminate-checkbox_${rest.id || rest.name}`
597
- }
598
- }, rest));
599
- });
600
- IndeterminateCheckbox.displayName = 'IndeterminateCheckbox';
601
- IndeterminateCheckbox.defaultProps = {
602
- isIndeterminate: false
603
- };
604
-
605
563
  /* eslint-disable react-hooks/rules-of-hooks */
606
564
  const DataTable = /*#__PURE__*/React.forwardRef((props, ref) => {
607
565
  const {
@@ -618,6 +576,7 @@ const DataTable = /*#__PURE__*/React.forwardRef((props, ref) => {
618
576
  manualSorting,
619
577
  onRowClick
620
578
  } = props;
579
+ const [isFirstLoad, setIsFirstLoad] = React.useState(true);
621
580
  const [sorting, setSorting] = React.useState(sortingState !== null && sortingState !== void 0 ? sortingState : []);
622
581
  const [rowSelection, onRowSelectionChange] = React.useState({});
623
582
  const dataColumns = React.useMemo(() => columns, [columns]);
@@ -625,20 +584,20 @@ const DataTable = /*#__PURE__*/React.forwardRef((props, ref) => {
625
584
  id: 'select',
626
585
  header: ({
627
586
  table
628
- }) => /*#__PURE__*/React.createElement(IndeterminateCheckbox, Object.assign({
629
- name: "select-header"
587
+ }) => /*#__PURE__*/React.createElement(react.Checkbox, Object.assign({
588
+ "data-test-id": "select-header-data-table"
630
589
  }, {
631
- checked: table.getIsAllRowsSelected(),
632
- indeterminate: table.getIsSomeRowsSelected(),
590
+ isChecked: table.getIsAllRowsSelected(),
591
+ isIndeterminate: table.getIsSomeRowsSelected(),
633
592
  onChange: table.getToggleAllRowsSelectedHandler()
634
593
  })),
635
594
  cell: ({
636
595
  row
637
- }) => /*#__PURE__*/React.createElement(IndeterminateCheckbox, Object.assign({
638
- name: `select-${row.index}`
596
+ }) => /*#__PURE__*/React.createElement(react.Checkbox, Object.assign({
597
+ "data-test-id": `select-data-table-${row.index}`
639
598
  }, {
640
- checked: row.getIsSelected(),
641
- indeterminate: row.getIsSomeSelected(),
599
+ isChecked: row.getIsSelected(),
600
+ isIndeterminate: row.getIsSomeSelected(),
642
601
  onChange: row.getToggleSelectedHandler()
643
602
  }))
644
603
  }], []);
@@ -650,9 +609,6 @@ const DataTable = /*#__PURE__*/React.forwardRef((props, ref) => {
650
609
  };
651
610
  const onSortingChange = data => {
652
611
  setSorting(data);
653
- if (onSort) {
654
- onSort(data);
655
- }
656
612
  };
657
613
  const table = reactTable.useReactTable({
658
614
  data: dataSource,
@@ -685,6 +641,14 @@ const DataTable = /*#__PURE__*/React.forwardRef((props, ref) => {
685
641
  React.useImperativeHandle(ref, () => ({
686
642
  toggleAllRowsSelected
687
643
  }));
644
+ React.useEffect(() => {
645
+ if (onSort && !isFirstLoad) {
646
+ onSort(sorting);
647
+ }
648
+ }, [sorting]);
649
+ React.useEffect(() => {
650
+ setIsFirstLoad(false);
651
+ }, []);
688
652
  return /*#__PURE__*/React.createElement(react.Box, Object.assign({}, props), isLoading && /*#__PURE__*/React.createElement(react.Flex, {
689
653
  w: "100%",
690
654
  h: "100%",
@@ -738,12 +702,12 @@ const DataTable = /*#__PURE__*/React.forwardRef((props, ref) => {
738
702
  key: row.id
739
703
  }, styles === null || styles === void 0 ? void 0 : styles.tableRow, {
740
704
  css: react$1.css`
741
- &:last-child {
742
- td {
743
- border-bottom: none;
744
- }
705
+ &:last-child {
706
+ td {
707
+ border-bottom: none;
745
708
  }
746
- `,
709
+ }
710
+ `,
747
711
  onClick: () => {
748
712
  if (onRowClick) {
749
713
  onRowClick(row.original);