feat: get active and disabled objects from backend in Objects Setting… (#2119)
* feat: get active and disabled objects from backend in Objects Settings page Closes #2005 * refactor: add useObjectMetadata hook
This commit is contained in:
16
front/src/modules/metadata/hooks/useObjectMetadata.ts
Normal file
16
front/src/modules/metadata/hooks/useObjectMetadata.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
|
import { activeMetadataObjectsSelector } from '../states/selectors/activeMetadataObjectsSelector';
|
||||||
|
import { disabledMetadataObjectsSelector } from '../states/selectors/disabledMetadataObjectsSelector';
|
||||||
|
|
||||||
|
export const useObjectMetadata = () => {
|
||||||
|
const activeMetadataObjects = useRecoilValue(activeMetadataObjectsSelector);
|
||||||
|
const disabledMetadataObjects = useRecoilValue(
|
||||||
|
disabledMetadataObjectsSelector,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
activeObjects: activeMetadataObjects,
|
||||||
|
disabledObjects: disabledMetadataObjects,
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
import { selector } from 'recoil';
|
||||||
|
|
||||||
|
import { MetadataObject } from '../../types/MetadataObject';
|
||||||
|
import { metadataObjectsState } from '../metadataObjectsState';
|
||||||
|
|
||||||
|
export const activeMetadataObjectsSelector = selector<MetadataObject[]>({
|
||||||
|
key: 'activeMetadataObjectsSelector',
|
||||||
|
get: ({ get }) =>
|
||||||
|
get(metadataObjectsState).filter(({ isActive }) => isActive),
|
||||||
|
});
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
import { selector } from 'recoil';
|
||||||
|
|
||||||
|
import { MetadataObject } from '../../types/MetadataObject';
|
||||||
|
import { metadataObjectsState } from '../metadataObjectsState';
|
||||||
|
|
||||||
|
export const disabledMetadataObjectsSelector = selector<MetadataObject[]>({
|
||||||
|
key: 'disabledMetadataObjectsSelector',
|
||||||
|
get: ({ get }) =>
|
||||||
|
get(metadataObjectsState).filter(({ isActive }) => !isActive),
|
||||||
|
});
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
|
import { useTheme } from '@emotion/react';
|
||||||
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
|
import { useFindManyObjects } from '@/metadata/hooks/useFindManyObjects';
|
||||||
|
import { MetadataObject } from '@/metadata/types/MetadataObject';
|
||||||
|
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||||
|
import { Tag } from '@/ui/display/tag/components/Tag';
|
||||||
|
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
||||||
|
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
||||||
|
|
||||||
|
type SettingsObjectItemTableRowProps = {
|
||||||
|
action: ReactNode;
|
||||||
|
Icon?: IconComponent;
|
||||||
|
objectItem: MetadataObject;
|
||||||
|
onClick?: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const StyledObjectTableRow = styled(TableRow)`
|
||||||
|
grid-template-columns: 180px 98.7px 98.7px 98.7px 36px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledNameTableCell = styled(TableCell)`
|
||||||
|
color: ${({ theme }) => theme.font.color.primary};
|
||||||
|
gap: ${({ theme }) => theme.spacing(2)};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledTag = styled(Tag)`
|
||||||
|
box-sizing: border-box;
|
||||||
|
height: ${({ theme }) => theme.spacing(4)};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledActionTableCell = styled(TableCell)`
|
||||||
|
justify-content: center;
|
||||||
|
padding-right: ${({ theme }) => theme.spacing(1)};
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const SettingsObjectItemTableRow = ({
|
||||||
|
action,
|
||||||
|
Icon,
|
||||||
|
objectItem,
|
||||||
|
onClick,
|
||||||
|
}: SettingsObjectItemTableRowProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const { objects } = useFindManyObjects({
|
||||||
|
objectNamePlural: objectItem.namePlural,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StyledObjectTableRow key={objectItem.namePlural} onClick={onClick}>
|
||||||
|
<StyledNameTableCell>
|
||||||
|
{!!Icon && <Icon size={theme.icon.size.md} />}
|
||||||
|
{objectItem.labelPlural}
|
||||||
|
</StyledNameTableCell>
|
||||||
|
<TableCell>
|
||||||
|
{objectItem.isCustom ? (
|
||||||
|
<StyledTag color="orange" text="Custom" />
|
||||||
|
) : (
|
||||||
|
<StyledTag color="blue" text="Standard" />
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell align="right">{objectItem.fields.length}</TableCell>
|
||||||
|
<TableCell align="right">{objects.length}</TableCell>
|
||||||
|
<StyledActionTableCell>{action}</StyledActionTableCell>
|
||||||
|
</StyledObjectTableRow>
|
||||||
|
);
|
||||||
|
};
|
||||||
@ -1,47 +1,28 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
import { useObjectMetadata } from '@/metadata/hooks/useObjectMetadata';
|
||||||
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 {
|
import {
|
||||||
activeObjectItems,
|
SettingsObjectItemTableRow,
|
||||||
disabledObjectItems,
|
StyledObjectTableRow,
|
||||||
} from '@/settings/data-model/constants/mockObjects';
|
} from '@/settings/data-model/object-details/components/SettingsObjectItemTableRow';
|
||||||
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 { Tag } from '@/ui/display/tag/components/Tag';
|
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';
|
||||||
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
||||||
import { Section } from '@/ui/layout/section/components/Section';
|
import { Section } from '@/ui/layout/section/components/Section';
|
||||||
import { Table } from '@/ui/layout/table/components/Table';
|
import { Table } from '@/ui/layout/table/components/Table';
|
||||||
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
|
||||||
import { TableHeader } from '@/ui/layout/table/components/TableHeader';
|
import { TableHeader } from '@/ui/layout/table/components/TableHeader';
|
||||||
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
|
||||||
import { TableSection } from '@/ui/layout/table/components/TableSection';
|
import { TableSection } from '@/ui/layout/table/components/TableSection';
|
||||||
|
|
||||||
const StyledTableRow = styled(TableRow)`
|
|
||||||
grid-template-columns: 180px 98.7px 98.7px 98.7px 36px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledNameTableCell = styled(TableCell)`
|
|
||||||
color: ${({ theme }) => theme.font.color.primary};
|
|
||||||
gap: ${({ theme }) => theme.spacing(2)};
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledTag = styled(Tag)`
|
|
||||||
box-sizing: border-box;
|
|
||||||
height: ${({ theme }) => theme.spacing(4)};
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledIconTableCell = styled(TableCell)`
|
|
||||||
justify-content: center;
|
|
||||||
padding-right: ${({ theme }) => theme.spacing(1)};
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledIconChevronRight = styled(IconChevronRight)`
|
const StyledIconChevronRight = styled(IconChevronRight)`
|
||||||
color: ${({ theme }) => theme.font.color.tertiary};
|
color: ${({ theme }) => theme.font.color.tertiary};
|
||||||
`;
|
`;
|
||||||
@ -54,6 +35,16 @@ export const SettingsObjects = () => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
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>
|
||||||
@ -74,72 +65,46 @@ export const SettingsObjects = () => {
|
|||||||
<Section>
|
<Section>
|
||||||
<H2Title title="Existing objects" />
|
<H2Title title="Existing objects" />
|
||||||
<Table>
|
<Table>
|
||||||
<StyledTableRow>
|
<StyledObjectTableRow>
|
||||||
<TableHeader>Name</TableHeader>
|
<TableHeader>Name</TableHeader>
|
||||||
<TableHeader>Type</TableHeader>
|
<TableHeader>Type</TableHeader>
|
||||||
<TableHeader align="right">Fields</TableHeader>
|
<TableHeader align="right">Fields</TableHeader>
|
||||||
<TableHeader align="right">Instances</TableHeader>
|
<TableHeader align="right">Instances</TableHeader>
|
||||||
<TableHeader></TableHeader>
|
<TableHeader></TableHeader>
|
||||||
</StyledTableRow>
|
</StyledObjectTableRow>
|
||||||
<TableSection title="Active">
|
<TableSection title="Active">
|
||||||
{activeObjectItems.map((objectItem) => (
|
{activeObjects.map((objectItem) => (
|
||||||
<StyledTableRow
|
<SettingsObjectItemTableRow
|
||||||
key={objectItem.name}
|
key={objectItem.namePlural}
|
||||||
onClick={() =>
|
Icon={icons[objectItem.icon || '']}
|
||||||
navigate(
|
objectItem={objectItem}
|
||||||
`/settings/objects/${objectItem.name.toLowerCase()}`,
|
action={
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<StyledNameTableCell>
|
|
||||||
<objectItem.Icon size={theme.icon.size.md} />
|
|
||||||
{objectItem.name}
|
|
||||||
</StyledNameTableCell>
|
|
||||||
<TableCell>
|
|
||||||
{objectItem.type === 'standard' ? (
|
|
||||||
<StyledTag color="blue" text="Standard" />
|
|
||||||
) : (
|
|
||||||
<StyledTag color="orange" text="Custom" />
|
|
||||||
)}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell align="right">{objectItem.fields}</TableCell>
|
|
||||||
<TableCell align="right">{objectItem.instances}</TableCell>
|
|
||||||
<StyledIconTableCell>
|
|
||||||
<StyledIconChevronRight
|
<StyledIconChevronRight
|
||||||
size={theme.icon.size.md}
|
size={theme.icon.size.md}
|
||||||
stroke={theme.icon.stroke.sm}
|
stroke={theme.icon.stroke.sm}
|
||||||
/>
|
/>
|
||||||
</StyledIconTableCell>
|
}
|
||||||
</StyledTableRow>
|
onClick={() =>
|
||||||
|
navigate(`/settings/objects/${objectItem.namePlural}`)
|
||||||
|
}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</TableSection>
|
</TableSection>
|
||||||
{!!disabledObjectItems.length && (
|
{!!disabledObjects.length && (
|
||||||
<TableSection title="Disabled">
|
<TableSection title="Disabled">
|
||||||
{disabledObjectItems.map((objectItem) => (
|
{disabledObjects.map((objectItem) => (
|
||||||
<StyledTableRow key={objectItem.name}>
|
<SettingsObjectItemTableRow
|
||||||
<StyledNameTableCell>
|
key={objectItem.namePlural}
|
||||||
<objectItem.Icon size={theme.icon.size.md} />
|
Icon={icons[objectItem.icon || '']}
|
||||||
{objectItem.name}
|
objectItem={objectItem}
|
||||||
</StyledNameTableCell>
|
action={
|
||||||
<TableCell>
|
|
||||||
{objectItem.type === 'standard' ? (
|
|
||||||
<StyledTag color="blue" text="Standard" />
|
|
||||||
) : (
|
|
||||||
<StyledTag color="orange" text="Custom" />
|
|
||||||
)}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell align="right">{objectItem.fields}</TableCell>
|
|
||||||
<TableCell align="right">
|
|
||||||
{objectItem.instances}
|
|
||||||
</TableCell>
|
|
||||||
<StyledIconTableCell>
|
|
||||||
<SettingsObjectDisabledMenuDropDown
|
<SettingsObjectDisabledMenuDropDown
|
||||||
scopeKey={objectItem.name}
|
scopeKey={objectItem.namePlural}
|
||||||
handleActivate={() => {}}
|
handleActivate={() => undefined}
|
||||||
handleErase={() => {}}
|
handleErase={() => undefined}
|
||||||
/>
|
/>
|
||||||
</StyledIconTableCell>
|
}
|
||||||
</StyledTableRow>
|
/>
|
||||||
))}
|
))}
|
||||||
</TableSection>
|
</TableSection>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user