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

Dheeraj_CTM_656 #212

wants to merge 5 commits into from

Conversation

dgavini
Copy link

@dgavini dgavini commented Jan 7, 2025

Added toggle functionality for a few fields in matching criteria.

@dgavini dgavini requested review from jagnathan and mickey-ng January 7, 2025 18:26
};

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.

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

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.

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.

} = 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

@@ -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.

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.

"!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.

@dgavini dgavini requested a review from mickey-ng January 21, 2025 17:00
const [selectedHugoSymbol, setSelectedHugoSymbol] = useState<string>(props.value || '');
const [excludeToggle, setExcludeToggle] = useState<boolean>(
props.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.

Initial value don't need to be determined by props.value since their values will be updated in the useEffect below, Initiation value can be simply "" and false, and the useEffect hook will update accordinly

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 made changes to set selectedHugoSymbol to "" and excludeToggle to "false"



useEffect(() => {
setSelectedHugoSymbol([props.value]);
const isExcluded = props.value?.startsWith('!');
Copy link
Collaborator

@mickey-ng mickey-ng Jan 22, 2025

Choose a reason for hiding this comment

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

Use type to simplify this: const isExcluded: boolean
Then you don't need to use "|| false" below

Copy link
Author

Choose a reason for hiding this comment

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

Added Boolean type for isExcluded

} = props;

const [valueState, setValueState] = useState(value?.replace('!', '') || '');
const [isNegated, setIsNegated] = useState(value?.startsWith('!'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Usually we set the initial value as '' or false, then have a useEffect hook depending on value to update the state constant. Since they are declared as "const", their value shouldn't be changed, and we rely on react's hook to update the value. The current way of declaration is more a "let" than "const".

Copy link
Author

Choose a reason for hiding this comment

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

Initialized the valueState with "" and isNegated with false.

};

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.

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

} = props;

let [valueState, setValueState] = useState(value?.replace('!', '') || '');
let [isNegated, setIsNegated] = useState(value?.startsWith('!'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

The proper way should use const, and leave the initial value as '' and false, and use a hook depending on the "value" to update the state.

Copy link
Author

Choose a reason for hiding this comment

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

The reason why I am replacing "!" with "" in the initial state is because in this particular scenario that enum has negative values and while displaying in the UI, I want to remove them and only show the regular values.

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.

useEffect(() => {
if (value) {
setValueState(value?.replace('!', ''));
setIsNegated(value?.startsWith('!'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

? is not necessary inside the if, it will always be defined

Copy link
Author

Choose a reason for hiding this comment

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

made code changes to remove ?.

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.

@jagnathan
Copy link
Contributor

jagnathan commented Jan 28, 2025

i reviewed the changes. looks good. lets split this into multiple PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants