Renamed nullable utils into isDefined and isUndefinedOrNull (#4402)

* Renamed nullable utils into isDefined and isUndefinedOrNull
This commit is contained in:
Lucas Bordeau
2024-03-11 14:28:57 +01:00
committed by GitHub
parent 3f15cc5b7a
commit 581dfafe11
169 changed files with 469 additions and 493 deletions

View File

@ -1,7 +1,7 @@
import { createContext } from 'react';
import { SpreadsheetOptions } from '@/spreadsheet-import/types';
import { isNullable } from '~/utils/isNullable';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
export const RsiContext = createContext({} as any);
@ -14,7 +14,7 @@ export const Providers = <T extends string>({
children,
values,
}: ProvidersProps<T>) => {
if (isNullable(values.fields)) {
if (isUndefinedOrNull(values.fields)) {
throw new Error('Fields must be provided to spreadsheet-import');
}

View File

@ -1,7 +1,7 @@
import styled from '@emotion/styled';
import { RawData } from '@/spreadsheet-import/types';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
import { Column } from '../MatchColumnsStep';
@ -39,7 +39,7 @@ export const UserTableColumn = <T extends string>({
entries,
}: UserTableColumnProps<T>) => {
const { header } = column;
const entry = entries.find(isNonNullable);
const entry = entries.find(isDefined);
return (
<StyledContainer>

View File

@ -14,7 +14,7 @@ import { useDialogManager } from '@/ui/feedback/dialog-manager/hooks/useDialogMa
import { Button } from '@/ui/input/button/components/Button';
import { Toggle } from '@/ui/input/components/Toggle';
import { Modal } from '@/ui/layout/modal/components/Modal';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
import { generateColumns } from './components/columns';
import { Meta } from './types';
@ -130,7 +130,7 @@ export const ValidationStep = <T extends string>({
const tableData = useMemo(() => {
if (filterByErrors) {
return data.filter((value) => {
if (isNonNullable(value?.__errors)) {
if (isDefined(value?.__errors)) {
return Object.values(value.__errors)?.filter(
(err) => err.level === 'error',
).length;
@ -147,7 +147,7 @@ export const ValidationStep = <T extends string>({
const calculatedData = data.reduce(
(acc, value) => {
const { __index, __errors, ...values } = value;
if (isNonNullable(__errors)) {
if (isDefined(__errors)) {
for (const key in __errors) {
if (__errors[key].level === 'error') {
acc.invalidData.push(values as unknown as Data<T>);
@ -166,7 +166,7 @@ export const ValidationStep = <T extends string>({
};
const onContinue = () => {
const invalidData = data.find((value) => {
if (isNonNullable(value?.__errors)) {
if (isDefined(value?.__errors)) {
return !!Object.values(value.__errors)?.filter(
(err) => err.level === 'error',
).length;

View File

@ -9,7 +9,7 @@ import { AppTooltip } from '@/ui/display/tooltip/AppTooltip';
import { Checkbox, CheckboxVariant } from '@/ui/input/components/Checkbox';
import { TextInput } from '@/ui/input/components/TextInput';
import { Toggle } from '@/ui/input/components/Toggle';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
import { Meta } from '../types';
@ -208,7 +208,7 @@ export const generateColumns = <T extends string>(
);
}
if (isNonNullable(row.__errors?.[columnKey])) {
if (isDefined(row.__errors?.[columnKey])) {
return (
<>
{component}

View File

@ -12,8 +12,8 @@ import {
RowHook,
TableHook,
} from '@/spreadsheet-import/types';
import { isNonNullable } from '~/utils/isNonNullable';
import { isNullable } from '~/utils/isNullable';
import { isDefined } from '~/utils/isDefined';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
export const addErrorsAndRunHooks = <T extends string>(
data: (Data<T> & Partial<Meta>)[],
@ -30,11 +30,11 @@ export const addErrorsAndRunHooks = <T extends string>(
};
};
if (isNonNullable(tableHook)) {
if (isDefined(tableHook)) {
data = tableHook(data, addHookError);
}
if (isNonNullable(rowHook)) {
if (isDefined(rowHook)) {
data = data.map((value, index) =>
rowHook(value, (...props) => addHookError(index, ...props), data),
);
@ -52,7 +52,7 @@ export const addErrorsAndRunHooks = <T extends string>(
values.forEach((value) => {
if (
validation.allowEmpty === true &&
(isNullable(value) || value === '' || !value)
(isUndefinedOrNull(value) || value === '' || !value)
) {
// If allowEmpty is set, we will not validate falsy fields such as undefined or empty string.
return;
@ -142,10 +142,10 @@ export const addErrorsAndRunHooks = <T extends string>(
}
const newValue = value as Data<T> & Meta;
if (isNonNullable(errors[index])) {
if (isDefined(errors[index])) {
return { ...newValue, __errors: errors[index] };
}
if (isNullable(errors[index]) && isNonNullable(value?.__errors)) {
if (isUndefinedOrNull(errors[index]) && isDefined(value?.__errors)) {
return { ...newValue, __errors: null };
}
return newValue;

View File

@ -6,7 +6,7 @@ import {
MatchColumnsStepProps,
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
import { Field, Fields } from '@/spreadsheet-import/types';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
import { findMatch } from './findMatch';
import { setColumn } from './setColumn';
@ -19,7 +19,7 @@ export const getMatchedColumns = <T extends string>(
) =>
columns.reduce<Column<T>[]>((arr, column) => {
const autoMatch = findMatch(column.header, fields, autoMapDistance);
if (isNonNullable(autoMatch)) {
if (isDefined(autoMatch)) {
const field = fields.find((field) => field.key === autoMatch) as Field<T>;
const duplicateIndex = arr.findIndex(
(column) => 'value' in column && column.value === field.key,