feat: get object metadata from backend in Object Detail and New Field… (#2122)
* feat: get object metadata from backend in Object Detail and New Field - Step 1 Closes #2008 * refactor: add useLazyLoadIcon hook
This commit is contained in:
@ -2,17 +2,17 @@ import { useTheme } from '@emotion/react';
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
import { IconDotsVertical } from '@/ui/display/icon';
|
import { IconDotsVertical } from '@/ui/display/icon';
|
||||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
|
||||||
import { Tag } from '@/ui/display/tag/components/Tag';
|
import { Tag } from '@/ui/display/tag/components/Tag';
|
||||||
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
||||||
|
import { useLazyLoadIcon } from '@/ui/input/hooks/useLazyLoadIcon';
|
||||||
import { Section } from '@/ui/layout/section/components/Section';
|
import { Section } from '@/ui/layout/section/components/Section';
|
||||||
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
||||||
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
||||||
|
|
||||||
type SettingsAboutSectionProps = {
|
type SettingsAboutSectionProps = {
|
||||||
Icon: IconComponent;
|
iconKey?: string;
|
||||||
|
isCustom: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
type: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledIconTableCell = styled(TableCell)`
|
const StyledIconTableCell = styled(TableCell)`
|
||||||
@ -45,25 +45,27 @@ const StyledFlexContainer = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const SettingsAboutSection = ({
|
export const SettingsAboutSection = ({
|
||||||
Icon,
|
iconKey = '',
|
||||||
|
isCustom,
|
||||||
name,
|
name,
|
||||||
type,
|
|
||||||
}: SettingsAboutSectionProps) => {
|
}: SettingsAboutSectionProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { Icon } = useLazyLoadIcon(iconKey);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section>
|
<Section>
|
||||||
<H2Title title="About" description={`Manage you object`} />
|
<H2Title title="About" description="Manage your object" />
|
||||||
<StyledTableRow>
|
<StyledTableRow>
|
||||||
<StyledNameTableCell>
|
<StyledNameTableCell>
|
||||||
<Icon size={theme.icon.size.md} />
|
{!!Icon && <Icon size={theme.icon.size.md} />}
|
||||||
{name}
|
{name}
|
||||||
</StyledNameTableCell>
|
</StyledNameTableCell>
|
||||||
<StyledFlexContainer>
|
<StyledFlexContainer>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{type === 'standard' ? (
|
{isCustom ? (
|
||||||
<StyledTag color="blue" text="Standard" />
|
|
||||||
) : (
|
|
||||||
<StyledTag color="orange" text="Custom" />
|
<StyledTag color="orange" text="Custom" />
|
||||||
|
) : (
|
||||||
|
<StyledTag color="blue" text="Standard" />
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<StyledIconTableCell>
|
<StyledIconTableCell>
|
||||||
|
|||||||
@ -11,9 +11,9 @@ import {
|
|||||||
} from '@/ui/display/icon';
|
} from '@/ui/display/icon';
|
||||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||||
|
|
||||||
import { ObjectFieldItem } from '../../types/ObjectFieldItem';
|
import { ObjectFieldDataType } from '../../types/ObjectFieldDataType';
|
||||||
|
|
||||||
const StyledDataType = styled.div<{ value: ObjectFieldItem['dataType'] }>`
|
const StyledDataType = styled.div<{ value: ObjectFieldDataType }>`
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
border-radius: ${({ theme }) => theme.border.radius.sm};
|
border-radius: ${({ theme }) => theme.border.radius.sm};
|
||||||
@ -33,7 +33,7 @@ const StyledDataType = styled.div<{ value: ObjectFieldItem['dataType'] }>`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const dataTypes: Record<
|
const dataTypes: Record<
|
||||||
ObjectFieldItem['dataType'],
|
ObjectFieldDataType,
|
||||||
{ label: string; Icon: IconComponent }
|
{ label: string; Icon: IconComponent }
|
||||||
> = {
|
> = {
|
||||||
boolean: { label: 'True/False', Icon: IconCheck },
|
boolean: { label: 'True/False', Icon: IconCheck },
|
||||||
@ -45,7 +45,7 @@ const dataTypes: Record<
|
|||||||
};
|
};
|
||||||
|
|
||||||
type SettingsObjectFieldDataTypeProps = {
|
type SettingsObjectFieldDataTypeProps = {
|
||||||
value: ObjectFieldItem['dataType'];
|
value: ObjectFieldDataType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SettingsObjectFieldDataType = ({
|
export const SettingsObjectFieldDataType = ({
|
||||||
|
|||||||
@ -3,16 +3,18 @@ import styled from '@emotion/styled';
|
|||||||
|
|
||||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||||
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
|
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
|
||||||
|
import { useLazyLoadIcon } from '@/ui/input/hooks/useLazyLoadIcon';
|
||||||
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
||||||
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
||||||
|
import { Field } from '~/generated-metadata/graphql';
|
||||||
|
|
||||||
import { ObjectFieldItem } from '../../types/ObjectFieldItem';
|
import { ObjectFieldDataType } from '../../types/ObjectFieldDataType';
|
||||||
|
|
||||||
import { SettingsObjectFieldDataType } from './SettingsObjectFieldDataType';
|
import { SettingsObjectFieldDataType } from './SettingsObjectFieldDataType';
|
||||||
|
|
||||||
type SettingsObjectFieldItemTableRowProps = {
|
type SettingsObjectFieldItemTableRowProps = {
|
||||||
ActionIcon: IconComponent;
|
ActionIcon: IconComponent;
|
||||||
fieldItem: ObjectFieldItem;
|
fieldItem: Field;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const StyledObjectFieldTableRow = styled(TableRow)`
|
export const StyledObjectFieldTableRow = styled(TableRow)`
|
||||||
@ -34,18 +36,19 @@ export const SettingsObjectFieldItemTableRow = ({
|
|||||||
fieldItem,
|
fieldItem,
|
||||||
}: SettingsObjectFieldItemTableRowProps) => {
|
}: SettingsObjectFieldItemTableRowProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { Icon } = useLazyLoadIcon(fieldItem.icon ?? '');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledObjectFieldTableRow>
|
<StyledObjectFieldTableRow>
|
||||||
<StyledNameTableCell>
|
<StyledNameTableCell>
|
||||||
<fieldItem.Icon size={theme.icon.size.md} />
|
{!!Icon && <Icon size={theme.icon.size.md} />}
|
||||||
{fieldItem.name}
|
{fieldItem.label}
|
||||||
</StyledNameTableCell>
|
</StyledNameTableCell>
|
||||||
|
<TableCell>{fieldItem.isCustom ? 'Custom' : 'Standard'}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{fieldItem.type === 'standard' ? 'Standard' : 'Custom'}
|
<SettingsObjectFieldDataType
|
||||||
</TableCell>
|
value={fieldItem.type as ObjectFieldDataType}
|
||||||
<TableCell>
|
/>
|
||||||
<SettingsObjectFieldDataType value={fieldItem.dataType} />
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<StyledIconTableCell>
|
<StyledIconTableCell>
|
||||||
<LightIconButton Icon={ActionIcon} accent="tertiary" />
|
<LightIconButton Icon={ActionIcon} accent="tertiary" />
|
||||||
|
|||||||
@ -4,14 +4,13 @@ import styled from '@emotion/styled';
|
|||||||
|
|
||||||
import { useFindManyObjects } from '@/metadata/hooks/useFindManyObjects';
|
import { useFindManyObjects } from '@/metadata/hooks/useFindManyObjects';
|
||||||
import { MetadataObject } from '@/metadata/types/MetadataObject';
|
import { MetadataObject } from '@/metadata/types/MetadataObject';
|
||||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
|
||||||
import { Tag } from '@/ui/display/tag/components/Tag';
|
import { Tag } from '@/ui/display/tag/components/Tag';
|
||||||
|
import { useLazyLoadIcon } from '@/ui/input/hooks/useLazyLoadIcon';
|
||||||
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
||||||
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
||||||
|
|
||||||
type SettingsObjectItemTableRowProps = {
|
type SettingsObjectItemTableRowProps = {
|
||||||
action: ReactNode;
|
action: ReactNode;
|
||||||
Icon?: IconComponent;
|
|
||||||
objectItem: MetadataObject;
|
objectItem: MetadataObject;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
};
|
};
|
||||||
@ -37,7 +36,6 @@ const StyledActionTableCell = styled(TableCell)`
|
|||||||
|
|
||||||
export const SettingsObjectItemTableRow = ({
|
export const SettingsObjectItemTableRow = ({
|
||||||
action,
|
action,
|
||||||
Icon,
|
|
||||||
objectItem,
|
objectItem,
|
||||||
onClick,
|
onClick,
|
||||||
}: SettingsObjectItemTableRowProps) => {
|
}: SettingsObjectItemTableRowProps) => {
|
||||||
@ -47,6 +45,8 @@ export const SettingsObjectItemTableRow = ({
|
|||||||
objectNamePlural: objectItem.namePlural,
|
objectNamePlural: objectItem.namePlural,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { Icon } = useLazyLoadIcon(objectItem.icon ?? '');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledObjectTableRow key={objectItem.namePlural} onClick={onClick}>
|
<StyledObjectTableRow key={objectItem.namePlural} onClick={onClick}>
|
||||||
<StyledNameTableCell>
|
<StyledNameTableCell>
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
export type ObjectFieldDataType =
|
||||||
|
| 'boolean'
|
||||||
|
| 'number'
|
||||||
|
| 'relation'
|
||||||
|
| 'social'
|
||||||
|
| 'teammate'
|
||||||
|
| 'text';
|
||||||
@ -1,8 +1,10 @@
|
|||||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||||
|
|
||||||
|
import { ObjectFieldDataType } from './ObjectFieldDataType';
|
||||||
|
|
||||||
export type ObjectFieldItem = {
|
export type ObjectFieldItem = {
|
||||||
name: string;
|
name: string;
|
||||||
Icon: IconComponent;
|
Icon: IconComponent;
|
||||||
type: 'standard' | 'custom';
|
type: 'standard' | 'custom';
|
||||||
dataType: 'boolean' | 'number' | 'relation' | 'social' | 'teammate' | 'text';
|
dataType: ObjectFieldDataType;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||||
@ -13,6 +13,7 @@ import { DropdownScope } from '@/ui/layout/dropdown/scopes/DropdownScope';
|
|||||||
import { IconButton } from '../button/components/IconButton';
|
import { IconButton } from '../button/components/IconButton';
|
||||||
import { LightIconButton } from '../button/components/LightIconButton';
|
import { LightIconButton } from '../button/components/LightIconButton';
|
||||||
import { IconApps } from '../constants/icons';
|
import { IconApps } from '../constants/icons';
|
||||||
|
import { useLazyLoadIcons } from '../hooks/useLazyLoadIcons';
|
||||||
import { DropdownMenuSkeletonItem } from '../relation-picker/components/skeletons/DropdownMenuSkeletonItem';
|
import { DropdownMenuSkeletonItem } from '../relation-picker/components/skeletons/DropdownMenuSkeletonItem';
|
||||||
import { IconPickerHotkeyScope } from '../types/IconPickerHotkeyScope';
|
import { IconPickerHotkeyScope } from '../types/IconPickerHotkeyScope';
|
||||||
|
|
||||||
@ -48,17 +49,10 @@ export const IconPicker = ({
|
|||||||
onOpen,
|
onOpen,
|
||||||
}: IconPickerProps) => {
|
}: IconPickerProps) => {
|
||||||
const [searchString, setSearchString] = useState('');
|
const [searchString, setSearchString] = useState('');
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [icons, setIcons] = useState<Record<string, IconComponent>>({});
|
|
||||||
|
|
||||||
const { closeDropdown } = useDropdown({ dropdownScopeId: 'icon-picker' });
|
const { closeDropdown } = useDropdown({ dropdownScopeId: 'icon-picker' });
|
||||||
|
|
||||||
useEffect(() => {
|
const { icons, isLoadingIcons: isLoading } = useLazyLoadIcons();
|
||||||
import('../constants/icons').then((lazyLoadedIcons) => {
|
|
||||||
setIcons(lazyLoadedIcons);
|
|
||||||
setIsLoading(false);
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const iconKeys = useMemo(() => {
|
const iconKeys = useMemo(() => {
|
||||||
const filteredIconKeys = Object.keys(icons).filter(
|
const filteredIconKeys = Object.keys(icons).filter(
|
||||||
|
|||||||
21
front/src/modules/ui/input/hooks/useLazyLoadIcon.ts
Normal file
21
front/src/modules/ui/input/hooks/useLazyLoadIcon.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||||
|
|
||||||
|
export const useLazyLoadIcon = (iconKey: string) => {
|
||||||
|
const [Icon, setIcon] = useState<IconComponent | undefined>();
|
||||||
|
const [isLoadingIcon, setIsLoadingIcon] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!iconKey) return;
|
||||||
|
|
||||||
|
import(`@tabler/icons-react/dist/esm/icons/${iconKey}.js`).then(
|
||||||
|
(lazyLoadedIcon) => {
|
||||||
|
setIcon(lazyLoadedIcon.default);
|
||||||
|
setIsLoadingIcon(false);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}, [iconKey]);
|
||||||
|
|
||||||
|
return { Icon, isLoadingIcon };
|
||||||
|
};
|
||||||
17
front/src/modules/ui/input/hooks/useLazyLoadIcons.ts
Normal file
17
front/src/modules/ui/input/hooks/useLazyLoadIcons.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||||
|
|
||||||
|
export const useLazyLoadIcons = () => {
|
||||||
|
const [icons, setIcons] = useState<Record<string, IconComponent>>({});
|
||||||
|
const [isLoadingIcons, setIsLoadingIcons] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
import('../constants/icons').then((lazyLoadedIcons) => {
|
||||||
|
setIcons(lazyLoadedIcons);
|
||||||
|
setIsLoadingIcons(false);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return { icons, isLoadingIcons };
|
||||||
|
};
|
||||||
@ -2,12 +2,8 @@ import { useEffect } from 'react';
|
|||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
|
import { useObjectMetadata } from '@/metadata/hooks/useObjectMetadata';
|
||||||
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
|
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
|
||||||
import {
|
|
||||||
activeFieldItems,
|
|
||||||
activeObjectItems,
|
|
||||||
disabledFieldItems,
|
|
||||||
} from '@/settings/data-model/constants/mockObjects';
|
|
||||||
import { SettingsAboutSection } from '@/settings/data-model/object-details/components/SettingsObjectAboutSection';
|
import { SettingsAboutSection } from '@/settings/data-model/object-details/components/SettingsObjectAboutSection';
|
||||||
import {
|
import {
|
||||||
SettingsObjectFieldItemTableRow,
|
SettingsObjectFieldItemTableRow,
|
||||||
@ -34,13 +30,23 @@ export const SettingsObjectDetail = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { pluralObjectName = '' } = useParams();
|
const { pluralObjectName = '' } = useParams();
|
||||||
const activeObject = activeObjectItems.find(
|
const { activeObjects } = useObjectMetadata();
|
||||||
(activeObject) => activeObject.name.toLowerCase() === pluralObjectName,
|
const activeObject = activeObjects.find(
|
||||||
|
(activeObject) => activeObject.namePlural === pluralObjectName,
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!activeObject) navigate(AppPath.NotFound);
|
if (activeObjects.length && !activeObject) {
|
||||||
}, [activeObject, navigate]);
|
navigate(AppPath.NotFound);
|
||||||
|
}
|
||||||
|
}, [activeObject, activeObjects.length, navigate]);
|
||||||
|
|
||||||
|
const activeFields = activeObject?.fields.filter(
|
||||||
|
(fieldItem) => fieldItem.isActive,
|
||||||
|
);
|
||||||
|
const disabledFields = activeObject?.fields.filter(
|
||||||
|
(fieldItem) => !fieldItem.isActive,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
|
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
|
||||||
@ -48,20 +54,20 @@ export const SettingsObjectDetail = () => {
|
|||||||
<Breadcrumb
|
<Breadcrumb
|
||||||
links={[
|
links={[
|
||||||
{ children: 'Objects', href: '/settings/objects' },
|
{ children: 'Objects', href: '/settings/objects' },
|
||||||
{ children: activeObject?.name ?? '' },
|
{ children: activeObject?.labelPlural ?? '' },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
{activeObject && (
|
{activeObject && (
|
||||||
<SettingsAboutSection
|
<SettingsAboutSection
|
||||||
Icon={activeObject?.Icon}
|
iconKey={activeObject.icon ?? undefined}
|
||||||
name={activeObject.name}
|
name={activeObject.labelPlural || ''}
|
||||||
type={activeObject.type}
|
isCustom={activeObject.isCustom}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Section>
|
<Section>
|
||||||
<H2Title
|
<H2Title
|
||||||
title="Fields"
|
title="Fields"
|
||||||
description={`Customise the fields available in the ${activeObject?.singularName} views and their display order in the ${activeObject?.singularName} detail view and menus.`}
|
description={`Customise the fields available in the ${activeObject?.nameSingular} views and their display order in the ${activeObject?.nameSingular} detail view and menus.`}
|
||||||
/>
|
/>
|
||||||
<Table>
|
<Table>
|
||||||
<StyledObjectFieldTableRow>
|
<StyledObjectFieldTableRow>
|
||||||
@ -71,21 +77,21 @@ export const SettingsObjectDetail = () => {
|
|||||||
<TableHeader></TableHeader>
|
<TableHeader></TableHeader>
|
||||||
</StyledObjectFieldTableRow>
|
</StyledObjectFieldTableRow>
|
||||||
<TableSection title="Active">
|
<TableSection title="Active">
|
||||||
{activeFieldItems.map((fieldItem) => (
|
{activeFields?.map((fieldItem) => (
|
||||||
<SettingsObjectFieldItemTableRow
|
<SettingsObjectFieldItemTableRow
|
||||||
key={fieldItem.name}
|
key={fieldItem.id}
|
||||||
ActionIcon={IconDotsVertical}
|
|
||||||
fieldItem={fieldItem}
|
fieldItem={fieldItem}
|
||||||
|
ActionIcon={IconDotsVertical}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</TableSection>
|
</TableSection>
|
||||||
{!!disabledFieldItems.length && (
|
{!!disabledFields?.length && (
|
||||||
<TableSection isInitiallyExpanded={false} title="Disabled">
|
<TableSection isInitiallyExpanded={false} title="Disabled">
|
||||||
{disabledFieldItems.map((fieldItem) => (
|
{disabledFields.map((fieldItem) => (
|
||||||
<SettingsObjectFieldItemTableRow
|
<SettingsObjectFieldItemTableRow
|
||||||
key={fieldItem.name}
|
key={fieldItem.id}
|
||||||
ActionIcon={IconDotsVertical}
|
|
||||||
fieldItem={fieldItem}
|
fieldItem={fieldItem}
|
||||||
|
ActionIcon={IconDotsVertical}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</TableSection>
|
</TableSection>
|
||||||
@ -99,7 +105,7 @@ export const SettingsObjectDetail = () => {
|
|||||||
variant="secondary"
|
variant="secondary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(
|
navigate(
|
||||||
disabledFieldItems.length
|
disabledFields?.length
|
||||||
? './new-field/step-1'
|
? './new-field/step-1'
|
||||||
: './new-field/step-2',
|
: './new-field/step-2',
|
||||||
)
|
)
|
||||||
|
|||||||
@ -2,14 +2,10 @@ import { useEffect } from 'react';
|
|||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
|
import { useObjectMetadata } from '@/metadata/hooks/useObjectMetadata';
|
||||||
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
|
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
|
||||||
import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer';
|
import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer';
|
||||||
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
|
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
|
||||||
import {
|
|
||||||
activeFieldItems,
|
|
||||||
activeObjectItems,
|
|
||||||
disabledFieldItems,
|
|
||||||
} from '@/settings/data-model/constants/mockObjects';
|
|
||||||
import {
|
import {
|
||||||
SettingsObjectFieldItemTableRow,
|
SettingsObjectFieldItemTableRow,
|
||||||
StyledObjectFieldTableRow,
|
StyledObjectFieldTableRow,
|
||||||
@ -37,14 +33,25 @@ const StyledAddCustomFieldButton = styled(Button)`
|
|||||||
|
|
||||||
export const SettingsObjectNewFieldStep1 = () => {
|
export const SettingsObjectNewFieldStep1 = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { pluralObjectName = '' } = useParams();
|
const { pluralObjectName = '' } = useParams();
|
||||||
const activeObject = activeObjectItems.find(
|
const { activeObjects } = useObjectMetadata();
|
||||||
(activeObject) => activeObject.name.toLowerCase() === pluralObjectName,
|
const activeObject = activeObjects.find(
|
||||||
|
(activeObject) => activeObject.namePlural === pluralObjectName,
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!activeObject) navigate(AppPath.NotFound);
|
if (activeObjects.length && !activeObject) {
|
||||||
}, [activeObject, navigate]);
|
navigate(AppPath.NotFound);
|
||||||
|
}
|
||||||
|
}, [activeObject, activeObjects.length, navigate]);
|
||||||
|
|
||||||
|
const activeFields = activeObject?.fields.filter(
|
||||||
|
(fieldItem) => fieldItem.isActive,
|
||||||
|
);
|
||||||
|
const disabledFields = activeObject?.fields.filter(
|
||||||
|
(fieldItem) => !fieldItem.isActive,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
|
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
|
||||||
@ -54,7 +61,7 @@ export const SettingsObjectNewFieldStep1 = () => {
|
|||||||
links={[
|
links={[
|
||||||
{ children: 'Objects', href: '/settings/objects' },
|
{ children: 'Objects', href: '/settings/objects' },
|
||||||
{
|
{
|
||||||
children: activeObject?.name ?? '',
|
children: activeObject?.labelPlural ?? '',
|
||||||
href: `/settings/objects/${pluralObjectName}`,
|
href: `/settings/objects/${pluralObjectName}`,
|
||||||
},
|
},
|
||||||
{ children: 'New Field' },
|
{ children: 'New Field' },
|
||||||
@ -65,7 +72,7 @@ export const SettingsObjectNewFieldStep1 = () => {
|
|||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
navigate(`/settings/objects/${pluralObjectName}`);
|
navigate(`/settings/objects/${pluralObjectName}`);
|
||||||
}}
|
}}
|
||||||
onSave={() => {}}
|
onSave={() => undefined}
|
||||||
/>
|
/>
|
||||||
</SettingsHeaderContainer>
|
</SettingsHeaderContainer>
|
||||||
<StyledSection>
|
<StyledSection>
|
||||||
@ -81,21 +88,21 @@ export const SettingsObjectNewFieldStep1 = () => {
|
|||||||
<TableHeader></TableHeader>
|
<TableHeader></TableHeader>
|
||||||
</StyledObjectFieldTableRow>
|
</StyledObjectFieldTableRow>
|
||||||
<TableSection isInitiallyExpanded={false} title="Active">
|
<TableSection isInitiallyExpanded={false} title="Active">
|
||||||
{activeFieldItems.map((fieldItem) => (
|
{activeFields?.map((fieldItem) => (
|
||||||
<SettingsObjectFieldItemTableRow
|
<SettingsObjectFieldItemTableRow
|
||||||
key={fieldItem.name}
|
key={fieldItem.id}
|
||||||
ActionIcon={IconMinus}
|
|
||||||
fieldItem={fieldItem}
|
fieldItem={fieldItem}
|
||||||
|
ActionIcon={IconMinus}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</TableSection>
|
</TableSection>
|
||||||
{!!disabledFieldItems.length && (
|
{!!disabledFields?.length && (
|
||||||
<TableSection title="Disabled">
|
<TableSection title="Disabled">
|
||||||
{disabledFieldItems.map((fieldItem) => (
|
{disabledFields.map((fieldItem) => (
|
||||||
<SettingsObjectFieldItemTableRow
|
<SettingsObjectFieldItemTableRow
|
||||||
key={fieldItem.name}
|
key={fieldItem.name}
|
||||||
ActionIcon={IconPlus}
|
|
||||||
fieldItem={fieldItem}
|
fieldItem={fieldItem}
|
||||||
|
ActionIcon={IconPlus}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</TableSection>
|
</TableSection>
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { useEffect, useState } from 'react';
|
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTheme } from '@emotion/react';
|
import { useTheme } from '@emotion/react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
@ -13,7 +12,6 @@ import {
|
|||||||
import { SettingsObjectCoverImage } from '@/settings/data-model/objects/SettingsObjectCoverImage';
|
import { SettingsObjectCoverImage } from '@/settings/data-model/objects/SettingsObjectCoverImage';
|
||||||
import { SettingsObjectDisabledMenuDropDown } from '@/settings/data-model/objects/SettingsObjectDisabledMenuDropDown';
|
import { SettingsObjectDisabledMenuDropDown } from '@/settings/data-model/objects/SettingsObjectDisabledMenuDropDown';
|
||||||
import { IconChevronRight, IconPlus, IconSettings } from '@/ui/display/icon';
|
import { IconChevronRight, IconPlus, IconSettings } from '@/ui/display/icon';
|
||||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
|
||||||
import { H1Title } from '@/ui/display/typography/components/H1Title';
|
import { H1Title } from '@/ui/display/typography/components/H1Title';
|
||||||
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
||||||
import { Button } from '@/ui/input/button/components/Button';
|
import { Button } from '@/ui/input/button/components/Button';
|
||||||
@ -37,14 +35,6 @@ export const SettingsObjects = () => {
|
|||||||
|
|
||||||
const { activeObjects, disabledObjects } = useObjectMetadata();
|
const { activeObjects, disabledObjects } = useObjectMetadata();
|
||||||
|
|
||||||
const [icons, setIcons] = useState<Record<string, IconComponent>>({});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
import('@/ui/input/constants/icons').then((lazyLoadedIcons) => {
|
|
||||||
setIcons(lazyLoadedIcons);
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
|
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
|
||||||
<SettingsPageContainer>
|
<SettingsPageContainer>
|
||||||
@ -76,7 +66,6 @@ export const SettingsObjects = () => {
|
|||||||
{activeObjects.map((objectItem) => (
|
{activeObjects.map((objectItem) => (
|
||||||
<SettingsObjectItemTableRow
|
<SettingsObjectItemTableRow
|
||||||
key={objectItem.namePlural}
|
key={objectItem.namePlural}
|
||||||
Icon={icons[objectItem.icon || '']}
|
|
||||||
objectItem={objectItem}
|
objectItem={objectItem}
|
||||||
action={
|
action={
|
||||||
<StyledIconChevronRight
|
<StyledIconChevronRight
|
||||||
@ -95,7 +84,6 @@ export const SettingsObjects = () => {
|
|||||||
{disabledObjects.map((objectItem) => (
|
{disabledObjects.map((objectItem) => (
|
||||||
<SettingsObjectItemTableRow
|
<SettingsObjectItemTableRow
|
||||||
key={objectItem.namePlural}
|
key={objectItem.namePlural}
|
||||||
Icon={icons[objectItem.icon || '']}
|
|
||||||
objectItem={objectItem}
|
objectItem={objectItem}
|
||||||
action={
|
action={
|
||||||
<SettingsObjectDisabledMenuDropDown
|
<SettingsObjectDisabledMenuDropDown
|
||||||
|
|||||||
Reference in New Issue
Block a user