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_AutoCompleteToggle #222

Open
wants to merge 2 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
26 changes: 26 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,29 @@
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);
}



45 changes: 33 additions & 12 deletions libs/ui/src/lib/components/CtimsAutoCompleteComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@ 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(() => {
if (props.value) {
const isExcluded : boolean = props.value.startsWith('!');
setSelectedHugoSymbol(props.value.replace('!', ''));
setExcludeToggle(isExcluded);
}
}, [props.value]);

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 +45,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 +73,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