Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions libs/ui/src/lib/components/forms/GenomicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ export const GenomicForm = (props: IFormProps) => {
addInvalidClassToElement('root_variantCategoryContainerObject_protein_change');
addInvalidClassToElement('root_variantCategoryContainerObject_wildcard_protein_change');
}
if (proteinChangeError) {
addInvalidClassToElement('root_variantCategoryContainerObject_protein_change');
}
if (hugoSymbolError) {
addInvalidClassToElement('root_variantCategoryContainerObject_hugo_symbol');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const CtimsInputWithExcludeToggle = (props: WidgetProps) => {
rawErrors = [],
} = props;

const [valueState, setValueState] = useState(value);
const [valueState, setValueState] = useState(value ? value.replace(/^!/, '') : '');
const [excludeToggle, setExcludeToggle] = useState(value ? value.startsWith('!') : false);

useEffect(() => {
const currentURL = window.location.href;
Expand All @@ -37,28 +38,42 @@ const CtimsInputWithExcludeToggle = (props: WidgetProps) => {
}
}, [])

// useEffect(() => {
// console.log('value', value)
// }, [value])
useEffect(() => {
if (value) {
setValueState(value.replace(/^!/, ''));
setExcludeToggle(value.startsWith('!'));
} else {
setValueState('');
setExcludeToggle(false);
}
}, [value]);

const handleToggleChange = (checked: boolean) => {
setExcludeToggle(checked);
const newValue = checked ? `!${valueState}` : valueState;
onChange(newValue === '' ? options.emptyValue : newValue);
};

const _onChange = ({
target: { value },
}: React.ChangeEvent<HTMLInputElement>) => {
// console.log('value', value)
setValueState(value)
// return onChange(value === "" ? options.emptyValue : value)
return onChange(value === "" ? options.emptyValue : value)
const handleChange = (
event: React.ChangeEvent<HTMLInputElement> | React.FocusEvent<HTMLInputElement>,
isBlur: boolean = false
) => {
const newValue = event.target.value.trim();
if (newValue.startsWith('!') && value?.startsWith('!')) {
setValueState(newValue.replace(/^!/, ''));
Copy link
Collaborator

Choose a reason for hiding this comment

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

onChange is only called in the else case, if you do this sequence:

  1. enter "!abc"
  2. setValues changes to "abc"
  3. toggle back to inclusion
  4. enter "!" in front of "abc" again, it won't enter onChange right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see this is only used in the dropdown, would there be a case where it starts with "!"?

} else {
setValueState(newValue);
const actualValue = excludeToggle ? `!${newValue}` : newValue;
onChange(actualValue === '' ? options.emptyValue : actualValue);
if (isBlur) {
onBlur(id, actualValue);
}
}
};
const _onBlur = ({ target: { value } }: React.FocusEvent<HTMLInputElement>) => {
value = value.trim();
onChange(value === "" ? options.emptyValue : value);
onBlur(id, value);
}

const _onFocus = ({
target: { value },
}: React.FocusEvent<HTMLInputElement>) => onFocus(id, value);
target: { value },
}: React.FocusEvent<HTMLInputElement>) => onFocus(id, value);
const inputType = (type || schema.type) === "string" ? "text" : `${type || schema.type}`
const labelValue = uiSchema?.["ui:title"] || schema.title || label;

Expand Down Expand Up @@ -87,17 +102,19 @@ const CtimsInputWithExcludeToggle = (props: WidgetProps) => {
className={cn("w-full")}
list={schema.examples ? `examples_${id}` : undefined}
type={inputType}
value={value || value === 0 ? value.replace('!', '') : ""}
onChange={_onChange}
onBlur={_onBlur}
value={valueState}
onChange={(event) => handleChange(event)}
onBlur={(event) => handleChange(event, true)}
onFocus={_onFocus}
/>
<div style={{ display: 'flex' }}>
<div className={styles.label}> Exclude this diagnosis from matches </div>
<div style={{marginLeft: 'auto', marginTop: '10px'}}><IOSSwitch disabled={!value} value={value ? value.startsWith('!') : false} onChange={(checked: boolean) => {
const newValue = checked ? '!' + value : value.replace('!', '');
onChange(newValue);
}} /></div>
<div style={{ marginLeft: 'auto', marginTop: '10px' }}><IOSSwitch
disabled={!props.value}
value={excludeToggle}
onChange={handleToggleChange}
/>
</div>
</div>
</div>
);
Expand Down