diff --git a/libs/ui/src/lib/components/forms/GenomicForm.tsx b/libs/ui/src/lib/components/forms/GenomicForm.tsx index 685ff7ac..8b217457 100644 --- a/libs/ui/src/lib/components/forms/GenomicForm.tsx +++ b/libs/ui/src/lib/components/forms/GenomicForm.tsx @@ -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'); } diff --git a/libs/ui/src/lib/custom-rjsf-templates/CtimsInputWithExcludeToggle.tsx b/libs/ui/src/lib/custom-rjsf-templates/CtimsInputWithExcludeToggle.tsx index bf0873bd..7191f020 100644 --- a/libs/ui/src/lib/custom-rjsf-templates/CtimsInputWithExcludeToggle.tsx +++ b/libs/ui/src/lib/custom-rjsf-templates/CtimsInputWithExcludeToggle.tsx @@ -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; @@ -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) => { - // console.log('value', value) - setValueState(value) - // return onChange(value === "" ? options.emptyValue : value) - return onChange(value === "" ? options.emptyValue : value) + const handleChange = ( + event: React.ChangeEvent | React.FocusEvent, + isBlur: boolean = false + ) => { + const newValue = event.target.value.trim(); + if (newValue.startsWith('!') && value?.startsWith('!')) { + setValueState(newValue.replace(/^!/, '')); + } else { + setValueState(newValue); + const actualValue = excludeToggle ? `!${newValue}` : newValue; + onChange(actualValue === '' ? options.emptyValue : actualValue); + if (isBlur) { + onBlur(id, actualValue); + } + } }; - const _onBlur = ({ target: { value } }: React.FocusEvent) => { - value = value.trim(); - onChange(value === "" ? options.emptyValue : value); - onBlur(id, value); - } const _onFocus = ({ - target: { value }, - }: React.FocusEvent) => onFocus(id, value); + target: { value }, + }: React.FocusEvent) => onFocus(id, value); const inputType = (type || schema.type) === "string" ? "text" : `${type || schema.type}` const labelValue = uiSchema?.["ui:title"] || schema.title || label; @@ -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} />
Exclude this diagnosis from matches
-
{ - const newValue = checked ? '!' + value : value.replace('!', ''); - onChange(newValue); - }} />
+
+
);