@megha-ui/react 1.2.284 → 1.2.286
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,
|
|
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 = {
|
|
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);
|
|
@@ -568,14 +568,17 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
|
|
|
568
568
|
setGridGroupBy(groupBy);
|
|
569
569
|
}
|
|
570
570
|
}, [gridColumns, groupBy]);
|
|
571
|
-
const groupByMultipleKeys = (data, groupByKeys
|
|
572
|
-
if
|
|
571
|
+
const groupByMultipleKeys = (data, groupByKeys) => {
|
|
572
|
+
// Backward compatibility: if compositeGroupBy is true and no '+' is used,
|
|
573
|
+
// and more than one key is provided, group all keys into a single composite bucket.
|
|
574
|
+
const hasPlus = groupByKeys.some((k) => k === null || k === void 0 ? void 0 : k.includes("+"));
|
|
575
|
+
if (groupByKeys.length > 1 && !hasPlus) {
|
|
573
576
|
const groupsMap = new Map();
|
|
574
577
|
const allKeys = groupByKeys.filter((k) => k);
|
|
575
578
|
const lastKey = allKeys[allKeys.length - 1];
|
|
576
579
|
data.forEach((item) => {
|
|
577
580
|
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 : ""; });
|
|
578
|
-
const compositeValue = values.join("
|
|
581
|
+
const compositeValue = values.join("+");
|
|
579
582
|
const key = compositeValue;
|
|
580
583
|
if (!groupsMap.has(key)) {
|
|
581
584
|
groupsMap.set(key, {
|
|
@@ -597,26 +600,51 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
|
|
|
597
600
|
});
|
|
598
601
|
return groupedResult;
|
|
599
602
|
}
|
|
603
|
+
// Parse keys into levels, where each level can be a composite (split by '+')
|
|
604
|
+
const parsedKeys = groupByKeys
|
|
605
|
+
.map((k) => (k !== null && k !== void 0 ? k : "").trim())
|
|
606
|
+
.filter((k) => k)
|
|
607
|
+
.map((k) => k.includes("+")
|
|
608
|
+
? k
|
|
609
|
+
.split("+")
|
|
610
|
+
.map((s) => s.trim())
|
|
611
|
+
.filter(Boolean)
|
|
612
|
+
: [k]);
|
|
600
613
|
const groupData = (items, keys, level = 0) => {
|
|
601
614
|
if (level >= keys.length)
|
|
602
615
|
return items;
|
|
603
616
|
const groupedResult = [];
|
|
604
|
-
const
|
|
617
|
+
const levelKeys = keys[level]; // one or more keys for this level
|
|
605
618
|
items.forEach((item) => {
|
|
606
619
|
var _a;
|
|
607
|
-
|
|
620
|
+
let groupValue = "";
|
|
621
|
+
let groupKeyLabel = levelKeys[levelKeys.length - 1] || "";
|
|
622
|
+
let allKeysForLevel = undefined;
|
|
623
|
+
if (levelKeys.length > 1) {
|
|
624
|
+
const values = levelKeys.map((k) => { var _a, _b; return (_b = (_a = item[k]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ""; });
|
|
625
|
+
groupValue = values.join(">");
|
|
626
|
+
allKeysForLevel = levelKeys;
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
const k = levelKeys[0];
|
|
630
|
+
groupValue = ((_a = item[k]) === null || _a === void 0 ? void 0 : _a.value) || "";
|
|
631
|
+
}
|
|
608
632
|
let existingGroup = groupedResult.find((g) => g.value === groupValue);
|
|
609
633
|
if (existingGroup) {
|
|
610
634
|
existingGroup.values.push(item);
|
|
611
635
|
}
|
|
612
636
|
else {
|
|
613
|
-
|
|
614
|
-
key:
|
|
637
|
+
const base = {
|
|
638
|
+
key: groupKeyLabel,
|
|
615
639
|
value: groupValue,
|
|
616
640
|
count: 0,
|
|
617
641
|
subGroups: [],
|
|
618
642
|
values: [item],
|
|
619
|
-
}
|
|
643
|
+
};
|
|
644
|
+
if (allKeysForLevel) {
|
|
645
|
+
base.allKeys = allKeysForLevel;
|
|
646
|
+
}
|
|
647
|
+
groupedResult.push(base);
|
|
620
648
|
}
|
|
621
649
|
});
|
|
622
650
|
groupedResult.forEach((group) => {
|
|
@@ -625,14 +653,16 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
|
|
|
625
653
|
});
|
|
626
654
|
return groupedResult;
|
|
627
655
|
};
|
|
628
|
-
return groupData(data,
|
|
656
|
+
return groupData(data, parsedKeys);
|
|
629
657
|
};
|
|
630
658
|
const flattenGroupedData = (groupedData, level, groupedValues = [], parentKeys = []) => {
|
|
631
659
|
const flatArray = [];
|
|
632
660
|
if (groupedData) {
|
|
633
661
|
groupedData.forEach((group) => {
|
|
634
662
|
const _groupedValues = [...groupedValues, group.value].map((item) => item ? item : "row");
|
|
635
|
-
const currentKeys = (group.allKeys
|
|
663
|
+
const currentKeys = (group.allKeys
|
|
664
|
+
? [...parentKeys, ...group.allKeys]
|
|
665
|
+
: [...parentKeys, group.key]).filter((item) => item);
|
|
636
666
|
const groupedValue = _groupedValues.join(">");
|
|
637
667
|
const groupedColumns = currentKeys.join(">");
|
|
638
668
|
if (group.values) {
|
|
@@ -672,7 +702,10 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
|
|
|
672
702
|
.split(",")
|
|
673
703
|
.map((s) => s.trim())
|
|
674
704
|
.filter((s) => s);
|
|
675
|
-
const groupedArray = sets.length
|
|
705
|
+
const groupedArray = sets.length
|
|
706
|
+
? groupByMultipleKeys(sortedData, sets)
|
|
707
|
+
: [];
|
|
708
|
+
console.log({ groupedArray });
|
|
676
709
|
const flatGroupedArray = flattenGroupedData(groupedArray, 1);
|
|
677
710
|
setGroupedData(flatGroupedArray);
|
|
678
711
|
const grouped = flatGroupedArray
|
|
@@ -104,8 +104,6 @@ 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;
|
|
109
107
|
hlBorderColor?: string;
|
|
110
108
|
selectedRow?: number;
|
|
111
109
|
selectedRowStyle?: React.CSSProperties;
|
|
@@ -55,7 +55,6 @@ const GroupedGrid = ({ groupedData, rowOpened, startIndex, endIndex, alternateRo
|
|
|
55
55
|
backgroundColor: "var(--summary-bg)",
|
|
56
56
|
}, children: [(_a = item.groupedKey) === null || _a === void 0 ? void 0 : _a.split(">").filter((key) => key !== item.key).map((columnKey) => {
|
|
57
57
|
const column = gridColumns.find((column) => column.key === columnKey);
|
|
58
|
-
console.log({ columnKey });
|
|
59
58
|
if (column) {
|
|
60
59
|
return (_jsx("div", { style: {
|
|
61
60
|
width: widthMode === "auto"
|
package/package.json
CHANGED