Skip to content
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

Open
wants to merge 5 commits into
base: qa
Choose a base branch
from
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
24 changes: 24 additions & 0 deletions libs/ui/src/lib/components/CtimsAutoCompleteComponent.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,27 @@
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);
}
43 changes: 31 additions & 12 deletions libs/ui/src/lib/components/CtimsAutoCompleteComponent.tsx
Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

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

reformatted the complete file

Copy link
Contributor

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

Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
if (props.value)
{...}
It makes reading the code easier by setting the context first
ie. If situation A, then the follow code happens, else the other code happens

Copy link
Author

Choose a reason for hiding this comment

The 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));
};


Expand All @@ -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}
Expand All @@ -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>
);
};
Expand Down
15 changes: 15 additions & 0 deletions libs/ui/src/lib/components/forms/GenomicForm.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Author

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. So, I am using the autocomplete component now to display toggle.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -160,6 +162,10 @@ export const GenomicForm = (props: IFormProps) => {
"Homozygous deletion",
"Gain",
"High level amplification",
"!Heterozygous deletion",
"!Homozygous deletion",
"!Gain",
"!High level amplification",
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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': {
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/ui/src/lib/components/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const wildcard_protein_change_validation_func = (str: string) => {
}

export const protein_change_validation_func = (str: string) => {
const regex = /^p\.(([A-Z]\d+_[A-Z]\d+)(del$|dup$)|([A-Z]\d+_[A-Z]\d+)(ins[A-Z]+\*?|ins\*\d*|delins[A-Z]+\*?|delins\*\d*|fs\*?\d*)|([A-Z]\d+[A-Z])$|([A-Z]\d+[A-Z])(fs\*?\d*)$|([A-Z]\d+)(\*)$|([A-Z]\d+)(del$|dup$)|([A-Z]\d+)(delins[A-Z]+\*?$|fs\*?(\d*))$)$/;
const regex = /^!?p\.(([A-Z]\d+_[A-Z]\d+)(del$|dup$)|([A-Z]\d+_[A-Z]\d+)(ins[A-Z]+\*?|ins\*\d*|delins[A-Z]+\*?|delins\*\d*|fs\*?\d*)|([A-Z]\d+[A-Z])$|([A-Z]\d+[A-Z])(fs\*?\d*)$|([A-Z]\d+)(\*)$|([A-Z]\d+)(del$|dup$)|([A-Z]\d+)(delins[A-Z]+\*?$|fs\*?(\d*))$)$/;

if (!str) {
return true;
Expand Down
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);
}


Copy link
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
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
@@ -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);
}
Copy link
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
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) => {
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;
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const CtimsInputWithExcludeToggle = (props: WidgetProps) => {
onFocus={_onFocus}
/>
<div style={{ display: 'flex' }}>
<div className={styles.label}> Exclude this diagnosis from matches </div>
<div className={styles.label}> Exclude this criteria 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);
Expand Down