-
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
Conversation
}; | ||
|
||
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 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
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.
lineHeight: '20px', | ||
color: '#495057', | ||
}; | ||
|
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.
can these 2 styles go into the css file?
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
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.
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 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 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); |
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.
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'; |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I have created a new CSS file for 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.
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 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", |
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.
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 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.
const [selectedHugoSymbol, setSelectedHugoSymbol] = useState<string>(props.value || ''); | ||
const [excludeToggle, setExcludeToggle] = useState<boolean>( | ||
props.value?.startsWith('!') || false | ||
); |
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.
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
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.
I have made changes to set selectedHugoSymbol to "" and excludeToggle to "false"
|
||
|
||
useEffect(() => { | ||
setSelectedHugoSymbol([props.value]); | ||
const isExcluded = props.value?.startsWith('!'); |
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.
Use type to simplify this: const isExcluded: boolean
Then you don't need to use "|| false" below
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.
Added Boolean type for isExcluded
} = props; | ||
|
||
const [valueState, setValueState] = useState(value?.replace('!', '') || ''); | ||
const [isNegated, setIsNegated] = useState(value?.startsWith('!')); |
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.
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".
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.
Initialized the valueState with "" and isNegated with false.
}; | ||
|
||
const handleBlur = () => { | ||
const trimmedValue = valueState?.trim?.(); |
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.
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 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.
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.
Can you reformat this file? There's some inconsistent spacing
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.
reformatted the complete file
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.
Dheeraj has fixed based on the comment
} = props; | ||
|
||
let [valueState, setValueState] = useState(value?.replace('!', '') || ''); | ||
let [isNegated, setIsNegated] = useState(value?.startsWith('!')); |
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.
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.
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.
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]); |
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.
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
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.
Ok, I will keep it in mind for my future commits.
useEffect(() => { | ||
if (value) { | ||
setValueState(value?.replace('!', '')); | ||
setIsNegated(value?.startsWith('!')); |
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 not necessary inside the if, it will always be defined
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.
made code changes to remove ?.
setValueState(selectedValue); | ||
if (!selectedValue) { | ||
setIsNegated(false); | ||
} |
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 is the same as setIsNegated(selectedValue)? or do you only want to trigger this when selectedValue is false?
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.
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.
i reviewed the changes. looks good. lets split this into multiple PRs. |
Added toggle functionality for a few fields in matching criteria.