Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is not much difference with CtimsDropDown, consider consolidating into 1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a multiselect within the Dropdown component, which we don't need in CTIMSDropDownwithExcludeToggle. So its better we have separate components for both.

Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const CtimsDropdownWithExcludeToggle = (props: WidgetProps) => {

useEffect(() => {
if (value) {
setValueState(value?.replace('!', ''));
setIsNegated(value?.startsWith('!'));
setValueState(value.replace('!', ''));
setIsNegated(value.startsWith('!'));
}
}, [value]);

Expand All @@ -59,7 +59,11 @@ const CtimsDropdownWithExcludeToggle = (props: WidgetProps) => {
}, [valueState, isNegated]);

const handleDropdownChange = (e: { value: any }) => {
setValueState(e.value);
const selectedValue = e.value;
setValueState(selectedValue);
if (!selectedValue) {
setIsNegated(false);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as setIsNegated(selectedValue)? or do you only want to trigger this when selectedValue is false?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one case when the selected value is empty, let's say when a user selects an empty value in a dropdown, so this condition makes sure the taggle is disabled.

};

const handleToggleChange = (checked: boolean) => {
Expand Down Expand Up @@ -110,7 +114,7 @@ const CtimsDropdownWithExcludeToggle = (props: WidgetProps) => {
<div className={styles.label}>Exclude this criteria from matches.</div>
<div style={{ marginLeft: 'auto', marginTop: '10px' }}>
<IOSSwitch
disabled={!valueState}
disabled={!valueState}
value={isNegated}
onChange={handleToggleChange}
/>
Expand Down