Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build empty state for remote tables #5652

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
orderBy,
limit,
onCompleted,
onError,
skip,
recordGqlFields,
fetchPolicy,
Expand All @@ -45,6 +46,7 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
totalCount?: number;
},
) => void;
onError?: (error?: Error) => void;
skip?: boolean;
recordGqlFields?: RecordGqlOperationGqlRecordFields;
fetchPolicy?: WatchQueryFetchPolicy;
Expand Down Expand Up @@ -120,6 +122,7 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
variant: SnackBarVariant.Error,
},
);
onError?.(error);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export const useLoadRecordIndexTable = (objectNameSingular: string) => {
setLastRowVisible(false);
setIsRecordTableInitialLoading(false);
},
onError: () => {
setIsRecordTableInitialLoading(false);
},
});

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useNavigate } from 'react-router-dom';
import { IconPlus, IconSettings } from 'twenty-ui';

import { Button } from '@/ui/input/button/components/Button';
import AnimatedPlaceholder from '@/ui/layout/animated-placeholder/components/AnimatedPlaceholder';
import {
AnimatedPlaceholderEmptyContainer,
AnimatedPlaceholderEmptySubTitle,
AnimatedPlaceholderEmptyTextContainer,
AnimatedPlaceholderEmptyTitle,
} from '@/ui/layout/animated-placeholder/components/EmptyPlaceholderStyled';

type RecordTableEmptyStateProps = {
objectLabel: string;
createRecord: () => void;
isRemote: boolean;
};

export const RecordTableEmptyState = ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add stories here!

objectLabel,
createRecord,
isRemote,
}: RecordTableEmptyStateProps) => {
const navigate = useNavigate();

const [title, subTitle, Icon, onClick, buttonTitle] = isRemote
? [
'No Data Available for Remote Table',
'If this is unexpected, please verify your settings.',
IconSettings,
() => navigate('/settings/integrations'),
'Go to Settings',
]
: [
`Add your first ${objectLabel}`,
`Use our API or add your first ${objectLabel} manually`,
IconPlus,
createRecord,
`Add a ${objectLabel}`,
];

return (
<AnimatedPlaceholderEmptyContainer>
<AnimatedPlaceholder type="noRecord" />
<AnimatedPlaceholderEmptyTextContainer>
<AnimatedPlaceholderEmptyTitle>{title}</AnimatedPlaceholderEmptyTitle>
<AnimatedPlaceholderEmptySubTitle>
{subTitle}
</AnimatedPlaceholderEmptySubTitle>
</AnimatedPlaceholderEmptyTextContainer>
<Button
Icon={Icon}
title={buttonTitle}
variant={'secondary'}
onClick={onClick}
/>
</AnimatedPlaceholderEmptyContainer>
);
};
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { useRef } from 'react';
import styled from '@emotion/styled';
import { useRecoilCallback, useRecoilValue } from 'recoil';
import { IconPlus } from 'twenty-ui';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
import { RecordTable } from '@/object-record/record-table/components/RecordTable';
import { RecordTableEmptyState } from '@/object-record/record-table/components/RecordTableEmptyState';
import { EntityDeleteContext } from '@/object-record/record-table/contexts/EntityDeleteHookContext';
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition';
import { Button } from '@/ui/input/button/components/Button';
import AnimatedPlaceholder from '@/ui/layout/animated-placeholder/components/AnimatedPlaceholder';
import {
AnimatedPlaceholderEmptyContainer,
AnimatedPlaceholderEmptySubTitle,
AnimatedPlaceholderEmptyTextContainer,
AnimatedPlaceholderEmptyTitle,
} from '@/ui/layout/animated-placeholder/components/EmptyPlaceholderStyled';
import { DragSelect } from '@/ui/utilities/drag-select/components/DragSelect';
import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';
import { useSaveCurrentViewFields } from '@/views/hooks/useSaveCurrentViewFields';
Expand Down Expand Up @@ -56,15 +48,15 @@ export const RecordTableWithWrappers = ({
}: RecordTableWithWrappersProps) => {
const tableBodyRef = useRef<HTMLDivElement>(null);

const { numberOfTableRowsState, isRecordTableInitialLoadingState } =
const { isRecordTableInitialLoadingState, tableRowIdsState } =
useRecordTableStates(recordTableId);

const numberOfTableRows = useRecoilValue(numberOfTableRowsState);

const isRecordTableInitialLoading = useRecoilValue(
isRecordTableInitialLoadingState,
);

const tableRowIds = useRecoilValue(tableRowIdsState);

const { resetTableRowSelection, setRowSelected } = useRecordTable({
recordTableId,
});
Expand Down Expand Up @@ -116,25 +108,13 @@ export const RecordTableWithWrappers = ({
tableBodyRef={tableBodyRef}
/>
{!isRecordTableInitialLoading &&
numberOfTableRows === 0 &&
!isRemote && (
<AnimatedPlaceholderEmptyContainer>
<AnimatedPlaceholder type="noRecord" />
<AnimatedPlaceholderEmptyTextContainer>
<AnimatedPlaceholderEmptyTitle>
Add your first {objectLabel}
</AnimatedPlaceholderEmptyTitle>
<AnimatedPlaceholderEmptySubTitle>
Use our API or add your first {objectLabel} manually
</AnimatedPlaceholderEmptySubTitle>
</AnimatedPlaceholderEmptyTextContainer>
<Button
Icon={IconPlus}
title={`Add a ${objectLabel}`}
variant={'secondary'}
onClick={createRecord}
/>
</AnimatedPlaceholderEmptyContainer>
// we cannot rely on count states because this is not available for remote objects
tableRowIds.length === 0 && (
<RecordTableEmptyState
objectLabel={objectLabel}
createRecord={createRecord}
isRemote={isRemote}
/>
)}
</StyledTableContainer>
</StyledTableWithHeader>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Meta, StoryObj } from '@storybook/react';

import { RecordTableEmptyState } from '@/object-record/record-table/components/RecordTableEmptyState';
import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';

const meta: Meta = {
title: 'Modules/ObjectRecord/RecordTable/RecordTableEmptyState',
component: RecordTableEmptyState,
decorators: [MemoryRouterDecorator],
};

export default meta;
type Story = StoryObj<typeof RecordTableEmptyState>;

export const Default: Story = {
args: {
objectLabel: 'person',
isRemote: false,
createRecord: () => {},
},
};

export const Remote: Story = {
args: {
objectLabel: 'remote person',
isRemote: true,
createRecord: () => {},
},
};
Loading