Skip to content

Commit

Permalink
feat: add initla load tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
a-kud committed Dec 19, 2023
1 parent ed6438a commit 62e78ac
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { turnFiltersIntoObjectRecordFilters } from '@/object-record/utils/turnFi
import { signInBackgroundMockCompanies } from '@/sign-in-background-mock/constants/signInBackgroundMockCompanies';

import { useFindManyRecords } from './useFindManyRecords';
import { isRecordTableInitialLoadingState } from '@/object-record/record-table/states/isRecordTableInitialLoadingState';

export const useObjectRecordTable = () => {
const { scopeId: objectNamePlural, setRecordTableData } = useRecordTable();
Expand Down Expand Up @@ -41,13 +42,16 @@ 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 @@ -20,6 +20,7 @@ import { RecordTableBody } from './RecordTableBody';
import { RecordTableBodyEffect } from './RecordTableBodyEffect';
import { RecordTableHeader } from './RecordTableHeader';
import { RecordTableInternalEffect } from './RecordTableInternalEffect';
import { isRecordTableInitialLoadingState } from '@/object-record/record-table/states/isRecordTableInitialLoadingState';

const StyledObjectEmptyContainer = styled.div`
align-items: center;
Expand Down Expand Up @@ -126,6 +127,8 @@ export const RecordTable = ({

const numberOfTableRows = useRecoilValue(numberOfTableRowsState);

const isInitialLoading = useRecoilValue(isRecordTableInitialLoadingState);

const {
scopeId: objectNamePlural,
resetTableRowSelection,
Expand Down Expand Up @@ -170,6 +173,22 @@ export const RecordTable = ({
/>
</div>
<RecordTableInternalEffect tableBodyRef={tableBodyRef} />
{!isInitialLoading && numberOfTableRows === 0 && (
<StyledObjectEmptyContainer>
<StyledEmptyObjectTitle>
No {foundObjectMetadataItem?.namePlural}
</StyledEmptyObjectTitle>
<StyledEmptyObjectSubTitle>
Create one:
</StyledEmptyObjectSubTitle>
<Button
Icon={IconPlus}
title={`Add a ${foundObjectMetadataItem?.nameSingular}`}
variant={'secondary'}
onClick={createRecord}
/>
</StyledObjectEmptyContainer>
)}
</StyledTableContainer>
</StyledTableWithHeader>
</EntityUpdateMutationContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ 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 { isRecordTableFetchingMoreDataState } from '@/object-record/record-table/states/isRecordTableFetchingMoreDataState';
import { tableRowIdsState } from '@/object-record/record-table/states/tableRowIdsState';

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

const isFetchingRecordTableData = useRecoilValue(
isFetchingRecordTableDataState,
isRecordTableFetchingMoreDataState,
);

if (isFetchingRecordTableData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 { isRecordTableFetchingMoreDataState } from '@/object-record/record-table/states/isRecordTableFetchingMoreDataState';
import { getRecordTableScopedStates } from '@/object-record/record-table/utils/getRecordTableScopedStates';
import { isFetchingMoreRecordsFamilyState } from '@/object-record/states/isFetchingMoreRecordsFamilyState';

Expand All @@ -17,7 +17,7 @@ export const RecordTableBodyFetchMoreLoader = () => {
);

const isFetchingRecordTableData = useRecoilValue(
isFetchingRecordTableDataState,
isRecordTableFetchingMoreDataState,
);

const onLastRowVisible = useRecoilCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 { isRecordTableFetchingMoreDataState } from '@/object-record/record-table/states/isRecordTableFetchingMoreDataState';
import { numberOfTableRowsState } from '@/object-record/record-table/states/numberOfTableRowsState';
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';

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

set(numberOfTableRowsState, entityIds.length);
onEntityCountChange(entityIds.length);
set(isFetchingRecordTableDataState, false);
set(isRecordTableFetchingMoreDataState, 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 isRecordTableFetchingMoreDataState = atom<boolean>({
key: 'isRecordTableFetchingMoreDataState',
default: true,
});
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,
});

0 comments on commit 62e78ac

Please sign in to comment.