Skip to content

Commit 21869b0

Browse files
committed
feat: get object metadata from backend in Object Edit
Closes #2009
1 parent 28407d1 commit 21869b0

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

front/src/modules/settings/data-model/object-edit/SettingsObjectIconSection.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import styled from '@emotion/styled';
22

3-
import { IconPigMoney } from '@/ui/display/icon';
43
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
54
import { H2Title } from '@/ui/display/typography/components/H2Title';
65
import { IconPicker } from '@/ui/input/components/IconPicker';
6+
import { useLazyLoadIcon } from '@/ui/input/hooks/useLazyLoadIcon';
77
import { Section } from '@/ui/layout/section/components/Section';
88

99
import ArrowRight from '../assets/ArrowRight.svg';
@@ -25,19 +25,19 @@ const StyledArrowContainer = styled.div`
2525

2626
type SettingsObjectIconSectionProps = {
2727
disabled?: boolean;
28-
Icon?: IconComponent;
2928
iconKey?: string;
3029
label?: string;
3130
onChange?: (icon: { Icon: IconComponent; iconKey: string }) => void;
3231
};
3332

3433
export const SettingsObjectIconSection = ({
3534
disabled,
36-
Icon = IconPigMoney,
3735
iconKey = 'IconPigMoney',
3836
label,
3937
onChange,
4038
}: SettingsObjectIconSectionProps) => {
39+
const { Icon } = useLazyLoadIcon(iconKey);
40+
4141
return (
4242
<Section>
4343
<H2Title

front/src/modules/settings/data-model/object-edit/SettingsObjectIconWithLabel.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const StyledItemLabel = styled.div`
2424
`;
2525

2626
type SettingsObjectIconWithLabelProps = {
27-
Icon: IconComponent;
27+
Icon?: IconComponent;
2828
label: string;
2929
};
3030

@@ -37,7 +37,9 @@ export const SettingsObjectIconWithLabel = ({
3737
return (
3838
<StyledContainer>
3939
<StyledSubContainer>
40-
<Icon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} />
40+
{!!Icon && (
41+
<Icon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} />
42+
)}
4143
<StyledItemLabel>{label}</StyledItemLabel>
4244
</StyledSubContainer>
4345
</StyledContainer>

front/src/pages/settings/data-model/SettingsObjectEdit.tsx

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useEffect } from 'react';
22
import { useNavigate, useParams } from 'react-router-dom';
33

4+
import { useObjectMetadata } from '@/metadata/hooks/useObjectMetadata';
45
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
56
import { SettingsObjectFormSection } from '@/settings/data-model/components/SettingsObjectFormSection';
6-
import { activeObjectItems } from '@/settings/data-model/constants/mockObjects';
77
import { SettingsObjectIconSection } from '@/settings/data-model/object-edit/SettingsObjectIconSection';
88
import { AppPath } from '@/types/AppPath';
99
import { IconArchive, IconSettings } from '@/ui/display/icon';
@@ -15,14 +15,16 @@ import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
1515

1616
export const SettingsObjectEdit = () => {
1717
const navigate = useNavigate();
18+
1819
const { pluralObjectName = '' } = useParams();
19-
const activeObject = activeObjectItems.find(
20-
(activeObject) => activeObject.name.toLowerCase() === pluralObjectName,
20+
const { activeObjects } = useObjectMetadata();
21+
const activeObject = activeObjects.find(
22+
(activeObject) => activeObject.namePlural === pluralObjectName,
2123
);
2224

2325
useEffect(() => {
24-
if (!activeObject) navigate(AppPath.NotFound);
25-
}, [activeObject, navigate]);
26+
if (activeObjects.length && !activeObject) navigate(AppPath.NotFound);
27+
}, [activeObject, activeObjects.length, navigate]);
2628

2729
return (
2830
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
@@ -31,7 +33,7 @@ export const SettingsObjectEdit = () => {
3133
links={[
3234
{ children: 'Objects', href: '/settings/objects' },
3335
{
34-
children: activeObject?.name ?? '',
36+
children: activeObject?.labelPlural ?? '',
3537
href: `/settings/objects/${pluralObjectName}`,
3638
},
3739
{ children: 'Edit' },
@@ -40,16 +42,15 @@ export const SettingsObjectEdit = () => {
4042
{activeObject && (
4143
<>
4244
<SettingsObjectIconSection
43-
disabled={activeObject.type === 'standard'}
44-
Icon={activeObject.Icon}
45-
iconKey={activeObject.Icon.name}
46-
label={activeObject.name}
45+
disabled={!activeObject.isCustom}
46+
iconKey={activeObject.icon ?? undefined}
47+
label={activeObject.labelPlural}
4748
/>
4849
<SettingsObjectFormSection
49-
disabled={activeObject.type === 'standard'}
50-
singularName={activeObject.singularName}
51-
pluralName={activeObject.name}
52-
description={activeObject.description}
50+
disabled={!activeObject.isCustom}
51+
singularName={activeObject.labelSingular}
52+
pluralName={activeObject.labelPlural}
53+
description={activeObject.description ?? undefined}
5354
/>
5455
</>
5556
)}

0 commit comments

Comments
 (0)