ar-design 0.2.46 → 0.2.48

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.
@@ -28,6 +28,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
28
28
  const [selectAll, setSelectAll] = useState(false);
29
29
  const [selectionItems, setSelectionItems] = useState([]);
30
30
  const [showSubitems, setShowSubitems] = useState({});
31
+ const [isTrueSubitems, setIsTrueSubitems] = useState({});
31
32
  // states -> File
32
33
  const [files, setFiles] = useState([]);
33
34
  const [formData, setFormData] = useState(undefined);
@@ -183,24 +184,23 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
183
184
  return false;
184
185
  });
185
186
  };
187
+ const openAllSubrowsRecursively = (data, parentKey = "") => {
188
+ let result = {};
189
+ data.forEach((item, index) => {
190
+ const key = parentKey ? `${parentKey}.${index}` : `${index}`;
191
+ const subitems = item[_subrowSelector];
192
+ if (subitems && Array.isArray(subitems) && subitems.length > 0) {
193
+ const nested = openAllSubrowsRecursively(subitems, key);
194
+ result[key] = true;
195
+ result = { ...result, ...nested };
196
+ }
197
+ });
198
+ return result;
199
+ };
186
200
  const getData = useMemo(() => {
187
201
  let _data = [...data];
188
- if (_subrowOpenAutomatically) {
189
- data.forEach((item, index) => {
190
- if (_subrowSelector in item) {
191
- setShowSubitems((prev) => ({
192
- ...prev,
193
- [`${index}`]: !prev[`${index}`],
194
- }));
195
- }
196
- else {
197
- setShowSubitems((prev) => ({
198
- ...prev,
199
- [`${index}`]: false,
200
- }));
201
- }
202
- });
203
- }
202
+ if (_subrowOpenAutomatically)
203
+ setShowSubitems(openAllSubrowsRecursively(data));
204
204
  if (searchedText && Object.keys(searchedText).length > 0) {
205
205
  _data = _data.filter((item) => deepSearch(item, searchedText));
206
206
  setTotalRecords(_data.length);
@@ -257,7 +257,6 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
257
257
  } }))),
258
258
  _subrowButton && isHasSubitems ? (React.createElement("td", null, item[_subrowSelector] && (React.createElement("div", { className: "subitem-open-button-wrapper" },
259
259
  React.createElement("span", { className: `subitem-open-button ${(showSubitems[index] && "opened") ?? ""}`, onClick: () => {
260
- console.log(showSubitems);
261
260
  setShowSubitems((prev) => ({
262
261
  ...prev,
263
262
  [`${index}`]: !prev[`${index}`],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.2.46",
3
+ "version": "0.2.48",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",