1
1
import { useEffect } from 'react' ;
2
2
import { useNavigate , useParams } from 'react-router-dom' ;
3
3
4
+ import { useObjectMetadata } from '@/metadata/hooks/useObjectMetadata' ;
4
5
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer' ;
5
6
import { SettingsObjectFormSection } from '@/settings/data-model/components/SettingsObjectFormSection' ;
6
- import { activeObjectItems } from '@/settings/data-model/constants/mockObjects' ;
7
7
import { SettingsObjectIconSection } from '@/settings/data-model/object-edit/SettingsObjectIconSection' ;
8
8
import { AppPath } from '@/types/AppPath' ;
9
9
import { IconArchive , IconSettings } from '@/ui/display/icon' ;
10
10
import { H2Title } from '@/ui/display/typography/components/H2Title' ;
11
11
import { Button } from '@/ui/input/button/components/Button' ;
12
+ import { useLazyLoadIcons } from '@/ui/input/hooks/useLazyLoadIcons' ;
12
13
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer' ;
13
14
import { Section } from '@/ui/layout/section/components/Section' ;
14
15
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb' ;
15
16
16
17
export const SettingsObjectEdit = ( ) => {
17
18
const navigate = useNavigate ( ) ;
19
+
18
20
const { pluralObjectName = '' } = useParams ( ) ;
19
- const activeObject = activeObjectItems . find (
20
- ( activeObject ) => activeObject . name . toLowerCase ( ) === pluralObjectName ,
21
+ const { activeObjects } = useObjectMetadata ( ) ;
22
+ const activeObject = activeObjects . find (
23
+ ( activeObject ) => activeObject . namePlural === pluralObjectName ,
21
24
) ;
22
25
23
26
useEffect ( ( ) => {
24
- if ( ! activeObject ) navigate ( AppPath . NotFound ) ;
25
- } , [ activeObject , navigate ] ) ;
27
+ if ( activeObjects . length && ! activeObject ) navigate ( AppPath . NotFound ) ;
28
+ } , [ activeObject , activeObjects . length , navigate ] ) ;
29
+
30
+ const { icons } = useLazyLoadIcons ( ) ;
26
31
27
32
return (
28
33
< SubMenuTopBarContainer Icon = { IconSettings } title = "Settings" >
@@ -31,7 +36,7 @@ export const SettingsObjectEdit = () => {
31
36
links = { [
32
37
{ children : 'Objects' , href : '/settings/objects' } ,
33
38
{
34
- children : activeObject ?. name ?? '' ,
39
+ children : activeObject ?. labelPlural ?? '' ,
35
40
href : `/settings/objects/${ pluralObjectName } ` ,
36
41
} ,
37
42
{ children : 'Edit' } ,
@@ -40,16 +45,16 @@ export const SettingsObjectEdit = () => {
40
45
{ activeObject && (
41
46
< >
42
47
< SettingsObjectIconSection
43
- disabled = { activeObject . type === 'standard' }
44
- Icon = { activeObject . Icon }
45
- iconKey = { activeObject . Icon . name }
46
- label = { activeObject . name }
48
+ disabled = { ! activeObject . isCustom }
49
+ Icon = { icons [ activeObject . icon || '' ] }
50
+ iconKey = { activeObject . icon ?? undefined }
51
+ label = { activeObject . labelPlural }
47
52
/>
48
53
< SettingsObjectFormSection
49
- disabled = { activeObject . type === 'standard' }
50
- singularName = { activeObject . singularName }
51
- pluralName = { activeObject . name }
52
- description = { activeObject . description }
54
+ disabled = { ! activeObject . isCustom }
55
+ singularName = { activeObject . labelSingular }
56
+ pluralName = { activeObject . labelPlural }
57
+ description = { activeObject . description ?? undefined }
53
58
/>
54
59
</ >
55
60
) }
0 commit comments