-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dheeraj_CTM_656 #212
base: qa
Are you sure you want to change the base?
Dheeraj_CTM_656 #212
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,26 @@ import { AutoComplete } from 'primereact/autocomplete'; | |
import { Tooltip } from 'antd'; | ||
import styles from "./CtimsAutoCompleteComponent.module.css"; | ||
import useGetGenes from '../../../../../apps/web/hooks/useGetGenes'; | ||
import IOSSwitch from '../components/IOSSwitch'; | ||
|
||
const AutocompleteField = ({ onChange, ...props }) => { | ||
const { filteredHugoSymbols, loading, searchSymbols } = useGetGenes(); | ||
const [selectedHugoSymbol, setSelectedHugoSymbol] = useState([props.value]); | ||
const [selectedHugoSymbol, setSelectedHugoSymbol] = useState<string>(""); | ||
const [excludeToggle, setExcludeToggle] = useState<boolean>(false); | ||
|
||
|
||
useEffect(() => { | ||
setSelectedHugoSymbol([props.value]); | ||
}, [props.value]); | ||
useEffect(() => { | ||
const isExcluded : boolean = props.value?.startsWith('!'); | ||
setSelectedHugoSymbol(props.value ? props.value.replace('!', '') : ''); | ||
setExcludeToggle(isExcluded); | ||
}, [props.value]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A stylistic suggestion for the future: use an if at the top to set the context There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I will keep it in mind for my future commits. |
||
|
||
const handleInputChange = (e: {value: string}) => { | ||
const handleInputChange = (e: { value: string }) => { | ||
|
||
const trimmedValue = e.value.trim(); | ||
trimmedValue !== "" ? | ||
(setSelectedHugoSymbol([trimmedValue]), onChange(trimmedValue)): | ||
(setSelectedHugoSymbol([]), onChange(undefined)); | ||
trimmedValue !== "" ? | ||
(setSelectedHugoSymbol(trimmedValue), onChange(trimmedValue)) : | ||
(setSelectedHugoSymbol(""), onChange(undefined)); | ||
}; | ||
|
||
|
||
|
@@ -39,14 +43,19 @@ const AutocompleteField = ({ onChange, ...props }) => { | |
color: '#495057', | ||
}; | ||
|
||
const handleToggleChange = (checked: boolean) => { | ||
setExcludeToggle(checked); | ||
const newValue = checked ? `!${selectedHugoSymbol}` : selectedHugoSymbol.replace('!', ''); | ||
onChange(newValue); | ||
}; | ||
|
||
const questionMarkStyle = `dropdown-target-icon ${styles['question-mark']} pi pi-question-circle question-mark-target `; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
{props.schema.title && ( | ||
<label style={labelStyle}> | ||
Hugo Symbol | ||
{props.schema.title} | ||
<Tooltip> | ||
<i | ||
className={questionMarkStyle} | ||
|
@@ -62,15 +71,25 @@ const AutocompleteField = ({ onChange, ...props }) => { | |
suggestions={filteredHugoSymbols} | ||
completeMethod={(e) => { | ||
const trimmedValue = e.query.trim(); | ||
trimmedValue === "" | ||
? [] | ||
: (setSelectedHugoSymbol([trimmedValue]), onChange(trimmedValue), searchSymbols(trimmedValue)); | ||
trimmedValue === "" | ||
? [] | ||
: (setSelectedHugoSymbol(trimmedValue), onChange(trimmedValue), searchSymbols(trimmedValue)); | ||
}} | ||
onChange={(e) => { | ||
handleInputChange(e) | ||
}} | ||
appendTo='self' | ||
/> | ||
<div style={{ display: 'flex', marginTop: '10px', alignItems: 'center' }}> | ||
<div className={styles.label}>Exclude this criteria from matches.</div> | ||
<div style={{ marginLeft: 'auto' }}> | ||
<IOSSwitch | ||
disabled={!selectedHugoSymbol} | ||
value={excludeToggle} | ||
onChange={handleToggleChange} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there more code to check in? I don't see AutocompleteFieldWithToggle defined in CtimsCombinedWidget There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component no longer exists, as this code is moved to the Autocomplete component. So, I am using the autocomplete component now to display toggle. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ import {CtimsDialogContext, CtimsDialogContextType} from "../CtimsMatchDialog"; | |
import { Checkbox } from 'primereact/checkbox'; | ||
import {wildcard_protein_change_validation_func, getCurrentOperator, protein_change_validation_func} from "../helpers"; | ||
import AutocompleteField from "../CtimsAutoCompleteComponent"; | ||
import CtimsInputWithExcludeToggle from '../../custom-rjsf-templates/CtimsInputWithExcludeToggle'; | ||
import CtimsDropdownWithExcludeToggle from '../../custom-rjsf-templates/CtimsDropdownWithExcludeToggle'; | ||
|
||
|
||
const RjsfForm = withTheme(PrimeTheme) | ||
|
@@ -160,6 +162,10 @@ export const GenomicForm = (props: IFormProps) => { | |
"Homozygous deletion", | ||
"Gain", | ||
"High level amplification", | ||
"!Heterozygous deletion", | ||
"!Homozygous deletion", | ||
"!Gain", | ||
"!High level amplification", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean we need to have all negated values in the form? Can this be just read in memory and not specified in enum? there's no corresponding enumNames There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to make sure the schema accepts a "!" value, we should add the negative values in the enum. I have added a check to make sure only the value without "!" is displayed in the UI in CtimsDropdownComponent. |
||
] | ||
}, | ||
'wildtype': { | ||
|
@@ -499,6 +505,15 @@ export const GenomicForm = (props: IFormProps) => { | |
"variantCategoryContainerObject": { | ||
"hugo_symbol": { | ||
"ui:widget": AutocompleteField, | ||
}, | ||
"fusion_partner_hugo_symbol": { | ||
"ui:widget": AutocompleteField, | ||
}, | ||
"protein_change": { | ||
"ui:widget": CtimsInputWithExcludeToggle, | ||
}, | ||
"cnv_call": { | ||
"ui:widget": CtimsDropdownWithExcludeToggle, | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.label-container { | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
.label { | ||
font-family: Inter, sans-serif; | ||
font-weight: 400; | ||
font-size: 14px; | ||
margin-bottom: 7px; | ||
margin-top: 7px; | ||
} | ||
|
||
.optional-label { | ||
font-family: Inter, sans-serif; | ||
font-weight: 400; | ||
font-size: 14px; | ||
margin-bottom: 7px; | ||
margin-top: 7px; | ||
margin-left: auto; | ||
color: rgba(0, 0, 0, 0.6); | ||
} | ||
|
||
.question-mark { | ||
margin-left: 8px; | ||
margin-top: 8px; | ||
margin-bottom: 7px; | ||
cursor: pointer; | ||
color: rgba(0, 0, 0, 0.6); | ||
} | ||
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is not much difference with CtimsDropDown, consider consolidating into 1 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { WidgetProps } from '@rjsf/utils'; | ||
import React, { useEffect, useState } from 'react'; | ||
import styles from './CtimsDropdownWithExcludeToggle.module.css'; | ||
import { Tooltip } from 'primereact/tooltip'; | ||
import { Dropdown } from 'primereact/dropdown'; | ||
import cn from 'clsx'; | ||
import IOSSwitch from '../components/IOSSwitch'; | ||
|
||
const CtimsDropdownWithExcludeToggle = (props: WidgetProps) => { | ||
let { | ||
id, | ||
placeholder, | ||
required, | ||
readonly, | ||
disabled, | ||
label, | ||
value, | ||
onChange, | ||
onBlur, | ||
onFocus, | ||
autofocus, | ||
options, | ||
schema, | ||
uiSchema, | ||
rawErrors = [], | ||
} = props; | ||
|
||
const [valueState, setValueState] = useState(''); | ||
const [isNegated, setIsNegated] = useState(false); | ||
|
||
useEffect(() => { | ||
const currentURL = window.location.href; | ||
if (label === 'Trial ID' && currentURL.includes('/trials/create')) { | ||
onChange(''); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (value) { | ||
setValueState(value.replace('!', '')); | ||
setIsNegated(value.startsWith('!')); | ||
} | ||
}, [value]); | ||
|
||
const dropdownOptions = | ||
options.enumOptions | ||
?.filter((opt: any) => !opt.value.startsWith('!')) | ||
.map((opt: any) => ({ | ||
label: opt.label || opt.value, | ||
value: opt.value, | ||
})) || []; | ||
|
||
const getBackendValue = (displayValue: string, negated: boolean) => | ||
negated ? `!${displayValue}` : displayValue; | ||
|
||
useEffect(() => { | ||
const backendValue = getBackendValue(valueState, isNegated); | ||
onChange(backendValue); | ||
}, [valueState, isNegated]); | ||
|
||
const handleDropdownChange = (e: { value: any }) => { | ||
const selectedValue = e.value; | ||
setValueState(selectedValue); | ||
if (!selectedValue) { | ||
setIsNegated(false); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) => { | ||
setIsNegated(checked); | ||
}; | ||
|
||
const handleBlur = () => { | ||
const trimmedValue = valueState.trim(); | ||
onBlur(id, trimmedValue); | ||
}; | ||
|
||
const handleFocus = () => onFocus(id, valueState); | ||
|
||
const labelValue = uiSchema?.['ui:title'] || schema.title || label; | ||
const questionMarkStyle = `input-target-icon ${styles['question-mark']} pi pi-question-circle .question-mark-target `; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<div className={styles['label-container']}> | ||
{labelValue && <span className={styles.label}>{labelValue}</span>} | ||
<Tooltip target=".input-target-icon" /> | ||
{schema.description && ( | ||
<i | ||
className={questionMarkStyle} | ||
data-pr-tooltip={schema.description} | ||
data-pr-position="top" | ||
></i> | ||
)} | ||
</div> | ||
|
||
<Dropdown | ||
id={id} | ||
placeholder={placeholder} | ||
autoFocus={autofocus} | ||
required={required} | ||
disabled={disabled} | ||
readOnly={readonly} | ||
className={cn('w-full', rawErrors.length > 0 ? 'p-invalid' : '')} | ||
options={dropdownOptions} | ||
value={valueState} | ||
onChange={handleDropdownChange} | ||
onBlur={handleBlur} | ||
onFocus={handleFocus} | ||
appendTo='self' | ||
/> | ||
|
||
<div style={{ display: 'flex' }}> | ||
<div className={styles.label}>Exclude this criteria from matches.</div> | ||
<div style={{ marginLeft: 'auto', marginTop: '10px' }}> | ||
<IOSSwitch | ||
disabled={!valueState} | ||
value={isNegated} | ||
onChange={handleToggleChange} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CtimsDropdownWithExcludeToggle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you reformat this file? There's some inconsistent spacing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformatted the complete file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dheeraj has fixed based on the comment