TWNTY-3794 - ESLint rule: only take explicit boolean predicates in if statements (#4354)
* ESLint rule: only take explicit boolean predicates in if statements Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Merge main Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Fix frontend linter errors Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Fix jest Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Fix lint on new code Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>
This commit is contained in:
committed by
GitHub
parent
40bea0d95e
commit
17511be0cf
@ -3,6 +3,7 @@ import { gql, useApolloClient } from '@apollo/client';
|
||||
import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMapFieldMetadataToGraphQLQuery';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const useGetRecordFromCache = ({
|
||||
@ -17,7 +18,7 @@ export const useGetRecordFromCache = ({
|
||||
recordId: string,
|
||||
cache = apolloClient.cache,
|
||||
) => {
|
||||
if (!objectMetadataItem) {
|
||||
if (isNullable(objectMetadataItem)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import { Modifiers } from '@apollo/client/cache';
|
||||
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const useModifyRecordFromCache = ({
|
||||
@ -16,7 +17,7 @@ export const useModifyRecordFromCache = ({
|
||||
recordId: string,
|
||||
fieldModifiers: Modifiers<CachedObjectRecord>,
|
||||
) => {
|
||||
if (!objectMetadataItem) return;
|
||||
if (isNullable(objectMetadataItem)) return;
|
||||
|
||||
const cachedRecordId = cache.identify({
|
||||
__typename: capitalize(objectMetadataItem.nameSingular),
|
||||
|
||||
@ -5,6 +5,7 @@ import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMeta
|
||||
import { useAddRecordInCache } from '@/object-record/cache/hooks/useAddRecordInCache';
|
||||
import { useGenerateObjectRecordOptimisticResponse } from '@/object-record/cache/hooks/useGenerateObjectRecordOptimisticResponse';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
export const useCreateManyRecordsInCache = <T extends ObjectRecord>({
|
||||
objectNameSingular,
|
||||
@ -34,7 +35,7 @@ export const useCreateManyRecordsInCache = <T extends ObjectRecord>({
|
||||
const generatedCachedObjectRecord =
|
||||
generateObjectRecordOptimisticResponse<T>(record);
|
||||
|
||||
if (generatedCachedObjectRecord) {
|
||||
if (isNonNullable(generatedCachedObjectRecord)) {
|
||||
addRecordInCache(generatedCachedObjectRecord);
|
||||
|
||||
createdRecordsInCache.push(generatedCachedObjectRecord);
|
||||
|
||||
@ -14,6 +14,7 @@ import { ObjectRecordEdge } from '@/object-record/types/ObjectRecordEdge';
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { filterUniqueRecordEdgesByCursor } from '@/object-record/utils/filterUniqueRecordEdgesByCursor';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
import { logError } from '~/utils/logError';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
@ -84,7 +85,7 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
|
||||
|
||||
onCompleted?.(data[objectMetadataItem.namePlural], pageInfo);
|
||||
|
||||
if (data?.[objectMetadataItem.namePlural]) {
|
||||
if (isNonNullable(data?.[objectMetadataItem.namePlural])) {
|
||||
setLastCursor(pageInfo.endCursor ?? '');
|
||||
setHasNextPage(pageInfo.hasNextPage ?? false);
|
||||
}
|
||||
@ -131,7 +132,7 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
|
||||
|
||||
const pageInfo =
|
||||
fetchMoreResult?.[objectMetadataItem.namePlural]?.pageInfo;
|
||||
if (data?.[objectMetadataItem.namePlural]) {
|
||||
if (isNonNullable(data?.[objectMetadataItem.namePlural])) {
|
||||
setLastCursor(pageInfo.endCursor ?? '');
|
||||
setHasNextPage(pageInfo.hasNextPage ?? false);
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ import { gql } from '@apollo/client';
|
||||
import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMapFieldMetadataToGraphQLQuery';
|
||||
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const getCreateManyRecordsMutationResponseField = (
|
||||
@ -16,7 +17,7 @@ export const useGenerateCreateManyRecordMutation = ({
|
||||
}) => {
|
||||
const mapFieldMetadataToGraphQLQuery = useMapFieldMetadataToGraphQLQuery();
|
||||
|
||||
if (!objectMetadataItem) {
|
||||
if (isNullable(objectMetadataItem)) {
|
||||
return EMPTY_MUTATION;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import { gql } from '@apollo/client';
|
||||
import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMapFieldMetadataToGraphQLQuery';
|
||||
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const getCreateOneRecordMutationResponseField = (
|
||||
@ -16,7 +17,7 @@ export const useGenerateCreateOneRecordMutation = ({
|
||||
}) => {
|
||||
const mapFieldMetadataToGraphQLQuery = useMapFieldMetadataToGraphQLQuery();
|
||||
|
||||
if (!objectMetadataItem) {
|
||||
if (isNullable(objectMetadataItem)) {
|
||||
return EMPTY_MUTATION;
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ import { gql } from '@apollo/client';
|
||||
|
||||
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const getDeleteManyRecordsMutationResponseField = (
|
||||
@ -13,7 +14,7 @@ export const useGenerateDeleteManyRecordMutation = ({
|
||||
}: {
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
}) => {
|
||||
if (!objectMetadataItem) {
|
||||
if (isNullable(objectMetadataItem)) {
|
||||
return EMPTY_MUTATION;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import { gql } from '@apollo/client';
|
||||
import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMapFieldMetadataToGraphQLQuery';
|
||||
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const getExecuteQuickActionOnOneRecordMutationGraphQLField = ({
|
||||
@ -20,7 +21,7 @@ export const useGenerateExecuteQuickActionOnOneRecordMutation = ({
|
||||
}) => {
|
||||
const mapFieldMetadataToGraphQLQuery = useMapFieldMetadataToGraphQLQuery();
|
||||
|
||||
if (!objectMetadataItem) {
|
||||
if (isNullable(objectMetadataItem)) {
|
||||
return EMPTY_MUTATION;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import { gql } from '@apollo/client';
|
||||
import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMapFieldMetadataToGraphQLQuery';
|
||||
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const getUpdateOneRecordMutationResponseField = (
|
||||
@ -16,7 +17,7 @@ export const useGenerateUpdateOneRecordMutation = ({
|
||||
}) => {
|
||||
const mapFieldMetadataToGraphQLQuery = useMapFieldMetadataToGraphQLQuery();
|
||||
|
||||
if (!objectMetadataItem) {
|
||||
if (isNullable(objectMetadataItem)) {
|
||||
return EMPTY_MUTATION;
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/
|
||||
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
|
||||
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
|
||||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
import { getOperandLabel } from '../utils/getOperandLabel';
|
||||
import { getOperandsForFilterType } from '../utils/getOperandsForFilterType';
|
||||
@ -24,7 +25,10 @@ export const ObjectFilterDropdownOperandSelect = () => {
|
||||
setSelectedOperandInDropdown(newOperand);
|
||||
setIsObjectFilterDropdownOperandSelectUnfolded(false);
|
||||
|
||||
if (filterDefinitionUsedInDropdown && selectedFilter) {
|
||||
if (
|
||||
isNonNullable(filterDefinitionUsedInDropdown) &&
|
||||
isNonNullable(selectedFilter)
|
||||
) {
|
||||
selectFilter?.({
|
||||
fieldMetadataId: selectedFilter.fieldMetadataId,
|
||||
displayValue: selectedFilter.displayValue,
|
||||
|
||||
@ -5,6 +5,7 @@ import { FieldMetadataItemOption } from '@/object-metadata/types/FieldMetadataIt
|
||||
import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
|
||||
import { useOptionsForSelect } from '@/object-record/object-filter-dropdown/hooks/useOptionsForSelect';
|
||||
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
export const EMPTY_FILTER_VALUE = '';
|
||||
export const MAX_OPTIONS_TO_DISPLAY = 3;
|
||||
@ -31,7 +32,7 @@ export const ObjectFilterDropdownOptionSelect = () => {
|
||||
>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectOptions) {
|
||||
if (isNonNullable(selectOptions)) {
|
||||
const options = selectOptions.map((option) => {
|
||||
const isSelected =
|
||||
objectFilterDropdownSelectedOptionValues?.includes(option.value) ??
|
||||
@ -70,7 +71,10 @@ export const ObjectFilterDropdownOptionSelect = () => {
|
||||
? `${selectedOptions.length} options`
|
||||
: selectedOptions.map((option) => option.label).join(', ');
|
||||
|
||||
if (filterDefinitionUsedInDropdown && selectedOperandInDropdown) {
|
||||
if (
|
||||
isNonNullable(filterDefinitionUsedInDropdown) &&
|
||||
isNonNullable(selectedOperandInDropdown)
|
||||
) {
|
||||
const newFilterValue =
|
||||
selectedOptions.length > 0
|
||||
? JSON.stringify(selectedOptions.map((option) => option.value))
|
||||
|
||||
@ -2,6 +2,7 @@ import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/
|
||||
import { MultipleRecordSelectDropdown } from '@/object-record/select/components/MultipleRecordSelectDropdown';
|
||||
import { useRecordsForSelect } from '@/object-record/select/hooks/useRecordsForSelect';
|
||||
import { SelectableRecord } from '@/object-record/select/types/SelectableRecord';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
export const EMPTY_FILTER_VALUE = '[]';
|
||||
export const MAX_RECORDS_TO_DISPLAY = 3;
|
||||
@ -66,7 +67,10 @@ export const ObjectFilterDropdownRecordSelect = () => {
|
||||
? `${selectedRecordNames.length} companies`
|
||||
: selectedRecordNames.join(', ');
|
||||
|
||||
if (filterDefinitionUsedInDropdown && selectedOperandInDropdown) {
|
||||
if (
|
||||
isNonNullable(filterDefinitionUsedInDropdown) &&
|
||||
isNonNullable(selectedOperandInDropdown)
|
||||
) {
|
||||
const newFilterValue =
|
||||
newSelectedRecordIds.length > 0
|
||||
? JSON.stringify(newSelectedRecordIds)
|
||||
|
||||
@ -2,6 +2,7 @@ import { OrderBy } from '@/object-metadata/types/OrderBy';
|
||||
import { OrderByField } from '@/object-metadata/types/OrderByField';
|
||||
import { Field } from '~/generated/graphql';
|
||||
import { mapArrayToObject } from '~/utils/array/mapArrayToObject';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
|
||||
import { Sort } from '../types/Sort';
|
||||
|
||||
@ -14,7 +15,7 @@ export const turnSortsIntoOrderBy = (
|
||||
sorts.map((sort) => {
|
||||
const correspondingField = fieldsById[sort.fieldMetadataId];
|
||||
|
||||
if (!correspondingField) {
|
||||
if (isNullable(correspondingField)) {
|
||||
throw new Error(
|
||||
`Could not find field ${sort.fieldMetadataId} in metadata object`,
|
||||
);
|
||||
|
||||
@ -19,6 +19,7 @@ import { actionBarEntriesState } from '@/ui/navigation/action-bar/states/actionB
|
||||
import { contextMenuEntriesState } from '@/ui/navigation/context-menu/states/contextMenuEntriesState';
|
||||
import { ContextMenuEntry } from '@/ui/navigation/context-menu/types/ContextMenuEntry';
|
||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
type useRecordActionBarProps = {
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
@ -62,7 +63,7 @@ export const useRecordActionBar = ({
|
||||
|
||||
if (isFavorite) {
|
||||
deleteFavorite(foundFavorite.id);
|
||||
} else if (selectedRecord) {
|
||||
} else if (isNonNullable(selectedRecord)) {
|
||||
createFavorite(selectedRecord, objectMetadataItem.nameSingular);
|
||||
}
|
||||
callback?.();
|
||||
|
||||
@ -80,7 +80,7 @@ export const recordBoardColumnsFamilySelectorScopeMap =
|
||||
true,
|
||||
);
|
||||
|
||||
if (lastColumn) {
|
||||
if (isNonNullable(lastColumn)) {
|
||||
set(
|
||||
isLastRecordBoardColumnFamilyStateScopeMap({
|
||||
scopeId,
|
||||
@ -100,7 +100,7 @@ export const recordBoardColumnsFamilySelectorScopeMap =
|
||||
true,
|
||||
);
|
||||
|
||||
if (firstColumn) {
|
||||
if (isNonNullable(firstColumn)) {
|
||||
set(
|
||||
isFirstRecordBoardColumnFamilyStateScopeMap({
|
||||
scopeId,
|
||||
|
||||
@ -3,6 +3,7 @@ import { useContext } from 'react';
|
||||
import { isFieldRelation } from '@/object-record/record-field/types/guards/isFieldRelation';
|
||||
import { IconPencil } from '@/ui/display/icon';
|
||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
|
||||
import { FieldContext } from '../contexts/FieldContext';
|
||||
import { isFieldEmail } from '../types/guards/isFieldEmail';
|
||||
@ -12,7 +13,7 @@ import { isFieldPhone } from '../types/guards/isFieldPhone';
|
||||
export const useGetButtonIcon = (): IconComponent | undefined => {
|
||||
const { fieldDefinition } = useContext(FieldContext);
|
||||
|
||||
if (!fieldDefinition) return undefined;
|
||||
if (isNullable(fieldDefinition)) return undefined;
|
||||
|
||||
if (
|
||||
isFieldLink(fieldDefinition) ||
|
||||
|
||||
@ -9,6 +9,7 @@ import { DropdownMenuSearchInput } from '@/ui/layout/dropdown/components/Dropdow
|
||||
import { DropdownMenuSeparator } from '@/ui/layout/dropdown/components/DropdownMenuSeparator';
|
||||
import { MenuItemSelectTag } from '@/ui/navigation/menu-item/components/MenuItemSelectTag';
|
||||
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
const StyledRelationPickerContainer = styled.div`
|
||||
left: -1px;
|
||||
@ -52,7 +53,7 @@ export const SelectFieldInput = ({
|
||||
event.target instanceof HTMLInputElement &&
|
||||
event.target.tagName === 'INPUT'
|
||||
);
|
||||
if (weAreNotInAnHTMLInput && onCancel) {
|
||||
if (weAreNotInAnHTMLInput && isNonNullable(onCancel)) {
|
||||
onCancel();
|
||||
}
|
||||
},
|
||||
|
||||
@ -74,7 +74,7 @@ const tabJestFn = fn();
|
||||
const shiftTabJestFn = fn();
|
||||
|
||||
const clearMocksDecorator: Decorator = (Story, context) => {
|
||||
if (context.parameters.clearMocks) {
|
||||
if (context.parameters.clearMocks === true) {
|
||||
enterJestFn.mockClear();
|
||||
escapeJestfn.mockClear();
|
||||
clickOutsideJestFn.mockClear();
|
||||
|
||||
@ -74,7 +74,7 @@ const tabJestFn = fn();
|
||||
const shiftTabJestFn = fn();
|
||||
|
||||
const clearMocksDecorator: Decorator = (Story, context) => {
|
||||
if (context.parameters.clearMocks) {
|
||||
if (context.parameters.clearMocks === true) {
|
||||
enterJestFn.mockClear();
|
||||
escapeJestfn.mockClear();
|
||||
clickOutsideJestFn.mockClear();
|
||||
|
||||
@ -75,7 +75,7 @@ const tabJestFn = fn();
|
||||
const shiftTabJestFn = fn();
|
||||
|
||||
const clearMocksDecorator: Decorator = (Story, context) => {
|
||||
if (context.parameters.clearMocks) {
|
||||
if (context.parameters.clearMocks === true) {
|
||||
enterJestFn.mockClear();
|
||||
escapeJestfn.mockClear();
|
||||
clickOutsideJestFn.mockClear();
|
||||
|
||||
@ -4,6 +4,7 @@ import { expect, fn, userEvent, waitFor, within } from '@storybook/test';
|
||||
|
||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
import { FieldRatingValue } from '../../../../types/FieldMetadata';
|
||||
import { FieldContextProvider } from '../../../__stories__/FieldContextProvider';
|
||||
@ -62,7 +63,7 @@ const RatingFieldInputWithContext = ({
|
||||
const submitJestFn = fn();
|
||||
|
||||
const clearMocksDecorator: Decorator = (Story, context) => {
|
||||
if (context.parameters.clearMocks) {
|
||||
if (context.parameters.clearMocks === true) {
|
||||
submitJestFn.mockClear();
|
||||
}
|
||||
return <Story />;
|
||||
@ -100,7 +101,7 @@ export const Submit: Story = {
|
||||
const firstStar = input.firstElementChild;
|
||||
|
||||
await waitFor(() => {
|
||||
if (firstStar) {
|
||||
if (isNonNullable(firstStar)) {
|
||||
userEvent.click(firstStar);
|
||||
expect(submitJestFn).toHaveBeenCalledTimes(1);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ const submitJestFn = fn();
|
||||
const cancelJestFn = fn();
|
||||
|
||||
const clearMocksDecorator: Decorator = (Story, context) => {
|
||||
if (context.parameters.clearMocks) {
|
||||
if (context.parameters.clearMocks === true) {
|
||||
submitJestFn.mockClear();
|
||||
cancelJestFn.mockClear();
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ const tabJestFn = fn();
|
||||
const shiftTabJestFn = fn();
|
||||
|
||||
const clearMocksDecorator: Decorator = (Story, context) => {
|
||||
if (context.parameters.clearMocks) {
|
||||
if (context.parameters.clearMocks === true) {
|
||||
enterJestFn.mockClear();
|
||||
escapeJestfn.mockClear();
|
||||
clickOutsideJestFn.mockClear();
|
||||
|
||||
@ -136,7 +136,7 @@ export const turnObjectDropdownFilterIntoQueryFilter = (
|
||||
});
|
||||
break;
|
||||
case ViewFilterOperand.IsNot:
|
||||
if (parsedRecordIds.length) {
|
||||
if (parsedRecordIds.length > 0) {
|
||||
objectRecordFilters.push({
|
||||
not: {
|
||||
[correspondingField.name + 'Id']: {
|
||||
|
||||
@ -4,6 +4,7 @@ import { useColumnDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/u
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural';
|
||||
import { useViewBar } from '@/views/hooks/useViewBar';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
|
||||
type RecordIndexViewBarEffectProps = {
|
||||
objectNamePlural: string;
|
||||
@ -33,7 +34,7 @@ export const RecordIndexViewBarEffect = ({
|
||||
} = useViewBar({ viewBarId });
|
||||
|
||||
useEffect(() => {
|
||||
if (!objectMetadataItem) {
|
||||
if (isNullable(objectMetadataItem)) {
|
||||
return;
|
||||
}
|
||||
setViewObjectMetadataId?.(objectMetadataItem.id);
|
||||
|
||||
@ -6,6 +6,7 @@ import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
||||
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
|
||||
import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
import { useFindManyParams } from '../../hooks/useLoadRecordIndexTable';
|
||||
|
||||
@ -52,7 +53,7 @@ export const generateCsv: GenerateExport = ({
|
||||
return hasSubFields;
|
||||
});
|
||||
|
||||
if (fieldsWithSubFields) {
|
||||
if (isNonNullable(fieldsWithSubFields)) {
|
||||
const nestedFieldsWithoutTypename = Object.keys(
|
||||
(fieldsWithSubFields as any)[column.field],
|
||||
)
|
||||
|
||||
@ -20,7 +20,7 @@ const StyledRecordInlineCellNormalModeOuterContainer = styled.div<
|
||||
padding: ${({ theme }) => theme.spacing(1)};
|
||||
|
||||
${(props) => {
|
||||
if (props.isHovered) {
|
||||
if (props.isHovered === true) {
|
||||
return css`
|
||||
background-color: ${!props.disableHoverEffect
|
||||
? props.theme.background.transparent.light
|
||||
|
||||
@ -5,6 +5,7 @@ import { FieldContext } from '@/object-record/record-field/contexts/FieldContext
|
||||
import { useRecordFieldInput } from '@/object-record/record-field/hooks/useRecordFieldInput';
|
||||
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
|
||||
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
import { isInlineCellInEditModeScopedState } from '../states/isInlineCellInEditModeScopedState';
|
||||
import { InlineCellHotkeyScope } from '../types/InlineCellHotkeyScope';
|
||||
@ -39,7 +40,7 @@ export const useInlineCell = () => {
|
||||
setIsInlineCellInEditMode(true);
|
||||
initFieldInputDraftValue();
|
||||
|
||||
if (customEditHotkeyScopeForField) {
|
||||
if (isNonNullable(customEditHotkeyScopeForField)) {
|
||||
setHotkeyScopeAndMemorizePreviousScope(
|
||||
customEditHotkeyScopeForField.scope,
|
||||
customEditHotkeyScopeForField.customScopes,
|
||||
|
||||
@ -31,6 +31,7 @@ import {
|
||||
useUploadImageMutation,
|
||||
} from '~/generated/graphql';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
|
||||
type RecordShowContainerProps = {
|
||||
objectNameSingular: string;
|
||||
@ -92,7 +93,7 @@ export const RecordShowContainer = ({
|
||||
if (!avatarUrl) {
|
||||
return;
|
||||
}
|
||||
if (!updateOneRecord) {
|
||||
if (isNullable(updateOneRecord)) {
|
||||
return;
|
||||
}
|
||||
if (!recordFromStore) {
|
||||
|
||||
@ -15,6 +15,7 @@ import { TableHotkeyScope } from '@/object-record/record-table/types/TableHotkey
|
||||
import { RelationPickerHotkeyScope } from '@/object-record/relation-picker/types/RelationPickerHotkeyScope';
|
||||
import { contextMenuIsOpenState } from '@/ui/navigation/context-menu/states/contextMenuIsOpenState';
|
||||
import { contextMenuPositionState } from '@/ui/navigation/context-menu/states/contextMenuPositionState';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
|
||||
const StyledContainer = styled.td<{ isSelected: boolean }>`
|
||||
background: ${({ isSelected, theme }) =>
|
||||
@ -45,7 +46,7 @@ export const RecordTableCellContainer = () => {
|
||||
|
||||
const updateRecord = useContext(RecordUpdateContext);
|
||||
|
||||
if (!columnDefinition) {
|
||||
if (isNullable(columnDefinition)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ const StyledColumnHeaderCell = styled.th<{
|
||||
`;
|
||||
}};
|
||||
${({ isResizing, theme }) => {
|
||||
if (isResizing) {
|
||||
if (isResizing === true) {
|
||||
return `&:after {
|
||||
background-color: ${theme.color.blue};
|
||||
bottom: 0;
|
||||
|
||||
@ -11,6 +11,7 @@ import { useLeaveTableFocus } from '@/object-record/record-table/hooks/internal/
|
||||
import { useDragSelect } from '@/ui/utilities/drag-select/hooks/useDragSelect';
|
||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
import { CellHotkeyScopeContext } from '../../contexts/CellHotkeyScopeContext';
|
||||
import { TableHotkeyScope } from '../../types/TableHotkeyScope';
|
||||
@ -56,7 +57,7 @@ export const useOpenRecordTableCell = () => {
|
||||
|
||||
initFieldInputDraftValue(options?.initialValue);
|
||||
|
||||
if (customCellHotkeyScope) {
|
||||
if (isNonNullable(customCellHotkeyScope)) {
|
||||
setHotkeyScope(
|
||||
customCellHotkeyScope.scope,
|
||||
customCellHotkeyScope.customScopes,
|
||||
|
||||
@ -19,6 +19,7 @@ import { DropdownMenuSeparator } from '@/ui/layout/dropdown/components/DropdownM
|
||||
import { SelectableItem } from '@/ui/layout/selectable-list/components/SelectableItem';
|
||||
import { SelectableList } from '@/ui/layout/selectable-list/components/SelectableList';
|
||||
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
export const StyledSelectableItem = styled(SelectableItem)`
|
||||
height: 100%;
|
||||
@ -152,7 +153,7 @@ export const MultipleObjectRecordSelect = ({
|
||||
(entity) => entity.record.id === recordId,
|
||||
);
|
||||
|
||||
if (correspondingRecordForSelect) {
|
||||
if (isNonNullable(correspondingRecordForSelect)) {
|
||||
handleSelectChange(
|
||||
correspondingRecordForSelect,
|
||||
!recordIsSelected,
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
} from '@/object-record/relation-picker/components/SingleEntitySelectMenuItemsWithSearch';
|
||||
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
|
||||
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
export type SingleEntitySelectProps = {
|
||||
disableBackgroundBlur?: boolean;
|
||||
@ -37,7 +38,7 @@ export const SingleEntitySelect = ({
|
||||
event.target instanceof HTMLInputElement &&
|
||||
event.target.tagName === 'INPUT'
|
||||
);
|
||||
if (weAreNotInAnHTMLInput && onCancel) {
|
||||
if (weAreNotInAnHTMLInput && isNonNullable(onCancel)) {
|
||||
onCancel();
|
||||
}
|
||||
},
|
||||
|
||||
@ -76,7 +76,7 @@ export const SingleEntitySelectMenuItems = ({
|
||||
selectableItemIdArray={selectableItemIds}
|
||||
hotkeyScope={RelationPickerHotkeyScope.RelationPicker}
|
||||
onEnter={(itemId) => {
|
||||
if (showCreateButton) {
|
||||
if (showCreateButton === true) {
|
||||
onCreate?.();
|
||||
} else {
|
||||
const entity = entitiesInDropdown.findIndex(
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { getLabelIdentifierFieldMetadataItem } from '@/object-metadata/utils/getLabelIdentifierFieldMetadataItem';
|
||||
import { ObjectRecordQueryFilter } from '@/object-record/record-filter/types/ObjectRecordQueryFilter';
|
||||
@ -23,10 +25,10 @@ export const useSearchFilterPerMetadataItem = ({
|
||||
|
||||
let searchFilter: ObjectRecordQueryFilter = {};
|
||||
|
||||
if (labelIdentifierFieldMetadataItem) {
|
||||
if (isNonNullable(labelIdentifierFieldMetadataItem)) {
|
||||
switch (labelIdentifierFieldMetadataItem.type) {
|
||||
case FieldMetadataType.FullName: {
|
||||
if (searchFilterValue) {
|
||||
if (isNonEmptyString(searchFilterValue)) {
|
||||
const fullNameFilter = makeOrFilterVariables([
|
||||
{
|
||||
[labelIdentifierFieldMetadataItem.name]: {
|
||||
@ -44,14 +46,14 @@ export const useSearchFilterPerMetadataItem = ({
|
||||
},
|
||||
]);
|
||||
|
||||
if (fullNameFilter) {
|
||||
if (isNonNullable(fullNameFilter)) {
|
||||
searchFilter = fullNameFilter;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (searchFilterValue) {
|
||||
if (isNonEmptyString(searchFilterValue)) {
|
||||
searchFilter = {
|
||||
[labelIdentifierFieldMetadataItem.name]: {
|
||||
ilike: `%${searchFilterValue}%`,
|
||||
|
||||
@ -56,7 +56,7 @@ export const useRecordsForSelect = ({
|
||||
fieldNames.map((fieldName) => {
|
||||
const [parentFieldName, subFieldName] = fieldName.split('.');
|
||||
|
||||
if (subFieldName) {
|
||||
if (isNonEmptyString(subFieldName)) {
|
||||
// Composite field
|
||||
return {
|
||||
[parentFieldName]: {
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { useCreateManyRecords } from '@/object-record/hooks/useCreateManyRecords';
|
||||
import { getSpreadSheetValidation } from '@/object-record/spreadsheet-import/util/getSpreadSheetValidation';
|
||||
@ -7,6 +9,7 @@ import { useIcons } from '@/ui/display/icon/hooks/useIcons';
|
||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
const firstName = 'Firstname';
|
||||
const lastName = 'Lastname';
|
||||
@ -128,14 +131,19 @@ export const useSpreadsheetRecordImport = (objectNameSingular: string) => {
|
||||
}
|
||||
break;
|
||||
case FieldMetadataType.Relation:
|
||||
if (value) {
|
||||
if (
|
||||
isNonNullable(value) &&
|
||||
(isNonEmptyString(value) || value !== false)
|
||||
) {
|
||||
fieldMapping[field.name + 'Id'] = value;
|
||||
}
|
||||
break;
|
||||
case FieldMetadataType.FullName:
|
||||
if (
|
||||
record[`${firstName} (${field.name})`] ||
|
||||
record[`${lastName} (${field.name})`]
|
||||
isNonNullable(
|
||||
record[`${firstName} (${field.name})`] ||
|
||||
record[`${lastName} (${field.name})`],
|
||||
)
|
||||
) {
|
||||
fieldMapping[field.name] = {
|
||||
firstName: record[`${firstName} (${field.name})`] || '',
|
||||
|
||||
@ -2,6 +2,7 @@ import { gql } from '@apollo/client';
|
||||
|
||||
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const getDeleteOneRecordMutationResponseField = (
|
||||
@ -13,7 +14,7 @@ export const generateDeleteOneRecordMutation = ({
|
||||
}: {
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
}) => {
|
||||
if (!objectMetadataItem) {
|
||||
if (isNullable(objectMetadataItem)) {
|
||||
return EMPTY_MUTATION;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user