Skip to content

Commit

Permalink
chore(label correlation): fix naming
Browse files Browse the repository at this point in the history
Related to #960
  • Loading branch information
Skaiir committed Jan 3, 2024
1 parent b7d68ca commit 167dbc4
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { useRef } from 'preact/hooks';
import useOptionsAsync, { LOAD_STATES } from '../../hooks/useOptionsAsync';
import useCleanupMultiSelectValues from '../../hooks/useCleanupMultiSelectValues';
import classNames from 'classnames';
import isDeepEqual from 'lodash/isEqual';
import isEqual from 'lodash/isEqual';

import Description from '../Description';
import Errors from '../Errors';
import Label from '../Label';

import { sanitizeMultiSelectValue, isDeepIncluded } from '../util/sanitizerUtil';
import { sanitizeMultiSelectValue, hasEqualValue } from '../util/sanitizerUtil';

import { createEmptyOptions } from '../util/optionsUtil';

Expand Down Expand Up @@ -44,8 +44,8 @@ export default function Checklist(props) {

const toggleCheckbox = (toggledValue) => {

const newValues = isDeepIncluded(toggledValue, values)
? values.filter(value => !isDeepEqual(value, toggledValue))
const newValues = hasEqualValue(toggledValue, values)
? values.filter(value => !isEqual(value, toggledValue))
: [ ...values, toggledValue ];

props.onChange({
Expand Down Expand Up @@ -93,7 +93,7 @@ export default function Checklist(props) {
loadState == LOAD_STATES.LOADED && options.map((o, index) => {

const itemDomId = `${domId}-${index}`;
const isChecked = isDeepIncluded(o.value, values);
const isChecked = hasEqualValue(o.value, values);

return (
<Label
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useRef } from 'preact/hooks';
import isDeepEqual from 'lodash/isEqual';
import isEqual from 'lodash/isEqual';
import useOptionsAsync, { LOAD_STATES } from '../../hooks/useOptionsAsync';
import useCleanupSingleSelectValue from '../../hooks/useCleanupSingleSelectValue';
import classNames from 'classnames';
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function Radio(props) {
loadState == LOAD_STATES.LOADED && options.map((option, index) => {

const itemDomId = `${domId}-${index}`;
const isChecked = isDeepEqual(option.value, value);
const isChecked = isEqual(option.value, value);

return (
<Label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMemo, useRef, useState } from 'preact/hooks';
import { useService } from '../../hooks';
import useOptionsAsync, { LOAD_STATES } from '../../hooks/useOptionsAsync';
import useCleanupMultiSelectValues from '../../hooks/useCleanupMultiSelectValues';
import { useLabelCorrelation } from '../../hooks/useLabelCorrelation';
import { useGetLabelCorrelation } from '../../hooks/useGetLabelCorrelation';

import classNames from 'classnames';

Expand All @@ -14,8 +14,8 @@ import Errors from '../Errors';
import Label from '../Label';
import SkipLink from './parts/SkipLink';

import { sanitizeMultiSelectValue, isDeepIncluded } from '../util/sanitizerUtil';
import isDeepEqual from 'lodash/isEqual';
import { sanitizeMultiSelectValue, hasEqualValue } from '../util/sanitizerUtil';
import isEqual from 'lodash/isEqual';

import { createEmptyOptions } from '../util/optionsUtil';

Expand Down Expand Up @@ -66,7 +66,7 @@ export default function Taglist(props) {
onChange: props.onChange
});

const correlateLabel = useLabelCorrelation(options);
const getLabelCorrelation = useGetLabelCorrelation(options);

const hasOptionsLeft = useMemo(() => options.length > values.length, [ options.length, values.length ]);

Expand All @@ -78,7 +78,7 @@ export default function Taglist(props) {

const isValidFilteredOption = (option) => {
const filterMatches = option.label.toLowerCase().includes(filter.toLowerCase());
return filterMatches && !isDeepIncluded(option.value, values);
return filterMatches && !hasEqualValue(option.value, values);
};

return options.filter(isValidFilteredOption);
Expand All @@ -98,7 +98,7 @@ export default function Taglist(props) {
};

const deselectValue = (value) => {
const newValues = values.filter((v) => !isDeepEqual(v, value));
const newValues = values.filter((v) => !isEqual(v, value));
props.onChange({ value: newValues, field });
};

Expand Down Expand Up @@ -201,7 +201,7 @@ export default function Taglist(props) {
return (
<div class={ classNames('fjs-taglist-tag', { 'fjs-disabled': disabled, 'fjs-readonly': readonly }) } onMouseDown={ (e) => e.preventDefault() }>
<span class="fjs-taglist-tag-label">
{ correlateLabel(v) }
{ getLabelCorrelation(v) }
</span>
{ (!disabled && !readonly) && <button
type="button"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'preact/hooks';
import useOptionsAsync, { LOAD_STATES } from '../../../hooks/useOptionsAsync';
import { useLabelCorrelation } from '../../../hooks/useLabelCorrelation';
import { useGetLabelCorrelation } from '../../../hooks/useGetLabelCorrelation';
import { useService } from '../../../hooks';
import useCleanupSingleSelectValue from '../../../hooks/useCleanupSingleSelectValue';

Expand Down Expand Up @@ -43,9 +43,9 @@ export default function SearchableSelect(props) {
onChange: props.onChange
});

const correlateLabel = useLabelCorrelation(options);
const getLabelCorrelation = useGetLabelCorrelation(options);

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

// whenever we change the underlying value, set the label to it
useEffect(() => { setFilter(label); }, [ label ]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import { findIndex } from 'min-dash';
import useOptionsAsync, { LOAD_STATES } from '../../../hooks/useOptionsAsync';
import useCleanupSingleSelectValue from '../../../hooks/useCleanupSingleSelectValue';
import { useLabelCorrelation } from '../../../hooks/useLabelCorrelation';
import { useGetLabelCorrelation } from '../../../hooks/useGetLabelCorrelation';

import XMarkIcon from '../icons/XMark.svg';
import AngelDownIcon from '../icons/AngelDown.svg';
Expand Down Expand Up @@ -39,9 +39,9 @@ export default function SimpleSelect(props) {
onChange: props.onChange
});

const correlateLabel = useLabelCorrelation(options);
const getLabelCorrelation = useGetLabelCorrelation(options);

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

const setValue = useCallback((option) => {
props.onChange({ value: option && option.value || null, field });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isDeepEqual from 'lodash/isEqual';
import isEqual from 'lodash/isEqual';
import { DATETIME_SUBTYPES } from '../../../util/constants/DatetimeConstants';
import { isDateInputInformationMatching, isDateTimeInputInformationSufficient, isInvalidDateString, parseIsoTime } from './dateTimeUtil';
import { getOptionsData, normalizeOptionsData } from './optionsUtil';
Expand All @@ -20,13 +20,13 @@ export function sanitizeDateTimePickerValue(options) {
return value;
}

export function isDeepIncluded(value, array) {
export function hasEqualValue(value, array) {

if (!Array.isArray(array)) {
return false;
}

return array.some(element => isDeepEqual(value, element));
return array.some(element => isEqual(value, element));
}

export function sanitizeSingleSelectValue(options) {
Expand All @@ -38,7 +38,7 @@ export function sanitizeSingleSelectValue(options) {

try {
const validValues = normalizeOptionsData(getOptionsData(formField, data)).map(v => v.value);
return isDeepIncluded(value, validValues) ? value : null;
return hasEqualValue(value, validValues) ? value : null;
} catch (error) {

// use default value in case of formatting error
Expand All @@ -56,7 +56,7 @@ export function sanitizeMultiSelectValue(options) {

try {
const validValues = normalizeOptionsData(getOptionsData(formField, data)).map(v => v.value);
return value.filter(v => isDeepIncluded(v, validValues));
return value.filter(v => hasEqualValue(v, validValues));
} catch (error) {

// use default value in case of formatting error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'preact/hooks';
import { LOAD_STATES } from './useOptionsAsync';
import { isDeepIncluded } from '../components/util/sanitizerUtil';
import { hasEqualValue } from '../components/util/sanitizerUtil';

export default function(props) {

Expand All @@ -20,12 +20,12 @@ export default function(props) {
}

const optionValues = options.map(o => o.value);
const hasValuesNotInOptions = values.some(v => !isDeepIncluded(v, optionValues));
const hasValuesNotInOptions = values.some(v => !hasEqualValue(v, optionValues));

if (hasValuesNotInOptions) {
onChange({
field,
value: values.filter(v => isDeepIncluded(v, optionValues))
value: values.filter(v => hasEqualValue(v, optionValues))
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'preact/hooks';
import { LOAD_STATES } from './useOptionsAsync';
import { isDeepIncluded } from '../components/util/sanitizerUtil';
import { hasEqualValue } from '../components/util/sanitizerUtil';

export default function(props) {

Expand All @@ -20,7 +20,7 @@ export default function(props) {
}

const optionValues = options.map(o => o.value);
const hasValueNotInOptions = value && !isDeepIncluded(value, optionValues);
const hasValueNotInOptions = value && !hasEqualValue(value, optionValues);

if (hasValueNotInOptions) {
onChange({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isObject } from 'min-dash';
* This hook allows us to retrieve the label from a value in linear time by caching it in a map
* @param {Array} options
*/
export function useLabelCorrelation(options) {
export function useGetLabelCorrelation(options) {

// This allows us to retrieve the label from a value in linear time
const labelMap = useMemo(() => Object.assign({}, ...options.map((o) => ({ [_getValueHash(o.value)]: o.label }))), [ options ]);
Expand Down

0 comments on commit 167dbc4

Please sign in to comment.