-
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 1 commit
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { AutoComplete } from 'primereact/autocomplete'; | ||
import { Tooltip } from 'primereact/tooltip'; | ||
import styles from './CtimsAutoCompleteComponent.module.css'; | ||
import useGetGenes from '../../../../../apps/web/hooks/useGetGenes'; | ||
import IOSSwitch from '../components/IOSSwitch'; | ||
|
||
interface AutocompleteFieldProps { | ||
value?: string; | ||
onChange: (value: string | undefined) => void; | ||
schema: { | ||
title?: string; | ||
description?: string; | ||
["ui:title"]?: string; | ||
}; | ||
} | ||
|
||
const AutocompleteField: React.FC<AutocompleteFieldProps> = ({ onChange, schema, ...props }) => { | ||
const { filteredHugoSymbols, searchSymbols } = useGetGenes(); | ||
const [selectedHugoSymbol, setSelectedHugoSymbol] = useState<string>(props.value || ''); | ||
const [excludeToggle, setExcludeToggle] = useState<boolean>( | ||
props.value?.startsWith('!') || false | ||
); | ||
|
||
useEffect(() => { | ||
const isExcluded = props.value?.startsWith('!'); | ||
setSelectedHugoSymbol(props.value ? props.value.replace('!', '') : ''); | ||
setExcludeToggle(isExcluded || false); | ||
}, [props.value]); | ||
|
||
const handleInputChange = (e: { value: string }) => { | ||
const trimmedValue = e.value.trim(); | ||
if (trimmedValue !== '') { | ||
const newValue = excludeToggle ? `!${trimmedValue}` : trimmedValue; | ||
setSelectedHugoSymbol(trimmedValue); | ||
onChange(newValue); | ||
} else { | ||
setSelectedHugoSymbol(''); | ||
onChange(undefined); | ||
} | ||
}; | ||
|
||
const handleToggleChange = (checked: boolean) => { | ||
setExcludeToggle(checked); | ||
const newValue = checked ? `!${selectedHugoSymbol}` : selectedHugoSymbol.replace('!', ''); | ||
onChange(newValue); | ||
}; | ||
|
||
const arrayContainer = { | ||
flexGrow: 1, | ||
minWidth: 0, | ||
marginLeft: 'auto', | ||
}; | ||
|
||
const labelStyle = { | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '0.5rem', | ||
height: '36px', | ||
fontFamily: "'Inter', sans-serif", | ||
fontStyle: 'normal', | ||
fontWeight: '400', | ||
fontSize: '14px', | ||
lineHeight: '20px', | ||
color: '#495057', | ||
}; | ||
|
||
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. can these 2 styles go into the css file? 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 |
||
const questionMarkStyle = `${styles['question-mark']} pi pi-question-circle`; | ||
const labelValue = schema?.["ui:title"] || schema.title || 'Hugo Symbol'; | ||
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. schema will never be null since it's a prop, the question mark is not necessary 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. |
||
|
||
return ( | ||
<div className={styles.container}> | ||
{labelValue && ( | ||
<label style={labelStyle}> | ||
{labelValue} | ||
{schema.description && ( | ||
<Tooltip target=".tooltip-icon" position="top" /> | ||
)} | ||
<i | ||
className={`tooltip-icon ${questionMarkStyle}`} | ||
data-pr-tooltip={schema.description} | ||
></i> | ||
</label> | ||
)} | ||
|
||
<AutoComplete | ||
inputStyle={arrayContainer} | ||
value={selectedHugoSymbol} | ||
suggestions={filteredHugoSymbols} | ||
completeMethod={(e) => { | ||
const trimmedValue = e.query.trim(); | ||
if (trimmedValue !== '') { | ||
const newValue = excludeToggle ? `!${trimmedValue}` : trimmedValue; | ||
setSelectedHugoSymbol(trimmedValue); | ||
onChange(newValue); | ||
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> | ||
); | ||
}; | ||
|
||
export default AutocompleteField; |
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,9 @@ 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'; | ||
import AutocompleteFieldWithToggle from "../CtimsCombinedWidget"; | ||
|
||
|
||
const RjsfForm = withTheme(PrimeTheme) | ||
|
@@ -160,6 +163,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': { | ||
|
@@ -498,7 +505,16 @@ export const GenomicForm = (props: IFormProps) => { | |
}, | ||
"variantCategoryContainerObject": { | ||
"hugo_symbol": { | ||
"ui:widget": AutocompleteField, | ||
"ui:widget": AutocompleteFieldWithToggle, | ||
}, | ||
"fusion_partner_hugo_symbol": { | ||
"ui:widget": AutocompleteFieldWithToggle, | ||
}, | ||
"protein_change": { | ||
"ui:widget": CtimsInputWithExcludeToggle, | ||
}, | ||
"cnv_call": { | ||
"ui:widget": CtimsDropdownWithExcludeToggle, | ||
} | ||
} | ||
} | ||
|
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,118 @@ | ||
import { WidgetProps } from '@rjsf/utils'; | ||
import React, { useEffect, useState } from 'react'; | ||
import styles from './CtimsInputWithExcludeToggle.module.css'; | ||
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. Avoid importing from other component's css class for maintainability. Generally the css file services its own module, if there's a change in CtimsInputWithExcludeToggle it will unknowingly affect other components. If it's global style, consider moving to the global style.css 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. I have created a new CSS file for CTIMSDropdownWithExcludeToggle. |
||
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(value?.replace('!', '') || ''); | ||
const [isNegated, setIsNegated] = useState(value?.startsWith('!') || 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. value.startsWith("!") will return a boolean, when state is boolean there's no need to check the value of a boolean to set a boolean value |
||
|
||
useEffect(() => { | ||
const currentURL = window.location.href; | ||
if (label === 'Trial ID' && currentURL.includes('/trials/create')) { | ||
onChange(''); | ||
} | ||
}, []); | ||
|
||
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; | ||
|
||
const handleDropdownChange = (e: { value: any }) => { | ||
const selectedValue = e.value; | ||
setValueState(selectedValue); | ||
const backendValue = getBackendValue(selectedValue, isNegated); | ||
onChange(backendValue); | ||
}; | ||
|
||
const handleToggleChange = (checked: boolean) => { | ||
setIsNegated(checked); | ||
const backendValue = getBackendValue(valueState, checked); | ||
onChange(backendValue); | ||
}; | ||
|
||
const handleBlur = () => { | ||
const trimmedValue = valueState?.trim?.(); | ||
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 valueState was initialized as "" by default, then it avoids redundant check to see if valueState is defined and if trim method exists 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. Initialized valueState with "", so removed checked if valueState exists with in handleBlur function. |
||
const backendValue = getBackendValue(trimmedValue, isNegated); | ||
onChange(backendValue); | ||
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.
is this the AutoCompleteField widget? Can you rename the file name to be more appropriate?
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.
Are there a lot of changes between this vs CtimsAutoCompleteComponent? can we just add the toggle to CtimsAutoCompleteComponent and have it shown controlled by a property
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.
This component no longer exists, as this code is moved to the Autocomplete component.