Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 28x 28x 28x 28x 28x 26x 28x 1x 1x 1x 1x 1x 1x 27x 27x 27x 27x 27x 1x 1x 1x 1x | // TODO: to refactor.
import { type Overwrite } from '@amalia/core/models';
import { type RecordContent } from '@amalia/data-capture/connectors/types';
const CLEAR_KEYWORD = 'clear';
const DELETE_KEYWORD = 'delete';
// in order to compare as a string
const stringify = (value: unknown) => JSON.stringify(value).replaceAll('"', '');
// 1. There's an overwrite and the sourceValue of this overwrite is equal to the new overwriteValue
// 2. If the new overwriteValue (type currency) = 'clean'
// 3. If the new overwriteValue (type ordinary) = 'clean'
export const isCleanOperation = (
overwriteToClear: Overwrite | null,
overwriteValue: Overwrite['overwriteValue'],
fieldMachineName: string,
) =>
(overwriteToClear && stringify(overwriteToClear.sourceValue)) === stringify(overwriteValue) ||
// @ts-expect-error -- fuck this
(overwriteValue as RecordContent | undefined)?.[fieldMachineName]?.value === CLEAR_KEYWORD ||
(overwriteValue as RecordContent | undefined)?.[fieldMachineName] === CLEAR_KEYWORD;
// TODO: to refactor.
// 2. If the new overwriteValue (type currency) = 'delete'
// 3. If the new overwriteValue (type ordinary) = 'delete'
export const isDeleteOperation = (overwrite: Overwrite, fieldMachineName: string) =>
// @ts-expect-error -- fuck this
['', DELETE_KEYWORD].includes((overwrite.overwriteValue as RecordContent | undefined)?.[fieldMachineName]) ||
['', DELETE_KEYWORD].includes(
// @ts-expect-error -- and that
(overwrite.overwriteValue as RecordContent | undefined)?.[fieldMachineName]?.value as string,
);
export const isValueUnchanged = (overwriteToClear: Overwrite | null, sourceValue: unknown, overwriteValue: unknown) =>
!overwriteToClear && stringify(sourceValue) === stringify(overwriteValue);
|