@ -1,5 +1,5 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { Trans, useLingui } from '@lingui/react/macro';
|
||||
import { FormProvider, useForm } from 'react-hook-form';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { H2Title, Section } from 'twenty-ui';
|
||||
@ -67,14 +67,14 @@ export const SettingsNewObject = () => {
|
||||
title={t`New Object`}
|
||||
links={[
|
||||
{
|
||||
children: t`Workspace`,
|
||||
children: <Trans>Workspace</Trans>,
|
||||
href: getSettingsPagePath(SettingsPath.Workspace),
|
||||
},
|
||||
{
|
||||
children: t`Objects`,
|
||||
children: <Trans>Objects</Trans>,
|
||||
href: getSettingsPagePath(SettingsPath.Objects),
|
||||
},
|
||||
{ children: t`New` },
|
||||
{ children: <Trans>New</Trans> },
|
||||
]}
|
||||
>
|
||||
<SettingsPageContainer>
|
||||
|
||||
@ -12,6 +12,7 @@ import { TableSection } from '@/ui/layout/table/components/TableSection';
|
||||
import { useSortedArray } from '@/ui/layout/table/hooks/useSortedArray';
|
||||
import { TableMetadata } from '@/ui/layout/table/types/TableMetadata';
|
||||
import styled from '@emotion/styled';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { isNonEmptyArray } from '@sniptt/guards';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
@ -19,63 +20,65 @@ import { IconSearch } from 'twenty-ui';
|
||||
import { useMapFieldMetadataItemToSettingsObjectDetailTableItem } from '~/pages/settings/data-model/hooks/useMapFieldMetadataItemToSettingsObjectDetailTableItem';
|
||||
import { SettingsObjectDetailTableItem } from '~/pages/settings/data-model/types/SettingsObjectDetailTableItem';
|
||||
|
||||
const SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD: TableMetadata<SettingsObjectDetailTableItem> =
|
||||
{
|
||||
tableId: 'settingsObjectDetail',
|
||||
fields: [
|
||||
{
|
||||
fieldLabel: 'Name',
|
||||
fieldName: 'label',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: 'Field type',
|
||||
fieldName: 'fieldType',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: 'Data type',
|
||||
fieldName: 'dataType',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
],
|
||||
initialSort: {
|
||||
const GET_SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD = (
|
||||
t: (literals: TemplateStringsArray) => string,
|
||||
): TableMetadata<SettingsObjectDetailTableItem> => ({
|
||||
tableId: 'settingsObjectDetail',
|
||||
fields: [
|
||||
{
|
||||
fieldLabel: t`Name`,
|
||||
fieldName: 'label',
|
||||
orderBy: 'AscNullsLast',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
};
|
||||
{
|
||||
fieldLabel: t`Field type`,
|
||||
fieldName: 'fieldType',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: t`Data type`,
|
||||
fieldName: 'dataType',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
],
|
||||
initialSort: {
|
||||
fieldName: 'label',
|
||||
orderBy: 'AscNullsLast',
|
||||
},
|
||||
});
|
||||
|
||||
const SETTINGS_OBJECT_DETAIL_TABLE_METADATA_CUSTOM: TableMetadata<SettingsObjectDetailTableItem> =
|
||||
{
|
||||
tableId: 'settingsObjectDetail',
|
||||
fields: [
|
||||
{
|
||||
fieldLabel: 'Name',
|
||||
fieldName: 'label',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: 'Identifier',
|
||||
fieldName: 'identifierType',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: 'Data type',
|
||||
fieldName: 'dataType',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
],
|
||||
initialSort: {
|
||||
const GET_SETTINGS_OBJECT_DETAIL_TABLE_METADATA_CUSTOM = (
|
||||
t: (literals: TemplateStringsArray) => string,
|
||||
): TableMetadata<SettingsObjectDetailTableItem> => ({
|
||||
tableId: 'settingsObjectDetail',
|
||||
fields: [
|
||||
{
|
||||
fieldLabel: t`Name`,
|
||||
fieldName: 'label',
|
||||
orderBy: 'AscNullsLast',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
};
|
||||
{
|
||||
fieldLabel: t`Identifier`,
|
||||
fieldName: 'identifierType',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: t`Data type`,
|
||||
fieldName: 'dataType',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
],
|
||||
initialSort: {
|
||||
fieldName: 'label',
|
||||
orderBy: 'AscNullsLast',
|
||||
},
|
||||
});
|
||||
|
||||
const StyledSearchInput = styled(TextInput)`
|
||||
padding-bottom: ${({ theme }) => theme.spacing(2)};
|
||||
@ -91,11 +94,12 @@ export const SettingsObjectFieldTable = ({
|
||||
objectMetadataItem,
|
||||
mode,
|
||||
}: SettingsObjectFieldTableProps) => {
|
||||
const { t } = useLingui();
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
|
||||
const tableMetadata = objectMetadataItem.isCustom
|
||||
? SETTINGS_OBJECT_DETAIL_TABLE_METADATA_CUSTOM
|
||||
: SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD;
|
||||
? GET_SETTINGS_OBJECT_DETAIL_TABLE_METADATA_CUSTOM(t)
|
||||
: GET_SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD(t);
|
||||
|
||||
const { mapFieldMetadataItemToSettingsObjectDetailTableItem } =
|
||||
useMapFieldMetadataItemToSettingsObjectDetailTableItem(objectMetadataItem);
|
||||
@ -176,7 +180,7 @@ export const SettingsObjectFieldTable = ({
|
||||
<>
|
||||
<StyledSearchInput
|
||||
LeftIcon={IconSearch}
|
||||
placeholder="Search a field..."
|
||||
placeholder={t`Search a field...`}
|
||||
value={searchTerm}
|
||||
onChange={setSearchTerm}
|
||||
/>
|
||||
@ -194,7 +198,7 @@ export const SettingsObjectFieldTable = ({
|
||||
<TableHeader></TableHeader>
|
||||
</StyledObjectFieldTableRow>
|
||||
{isNonEmptyArray(filteredActiveItems) && (
|
||||
<TableSection title="Active">
|
||||
<TableSection title={t`Active`}>
|
||||
{filteredActiveItems.map((objectSettingsDetailItem) => (
|
||||
<SettingsObjectFieldItemTableRow
|
||||
key={objectSettingsDetailItem.fieldMetadataItem.id}
|
||||
@ -208,7 +212,7 @@ export const SettingsObjectFieldTable = ({
|
||||
{isNonEmptyArray(filteredDisabledItems) && (
|
||||
<TableSection
|
||||
isInitiallyExpanded={mode === 'new-field' ? true : false}
|
||||
title="Inactive"
|
||||
title={t`Inactive`}
|
||||
>
|
||||
{filteredDisabledItems.map((objectSettingsDetailItem) => (
|
||||
<SettingsObjectFieldItemTableRow
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
|
||||
import { settingsObjectIndexesFamilyState } from '@/settings/data-model/object-details/states/settingsObjectIndexesFamilyState';
|
||||
import { TextInput } from '@/ui/input/components/TextInput';
|
||||
import { SortableTableHeader } from '@/ui/layout/table/components/SortableTableHeader';
|
||||
@ -10,6 +9,7 @@ import { TableRow } from '@/ui/layout/table/components/TableRow';
|
||||
import { useSortedArray } from '@/ui/layout/table/hooks/useSortedArray';
|
||||
import { TableMetadata } from '@/ui/layout/table/types/TableMetadata';
|
||||
import styled from '@emotion/styled';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { isNonEmptyArray } from '@sniptt/guards';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
@ -20,12 +20,26 @@ export const StyledObjectIndexTableRow = styled(TableRow)`
|
||||
grid-template-columns: 350px 70px 80px;
|
||||
`;
|
||||
|
||||
const SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD: TableMetadata<SettingsObjectIndexesTableItem> =
|
||||
{
|
||||
const StyledSearchInput = styled(TextInput)`
|
||||
padding-bottom: ${({ theme }) => theme.spacing(2)};
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
export type SettingsObjectIndexTableProps = {
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
};
|
||||
|
||||
export const SettingsObjectIndexTable = ({
|
||||
objectMetadataItem,
|
||||
}: SettingsObjectIndexTableProps) => {
|
||||
const { t } = useLingui();
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
|
||||
const tableMetadata: TableMetadata<SettingsObjectIndexesTableItem> = {
|
||||
tableId: 'settingsObjectIndexs',
|
||||
fields: [
|
||||
{
|
||||
fieldLabel: 'Fields',
|
||||
fieldLabel: t`Fields`,
|
||||
fieldName: 'indexFields',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
@ -38,7 +52,7 @@ const SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD: TableMetadata<SettingsObje
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: 'Type',
|
||||
fieldLabel: t`Type`,
|
||||
fieldName: 'indexType',
|
||||
fieldType: 'string',
|
||||
align: 'right',
|
||||
@ -50,19 +64,6 @@ const SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD: TableMetadata<SettingsObje
|
||||
},
|
||||
};
|
||||
|
||||
const StyledSearchInput = styled(TextInput)`
|
||||
padding-bottom: ${({ theme }) => theme.spacing(2)};
|
||||
width: 100%;
|
||||
`;
|
||||
export type SettingsObjectIndexTableProps = {
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
};
|
||||
|
||||
export const SettingsObjectIndexTable = ({
|
||||
objectMetadataItem,
|
||||
}: SettingsObjectIndexTableProps) => {
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
|
||||
const [settingsObjectIndexes, setSettingsObjectIndexes] = useRecoilState(
|
||||
settingsObjectIndexesFamilyState({
|
||||
objectMetadataItemId: objectMetadataItem.id,
|
||||
@ -95,7 +96,7 @@ export const SettingsObjectIndexTable = ({
|
||||
|
||||
const sortedActiveObjectSettingsDetailItems = useSortedArray(
|
||||
objectSettingsDetailItems,
|
||||
SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD,
|
||||
tableMetadata,
|
||||
);
|
||||
|
||||
const filteredActiveItems = useMemo(
|
||||
@ -112,22 +113,20 @@ export const SettingsObjectIndexTable = ({
|
||||
<>
|
||||
<StyledSearchInput
|
||||
LeftIcon={IconSearch}
|
||||
placeholder="Search an index..."
|
||||
placeholder={t`Search an index...`}
|
||||
value={searchTerm}
|
||||
onChange={setSearchTerm}
|
||||
/>
|
||||
<Table>
|
||||
<StyledObjectIndexTableRow>
|
||||
{SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD.fields.map((item) => (
|
||||
{tableMetadata.fields.map((item) => (
|
||||
<SortableTableHeader
|
||||
key={item.fieldName}
|
||||
fieldName={item.fieldName}
|
||||
label={item.fieldLabel}
|
||||
Icon={item.FieldIcon}
|
||||
tableId={SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD.tableId}
|
||||
initialSort={
|
||||
SETTINGS_OBJECT_DETAIL_TABLE_METADATA_STANDARD.initialSort
|
||||
}
|
||||
tableId={tableMetadata.tableId}
|
||||
initialSort={tableMetadata.initialSort}
|
||||
/>
|
||||
))}
|
||||
<TableHeader></TableHeader>
|
||||
|
||||
@ -21,7 +21,7 @@ import { TableSection } from '@/ui/layout/table/components/TableSection';
|
||||
import { useSortedArray } from '@/ui/layout/table/hooks/useSortedArray';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import styled from '@emotion/styled';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { Trans, useLingui } from '@lingui/react/macro';
|
||||
import { isNonEmptyArray } from '@sniptt/guards';
|
||||
import { useMemo, useState } from 'react';
|
||||
import {
|
||||
@ -33,7 +33,7 @@ import {
|
||||
Section,
|
||||
UndecoratedLink,
|
||||
} from 'twenty-ui';
|
||||
import { SETTINGS_OBJECT_TABLE_METADATA } from '~/pages/settings/data-model/constants/SettingsObjectTableMetadata';
|
||||
import { GET_SETTINGS_OBJECT_TABLE_METADATA } from '~/pages/settings/data-model/constants/SettingsObjectTableMetadata';
|
||||
import { SettingsObjectTableItem } from '~/pages/settings/data-model/types/SettingsObjectTableItem';
|
||||
|
||||
const StyledIconChevronRight = styled(IconChevronRight)`
|
||||
@ -46,8 +46,8 @@ const StyledSearchInput = styled(TextInput)`
|
||||
`;
|
||||
|
||||
export const SettingsObjects = () => {
|
||||
const theme = useTheme();
|
||||
const { t } = useLingui();
|
||||
const theme = useTheme();
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const { deleteOneObjectMetadataItem } = useDeleteOneObjectMetadataItem();
|
||||
const { updateOneObjectMetadataItem } = useUpdateOneObjectMetadataItem();
|
||||
@ -104,14 +104,19 @@ export const SettingsObjects = () => {
|
||||
[inactiveObjectMetadataItems, totalCountByObjectMetadataItemNamePlural],
|
||||
);
|
||||
|
||||
const tableMetadata = useMemo(
|
||||
() => GET_SETTINGS_OBJECT_TABLE_METADATA(t),
|
||||
[t],
|
||||
);
|
||||
|
||||
const sortedActiveObjectSettingsItems = useSortedArray(
|
||||
activeObjectSettingsArray,
|
||||
SETTINGS_OBJECT_TABLE_METADATA,
|
||||
tableMetadata,
|
||||
);
|
||||
|
||||
const sortedInactiveObjectSettingsItems = useSortedArray(
|
||||
inactiveObjectSettingsArray,
|
||||
SETTINGS_OBJECT_TABLE_METADATA,
|
||||
tableMetadata,
|
||||
);
|
||||
|
||||
const filteredActiveObjectSettingsItems = useMemo(
|
||||
@ -149,12 +154,10 @@ export const SettingsObjects = () => {
|
||||
}
|
||||
links={[
|
||||
{
|
||||
children: t`Workspace`,
|
||||
children: <Trans>Workspace</Trans>,
|
||||
href: getSettingsPagePath(SettingsPath.Workspace),
|
||||
},
|
||||
{
|
||||
children: t`Objects`,
|
||||
},
|
||||
{ children: <Trans>Objects</Trans> },
|
||||
]}
|
||||
>
|
||||
<SettingsPageContainer>
|
||||
@ -165,22 +168,22 @@ export const SettingsObjects = () => {
|
||||
|
||||
<StyledSearchInput
|
||||
LeftIcon={IconSearch}
|
||||
placeholder={t`Search an object...`}
|
||||
placeholder={t`Search for an object...`}
|
||||
value={searchTerm}
|
||||
onChange={setSearchTerm}
|
||||
/>
|
||||
|
||||
<Table>
|
||||
<StyledObjectTableRow>
|
||||
{SETTINGS_OBJECT_TABLE_METADATA.fields.map(
|
||||
{tableMetadata.fields.map(
|
||||
(settingsObjectsTableMetadataField) => (
|
||||
<SortableTableHeader
|
||||
key={settingsObjectsTableMetadataField.fieldName}
|
||||
fieldName={settingsObjectsTableMetadataField.fieldName}
|
||||
label={settingsObjectsTableMetadataField.fieldLabel}
|
||||
tableId={SETTINGS_OBJECT_TABLE_METADATA.tableId}
|
||||
tableId={tableMetadata.tableId}
|
||||
align={settingsObjectsTableMetadataField.align}
|
||||
initialSort={SETTINGS_OBJECT_TABLE_METADATA.initialSort}
|
||||
initialSort={tableMetadata.initialSort}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
|
||||
@ -1,37 +1,43 @@
|
||||
import { TableMetadata } from '@/ui/layout/table/types/TableMetadata';
|
||||
import { SettingsObjectTableItem } from '~/pages/settings/data-model/types/SettingsObjectTableItem';
|
||||
|
||||
export const SETTINGS_OBJECT_TABLE_METADATA: TableMetadata<SettingsObjectTableItem> =
|
||||
{
|
||||
tableId: 'settingsObject',
|
||||
fields: [
|
||||
{
|
||||
fieldLabel: 'Name',
|
||||
fieldName: 'labelPlural',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: 'Type',
|
||||
fieldName: 'objectTypeLabel',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: 'Fields',
|
||||
fieldName: 'fieldsCount',
|
||||
fieldType: 'number',
|
||||
align: 'right',
|
||||
},
|
||||
{
|
||||
fieldLabel: 'Instances',
|
||||
fieldName: 'totalObjectCount',
|
||||
fieldType: 'number',
|
||||
align: 'right',
|
||||
},
|
||||
],
|
||||
initialSort: {
|
||||
type GET_SETTINGS_OBJECT_TABLE_METADATAProps = {
|
||||
(descriptor: { id: string }): string;
|
||||
(literals: TemplateStringsArray, ...placeholders: any[]): string;
|
||||
};
|
||||
|
||||
export const GET_SETTINGS_OBJECT_TABLE_METADATA = (
|
||||
t: GET_SETTINGS_OBJECT_TABLE_METADATAProps,
|
||||
): TableMetadata<SettingsObjectTableItem> => ({
|
||||
tableId: 'settingsObject',
|
||||
fields: [
|
||||
{
|
||||
fieldLabel: t({ id: 'Name' }),
|
||||
fieldName: 'labelPlural',
|
||||
orderBy: 'AscNullsLast',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
};
|
||||
{
|
||||
fieldLabel: t({ id: 'Type' }),
|
||||
fieldName: 'objectTypeLabel',
|
||||
fieldType: 'string',
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
fieldLabel: t({ id: 'Fields' }),
|
||||
fieldName: 'fieldsCount',
|
||||
fieldType: 'number',
|
||||
align: 'right',
|
||||
},
|
||||
{
|
||||
fieldLabel: t({ id: 'Instances' }),
|
||||
fieldName: 'totalObjectCount',
|
||||
fieldType: 'number',
|
||||
align: 'right',
|
||||
},
|
||||
],
|
||||
initialSort: {
|
||||
fieldName: 'labelPlural',
|
||||
orderBy: 'AscNullsLast',
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user