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

fix: empty state should not appear during table loading #3040

Merged
merged 4 commits into from
Dec 20, 2023
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 @@ -6,6 +6,7 @@ import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObje
import { turnSortsIntoOrderBy } from '@/object-record/object-sort-dropdown/utils/turnSortsIntoOrderBy';
import { useRecordTableScopedStates } from '@/object-record/record-table/hooks/internal/useRecordTableScopedStates';
import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable';
import { isRecordTableInitialLoadingState } from '@/object-record/record-table/states/isRecordTableInitialLoadingState';
import { turnFiltersIntoObjectRecordFilters } from '@/object-record/utils/turnFiltersIntoWhereClause';
import { signInBackgroundMockCompanies } from '@/sign-in-background-mock/constants/signInBackgroundMockCompanies';

Expand Down Expand Up @@ -41,13 +42,18 @@ export const useObjectRecordTable = () => {
foundObjectMetadataItem?.fields ?? [],
);

const setIsRecordTableInitialLoading = useSetRecoilState(
isRecordTableInitialLoadingState,
);

const { records, loading, fetchMoreRecords, queryStateIdentifier } =
useFindManyRecords({
objectNameSingular,
filter: requestFilters,
orderBy,
onCompleted: () => {
setLastRowVisible(false);
setIsRecordTableInitialLoading(false);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRecoilCallback, useRecoilValue } from 'recoil';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural';
import { isRecordTableInitialLoadingState } from '@/object-record/record-table/states/isRecordTableInitialLoadingState';
import { IconPlus } from '@/ui/display/icon';
import { Button } from '@/ui/input/button/components/Button';
import { DragSelect } from '@/ui/utilities/drag-select/components/DragSelect';
Expand Down Expand Up @@ -126,6 +127,10 @@ export const RecordTable = ({

const numberOfTableRows = useRecoilValue(numberOfTableRowsState);

const isRecordTableInitialLoading = useRecoilValue(
isRecordTableInitialLoadingState,
);

const {
scopeId: objectNamePlural,
resetTableRowSelection,
Expand Down Expand Up @@ -170,7 +175,7 @@ export const RecordTable = ({
/>
</div>
<RecordTableInternalEffect tableBodyRef={tableBodyRef} />
{numberOfTableRows === 0 && (
{!isRecordTableInitialLoading && numberOfTableRows === 0 && (
<StyledObjectEmptyContainer>
<StyledEmptyObjectTitle>
No {foundObjectMetadataItem?.namePlural}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@ import { RecordTableBodyFetchMoreLoader } from '@/object-record/record-table/com
import { RecordTableRow } from '@/object-record/record-table/components/RecordTableRow';
import { RowIdContext } from '@/object-record/record-table/contexts/RowIdContext';
import { RowIndexContext } from '@/object-record/record-table/contexts/RowIndexContext';
import { isFetchingRecordTableDataState } from '@/object-record/record-table/states/isFetchingRecordTableDataState';
import { tableRowIdsState } from '@/object-record/record-table/states/tableRowIdsState';

export const RecordTableBody = () => {
const tableRowIds = useRecoilValue(tableRowIdsState);

const isFetchingRecordTableData = useRecoilValue(
isFetchingRecordTableDataState,
);

if (isFetchingRecordTableData) {
return <></>;
}

return (
<>
{tableRowIds.map((rowId, rowIndex) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useRecoilCallback, useRecoilValue } from 'recoil';
import { useObjectRecordTable } from '@/object-record/hooks/useObjectRecordTable';
import { StyledRow } from '@/object-record/record-table/components/RecordTableRow';
import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable';
import { isFetchingRecordTableDataState } from '@/object-record/record-table/states/isFetchingRecordTableDataState';
import { getRecordTableScopedStates } from '@/object-record/record-table/utils/getRecordTableScopedStates';
import { isFetchingMoreRecordsFamilyState } from '@/object-record/states/isFetchingMoreRecordsFamilyState';

Expand All @@ -16,10 +15,6 @@ export const RecordTableBodyFetchMoreLoader = () => {
isFetchingMoreRecordsFamilyState(queryStateIdentifier),
);

const isFetchingRecordTableData = useRecoilValue(
isFetchingRecordTableDataState,
);

const onLastRowVisible = useRecoilCallback(
({ set }) =>
async (inView: boolean) => {
Expand All @@ -35,10 +30,6 @@ export const RecordTableBodyFetchMoreLoader = () => {
onChange: onLastRowVisible,
});

if (isFetchingRecordTableData) {
return <></>;
}

return (
<tbody ref={tbodyRef}>
{isFetchingMoreObjects && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useRecoilCallback } from 'recoil';

import { entityFieldsFamilyState } from '@/object-record/field/states/entityFieldsFamilyState';
import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection';
import { isFetchingRecordTableDataState } from '@/object-record/record-table/states/isFetchingRecordTableDataState';
import { numberOfTableRowsState } from '@/object-record/record-table/states/numberOfTableRowsState';
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';

Expand Down Expand Up @@ -41,7 +40,6 @@ export const useSetRecordTableData = ({

set(numberOfTableRowsState, entityIds.length);
onEntityCountChange(entityIds.length);
set(isFetchingRecordTableDataState, false);
},
[onEntityCountChange, resetTableRowSelection],
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { atom } from 'recoil';

export const isRecordTableInitialLoadingState = atom<boolean>({
key: 'isRecordTableInitialLoadingState',
default: true,
});