Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR][FRONT]: Remove objectMetadata and fieldMetadata sluggification #9441

Merged
merged 7 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const useLastVisitedObjectMetadataItem = () => {
useRecoilState(lastVisitedObjectMetadataItemIdState);

const {
findActiveObjectMetadataItemBySlug,
findActiveObjectMetadataItemByNamePlural,
alphaSortedActiveObjectMetadataItems,
} = useFilteredObjectMetadataItems();

Expand Down Expand Up @@ -51,7 +51,7 @@ export const useLastVisitedObjectMetadataItem = () => {

const setLastVisitedObjectMetadataItem = (objectNamePlural: string) => {
const fallbackObjectMetadataItem =
findActiveObjectMetadataItemBySlug(objectNamePlural);
findActiveObjectMetadataItemByNamePlural(objectNamePlural);
prastoin marked this conversation as resolved.
Show resolved Hide resolved

if (isDefined(fallbackObjectMetadataItem)) {
setLastVisitedObjectMetadataItemId(fallbackObjectMetadataItem.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Wrapper = ({ children }: { children: ReactNode }) => (
);

describe('useFilteredObjectMetadataItems', () => {
it('should findActiveObjectMetadataItemBySlug', async () => {
it('should findActiveObjectMetadataItemByNamePlural', async () => {
const { result } = renderHook(
() => {
const setMetadataItems = useSetRecoilState(objectMetadataItemsState);
Expand All @@ -49,13 +49,14 @@ describe('useFilteredObjectMetadataItems', () => {
);

act(() => {
const res = result.current.findActiveObjectMetadataItemBySlug('people');
const res =
result.current.findActiveObjectMetadataItemByNamePlural('people');
expect(res).toBeDefined();
expect(res?.namePlural).toBe('people');
});
});

it('should findObjectMetadataItemBySlug', async () => {
it('should findObjectMetadataItemByNamePlural', async () => {
const { result } = renderHook(
() => {
const setMetadataItems = useSetRecoilState(objectMetadataItemsState);
Expand All @@ -69,7 +70,7 @@ describe('useFilteredObjectMetadataItems', () => {
);

act(() => {
const res = result.current.findObjectMetadataItemBySlug('people');
const res = result.current.findObjectMetadataItemByNamePlural('people');
expect(res).toBeDefined();
expect(res?.namePlural).toBe('people');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { useRecoilValue } from 'recoil';

import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';

import { getObjectSlug } from '../utils/getObjectSlug';

export const useFilteredObjectMetadataItems = () => {
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);

Expand All @@ -27,17 +25,6 @@ export const useFilteredObjectMetadataItems = () => {
({ isActive, isSystem }) => !isActive && !isSystem,
);

const findObjectMetadataItemBySlug = (slug: string) =>
objectMetadataItems.find(
(objectMetadataItem) => getObjectSlug(objectMetadataItem) === slug,
);

const findActiveObjectMetadataItemBySlug = (slug: string) =>
activeObjectMetadataItems.find(
(activeObjectMetadataItem) =>
getObjectSlug(activeObjectMetadataItem) === slug,
);

const findActiveObjectMetadataItemByNamePlural = (namePlural: string) =>
activeObjectMetadataItems.find(
(activeObjectMetadataItem) =>
Expand All @@ -56,13 +43,11 @@ export const useFilteredObjectMetadataItems = () => {

return {
activeObjectMetadataItems,
findActiveObjectMetadataItemBySlug,
findObjectMetadataItemById,
findObjectMetadataItemByNamePlural,
findActiveObjectMetadataItemByNamePlural,
inactiveObjectMetadataItems,
objectMetadataItems,
findObjectMetadataItemBySlug,
alphaSortedActiveObjectMetadataItems,
};
};
prastoin marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

This file was deleted.

prastoin marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

prastoin marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ObjectOptionsDropdownHiddenFieldsContent = () => {
});

const settingsUrl = getSettingsPagePath(SettingsPath.ObjectDetail, {
objectSlug: objectNamePlural,
objectNamePlural,
});
prastoin marked this conversation as resolved.
Show resolved Hide resolved

const { handleColumnVisibilityChange, hiddenTableColumns } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const ObjectOptionsDropdownHiddenRecordGroupsContent = () => {
const viewGroupSettingsUrl = getSettingsPagePath(
SettingsPath.ObjectFieldEdit,
{
objectSlug: objectNamePlural,
fieldSlug: recordGroupFieldMetadata?.name ?? '',
objectNamePlural,
fieldName: recordGroupFieldMetadata?.name ?? '',
},
prastoin marked this conversation as resolved.
Show resolved Hide resolved
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const ObjectOptionsDropdownRecordGroupFieldsContent = () => {
const newSelectFieldSettingsUrl = getSettingsPagePath(
SettingsPath.ObjectNewFieldConfigure,
{
objectSlug: objectNamePlural,
objectNamePlural,
},
prastoin marked this conversation as resolved.
Show resolved Hide resolved
{
fieldType: FieldMetadataType.Select,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { getFieldSlug } from '@/object-metadata/utils/getFieldSlug';
import { getObjectSlug } from '@/object-metadata/utils/getObjectSlug';
import { RecordBoardColumnContext } from '@/object-record/record-board/record-board-column/contexts/RecordBoardColumnContext';
import { useRecordGroupVisibility } from '@/object-record/record-group/hooks/useRecordGroupVisibility';
import { recordGroupFieldMetadataComponentState } from '@/object-record/record-group/states/recordGroupFieldMetadataComponentState';
Expand Down Expand Up @@ -55,7 +53,7 @@ export const useRecordGroupActions = ({
throw new Error('recordGroupFieldMetadata is not a non-empty string');
}

const settingsPath = `/settings/objects/${getObjectSlug(objectMetadataItem)}/${getFieldSlug(recordGroupFieldMetadata)}`;
const settingsPath = `/settings/objects/${objectMetadataItem.namePlural}/${recordGroupFieldMetadata.name}`;

navigate(settingsPath);
}, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useLocation } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';
import { IconSettings, MenuItem, UndecoratedLink, useIcons } from 'twenty-ui';

import { getObjectSlug } from '@/object-metadata/utils/getObjectSlug';
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
import { useTableColumns } from '@/object-record/record-table/hooks/useTableColumns';
Expand Down Expand Up @@ -56,7 +55,7 @@ export const RecordTableHeaderPlusButtonContent = () => {
<DropdownMenuItemsContainer scrollable={false}>
<UndecoratedLink
fullWidth
to={`/settings/objects/${getObjectSlug(objectMetadataItem)}`}
to={`/settings/objects/${objectMetadataItem.namePlural}`}
prastoin marked this conversation as resolved.
Show resolved Hide resolved
prastoin marked this conversation as resolved.
Show resolved Hide resolved
onClick={() => {
setNavigationMemorizedUrl(location.pathname + location.search);
prastoin marked this conversation as resolved.
Show resolved Hide resolved
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const SettingsDataModelNewFieldBreadcrumbDropDown = () => {
const { closeDropdown } = useDropdown(dropdownId);
const navigate = useNavigate();
const location = useLocation();
const { objectSlug = '' } = useParams();
const { objectNamePlural = '' } = useParams();
const [searchParams] = useSearchParams();
const theme = useTheme();

Expand All @@ -78,11 +78,11 @@ export const SettingsDataModelNewFieldBreadcrumbDropDown = () => {
const handleClick = (step: 'select' | 'configure') => {
if (step === 'configure' && isDefined(fieldType)) {
navigate(
`/settings/objects/${objectSlug}/new-field/configure?fieldType=${fieldType}`,
`/settings/objects/${objectNamePlural}/new-field/configure?fieldType=${fieldType}`,
prastoin marked this conversation as resolved.
Show resolved Hide resolved
);
} else {
navigate(
`/settings/objects/${objectSlug}/new-field/select${fieldType ? `?fieldType=${fieldType}` : ''}`,
`/settings/objects/${objectNamePlural}/new-field/select${fieldType ? `?fieldType=${fieldType}` : ''}`,
);
}
closeDropdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type SettingsObjectNewFieldSelectorProps = {
'defaultValue' | 'options' | 'type'
>;

objectSlug: string;
objectNamePlural: string;
};

const StyledTypeSelectContainer = styled.div`
Expand Down Expand Up @@ -58,7 +58,7 @@ const StyledSearchInput = styled(TextInput)`
export const SettingsObjectNewFieldSelector = ({
excludedFieldTypes = [],
fieldMetadataItem,
objectSlug,
objectNamePlural,
}: SettingsObjectNewFieldSelectorProps) => {
const theme = useTheme();
const { control, setValue } =
Expand Down Expand Up @@ -128,7 +128,7 @@ export const SettingsObjectNewFieldSelector = ({
.map(([key, config]) => (
<StyledCardContainer key={key}>
<UndecoratedLink
to={`/settings/objects/${objectSlug}/new-field/configure?fieldType=${key}`}
to={`/settings/objects/${objectNamePlural}/new-field/configure?fieldType=${key}`}
fullWidth
prastoin marked this conversation as resolved.
Show resolved Hide resolved
onClick={() => {
setValue('type', key as SettingsFieldType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Link } from 'react-router-dom';
import { IconChevronDown, IconChevronUp, useIcons } from 'twenty-ui';

import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { getObjectSlug } from '@/object-metadata/utils/getObjectSlug';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { ObjectFieldRow } from '@/settings/data-model/graph-overview/components/SettingsDataModelOverviewField';
import { SettingsDataModelObjectTypeTag } from '@/settings/data-model/objects/components/SettingsDataModelObjectTypeTag';
Expand Down Expand Up @@ -100,36 +99,38 @@ const StyledObjectLink = styled(Link)`
`;

export const SettingsDataModelOverviewObject = ({
data,
data: objectMetadataItem,
lucasbordeau marked this conversation as resolved.
Show resolved Hide resolved
}: SettingsDataModelOverviewObjectProps) => {
const theme = useTheme();
const { getIcon } = useIcons();
const [otherFieldsExpanded, setOtherFieldsExpanded] = useState(false);

const { totalCount } = useFindManyRecords({
objectNameSingular: data.nameSingular,
objectNameSingular: objectMetadataItem.nameSingular,
});

const fields = data.fields.filter((x) => !x.isSystem);
const fields = objectMetadataItem.fields.filter((x) => !x.isSystem);

const countNonRelation = fields.filter(
(x) => x.type !== FieldMetadataType.Relation,
).length;

const Icon = getIcon(data.icon);
const Icon = getIcon(objectMetadataItem.icon);

return (
<StyledNode>
<StyledHeader>
<StyledObjectName onMouseEnter={() => {}} onMouseLeave={() => {}}>
prastoin marked this conversation as resolved.
Show resolved Hide resolved
<StyledObjectLink to={`/settings/objects/${getObjectSlug(data)}`}>
<StyledObjectLink
to={`/settings/objects/${objectMetadataItem.namePlural}`}
prastoin marked this conversation as resolved.
Show resolved Hide resolved
>
{Icon && <Icon size={theme.icon.size.md} />}
{capitalize(data.namePlural)}
{capitalize(objectMetadataItem.namePlural)}
</StyledObjectLink>
<StyledObjectInstanceCount> · {totalCount}</StyledObjectInstanceCount>
</StyledObjectName>
<SettingsDataModelObjectTypeTag
objectTypeLabel={getObjectTypeLabel(data)}
objectTypeLabel={getObjectTypeLabel(objectMetadataItem)}
></SettingsDataModelObjectTypeTag>
</StyledHeader>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { useGetRelationMetadata } from '@/object-metadata/hooks/useGetRelationMe
import { useUpdateOneObjectMetadataItem } from '@/object-metadata/hooks/useUpdateOneObjectMetadataItem';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { getFieldSlug } from '@/object-metadata/utils/getFieldSlug';
import { getObjectSlug } from '@/object-metadata/utils/getObjectSlug';
import { isLabelIdentifierField } from '@/object-metadata/utils/isLabelIdentifierField';
import { useDeleteRecordFromCache } from '@/object-record/cache/hooks/useDeleteRecordFromCache';
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
Expand Down Expand Up @@ -110,7 +108,7 @@ export const SettingsObjectFieldItemTableRow = ({
!isLabelIdentifier &&
LABEL_IDENTIFIER_FIELD_METADATA_TYPES.includes(fieldMetadataItem.type);

const linkToNavigate = `./${getFieldSlug(fieldMetadataItem)}`;
const linkToNavigate = `./${fieldMetadataItem.name}`;
prastoin marked this conversation as resolved.
Show resolved Hide resolved

const {
activateMetadataField,
Expand Down Expand Up @@ -246,7 +244,7 @@ export const SettingsObjectFieldItemTableRow = ({
}
to={
isRelatedObjectLinkable
? `/settings/objects/${getObjectSlug(relationObjectMetadataItem)}`
? `/settings/objects/${relationObjectMetadataItem.namePlural}`
: undefined
prastoin marked this conversation as resolved.
Show resolved Hide resolved
}
value={fieldType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { z, ZodError } from 'zod';
import { useLastVisitedObjectMetadataItem } from '@/navigation/hooks/useLastVisitedObjectMetadataItem';
import { useLastVisitedView } from '@/navigation/hooks/useLastVisitedView';
import { useUpdateOneObjectMetadataItem } from '@/object-metadata/hooks/useUpdateOneObjectMetadataItem';
import { getObjectSlug } from '@/object-metadata/utils/getObjectSlug';
import { RecordFieldValueSelectorContextProvider } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';
import {
IS_LABEL_SYNCED_WITH_NAME_LABEL,
Expand All @@ -28,7 +27,7 @@ import styled from '@emotion/styled';
import isEmpty from 'lodash.isempty';
import pick from 'lodash.pick';
import { useSetRecoilState } from 'recoil';
import { updatedObjectSlugState } from '~/pages/settings/data-model/states/updatedObjectSlugState';
import { updatedObjectNamePluralState } from '~/pages/settings/data-model/states/updatedObjectNamePluralState';
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils';

const objectEditFormSchema = z
Expand Down Expand Up @@ -57,7 +56,9 @@ const StyledFormSection = styled(Section)`
export const ObjectSettings = ({ objectMetadataItem }: ObjectSettingsProps) => {
const navigate = useNavigate();
const { enqueueSnackBar } = useSnackBar();
const setUpdatedObjectSlugState = useSetRecoilState(updatedObjectSlugState);
const setUpdatedObjectNamePluralState = useSetRecoilState(
prastoin marked this conversation as resolved.
Show resolved Hide resolved
updatedObjectNamePluralState,
);

const { updateOneObjectMetadataItem } = useUpdateOneObjectMetadataItem();
const { lastVisitedObjectMetadataItemId } =
Expand Down Expand Up @@ -131,12 +132,8 @@ export const ObjectSettings = ({ objectMetadataItem }: ObjectSettingsProps) => {
const updatePayload = getUpdatePayload(formValues);
const objectNamePluralForRedirection =
updatePayload.namePlural ?? objectMetadataItem.namePlural;
const objectSlug = getObjectSlug({
...updatePayload,
namePlural: objectNamePluralForRedirection,
});

setUpdatedObjectSlugState(objectSlug);
setUpdatedObjectNamePluralState(objectNamePluralForRedirection);

await updateOneObjectMetadataItem({
idToUpdate: objectMetadataItem.id,
Expand All @@ -154,7 +151,7 @@ export const ObjectSettings = ({ objectMetadataItem }: ObjectSettingsProps) => {
);
}

navigate(`${settingsObjectsPagePath}/${objectSlug}`);
navigate(`${settingsObjectsPagePath}/${objectNamePluralForRedirection}`);
prastoin marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
if (error instanceof ZodError) {
enqueueSnackBar(error.issues[0].message, {
Expand Down
8 changes: 4 additions & 4 deletions packages/twenty-front/src/modules/types/SettingsPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export enum SettingsPath {
Billing = 'billing',
Objects = 'objects',
ObjectOverview = 'objects/overview',
ObjectDetail = 'objects/:objectSlug',
ObjectNewFieldSelect = 'objects/:objectSlug/new-field/select',
ObjectNewFieldConfigure = 'objects/:objectSlug/new-field/configure',
ObjectFieldEdit = 'objects/:objectSlug/:fieldSlug',
ObjectDetail = 'objects/:objectNamePlural',
ObjectNewFieldSelect = 'objects/:objectNamePlural/new-field/select',
ObjectNewFieldConfigure = 'objects/:objectNamePlural/new-field/configure',
ObjectFieldEdit = 'objects/:objectNamePlural/:fieldName',
prastoin marked this conversation as resolved.
Show resolved Hide resolved
prastoin marked this conversation as resolved.
Show resolved Hide resolved
NewObject = 'objects/new',
NewServerlessFunction = 'functions/new',
ServerlessFunctionDetail = 'functions/:serverlessFunctionId',
Expand Down
Loading
Loading