@equinor/apollo-components 3.1.2-rowfix.2 → 3.1.2-rowfix.21

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.js CHANGED
@@ -663,7 +663,7 @@ function TableHeader({ table, sticky }) {
663
663
  // src/DataTable/DataTable.tsx
664
664
  var import_eds_core_react18 = require("@equinor/eds-core-react");
665
665
  var import_react_table3 = require("@tanstack/react-table");
666
- var import_react6 = require("react");
666
+ var import_react7 = require("react");
667
667
  var import_styled_components16 = __toESM(require("styled-components"));
668
668
 
669
669
  // src/DataTable/components/BasicTable.tsx
@@ -944,6 +944,7 @@ function VirtualTableBody({
944
944
  table,
945
945
  rowConfig,
946
946
  cellConfig,
947
+ hasRef,
947
948
  containerRef,
948
949
  ...props
949
950
  }) {
@@ -959,6 +960,7 @@ function VirtualTableBody({
959
960
  if (!rowVirtualizer)
960
961
  return null;
961
962
  const virtualRows = rowVirtualizer.getVirtualItems();
963
+ console.log("VirtualTableBody", { container: containerRef.current, virtualRows, hasRef });
962
964
  const paddingTop = virtualRows.length > 0 ? ((_a = virtualRows == null ? void 0 : virtualRows[0]) == null ? void 0 : _a.start) || 0 : 0;
963
965
  const paddingBottom = virtualRows.length > 0 ? rowVirtualizer.getTotalSize() - (((_b = virtualRows == null ? void 0 : virtualRows[virtualRows.length - 1]) == null ? void 0 : _b.end) || 0) : 0;
964
966
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(TableBody, {
@@ -1015,6 +1017,13 @@ function useFetchMoreOnBottomReached(tableContainerRef, infiniteScrollConfig) {
1015
1017
  return onTableContainerScroll;
1016
1018
  }
1017
1019
 
1020
+ // src/DataTable/hooks/useForceRerender.ts
1021
+ var import_react6 = require("react");
1022
+ function useForceRerender() {
1023
+ const [, setTick] = (0, import_react6.useState)(0);
1024
+ return (0, import_react6.useCallback)(() => setTick((tick) => tick + 1), []);
1025
+ }
1026
+
1018
1027
  // src/DataTable/DataTable.tsx
1019
1028
  var import_jsx_runtime19 = require("react/jsx-runtime");
1020
1029
  var DataTableWrapper = import_styled_components16.default.div`
@@ -1037,12 +1046,12 @@ var DataTableWrapper = import_styled_components16.default.div`
1037
1046
  function DataTable(props) {
1038
1047
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1039
1048
  const { columns, data, bannerConfig, cellConfig, sorting } = props;
1040
- const [internalColumnVisibility, setInternalColumnVisibility] = (0, import_react6.useState)({});
1049
+ const [internalColumnVisibility, setInternalColumnVisibility] = (0, import_react7.useState)({});
1041
1050
  const [columnVisibility, setColumnVisibility] = [
1042
1051
  ((_a = props.columnVisibility) == null ? void 0 : _a.state) ?? internalColumnVisibility,
1043
1052
  ((_b = props.columnVisibility) == null ? void 0 : _b.onChange) ?? setInternalColumnVisibility
1044
1053
  ];
1045
- const [internalGlobalFilterState, setInternalGlobalFilterState] = (0, import_react6.useState)("");
1054
+ const [internalGlobalFilterState, setInternalGlobalFilterState] = (0, import_react7.useState)("");
1046
1055
  const [globalFilterState, setGlobalFilterState] = [
1047
1056
  ((_c = props.globalFilter) == null ? void 0 : _c.state) ?? internalGlobalFilterState,
1048
1057
  ((_d = props.globalFilter) == null ? void 0 : _d.onChange) ?? setInternalGlobalFilterState
@@ -1051,17 +1060,17 @@ function DataTable(props) {
1051
1060
  function enableGlobalFilter(value) {
1052
1061
  return enableOrUndefined(shouldEnableGlobalFilter, value);
1053
1062
  }
1054
- const [internalSortingState, setInternalSortingState] = (0, import_react6.useState)([]);
1063
+ const [internalSortingState, setInternalSortingState] = (0, import_react7.useState)([]);
1055
1064
  const [sortingState, setSortingState] = [
1056
1065
  ((_f = props.sorting) == null ? void 0 : _f.state) ?? internalSortingState,
1057
1066
  ((_g = props.sorting) == null ? void 0 : _g.onChange) ?? setInternalSortingState
1058
1067
  ];
1059
- const [internalRowSelectionState, setInternalRowSelectionState] = (0, import_react6.useState)({});
1068
+ const [internalRowSelectionState, setInternalRowSelectionState] = (0, import_react7.useState)({});
1060
1069
  const [rowSelectionState, setRowSelectionState] = [
1061
1070
  ((_h = props.rowSelection) == null ? void 0 : _h.state) ?? internalRowSelectionState,
1062
1071
  ((_i = props.rowSelection) == null ? void 0 : _i.onChange) ?? setInternalRowSelectionState
1063
1072
  ];
1064
- const [internalExpandedState, setInternalExpandedState] = (0, import_react6.useState)({});
1073
+ const [internalExpandedState, setInternalExpandedState] = (0, import_react7.useState)({});
1065
1074
  const [expandedState, setExpandedState] = [
1066
1075
  ((_j = props.expansion) == null ? void 0 : _j.state) ?? internalExpandedState,
1067
1076
  ((_k = props.expansion) == null ? void 0 : _k.onChange) ?? setInternalExpandedState
@@ -1104,18 +1113,24 @@ function DataTable(props) {
1104
1113
  getSubRows: props == null ? void 0 : props.getSubRows,
1105
1114
  getRowId: props == null ? void 0 : props.getRowId
1106
1115
  });
1107
- (0, import_react6.useEffect)(() => {
1116
+ (0, import_react7.useEffect)(() => {
1108
1117
  var _a2;
1109
1118
  if ((_a2 = props.expansion) == null ? void 0 : _a2.expandAllByDefault) {
1110
1119
  table.toggleAllRowsExpanded();
1111
1120
  }
1112
1121
  }, [table, (_p = props.expansion) == null ? void 0 : _p.expandAllByDefault]);
1113
1122
  const { isLoading, rowConfig } = props;
1114
- const tableContainerRef = (0, import_react6.useRef)(null);
1123
+ const tableContainerRef = (0, import_react7.useRef)(null);
1124
+ console.log("DataTable", { container: tableContainerRef.current });
1115
1125
  const onTableContainerScroll = useFetchMoreOnBottomReached(
1116
1126
  tableContainerRef,
1117
1127
  props.infiniteScroll
1118
1128
  );
1129
+ const forceRerender = useForceRerender();
1130
+ (0, import_react7.useEffect)(() => {
1131
+ if (Boolean(tableContainerRef.current))
1132
+ forceRerender();
1133
+ }, [tableContainerRef.current === null]);
1119
1134
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DataTableWrapper, {
1120
1135
  height: props == null ? void 0 : props.height,
1121
1136
  width: props == null ? void 0 : props.width,
@@ -1129,10 +1144,12 @@ function DataTable(props) {
1129
1144
  }),
1130
1145
  /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", {
1131
1146
  ...props.tableContainerProps,
1132
- className: "--table-container " + ((_q = props.tableContainerProps) == null ? void 0 : _q.className),
1147
+ className: "--table-container " + (((_q = props.tableContainerProps) == null ? void 0 : _q.className) ?? ""),
1148
+ style: { contain: "strict" },
1133
1149
  onScroll: ((_r = props.tableContainerProps) == null ? void 0 : _r.onScroll) ?? onTableContainerScroll,
1134
1150
  ref: (node) => {
1135
1151
  var _a2;
1152
+ console.log({ node });
1136
1153
  if (node) {
1137
1154
  tableContainerRef.current = node;
1138
1155
  if ((_a2 = props.tableContainerProps) == null ? void 0 : _a2.ref) {
@@ -1150,7 +1167,7 @@ function DataTable(props) {
1150
1167
  sticky: props.stickyHeader,
1151
1168
  table
1152
1169
  }),
1153
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(VirtualTableBody, {
1170
+ tableContainerRef.current !== null && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(VirtualTableBody, {
1154
1171
  containerRef: tableContainerRef,
1155
1172
  tableCaption: props.tableCaption,
1156
1173
  table,
package/dist/index.mjs CHANGED
@@ -620,7 +620,7 @@ import {
620
620
  getSortedRowModel,
621
621
  useReactTable
622
622
  } from "@tanstack/react-table";
623
- import { useEffect as useEffect3, useRef as useRef3, useState as useState5 } from "react";
623
+ import { useEffect as useEffect3, useRef as useRef3, useState as useState6 } from "react";
624
624
  import styled16 from "styled-components";
625
625
 
626
626
  // src/DataTable/components/BasicTable.tsx
@@ -901,6 +901,7 @@ function VirtualTableBody({
901
901
  table,
902
902
  rowConfig,
903
903
  cellConfig,
904
+ hasRef,
904
905
  containerRef,
905
906
  ...props
906
907
  }) {
@@ -916,6 +917,7 @@ function VirtualTableBody({
916
917
  if (!rowVirtualizer)
917
918
  return null;
918
919
  const virtualRows = rowVirtualizer.getVirtualItems();
920
+ console.log("VirtualTableBody", { container: containerRef.current, virtualRows, hasRef });
919
921
  const paddingTop = virtualRows.length > 0 ? ((_a = virtualRows == null ? void 0 : virtualRows[0]) == null ? void 0 : _a.start) || 0 : 0;
920
922
  const paddingBottom = virtualRows.length > 0 ? rowVirtualizer.getTotalSize() - (((_b = virtualRows == null ? void 0 : virtualRows[virtualRows.length - 1]) == null ? void 0 : _b.end) || 0) : 0;
921
923
  return /* @__PURE__ */ jsxs10(TableBody, {
@@ -972,6 +974,13 @@ function useFetchMoreOnBottomReached(tableContainerRef, infiniteScrollConfig) {
972
974
  return onTableContainerScroll;
973
975
  }
974
976
 
977
+ // src/DataTable/hooks/useForceRerender.ts
978
+ import { useCallback as useCallback2, useState as useState5 } from "react";
979
+ function useForceRerender() {
980
+ const [, setTick] = useState5(0);
981
+ return useCallback2(() => setTick((tick) => tick + 1), []);
982
+ }
983
+
975
984
  // src/DataTable/DataTable.tsx
976
985
  import { jsx as jsx19, jsxs as jsxs11 } from "react/jsx-runtime";
977
986
  var DataTableWrapper = styled16.div`
@@ -994,12 +1003,12 @@ var DataTableWrapper = styled16.div`
994
1003
  function DataTable(props) {
995
1004
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
996
1005
  const { columns, data, bannerConfig, cellConfig, sorting } = props;
997
- const [internalColumnVisibility, setInternalColumnVisibility] = useState5({});
1006
+ const [internalColumnVisibility, setInternalColumnVisibility] = useState6({});
998
1007
  const [columnVisibility, setColumnVisibility] = [
999
1008
  ((_a = props.columnVisibility) == null ? void 0 : _a.state) ?? internalColumnVisibility,
1000
1009
  ((_b = props.columnVisibility) == null ? void 0 : _b.onChange) ?? setInternalColumnVisibility
1001
1010
  ];
1002
- const [internalGlobalFilterState, setInternalGlobalFilterState] = useState5("");
1011
+ const [internalGlobalFilterState, setInternalGlobalFilterState] = useState6("");
1003
1012
  const [globalFilterState, setGlobalFilterState] = [
1004
1013
  ((_c = props.globalFilter) == null ? void 0 : _c.state) ?? internalGlobalFilterState,
1005
1014
  ((_d = props.globalFilter) == null ? void 0 : _d.onChange) ?? setInternalGlobalFilterState
@@ -1008,17 +1017,17 @@ function DataTable(props) {
1008
1017
  function enableGlobalFilter(value) {
1009
1018
  return enableOrUndefined(shouldEnableGlobalFilter, value);
1010
1019
  }
1011
- const [internalSortingState, setInternalSortingState] = useState5([]);
1020
+ const [internalSortingState, setInternalSortingState] = useState6([]);
1012
1021
  const [sortingState, setSortingState] = [
1013
1022
  ((_f = props.sorting) == null ? void 0 : _f.state) ?? internalSortingState,
1014
1023
  ((_g = props.sorting) == null ? void 0 : _g.onChange) ?? setInternalSortingState
1015
1024
  ];
1016
- const [internalRowSelectionState, setInternalRowSelectionState] = useState5({});
1025
+ const [internalRowSelectionState, setInternalRowSelectionState] = useState6({});
1017
1026
  const [rowSelectionState, setRowSelectionState] = [
1018
1027
  ((_h = props.rowSelection) == null ? void 0 : _h.state) ?? internalRowSelectionState,
1019
1028
  ((_i = props.rowSelection) == null ? void 0 : _i.onChange) ?? setInternalRowSelectionState
1020
1029
  ];
1021
- const [internalExpandedState, setInternalExpandedState] = useState5({});
1030
+ const [internalExpandedState, setInternalExpandedState] = useState6({});
1022
1031
  const [expandedState, setExpandedState] = [
1023
1032
  ((_j = props.expansion) == null ? void 0 : _j.state) ?? internalExpandedState,
1024
1033
  ((_k = props.expansion) == null ? void 0 : _k.onChange) ?? setInternalExpandedState
@@ -1069,10 +1078,16 @@ function DataTable(props) {
1069
1078
  }, [table, (_p = props.expansion) == null ? void 0 : _p.expandAllByDefault]);
1070
1079
  const { isLoading, rowConfig } = props;
1071
1080
  const tableContainerRef = useRef3(null);
1081
+ console.log("DataTable", { container: tableContainerRef.current });
1072
1082
  const onTableContainerScroll = useFetchMoreOnBottomReached(
1073
1083
  tableContainerRef,
1074
1084
  props.infiniteScroll
1075
1085
  );
1086
+ const forceRerender = useForceRerender();
1087
+ useEffect3(() => {
1088
+ if (Boolean(tableContainerRef.current))
1089
+ forceRerender();
1090
+ }, [tableContainerRef.current === null]);
1076
1091
  return /* @__PURE__ */ jsxs11(DataTableWrapper, {
1077
1092
  height: props == null ? void 0 : props.height,
1078
1093
  width: props == null ? void 0 : props.width,
@@ -1086,10 +1101,12 @@ function DataTable(props) {
1086
1101
  }),
1087
1102
  /* @__PURE__ */ jsx19("div", {
1088
1103
  ...props.tableContainerProps,
1089
- className: "--table-container " + ((_q = props.tableContainerProps) == null ? void 0 : _q.className),
1104
+ className: "--table-container " + (((_q = props.tableContainerProps) == null ? void 0 : _q.className) ?? ""),
1105
+ style: { contain: "strict" },
1090
1106
  onScroll: ((_r = props.tableContainerProps) == null ? void 0 : _r.onScroll) ?? onTableContainerScroll,
1091
1107
  ref: (node) => {
1092
1108
  var _a2;
1109
+ console.log({ node });
1093
1110
  if (node) {
1094
1111
  tableContainerRef.current = node;
1095
1112
  if ((_a2 = props.tableContainerProps) == null ? void 0 : _a2.ref) {
@@ -1107,7 +1124,7 @@ function DataTable(props) {
1107
1124
  sticky: props.stickyHeader,
1108
1125
  table
1109
1126
  }),
1110
- /* @__PURE__ */ jsx19(VirtualTableBody, {
1127
+ tableContainerRef.current !== null && /* @__PURE__ */ jsx19(VirtualTableBody, {
1111
1128
  containerRef: tableContainerRef,
1112
1129
  tableCaption: props.tableCaption,
1113
1130
  table,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-components",
3
- "version": "3.1.2-rowfix.2",
3
+ "version": "3.1.2-rowfix.21",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",