Remove some dead code (#6611)
We could remove a lot more than this, this is just a start. There are various tools to help with this, knip is a good one
This commit is contained in:
@ -4,7 +4,7 @@ import { AddressInput } from '@/ui/field/input/components/AddressInput';
|
||||
|
||||
import { usePersistField } from '../../../hooks/usePersistField';
|
||||
|
||||
import { FieldInputEvent } from './DateFieldInput';
|
||||
import { FieldInputEvent } from './DateTimeFieldInput';
|
||||
|
||||
export type AddressFieldInputProps = {
|
||||
onClickOutside?: FieldInputEvent;
|
||||
|
||||
@ -9,7 +9,7 @@ import { useCurrencyField } from '../../hooks/useCurrencyField';
|
||||
|
||||
import { FieldInputEvent } from './DateTimeFieldInput';
|
||||
|
||||
export type CurrencyFieldInputProps = {
|
||||
type CurrencyFieldInputProps = {
|
||||
onClickOutside?: FieldInputEvent;
|
||||
onEnter?: FieldInputEvent;
|
||||
onEscape?: FieldInputEvent;
|
||||
|
||||
@ -6,9 +6,9 @@ import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
import { usePersistField } from '../../../hooks/usePersistField';
|
||||
|
||||
export type FieldInputEvent = (persist: () => void) => void;
|
||||
type FieldInputEvent = (persist: () => void) => void;
|
||||
|
||||
export type DateFieldInputProps = {
|
||||
type DateFieldInputProps = {
|
||||
onClickOutside?: FieldInputEvent;
|
||||
onEnter?: FieldInputEvent;
|
||||
onEscape?: FieldInputEvent;
|
||||
|
||||
@ -13,7 +13,7 @@ const FIRST_NAME_PLACEHOLDER_WITH_SPECIAL_CHARACTER_TO_AVOID_PASSWORD_MANAGERS =
|
||||
const LAST_NAME_PLACEHOLDER_WITH_SPECIAL_CHARACTER_TO_AVOID_PASSWORD_MANAGERS =
|
||||
'Last name';
|
||||
|
||||
export type FullNameFieldInputProps = {
|
||||
type FullNameFieldInputProps = {
|
||||
onClickOutside?: FieldInputEvent;
|
||||
onEnter?: FieldInputEvent;
|
||||
onEscape?: FieldInputEvent;
|
||||
|
||||
@ -5,7 +5,7 @@ import { useLinkField } from '../../hooks/useLinkField';
|
||||
|
||||
import { FieldInputEvent } from './DateTimeFieldInput';
|
||||
|
||||
export type LinkFieldInputProps = {
|
||||
type LinkFieldInputProps = {
|
||||
onClickOutside?: FieldInputEvent;
|
||||
onEnter?: FieldInputEvent;
|
||||
onEscape?: FieldInputEvent;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { useMemo, useRef, useState } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { useMemo, useRef, useState } from 'react';
|
||||
import { Key } from 'ts-key-enum';
|
||||
import { IconCheck, IconPlus } from 'twenty-ui';
|
||||
|
||||
@ -24,7 +24,7 @@ const StyledDropdownMenu = styled(DropdownMenu)`
|
||||
top: -1px;
|
||||
`;
|
||||
|
||||
export type LinksFieldInputProps = {
|
||||
type LinksFieldInputProps = {
|
||||
onCancel?: () => void;
|
||||
};
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
IconBookmark,
|
||||
IconBookmarkPlus,
|
||||
|
||||
@ -23,7 +23,7 @@ const StyledRelationPickerContainer = styled.div`
|
||||
top: -1px;
|
||||
`;
|
||||
|
||||
export type MultiSelectFieldInputProps = {
|
||||
type MultiSelectFieldInputProps = {
|
||||
onCancel?: () => void;
|
||||
};
|
||||
|
||||
|
||||
@ -3,9 +3,9 @@ import { TextAreaInput } from '@/ui/field/input/components/TextAreaInput';
|
||||
|
||||
import { useJsonField } from '../../hooks/useJsonField';
|
||||
|
||||
import { FieldInputEvent } from './DateFieldInput';
|
||||
import { FieldInputEvent } from './DateTimeFieldInput';
|
||||
|
||||
export type RawJsonFieldInputProps = {
|
||||
type RawJsonFieldInputProps = {
|
||||
onClickOutside?: FieldInputEvent;
|
||||
onEnter?: FieldInputEvent;
|
||||
onEscape?: FieldInputEvent;
|
||||
|
||||
@ -12,7 +12,7 @@ import { MultiRecordSelect } from '@/object-record/relation-picker/components/Mu
|
||||
import { useAddNewRecordAndOpenRightDrawer } from '@/object-record/relation-picker/hooks/useAddNewRecordAndOpenRightDrawer';
|
||||
import { RelationPickerScope } from '@/object-record/relation-picker/scopes/RelationPickerScope';
|
||||
|
||||
export type RelationFromManyFieldInputProps = {
|
||||
type RelationFromManyFieldInputProps = {
|
||||
onSubmit?: FieldInputEvent;
|
||||
};
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ const StyledRelationPickerContainer = styled.div`
|
||||
top: -1px;
|
||||
`;
|
||||
|
||||
export type SelectFieldInputProps = {
|
||||
type SelectFieldInputProps = {
|
||||
onSubmit?: FieldInputEvent;
|
||||
onCancel?: () => void;
|
||||
};
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
import { createState } from 'twenty-ui';
|
||||
|
||||
export const recordPositionInternalState = createState<number | null>({
|
||||
key: 'recordPositionInternalState',
|
||||
defaultValue: null,
|
||||
});
|
||||
@ -1,7 +0,0 @@
|
||||
import { FieldDefinition } from './FieldDefinition';
|
||||
import { FieldMetadata } from './FieldMetadata';
|
||||
|
||||
export type FieldDefinitionSerializable = Omit<
|
||||
FieldDefinition<FieldMetadata>,
|
||||
'Icon'
|
||||
>;
|
||||
@ -1 +0,0 @@
|
||||
export const CREATE_BUTTON_ID = 'create-button';
|
||||
@ -1 +0,0 @@
|
||||
export const EMPTY_BUTTON_ID = 'empty-button';
|
||||
@ -1,10 +0,0 @@
|
||||
export const getPreselectedIdIndex = (
|
||||
selectableOptionIds: string[],
|
||||
preselectedOptionId: string,
|
||||
) => {
|
||||
const preselectedIdIndex = selectableOptionIds.findIndex(
|
||||
(option) => option === preselectedOptionId,
|
||||
);
|
||||
|
||||
return preselectedIdIndex === -1 ? 0 : preselectedIdIndex;
|
||||
};
|
||||
@ -1,5 +0,0 @@
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
|
||||
export const mapToRecordId = (objectRecord: ObjectRecord) => {
|
||||
return objectRecord.id;
|
||||
};
|
||||
@ -1,5 +0,0 @@
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
|
||||
export const sortByObjectRecordId = (a: ObjectRecord, b: ObjectRecord) => {
|
||||
return a.id.localeCompare(b.id);
|
||||
};
|
||||
@ -1,85 +0,0 @@
|
||||
import { OrderBy } from '@/object-metadata/types/OrderBy';
|
||||
|
||||
import { sortObjectRecordByDateField } from './sortObjectRecordByDateField';
|
||||
|
||||
describe('sortByObjectRecordByCreatedAt', () => {
|
||||
const recordOldest = {
|
||||
id: '',
|
||||
createdAt: '2022-01-01T00:00:00.000Z',
|
||||
__typename: 'RecordType',
|
||||
};
|
||||
const recordNewest = {
|
||||
id: '',
|
||||
createdAt: '2022-01-02T00:00:00.000Z',
|
||||
__typename: 'RecordType',
|
||||
};
|
||||
const recordNull1 = { id: '', createdAt: null, __typename: 'RecordType' };
|
||||
const recordNull2 = { id: '', createdAt: null, __typename: 'RecordType' };
|
||||
|
||||
it('should sort in ascending order with null values first', () => {
|
||||
const sortDirection = 'AscNullsFirst' satisfies OrderBy;
|
||||
const sortedArray = [
|
||||
recordNull2,
|
||||
recordNewest,
|
||||
recordNull1,
|
||||
recordOldest,
|
||||
].sort(sortObjectRecordByDateField('createdAt', sortDirection));
|
||||
|
||||
expect(sortedArray).toEqual([
|
||||
recordNull1,
|
||||
recordNull2,
|
||||
recordOldest,
|
||||
recordNewest,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should sort in descending order with null values first', () => {
|
||||
const sortDirection = 'DescNullsFirst' satisfies OrderBy;
|
||||
const sortedArray = [
|
||||
recordNull2,
|
||||
recordOldest,
|
||||
recordNewest,
|
||||
recordNull1,
|
||||
].sort(sortObjectRecordByDateField('createdAt', sortDirection));
|
||||
|
||||
expect(sortedArray).toEqual([
|
||||
recordNull2,
|
||||
recordNull1,
|
||||
recordNewest,
|
||||
recordOldest,
|
||||
]);
|
||||
});
|
||||
it('should sort in ascending order with null values last', () => {
|
||||
const sortDirection = 'AscNullsLast' satisfies OrderBy;
|
||||
const sortedArray = [
|
||||
recordOldest,
|
||||
recordNull2,
|
||||
recordNewest,
|
||||
recordNull1,
|
||||
].sort(sortObjectRecordByDateField('createdAt', sortDirection));
|
||||
|
||||
expect(sortedArray).toEqual([
|
||||
recordOldest,
|
||||
recordNewest,
|
||||
recordNull1,
|
||||
recordNull2,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should sort in descending order with null values last', () => {
|
||||
const sortDirection = 'DescNullsLast' satisfies OrderBy;
|
||||
const sortedArray = [
|
||||
recordNull1,
|
||||
recordOldest,
|
||||
recordNewest,
|
||||
recordNull2,
|
||||
].sort(sortObjectRecordByDateField('createdAt', sortDirection));
|
||||
|
||||
expect(sortedArray).toEqual([
|
||||
recordNewest,
|
||||
recordOldest,
|
||||
recordNull1,
|
||||
recordNull2,
|
||||
]);
|
||||
});
|
||||
});
|
||||
@ -1,68 +0,0 @@
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { OrderBy } from '@/object-metadata/types/OrderBy';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
const SORT_BEFORE = -1;
|
||||
const SORT_AFTER = 1;
|
||||
const SORT_EQUAL = 0;
|
||||
|
||||
export const sortObjectRecordByDateField =
|
||||
<T extends ObjectRecord>(dateField: keyof T, sortDirection: OrderBy) =>
|
||||
(a: T, b: T) => {
|
||||
const aDate = a[dateField];
|
||||
const bDate = b[dateField];
|
||||
|
||||
if (!isDefined(aDate) && !isDefined(bDate)) {
|
||||
return SORT_EQUAL;
|
||||
}
|
||||
|
||||
if (!isDefined(aDate)) {
|
||||
if (sortDirection === 'AscNullsFirst') {
|
||||
return SORT_BEFORE;
|
||||
} else if (sortDirection === 'DescNullsFirst') {
|
||||
return SORT_BEFORE;
|
||||
} else if (sortDirection === 'AscNullsLast') {
|
||||
return SORT_AFTER;
|
||||
} else if (sortDirection === 'DescNullsLast') {
|
||||
return SORT_AFTER;
|
||||
}
|
||||
|
||||
throw new Error(`Invalid sortDirection: ${sortDirection}`);
|
||||
}
|
||||
|
||||
if (!isDefined(bDate)) {
|
||||
if (sortDirection === 'AscNullsFirst') {
|
||||
return SORT_AFTER;
|
||||
} else if (sortDirection === 'DescNullsFirst') {
|
||||
return SORT_AFTER;
|
||||
} else if (sortDirection === 'AscNullsLast') {
|
||||
return SORT_BEFORE;
|
||||
} else if (sortDirection === 'DescNullsLast') {
|
||||
return SORT_BEFORE;
|
||||
}
|
||||
|
||||
throw new Error(`Invalid sortDirection: ${sortDirection}`);
|
||||
}
|
||||
|
||||
const differenceInMs = DateTime.fromISO(aDate)
|
||||
.diff(DateTime.fromISO(bDate))
|
||||
.as('milliseconds');
|
||||
|
||||
if (differenceInMs === 0) {
|
||||
return SORT_EQUAL;
|
||||
} else if (
|
||||
sortDirection === 'AscNullsFirst' ||
|
||||
sortDirection === 'AscNullsLast'
|
||||
) {
|
||||
return differenceInMs > 0 ? SORT_AFTER : SORT_BEFORE;
|
||||
} else if (
|
||||
sortDirection === 'DescNullsFirst' ||
|
||||
sortDirection === 'DescNullsLast'
|
||||
) {
|
||||
return differenceInMs > 0 ? SORT_BEFORE : SORT_AFTER;
|
||||
}
|
||||
|
||||
throw new Error(`Invalid sortDirection: ${sortDirection}`);
|
||||
};
|
||||
Reference in New Issue
Block a user