@megha-ui/react 1.2.238 → 1.2.240

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.
@@ -22,7 +22,7 @@ import Button from "../button";
22
22
  import { TbAntennaBarsOff, TbCalculator, TbCalculatorFilled, TbCalculatorOff, } from "react-icons/tb";
23
23
  import { TbCopy, TbCopyOff } from "react-icons/tb";
24
24
  import { formatValue } from "../../services/commonService";
25
- const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable = true, paginate, rowsPerPageOptions = [10, 20, 50, 100], defaultRowsPerPage = 100, widthMode = "custom", bulkSelect = false, cellBorder = false, rowHeight = 38, onRowClick, rowCount = false, rowBorder = true, showMenu = false, search = false, defaultSearchOperation = "contains", gridBorder = false, isLoading = false, rowTopBorder, rowBottomBorder, rowLeftBorder, rowRightBorder, headerBackground = "var(--row-header-bg)", headerTopBorder = "none", headerBottomBorder = "none", SettingIcon, ExportIcon, ignoredExportItems = ["action", "actions"], borderColor = "#dbdfe9", updateColumns, showHideAvailable = false, columnSearchOutside = false, multiSorting = false, exportAvailable = false, exportableFileName = "", groupBy, updateGroupBy, rowKey = "id", hlBorderColor = "black", selectedRow, selectedRowStyle = {
25
+ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable = true, paginate, rowsPerPageOptions = [10, 20, 50, 100], defaultRowsPerPage = 100, widthMode = "custom", bulkSelect = false, cellBorder = false, rowHeight = 38, onRowClick, rowCount = false, rowBorder = true, showMenu = false, search = false, defaultSearchOperation = "contains", gridBorder = false, isLoading = false, rowTopBorder, rowBottomBorder, rowLeftBorder, rowRightBorder, headerBackground = "var(--row-header-bg)", headerTopBorder = "none", headerBottomBorder = "none", SettingIcon, ExportIcon, ignoredExportItems = ["action", "actions"], borderColor = "#dbdfe9", updateColumns, showHideAvailable = false, columnSearchOutside = false, multiSorting = false, exportAvailable = false, exportableFileName = "", groupBy, updateGroupBy, compositeGroupBy = false, rowKey = "id", hlBorderColor = "black", selectedRow, selectedRowStyle = {
26
26
  borderLeft: "0.5rem solid #d9d9d9",
27
27
  }, defaultSort, noKeyEvents = true, customOperation, hasCustomOperation, globalSearch, headerDropdownIndex, draggable = false, resizable = false, updateGridData, widthUnits, checkboxWrapper, ignoreHugContent = false, setRendered, isSummarise = true, isHideDups = false, fullScreenAvailable = true, defaultGroupOpen, alternateRowColor = true, activeCalculateColor = "#2377BA", calculatetextColor = "#fff", actionsKey = "actions", saveAsNewView = false, handleSaveAsView, saveAsViewIcon, filterData, chipColor = "#ccc", withAscii = false, propSummariseKeys, SummariseIcon, summarizeColor = "black", isExpandable = false, expandedRow, extraRow, selectedCheckBox, setSelectedCheckbox, ignoreRowSelect, setOpenedRows, openedRows, getLoadingState, globalSearchOpen = false, updateFixedFilterValues = (fixedFilterValues) => {
28
28
  console.log("Update fixed filter values not implemented", fixedFilterValues);
@@ -549,6 +549,38 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
549
549
  }
550
550
  }, [gridColumns, groupBy]);
551
551
  const groupByMultipleKeys = (data, groupByKeys) => {
552
+ // When compositeGroupBy is enabled and multiple keys are selected,
553
+ // treat the selected keys as a single composite grouping (one level)
554
+ if (compositeGroupBy && groupByKeys.length > 1) {
555
+ const groupsMap = new Map();
556
+ const allKeys = groupByKeys.filter((k) => k);
557
+ const lastKey = allKeys[allKeys.length - 1];
558
+ data.forEach((item) => {
559
+ const values = allKeys.map((k) => { var _a, _b; return (_b = (_a = item[k]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ""; });
560
+ const compositeValue = values.join(">");
561
+ const key = compositeValue; // unique per composite
562
+ if (!groupsMap.has(key)) {
563
+ groupsMap.set(key, {
564
+ key: lastKey,
565
+ value: compositeValue,
566
+ count: 0,
567
+ subGroups: [],
568
+ values: [],
569
+ allKeys: allKeys,
570
+ });
571
+ }
572
+ const group = groupsMap.get(key);
573
+ group.values.push(item);
574
+ });
575
+ const groupedResult = Array.from(groupsMap.values());
576
+ groupedResult.forEach((group) => {
577
+ group.count = group.values.length;
578
+ // Put items as subGroups so the flattener emits the row items
579
+ group.subGroups = group.values;
580
+ });
581
+ return groupedResult;
582
+ }
583
+ // Default behavior: nested grouping by each key level-by-level
552
584
  const groupData = (items, keys, level = 0) => {
553
585
  if (level >= keys.length)
554
586
  return items;
@@ -584,7 +616,11 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
584
616
  if (groupedData) {
585
617
  groupedData.forEach((group) => {
586
618
  const _groupedValues = [...groupedValues, group.value].map((item) => item ? item : "row");
587
- const currentKeys = [...parentKeys, group.key].filter((item) => item);
619
+ // If composite grouping is used, the group may carry allKeys to
620
+ // indicate the full set of keys for width/alignment purposes
621
+ const currentKeys = (group.allKeys
622
+ ? group.allKeys
623
+ : [...parentKeys, group.key]).filter((item) => item);
588
624
  const groupedValue = _groupedValues.join(">");
589
625
  const groupedKey = currentKeys.join(">");
590
626
  if (group.values) {
@@ -615,9 +651,50 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
615
651
  }
616
652
  return flatArray;
617
653
  };
654
+ // Support grouping by comma-separated sets, where each set may contain
655
+ // multiple keys separated by "+" to indicate a composite group at that level.
656
+ const groupBySets = (data, groupSets) => {
657
+ const groupLevel = (items, level) => {
658
+ if (level >= groupSets.length)
659
+ return items;
660
+ const keys = groupSets[level];
661
+ const map = new Map();
662
+ const lastKey = keys[keys.length - 1];
663
+ items.forEach((item) => {
664
+ const values = keys.map((k) => { var _a, _b; return (_b = (_a = item[k]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ""; });
665
+ const composite = values.join(">");
666
+ if (!map.has(composite)) {
667
+ map.set(composite, {
668
+ key: lastKey,
669
+ value: composite,
670
+ count: 0,
671
+ subGroups: [],
672
+ values: [],
673
+ allKeys: keys,
674
+ });
675
+ }
676
+ const g = map.get(composite);
677
+ g.values.push(item);
678
+ });
679
+ const groups = Array.from(map.values());
680
+ groups.forEach((g) => {
681
+ g.count = g.values.length;
682
+ g.subGroups = groupLevel(g.values, level + 1);
683
+ });
684
+ return groups;
685
+ };
686
+ return groupLevel(data, 0);
687
+ };
618
688
  useEffect(() => {
619
689
  if (gridGroupBy && gridGroupBy !== "") {
620
- const groupedArray = groupByMultipleKeys(sortedData, gridGroupBy.split(","));
690
+ const sets = gridGroupBy
691
+ .split(",")
692
+ .map((s) => s.trim())
693
+ .filter((s) => s)
694
+ .map((s) => s.split("+").map((k) => k.trim()).filter((k) => k));
695
+ const groupedArray = sets.length
696
+ ? groupBySets(sortedData, sets)
697
+ : [];
621
698
  const flatGroupedArray = flattenGroupedData(groupedArray, 1);
622
699
  setGroupedData(flatGroupedArray);
623
700
  const grouped = flatGroupedArray
@@ -104,6 +104,8 @@ export interface OjasGridProps {
104
104
  exportableFileName?: string;
105
105
  groupBy?: string;
106
106
  updateGroupBy?: (value: string) => void;
107
+ /** When multiple keys are chosen for groupBy, treat them as a single composite group instead of nested groups */
108
+ compositeGroupBy?: boolean;
107
109
  hlBorderColor?: string;
108
110
  selectedRow?: number;
109
111
  selectedRowStyle?: React.CSSProperties;
@@ -46,6 +46,11 @@ const GridHeader = ({ columns, onSearch, searchQueries, sortable, search, resiza
46
46
  const [searchOpsPosition, setSearchOpsPosition] = useState(null);
47
47
  const [headerColumns, setHeaderColumns] = useState([]);
48
48
  const [resizeIndex, setResizeIndex] = useState(-1);
49
+ // Support composite groupBy (e.g., "colA+colB,colC") by flattening to keys
50
+ const groupByKeys = useMemo(() => (groupBy || "")
51
+ .split(",")
52
+ .filter((g) => g)
53
+ .flatMap((g) => g.split("+").filter((k) => k)), [groupBy]);
49
54
  const handleMenuClick = (e, columnKey) => {
50
55
  e.stopPropagation();
51
56
  const rect = e.currentTarget.getBoundingClientRect();
@@ -230,10 +235,7 @@ const GridHeader = ({ columns, onSearch, searchQueries, sortable, search, resiza
230
235
  position: "sticky",
231
236
  top: 0,
232
237
  zIndex: 1,
233
- }, id: "header", children: [bulkSelect && (_jsx("div", { style: Object.assign(Object.assign({}, cellStyle), { textTransform: "uppercase", padding: "0.5rem", textAlign: "left", whiteSpace: "nowrap", textOverflow: "ellipsis" }), children: _jsx(Checkbox, { selected: allRowsSelected, onChange: () => toggleSelectAll(), noLabel: true, wrapperClass: checkboxWrapper }) })), groupBy
234
- .split(",")
235
- .filter((item) => item)
236
- .map((_groupBy) => {
238
+ }, id: "header", children: [bulkSelect && (_jsx("div", { style: Object.assign(Object.assign({}, cellStyle), { textTransform: "uppercase", padding: "0.5rem", textAlign: "left", whiteSpace: "nowrap", textOverflow: "ellipsis" }), children: _jsx(Checkbox, { selected: allRowsSelected, onChange: () => toggleSelectAll(), noLabel: true, wrapperClass: checkboxWrapper }) })), groupByKeys.map((_groupBy) => {
237
239
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62;
238
240
  return (_jsx(_Fragment, { children: headerColumns.find((column) => column.key === _groupBy) && (_jsxs("div", { className: `${sortable &&
239
241
  ((_a = headerColumns.find((column) => column.key === _groupBy)) === null || _a === void 0 ? void 0 : _a.sortable)
@@ -507,7 +509,7 @@ const GridHeader = ({ columns, onSearch, searchQueries, sortable, search, resiza
507
509
  : "var(--disabled-bg)",
508
510
  }, height: 32, extraInputStyle: { minWidth: 10 }, className: "w-full", backgroundColor: "var(--background)" }) }))] }, (_62 = headerColumns.find((column) => column.key === _groupBy)) === null || _62 === void 0 ? void 0 : _62.key)) }));
509
511
  }), headerColumns
510
- .filter((column) => !groupBy.includes(column.key))
512
+ .filter((column) => !groupByKeys.includes(column.key))
511
513
  .map((column, colIndex) => {
512
514
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
513
515
  if (!column.hidden) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megha-ui/react",
3
- "version": "1.2.238",
3
+ "version": "1.2.240",
4
4
  "description": "A collection of reusable UI components for React applications, built with TypeScript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",