Skip to content

Commit

Permalink
chore: cleanup option named o and option keys
Browse files Browse the repository at this point in the history
Related to #3688
  • Loading branch information
Skaiir committed Sep 12, 2024
1 parent 6325f64 commit b7ae83f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ export function Checklist(props) {
<div class={classNames(formFieldClasses(type, { errors, disabled, readonly }))} ref={outerDivRef}>
<Label label={label} required={required} />
{loadState == LOAD_STATES.LOADED &&
options.map((o, index) => {
options.map((option, index) => {
const itemDomId = `${domId}-${index}`;
const isChecked = hasEqualValue(o.value, values);
const isChecked = hasEqualValue(option.value, values);

return (
<div className="fjs-inline-label" key={index}>
<div className="fjs-inline-label" key={option.value}>
<input
checked={isChecked}
class="fjs-input"
disabled={disabled}
readOnly={readonly}
id={itemDomId}
type="checkbox"
onClick={() => toggleCheckbox(o.value)}
onClick={() => toggleCheckbox(option.value)}
onBlur={onCheckboxBlur}
onFocus={onCheckboxFocus}
required={required}
Expand All @@ -90,7 +90,7 @@ export function Checklist(props) {
/>
<Label
htmlFor={itemDomId}
label={o.label}
label={option.label}
class={classNames({
'fjs-checked': isChecked,
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function Radio(props) {
const isChecked = isEqual(option.value, value);

return (
<div className="fjs-inline-label" key={index}>
<div className="fjs-inline-label" key={option.value}>
<input
checked={isChecked}
class="fjs-input"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export function Taglist(props) {
{shouldDisplayDropdown && (
<DropdownList
values={filteredOptions}
getLabel={(o) => o.label}
onValueSelected={(o) => selectValue(o.value)}
getLabel={(option) => option.label}
onValueSelected={(option) => selectValue(option.value)}
emptyListMessage={hasOptionsLeft ? 'No results' : 'All values selected'}
listenerElement={inputRef.current}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ export function SearchableSelect(props) {
return options;
}

return options.filter((o) => o.label && o.value && o.label.toLowerCase().includes(filter.toLowerCase()));
return options.filter(
(option) => option.label && option.value && option.label.toLowerCase().includes(filter.toLowerCase()),
);
}, [filter, loadState, options, isFilterActive]);

const setValue = useCallback(
const pickOption = useCallback(
(option) => {
setFilter((option && option.label) || '');
props.onChange({ value: (option && option.value) || null });
Expand Down Expand Up @@ -159,7 +161,7 @@ export function SearchableSelect(props) {
<span
class="fjs-select-cross"
onMouseDown={(e) => {
setValue(null);
pickOption(null);
e.preventDefault();
}}>
<XMarkIcon />{' '}
Expand All @@ -173,9 +175,9 @@ export function SearchableSelect(props) {
{displayState.displayDropdown && (
<DropdownList
values={filteredOptions}
getLabel={(o) => o.label}
onValueSelected={(o) => {
setValue(o);
getLabel={(option) => option.label}
onValueSelected={(option) => {
pickOption(option);
setIsDropdownExpanded(false);
}}
listenerElement={searchbarRef.current}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function SimpleSelect(props) {

const valueLabel = useMemo(() => value && getLabelCorrelation(value), [value, getLabelCorrelation]);

const setValue = useCallback(
const pickOption = useCallback(
(option) => {
props.onChange({ value: (option && option.value) || null });
},
Expand Down Expand Up @@ -68,7 +68,7 @@ export function SimpleSelect(props) {
);

const initialFocusIndex = useMemo(
() => (value && findIndex(options, (o) => o.value === value)) || 0,
() => (value && findIndex(options, (option) => option.value === value)) || 0,
[options, value],
);

Expand Down Expand Up @@ -112,7 +112,7 @@ export function SimpleSelect(props) {
<span
class="fjs-select-cross"
onMouseDown={(e) => {
setValue(null);
pickOption(null);
e.stopPropagation();
}}>
<XMarkIcon />
Expand All @@ -124,10 +124,10 @@ export function SimpleSelect(props) {
{displayState.displayDropdown && (
<DropdownList
values={options}
getLabel={(o) => o.label}
getLabel={(option) => option.label}
initialFocusIndex={initialFocusIndex}
onValueSelected={(o) => {
setValue(o);
onValueSelected={(option) => {
pickOption(option);
setIsDropdownExpanded(false);
}}
listenerElement={selectRef.current}
Expand Down

0 comments on commit b7ae83f

Please sign in to comment.