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 1 commit
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);
}
117 changes: 117 additions & 0 deletions libs/ui/src/lib/components/CtimsCombinedWidget.tsx
Copy link
Collaborator

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?

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 a lot of changes between this vs CtimsAutoCompleteComponent? can we just add the toggle to CtimsAutoCompleteComponent and have it shown controlled by a property

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.

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',
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

can these 2 styles go into the css file?

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

const questionMarkStyle = `${styles['question-mark']} pi pi-question-circle`;
const labelValue = schema?.["ui:title"] || schema.title || 'Hugo Symbol';
Copy link
Collaborator

@mickey-ng mickey-ng Jan 10, 2025

Choose a reason for hiding this comment

The 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

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.


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;
18 changes: 17 additions & 1 deletion 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,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)
Expand Down Expand Up @@ -160,6 +163,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 @@ -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,
}
}
}
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
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,118 @@
import { WidgetProps } from '@rjsf/utils';
import React, { useEffect, useState } from 'react';
import styles from './CtimsInputWithExcludeToggle.module.css';
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?.();
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

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