Skip to content

Commit 988fba5

Browse files
committed
to be continued
1 parent aa6d63d commit 988fba5

File tree

1 file changed

+90
-37
lines changed

1 file changed

+90
-37
lines changed

UI/web-app/src/components/HRQuerySource/HRQuerySource.base.tsx

Lines changed: 90 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const HRQuerySourceBase: React.FunctionComponent<HRQuerySourceProps> = (p
8484
const [groupingEnabled, setGroupingEnabled] = useState(false);
8585
const [filterTextEnabled, setFilterTextEnabled] = useState(false);
8686
const [groupQuery, setGroupQuery] = useState<string>();
87+
const [forceUpdate, setForceUpdate] = useState<number>(0);
8788

8889
useEffect(() => {
8990
if (!groupingEnabled) {
@@ -313,6 +314,7 @@ function setItemsBasedOnGroups(groups: Group[]) {
313314
});
314315
setItemsBasedOnGroups(group.children);
315316
});
317+
console.log("items", items);
316318
setItems(items);
317319
}
318320

@@ -1029,73 +1031,124 @@ const checkType = (value: string, type: string | undefined): string => {
10291031
];
10301032

10311033
function onUpClick(index: number, items: IFilterPart[]) {
1032-
// alert("OnUpClick" + index + items.length);
1034+
console.log("onUpClick");
10331035
console.log("items", items);
1034-
console.log("groups", groups);
1036+
console.log("index", index);
1037+
console.log("groupingEnabled", groupingEnabled);
10351038

1036-
let newItems = [...items];
1037-
let newSelectedIndices = [];
1038-
const insertIndex = index-1;
1039-
if (insertIndex < 0) { return; }
1040-
newItems = newItems.filter(i => i !== items[index]);
1041-
newItems.splice(insertIndex, 0, items[index]);
1042-
newSelectedIndices.push(insertIndex);
1043-
let newChildren: ChildType[] = newItems.map((item) => ({
1044-
filter: `${item.attribute} ${item.equalityOperator} ${item.value} ${item.andOr}`,
1045-
}));
1039+
10461040

1041+
let newItems = [...items];
1042+
const insertIndex = index - 1;
1043+
if (insertIndex < 0) { return; }
1044+
setIsDragAndDropEnabled(true);
1045+
newItems = newItems.filter((_, i) => i !== index);
1046+
newItems.splice(insertIndex, 0, { ...items[index] });
1047+
console.log("newItems", newItems);
1048+
let newChildren: ChildType[] = newItems.map((item) => ({
1049+
filter: `${item.attribute} ${item.equalityOperator} ${item.value} ${item.andOr}`,
1050+
}));
1051+
console.log("groups", groups);
10471052

1053+
if (groupingEnabled) {
10481054
const groupIndex = groups.findIndex(group =>
10491055
group.children?.some(child =>
10501056
child.items.some(item =>
1051-
JSON.stringify(item) === JSON.stringify(items[selectedIndices[0]])
1057+
JSON.stringify(item) === JSON.stringify(items[index])
10521058
)
10531059
) || group.items?.some(item =>
1054-
JSON.stringify(item) === JSON.stringify(items[selectedIndices[0]])
1060+
JSON.stringify(item) === JSON.stringify(items[index])
10551061
)
10561062
);
10571063
const childIndex = groupIndex !== -1 ? groups[groupIndex].children.findIndex(child =>
10581064
child.items.some(item =>
1059-
JSON.stringify(item) === JSON.stringify(items[selectedIndices[0]])
1065+
JSON.stringify(item) === JSON.stringify(items[index])
10601066
)
10611067
) : -1;
10621068

1069+
10631070
console.log("groupIndex", groupIndex);
10641071
console.log("childIndex", childIndex);
10651072

1066-
1073+
if (groupIndex !== -1 && childIndex === -1) {
1074+
groups[groupIndex].items = newItems;
1075+
console.log("groups", groups);
1076+
setGroups(groups);
1077+
getGroupLabels(groups);
1078+
setItemsBasedOnGroups(groups);
1079+
}
1080+
else if (groupIndex !== -1 && childIndex !== -1) {
1081+
groups[groupIndex].children[childIndex].items = newItems;
1082+
console.log("groups", groups);
1083+
setGroups(groups);
1084+
getGroupLabels(groups);
1085+
setItemsBasedOnGroups(groups);
1086+
}
1087+
}
1088+
else {
1089+
groups[0].items = newItems;
1090+
setGroups(groups);
10671091
setChildren(newChildren);
10681092
setItems(newItems);
1069-
console.log("newItems", newItems);
1093+
}
1094+
1095+
1096+
1097+
10701098
}
10711099

10721100
function onDownClick(index: number, items: IFilterPart[]) {
1073-
// alert("onDownClick" + index + items.length);
1074-
console.log("items", items);
1075-
// console.log("selectedItem", items[index]);
1076-
10771101
let newItems = [...items];
1078-
let newSelectedIndices = [];
1079-
const insertIndex = index+1;
1080-
if (insertIndex > items.length) { return; }
1081-
newItems = newItems.filter(i => i !== items[index]);
1082-
newItems.splice(insertIndex, 0, items[index]);
1083-
newSelectedIndices.push(insertIndex);
1084-
let newChildren: ChildType[] = newItems.map((item) => ({
1085-
filter: `${item.attribute} ${item.equalityOperator} ${item.value} ${item.andOr}`,
1086-
}));
1102+
const insertIndex = index + 1;
1103+
if (insertIndex > items.length) { return; }
1104+
setIsDragAndDropEnabled(true);
1105+
newItems = newItems.filter(i => i !== items[index]);
1106+
newItems.splice(insertIndex, 0, items[index]);
1107+
let newChildren: ChildType[] = newItems.map((item) => ({
1108+
filter: `${item.attribute} ${item.equalityOperator} ${item.value} ${item.andOr}`,
1109+
}));
1110+
1111+
if (groupingEnabled) {
1112+
const groupIndex = groups.findIndex(group =>
1113+
group.children?.some(child =>
1114+
child.items.some(item =>
1115+
JSON.stringify(item) === JSON.stringify(items[index])
1116+
)
1117+
) || group.items?.some(item =>
1118+
JSON.stringify(item) === JSON.stringify(items[index])
1119+
)
1120+
);
1121+
const childIndex = groupIndex !== -1 ? groups[groupIndex].children.findIndex(child =>
1122+
child.items.some(item =>
1123+
JSON.stringify(item) === JSON.stringify(items[index])
1124+
)
1125+
) : -1;
1126+
1127+
1128+
console.log("groupIndex", groupIndex);
1129+
console.log("childIndex", childIndex);
1130+
1131+
if (groupIndex !== -1) {
1132+
groups[groupIndex].items = newItems;
1133+
setGroups(groups);
1134+
setItemsBasedOnGroups(groups);
1135+
}
1136+
}
1137+
else {
10871138
setChildren(newChildren);
10881139
setItems(newItems);
1089-
console.log("newItems", newItems);
1140+
}
1141+
1142+
10901143
}
10911144

10921145
const onRenderItemColumn = (items: IFilterPart[], item?: any, index?: number, column?: IColumn): JSX.Element => {
10931146
if (typeof index !== 'undefined' && items[index]) {
10941147
switch (column?.key) {
10951148
case 'upDown':
1096-
return <div className={classNames.upDown}>
1097-
<ActionButton iconProps={{ iconName: 'ChevronUp' }} onClick={() => onUpClick(index, items)} style={{ marginBottom: '2px' }} />
1098-
<ActionButton iconProps={{ iconName: 'ChevronDown' }} onClick={() => onDownClick(index, items)} style={{ marginTop: '2px' }} />
1149+
return <div className={classNames.upDown}>
1150+
<ActionButton iconProps={{ iconName: 'ChevronUp' }} onClick={() => onUpClick(index, items)} style={{ marginTop: '-15px', marginBottom: '-5px' }} />
1151+
<ActionButton iconProps={{ iconName: 'ChevronDown' }} onClick={() => onDownClick(index, items)} style={{ marginTop: '-5px', marginBottom: '-15px' }} />
10991152
</div>;
11001153
case 'attribute':
11011154
return <ComboBox
@@ -1364,8 +1417,8 @@ const checkType = (value: string, type: string | undefined): string => {
13641417
}
13651418

13661419
function onGroupClick() {
1367-
console.log("items", items);
1368-
console.log("selectedIndices", selectedIndices);
1420+
console.log("onGroupClick - items", items);
1421+
console.log("onGroupClick - selectedIndices", selectedIndices);
13691422
let newGroups = [...groups];
13701423
let indices: { selectedItemIndex: number, groupIndex: number; childIndex: number }[] = [];
13711424
const selectedItems = items.filter((item, index) => selectedIndices.includes(index));
@@ -1503,7 +1556,7 @@ const checkType = (value: string, type: string | undefined): string => {
15031556
function handleSelectionChange(selection: Selection, index: number) {
15041557
const selectedItems = selection.getSelection() as any[];
15051558
console.log("handleSelectionChange selectedItems", selectedItems);
1506-
console.log("handleSelectionChange items", items);
1559+
15071560
const selectedIndices = selectedItems.map(selectedItem => {
15081561
return items.findIndex(item =>
15091562
item.attribute === selectedItem.attribute &&

0 commit comments

Comments
 (0)