Renamed nullable utils into isDefined and isUndefinedOrNull (#4402)
* Renamed nullable utils into isDefined and isUndefinedOrNull
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user