Skip to content

Commit

Permalink
Rename utils
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Oct 10, 2024
1 parent e9bb2d0 commit 1a56bfc
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { isWorkflowSubObjectMetadata } from '@/object-metadata/utils/isWorkflowSubObjectMetadata';

export const isObjectMetadataReadOnly = (
objectMetadataItem: Pick<ObjectMetadataItem, 'isRemote' | 'nameSingular'>,
) =>
objectMetadataItem.isRemote ||
isWorkflowSubObjectMetadata(objectMetadataItem.nameSingular);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';

export const isWorkflowSubObject = (objectMetadataNameSingular?: string) =>
export const isWorkflowSubObjectMetadata = (
objectMetadataNameSingular?: string,
) =>
objectMetadataNameSingular === CoreObjectNameSingular.WorkflowVersion ||
objectMetadataNameSingular === CoreObjectNameSingular.WorkflowRun;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IconFileExport, IconHeart, IconHeartOff, IconTrash } from 'twenty-ui';

import { useFavorites } from '@/favorites/hooks/useFavorites';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { isReadOnlyObject } from '@/object-metadata/utils/isReadOnlyObject';
import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly';
import { DELETE_MAX_COUNT } from '@/object-record/constants/DeleteMaxCount';
import { useDeleteTableData } from '@/object-record/record-index/options/hooks/useDeleteTableData';
import {
Expand Down Expand Up @@ -91,7 +91,7 @@ export const useRecordActionBar = ({
filename: `${objectMetadataItem.nameSingular}.csv`,
});

const isReadOnly = isReadOnlyObject(objectMetadataItem);
const isReadOnly = isObjectMetadataReadOnly(objectMetadataItem);

const numberOfSelectedRecords =
totalNumberOfRecordsSelected ?? selectedRecordIds.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@ import { useContext } from 'react';

import { isFieldActor } from '@/object-record/record-field/types/guards/isFieldActor';
import { isFieldRichText } from '@/object-record/record-field/types/guards/isFieldRichText';
import { isFieldReadonlyFromObjectMetadataName } from '@/object-record/record-field/utils/isFieldReadonlyFromObjectMetadataName';
import { FieldContext } from '../contexts/FieldContext';
import { isFieldMetadataReadOnly } from '../utils/isFieldMetadataReadOnly';

export const useIsFieldReadOnly = () => {
const { fieldDefinition } = useContext(FieldContext);

const { metadata } = fieldDefinition;

return (
metadata.fieldName === 'noteTargets' ||
metadata.fieldName === 'taskTargets' ||
isFieldActor(fieldDefinition) ||
isFieldRichText(fieldDefinition) ||
isFieldReadonlyFromObjectMetadataName(
metadata.fieldName,
metadata.objectMetadataNameSingular,
)
isFieldMetadataReadOnly(metadata)
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { isWorkflowSubObjectMetadata } from '@/object-metadata/utils/isWorkflowSubObjectMetadata';
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';

export const isFieldMetadataReadOnly = (fieldMetadata: FieldMetadata) => {
if (
fieldMetadata.fieldName === 'noteTargets' ||
fieldMetadata.fieldName === 'taskTargets'
) {
return true;
}

return (
isWorkflowSubObjectMetadata(fieldMetadata.objectMetadataNameSingular) ||
(fieldMetadata.objectMetadataNameSingular ===
CoreObjectNameSingular.Workflow &&
fieldMetadata.fieldName !== 'name')
);
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useRecoilValue } from 'recoil';
import { useIcons } from 'twenty-ui';

import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
import { isReadOnlyObject } from '@/object-metadata/utils/isReadOnlyObject';
import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly';
import { RecordIndexPageKanbanAddButton } from '@/object-record/record-index/components/RecordIndexPageKanbanAddButton';
import { RecordIndexRootPropsContext } from '@/object-record/record-index/contexts/RecordIndexRootPropsContext';
import { recordIndexViewTypeState } from '@/object-record/record-index/states/recordIndexViewTypeState';
Expand Down Expand Up @@ -32,7 +32,7 @@ export const RecordIndexPageHeader = () => {
const recordIndexViewType = useRecoilValue(recordIndexViewTypeState);

const shouldDisplayAddButton = objectMetadataItem
? !isReadOnlyObject(objectMetadataItem)
? !isObjectMetadataReadOnly(objectMetadataItem)
: false;

const isTable = recordIndexViewType === ViewType.Table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '@/object-record/record-field/contexts/FieldContext';
import { usePersistField } from '@/object-record/record-field/hooks/usePersistField';
import { FieldRelationMetadata } from '@/object-record/record-field/types/FieldMetadata';
import { isFieldReadonlyFromObjectMetadataName } from '@/object-record/record-field/utils/isFieldReadonlyFromObjectMetadataName';
import { isFieldMetadataReadOnly } from '@/object-record/record-field/utils/isFieldMetadataReadOnly';
import { RecordInlineCell } from '@/object-record/record-inline-cell/components/RecordInlineCell';
import { PropertyBox } from '@/object-record/record-inline-cell/property-box/components/PropertyBox';
import { InlineCellHotkeyScope } from '@/object-record/record-inline-cell/types/InlineCellHotkeyScope';
Expand Down Expand Up @@ -181,10 +181,7 @@ export const RecordDetailRelationRecordsListItem = ({
[isExpanded],
);

const canEdit = !isFieldReadonlyFromObjectMetadataName(
fieldDefinition.metadata.fieldName,
fieldDefinition.metadata.objectMetadataNameSingular,
);
const canEdit = !isFieldMetadataReadOnly(fieldDefinition.metadata);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { usePersistField } from '@/object-record/record-field/hooks/usePersistFi
import { RelationFromManyFieldInputMultiRecordsEffect } from '@/object-record/record-field/meta-types/input/components/RelationFromManyFieldInputMultiRecordsEffect';
import { useUpdateRelationFromManyFieldInput } from '@/object-record/record-field/meta-types/input/hooks/useUpdateRelationFromManyFieldInput';
import { FieldRelationMetadata } from '@/object-record/record-field/types/FieldMetadata';
import { isFieldReadonlyFromObjectMetadataName } from '@/object-record/record-field/utils/isFieldReadonlyFromObjectMetadataName';
import { isFieldMetadataReadOnly } from '@/object-record/record-field/utils/isFieldMetadataReadOnly';
import { RecordDetailRelationRecordsList } from '@/object-record/record-show/record-detail-section/components/RecordDetailRelationRecordsList';
import { RecordDetailSection } from '@/object-record/record-show/record-detail-section/components/RecordDetailSection';
import { RecordDetailSectionHeader } from '@/object-record/record-show/record-detail-section/components/RecordDetailSectionHeader';
Expand Down Expand Up @@ -159,10 +159,7 @@ export const RecordDetailRelationSection = ({
recordId,
});

const canEdit = !isFieldReadonlyFromObjectMetadataName(
fieldDefinition.metadata.fieldName,
fieldDefinition.metadata.objectMetadataNameSingular,
);
const canEdit = !isFieldMetadataReadOnly(fieldDefinition.metadata);

if (loading) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
AnimatedPlaceholderEmptyTitle,
} from '@/ui/layout/animated-placeholder/components/EmptyPlaceholderStyled';

import { isReadOnlyObject } from '@/object-metadata/utils/isReadOnlyObject';
import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly';
import { RecordTableContext } from '@/object-record/record-table/contexts/RecordTableContext';
import { Button } from '@/ui/input/button/components/Button';
import { useContext } from 'react';
Expand All @@ -32,7 +32,7 @@ export const RecordTableEmptyStateDisplay = ({
title,
}: RecordTableEmptyStateDisplayProps) => {
const { objectMetadataItem } = useContext(RecordTableContext);
const isReadOnly = isReadOnlyObject(objectMetadataItem);
const isReadOnly = isObjectMetadataReadOnly(objectMetadataItem);

return (
<AnimatedPlaceholderEmptyContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRecoilCallback, useRecoilState, useRecoilValue } from 'recoil';
import { IconPlus } from 'twenty-ui';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { isReadOnlyObject } from '@/object-metadata/utils/isReadOnlyObject';
import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly';
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
import { useCreateNewTableRecord } from '@/object-record/record-table/hooks/useCreateNewTableRecords';
Expand Down Expand Up @@ -198,7 +198,7 @@ export const RecordTableHeaderCell = ({
createNewTableRecord();
};

const isReadOnly = isReadOnlyObject(objectMetadataItem);
const isReadOnly = isObjectMetadataReadOnly(objectMetadataItem);

return (
<StyledColumnHeaderCell
Expand Down

0 comments on commit 1a56bfc

Please sign in to comment.