feat: get object metadata from backend in Object Edit (#2125)

Closes #2009
This commit is contained in:
Thaïs
2023-10-19 17:14:29 +02:00
committed by GitHub
parent f35ea19f4d
commit 2f0da64e1b
4 changed files with 22 additions and 20 deletions

View File

@ -1,9 +1,9 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { IconPigMoney } from '@/ui/display/icon';
import { IconComponent } from '@/ui/display/icon/types/IconComponent'; import { IconComponent } from '@/ui/display/icon/types/IconComponent';
import { H2Title } from '@/ui/display/typography/components/H2Title'; import { H2Title } from '@/ui/display/typography/components/H2Title';
import { IconPicker } from '@/ui/input/components/IconPicker'; import { IconPicker } from '@/ui/input/components/IconPicker';
import { useLazyLoadIcon } from '@/ui/input/hooks/useLazyLoadIcon';
import { Section } from '@/ui/layout/section/components/Section'; import { Section } from '@/ui/layout/section/components/Section';
import ArrowRight from '../assets/ArrowRight.svg'; import ArrowRight from '../assets/ArrowRight.svg';
@ -25,7 +25,6 @@ const StyledArrowContainer = styled.div`
type SettingsObjectIconSectionProps = { type SettingsObjectIconSectionProps = {
disabled?: boolean; disabled?: boolean;
Icon?: IconComponent;
iconKey?: string; iconKey?: string;
label?: string; label?: string;
onChange?: (icon: { Icon: IconComponent; iconKey: string }) => void; onChange?: (icon: { Icon: IconComponent; iconKey: string }) => void;
@ -33,11 +32,12 @@ type SettingsObjectIconSectionProps = {
export const SettingsObjectIconSection = ({ export const SettingsObjectIconSection = ({
disabled, disabled,
Icon = IconPigMoney,
iconKey = 'IconPigMoney', iconKey = 'IconPigMoney',
label, label,
onChange, onChange,
}: SettingsObjectIconSectionProps) => { }: SettingsObjectIconSectionProps) => {
const { Icon } = useLazyLoadIcon(iconKey);
return ( return (
<Section> <Section>
<H2Title <H2Title

View File

@ -24,7 +24,7 @@ const StyledItemLabel = styled.div`
`; `;
type SettingsObjectIconWithLabelProps = { type SettingsObjectIconWithLabelProps = {
Icon: IconComponent; Icon?: IconComponent;
label: string; label: string;
}; };
@ -37,7 +37,9 @@ export const SettingsObjectIconWithLabel = ({
return ( return (
<StyledContainer> <StyledContainer>
<StyledSubContainer> <StyledSubContainer>
<Icon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} /> {!!Icon && (
<Icon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} />
)}
<StyledItemLabel>{label}</StyledItemLabel> <StyledItemLabel>{label}</StyledItemLabel>
</StyledSubContainer> </StyledSubContainer>
</StyledContainer> </StyledContainer>

View File

@ -69,7 +69,6 @@ export {
IconNumbers, IconNumbers,
IconPencil, IconPencil,
IconPhone, IconPhone,
IconPigMoney,
IconPlane, IconPlane,
IconPlug, IconPlug,
IconPlus, IconPlus,

View File

@ -1,9 +1,9 @@
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom'; import { useNavigate, useParams } from 'react-router-dom';
import { useObjectMetadata } from '@/metadata/hooks/useObjectMetadata';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer'; import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { SettingsObjectFormSection } from '@/settings/data-model/components/SettingsObjectFormSection'; import { SettingsObjectFormSection } from '@/settings/data-model/components/SettingsObjectFormSection';
import { activeObjectItems } from '@/settings/data-model/constants/mockObjects';
import { SettingsObjectIconSection } from '@/settings/data-model/object-edit/SettingsObjectIconSection'; import { SettingsObjectIconSection } from '@/settings/data-model/object-edit/SettingsObjectIconSection';
import { AppPath } from '@/types/AppPath'; import { AppPath } from '@/types/AppPath';
import { IconArchive, IconSettings } from '@/ui/display/icon'; import { IconArchive, IconSettings } from '@/ui/display/icon';
@ -15,14 +15,16 @@ import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
export const SettingsObjectEdit = () => { export const SettingsObjectEdit = () => {
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) navigate(AppPath.NotFound);
}, [activeObject, navigate]); }, [activeObject, activeObjects.length, navigate]);
return ( return (
<SubMenuTopBarContainer Icon={IconSettings} title="Settings"> <SubMenuTopBarContainer Icon={IconSettings} title="Settings">
@ -31,7 +33,7 @@ export const SettingsObjectEdit = () => {
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: 'Edit' }, { children: 'Edit' },
@ -40,16 +42,15 @@ export const SettingsObjectEdit = () => {
{activeObject && ( {activeObject && (
<> <>
<SettingsObjectIconSection <SettingsObjectIconSection
disabled={activeObject.type === 'standard'} disabled={!activeObject.isCustom}
Icon={activeObject.Icon} iconKey={activeObject.icon ?? undefined}
iconKey={activeObject.Icon.name} label={activeObject.labelPlural}
label={activeObject.name}
/> />
<SettingsObjectFormSection <SettingsObjectFormSection
disabled={activeObject.type === 'standard'} disabled={!activeObject.isCustom}
singularName={activeObject.singularName} singularName={activeObject.labelSingular}
pluralName={activeObject.name} pluralName={activeObject.labelPlural}
description={activeObject.description} description={activeObject.description ?? undefined}
/> />
</> </>
)} )}