Added empty card for show relations (#3612)
#3610 Add empty states for show relations Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useContext } from 'react';
|
import { useCallback, useContext } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { css } from '@emotion/react';
|
import { css, useTheme } from '@emotion/react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
@ -20,6 +20,7 @@ import { RelationPickerScope } from '@/object-record/relation-picker/scopes/Rela
|
|||||||
import { EntityForSelect } from '@/object-record/relation-picker/types/EntityForSelect';
|
import { EntityForSelect } from '@/object-record/relation-picker/types/EntityForSelect';
|
||||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||||
import { IconForbid, IconPlus } from '@/ui/display/icon';
|
import { IconForbid, IconPlus } from '@/ui/display/icon';
|
||||||
|
import { useIcons } from '@/ui/display/icon/hooks/useIcons';
|
||||||
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
|
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
|
||||||
import { Card } from '@/ui/layout/card/components/Card';
|
import { Card } from '@/ui/layout/card/components/Card';
|
||||||
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
|
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
|
||||||
@ -79,7 +80,22 @@ const StyledLink = styled(Link)`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const StyledCardNoContent = styled.div`
|
||||||
|
border: 1px solid ${({ theme }) => theme.border.color.medium};
|
||||||
|
border-radius: ${({ theme }) => theme.border.radius.sm};
|
||||||
|
color: ${({ theme }) => theme.font.color.light};
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: ${({ theme }) => theme.spacing(2)};
|
||||||
|
display: flex;
|
||||||
|
height: ${({ theme }) => theme.spacing(10)};
|
||||||
|
padding: ${({ theme }) => theme.spacing(0, 2)};
|
||||||
|
`;
|
||||||
|
|
||||||
export const RecordRelationFieldCardSection = () => {
|
export const RecordRelationFieldCardSection = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
const { entityId, fieldDefinition } = useContext(FieldContext);
|
const { entityId, fieldDefinition } = useContext(FieldContext);
|
||||||
const {
|
const {
|
||||||
fieldName,
|
fieldName,
|
||||||
@ -160,17 +176,21 @@ export const RecordRelationFieldCardSection = () => {
|
|||||||
relationObjectMetadataItem.namePlural
|
relationObjectMetadataItem.namePlural
|
||||||
}?${qs.stringify(filterQueryParams)}`;
|
}?${qs.stringify(filterQueryParams)}`;
|
||||||
|
|
||||||
|
const { getIcon } = useIcons();
|
||||||
|
const Icon = getIcon(relationObjectMetadataItem.icon);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section>
|
<Section>
|
||||||
<StyledHeader isDropdownOpen={isDropdownOpen}>
|
<StyledHeader isDropdownOpen={isDropdownOpen}>
|
||||||
<StyledTitle>
|
<StyledTitle>
|
||||||
<StyledTitleLabel>{fieldDefinition.label}</StyledTitleLabel>
|
<StyledTitleLabel>{fieldDefinition.label}</StyledTitleLabel>
|
||||||
{parseFieldRelationType(relationFieldMetadataItem) ===
|
{parseFieldRelationType(relationFieldMetadataItem) ===
|
||||||
'TO_ONE_OBJECT' && (
|
'TO_ONE_OBJECT' &&
|
||||||
<StyledLink to={filterLinkHref}>
|
relationRecords.length > 0 && (
|
||||||
All ({relationRecords.length})
|
<StyledLink to={filterLinkHref}>
|
||||||
</StyledLink>
|
All ({relationRecords.length})
|
||||||
)}
|
</StyledLink>
|
||||||
|
)}
|
||||||
</StyledTitle>
|
</StyledTitle>
|
||||||
<DropdownScope dropdownScopeId={dropdownId}>
|
<DropdownScope dropdownScopeId={dropdownId}>
|
||||||
<StyledAddDropdown
|
<StyledAddDropdown
|
||||||
@ -203,6 +223,12 @@ export const RecordRelationFieldCardSection = () => {
|
|||||||
/>
|
/>
|
||||||
</DropdownScope>
|
</DropdownScope>
|
||||||
</StyledHeader>
|
</StyledHeader>
|
||||||
|
{relationRecords.length === 0 && (
|
||||||
|
<StyledCardNoContent>
|
||||||
|
<Icon size={theme.icon.size.sm} />
|
||||||
|
<div>No {relationObjectMetadataItem.labelSingular}</div>
|
||||||
|
</StyledCardNoContent>
|
||||||
|
)}
|
||||||
{!!relationRecords.length && (
|
{!!relationRecords.length && (
|
||||||
<Card>
|
<Card>
|
||||||
{relationRecords.slice(0, 5).map((relationRecord, index) => (
|
{relationRecords.slice(0, 5).map((relationRecord, index) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user