Skip to content

Commit 6b77416

Browse files
committed
check type of attribute
1 parent 68e0c19 commit 6b77416

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ export const HRQuerySourceBase: React.FunctionComponent<HRQuerySourceProps> = (p
8585
let items: IFilterPart[] = children.map((child, index) => ({
8686
attribute: child.filter.split(' ')[0],
8787
equalityOperator: child.filter.split(' ')[1],
88-
value: attributeValues[child.filter.split(' ')[0]] &&
89-
attributeValues[child.filter.split(' ')[0]].values &&
90-
attributeValues[child.filter.split(' ')[0]].values.length > 0 &&
91-
child.filter.split(' ')[2] && child.filter.split(' ')[2].startsWith("'") && child.filter.split(' ')[2].endsWith("'") ? child.filter.split(' ')[2].slice(1, -1) : child.filter.split(' ')[2],
88+
value: child.filter.split(' ')[2],
9289
andOr: child.filter.split(' ')[3]
9390
}));
9491
setItems(items);
@@ -777,18 +774,18 @@ const checkType = (value: string, type: string | undefined): string => {
777774
}
778775
};
779776

780-
const handleAttributeValueChange = (event: React.FormEvent<IComboBox>, item?: IComboBoxOption, index?: number): void => {
777+
const handleAttributeValueChange = (attribute: string, event: React.FormEvent<IComboBox>, item?: IComboBoxOption, index?: number): void => {
781778
if (item) {
779+
const selectedValue = item.key.toString();
780+
const selectedValueAfterConversion = attributeValues[attribute] ? checkType(selectedValue, attributeValues[attribute.toString()].type) : selectedValue;
781+
782782
const updatedItems = items.map((it, idx) => {
783783
if (idx === index) {
784-
return { ...it, value: item.text };
784+
return { ...it, value: selectedValueAfterConversion || selectedValue };
785785
}
786786
return it;
787787
});
788788

789-
const selectedValue = item.key.toString();
790-
const selectedValueAfterConversion = attributeValues[updatedItems[index ?? 0].attribute] ? checkType(selectedValue, attributeValues[updatedItems[index ?? 0].attribute.toString()].type) : selectedValue;
791-
792789
setItems(updatedItems);
793790

794791
if (groupingEnabled && index != null) {
@@ -835,10 +832,13 @@ const checkType = (value: string, type: string | undefined): string => {
835832
}
836833
};
837834

838-
const handleTAttributeValueChange = (event: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, newValue: string = '', index: number) => {
835+
const handleTAttributeValueChange = (attribute: string, event: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, newValue: string = '', index: number) => {
836+
const selectedValue = newValue;
837+
const selectedValueAfterConversion = attributeValues[attribute] ? checkType(selectedValue, attributeValues[attribute].type) : selectedValue;
838+
839839
const updatedItems = items.map((it, idx) => {
840840
if (idx === index) {
841-
return { ...it, value: newValue };
841+
return { ...it, value: selectedValueAfterConversion || selectedValue };
842842
}
843843
return it;
844844
});
@@ -848,20 +848,20 @@ const checkType = (value: string, type: string | undefined): string => {
848848
if (groupingEnabled && index != null) {
849849
const updateParams: UpdateParam = {
850850
property: "value",
851-
newValue: newValue
851+
newValue: selectedValueAfterConversion || selectedValue
852852
};
853853
updateGroupItem(updateParams, index);
854854
return;
855855
}
856856
}
857857

858-
const handleBlur = (event: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>, index?: number) => {
858+
const handleBlur = (attribute: string, event: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>, index?: number) => {
859859
if (groupingEnabled && index != null) {
860860
return;
861861
}
862862
var newValue = event.target.value.trim();
863863
const selectedValue = newValue;
864-
const selectedValueAfterConversion = attributeValues[items[index ?? 0].attribute] ? checkType(selectedValue, attributeValues[items[index ?? 0].attribute].type) : selectedValue;
864+
const selectedValueAfterConversion = attributeValues[attribute] ? checkType(selectedValue, attributeValues[attribute].type) : selectedValue;
865865
const regex = /(?<= And | Or )/;
866866
let segments = props.source.filter?.split(regex);
867867
if (selectedValueAfterConversion !== "" && (props.source.filter?.length === 0 || (segments?.length == children.length - 1))) {
@@ -1207,16 +1207,16 @@ const checkType = (value: string, type: string | undefined): string => {
12071207
selectedKey={items[index].value && items[index].value.startsWith("'") && items[index].value.endsWith("'") ? items[index].value.slice(1,-1) : items[index].value}
12081208
options={filteredValueOptions[index] || getValueOptions(attributeValues[items[index].attribute].values)}
12091209
onInputValueChange={(text) => onAttributeValueChange(text, index)}
1210-
onChange={(event, option) => handleAttributeValueChange(event, option, index)}
1210+
onChange={(event, option) => handleAttributeValueChange(item.attribute, event, option, index)}
12111211
allowFreeInput
12121212
autoComplete="off"
12131213
useComboBoxAsMenuWidth={true}
12141214
/>
12151215
} else {
12161216
return <TextField
12171217
value={attributeValues && attributeValues[item.attribute] === undefined ? getAttributeValues(item.attribute, items[index].value) : items[index].value && items[index].value.startsWith("'") && items[index].value.endsWith("'") ? items[index].value.slice(1,-1) : items[index].value}
1218-
onChange={(event, newValue) => handleTAttributeValueChange(event, newValue!, index)}
1219-
onBlur={(event) => handleBlur(event, index)}
1218+
onChange={(event, newValue) => handleTAttributeValueChange(item.attribute, event, newValue!, index)}
1219+
onBlur={(event) => handleBlur(item.attribute, event, index)}
12201220
styles={{ fieldGroup: classNames.textField }}
12211221
validateOnLoad={false}
12221222
validateOnFocusOut={false}

0 commit comments

Comments
 (0)