-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: record group fetch more #8868
Changes from 1 commit
0496f8a
4438501
2bebc12
39bc81b
a765925
d51a642
e71e747
b39c6e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { RecordGroupDefinition } from '@/object-record/record-group/types/RecordGroupDefinition'; | ||
import { createComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentFamilyStateV2'; | ||
import { ViewComponentInstanceContext } from '@/views/states/contexts/ViewComponentInstanceContext'; | ||
|
||
export const recordIndexHasFetchedAllRecordsByGroupComponentState = | ||
createComponentFamilyStateV2<boolean, RecordGroupDefinition['id']>({ | ||
key: 'recordIndexHasFetchedAllRecordsByGroupComponentState', | ||
componentInstanceContext: ViewComponentInstanceContext, | ||
defaultValue: false, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { RecordGroupDefinition } from '@/object-record/record-group/types/RecordGroupDefinition'; | ||
import { createComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentFamilyStateV2'; | ||
import { ViewComponentInstanceContext } from '@/views/states/contexts/ViewComponentInstanceContext'; | ||
|
||
export const recordIndexShouldFetchMoreRecordsByGroupComponentState = | ||
createComponentFamilyStateV2<boolean, RecordGroupDefinition['id']>({ | ||
key: 'recordIndexShouldFetchMoreRecordsByGroupComponentState', | ||
componentInstanceContext: ViewComponentInstanceContext, | ||
defaultValue: false, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,12 @@ import { useRecoilState } from 'recoil'; | |
import { lastShowPageRecordIdState } from '@/object-record/record-field/states/lastShowPageRecordId'; | ||
import { useCurrentRecordGroupId } from '@/object-record/record-group/hooks/useCurrentRecordGroupId'; | ||
import { useLoadRecordIndexTable } from '@/object-record/record-index/hooks/useLoadRecordIndexTable'; | ||
import { recordIndexHasFetchedAllRecordsByGroupComponentState } from '@/object-record/record-index/states/recordIndexHasFetchedAllRecordsByGroupComponentState'; | ||
import { recordIndexShouldFetchMoreRecordsByGroupComponentState } from '@/object-record/record-index/states/recordIndexShouldFetchMoreRecordsByGroupComponentState'; | ||
import { ROW_HEIGHT } from '@/object-record/record-table/constants/RowHeight'; | ||
import { RecordTableContext } from '@/object-record/record-table/contexts/RecordTableContext'; | ||
import { hasRecordTableFetchedAllRecordsComponentStateV2 } from '@/object-record/record-table/states/hasRecordTableFetchedAllRecordsComponentStateV2'; | ||
import { useSetRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentStateV2'; | ||
import { useRecoilComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyStateV2'; | ||
import { useSetRecoilComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentFamilyStateV2'; | ||
import { isNonEmptyString } from '@sniptt/guards'; | ||
import { useScrollToPosition } from '~/hooks/useScrollToPosition'; | ||
|
||
|
@@ -18,12 +20,25 @@ export const RecordTableRecordGroupBodyEffect = () => { | |
|
||
const [hasInitializedScroll, setHasInitializedScroll] = useState(false); | ||
|
||
const { records, totalCount, setRecordTableData, loading, hasNextPage } = | ||
useLoadRecordIndexTable(objectNameSingular); | ||
const [shouldFetchMoreRecords, setShouldFetchMoreRecords] = | ||
useRecoilComponentFamilyStateV2( | ||
recordIndexShouldFetchMoreRecordsByGroupComponentState, | ||
recordGroupId, | ||
); | ||
|
||
const { | ||
fetchMoreRecords, | ||
records, | ||
totalCount, | ||
setRecordTableData, | ||
loading, | ||
hasNextPage, | ||
} = useLoadRecordIndexTable(objectNameSingular); | ||
|
||
const setHasRecordTableFetchedAllRecordsComponents = | ||
useSetRecoilComponentStateV2( | ||
hasRecordTableFetchedAllRecordsComponentStateV2, | ||
const setHasRecordFetchedAllRecordsComponents = | ||
useSetRecoilComponentFamilyStateV2( | ||
recordIndexHasFetchedAllRecordsByGroupComponentState, | ||
recordGroupId, | ||
); | ||
|
||
const [lastShowPageRecordId] = useRecoilState(lastShowPageRecordIdState); | ||
|
@@ -65,8 +80,16 @@ export const RecordTableRecordGroupBodyEffect = () => { | |
useEffect(() => { | ||
const allRecordsHaveBeenFetched = !hasNextPage; | ||
|
||
setHasRecordTableFetchedAllRecordsComponents(allRecordsHaveBeenFetched); | ||
}, [hasNextPage, setHasRecordTableFetchedAllRecordsComponents]); | ||
setHasRecordFetchedAllRecordsComponents(allRecordsHaveBeenFetched); | ||
}, [hasNextPage, setHasRecordFetchedAllRecordsComponents]); | ||
|
||
useEffect(() => { | ||
if (shouldFetchMoreRecords) { | ||
fetchMoreRecords().finally(() => { | ||
setShouldFetchMoreRecords(false); | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Missing error handling for failed fetch operations. The state should be reset even if the fetch fails. |
||
}, [fetchMoreRecords, setShouldFetchMoreRecords, shouldFetchMoreRecords]); | ||
|
||
return <></>; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import { RecordTableTd } from '@/object-record/record-table/record-table-cell/components/RecordTableTd'; | ||
import { visibleTableColumnsComponentSelector } from '@/object-record/record-table/states/selectors/visibleTableColumnsComponentSelector'; | ||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; | ||
import { useTheme } from '@emotion/react'; | ||
import { IconComponent } from 'twenty-ui'; | ||
|
||
const StyledTrContainer = styled.tr` | ||
cursor: pointer; | ||
`; | ||
|
||
const StyledIconContainer = styled(RecordTableTd)` | ||
border-right: none; | ||
color: ${({ theme }) => theme.font.color.secondary}; | ||
text-align: center; | ||
vertical-align: middle; | ||
padding-top: 3px; | ||
`; | ||
|
||
const StyledRecordTableTdTextContainer = styled(RecordTableTd)` | ||
border-right: none; | ||
height: 32px; | ||
`; | ||
|
||
const StyledText = styled.span` | ||
color: ${({ theme }) => theme.font.color.tertiary}; | ||
margin-left: ${({ theme }) => theme.spacing(2)}; | ||
font-size: ${({ theme }) => theme.font.size.md}; | ||
text-align: center; | ||
vertical-align: middle; | ||
`; | ||
|
||
const StyledEmptyTd = styled.td` | ||
border-bottom: 1px solid ${({ theme }) => theme.border.color.light}; | ||
`; | ||
|
||
type RecordTableActionRowProps = { | ||
LeftIcon: IconComponent; | ||
text: string; | ||
onClick?: (event?: React.MouseEvent<HTMLTableRowElement>) => void; | ||
}; | ||
Comment on lines
+38
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: onClick handler should be required since this is an interactive component - remove the optional '?' from the type definition |
||
|
||
export const RecordTableActionRow = ({ | ||
LeftIcon, | ||
text, | ||
onClick, | ||
}: RecordTableActionRowProps) => { | ||
const theme = useTheme(); | ||
|
||
const visibleColumns = useRecoilComponentValueV2( | ||
visibleTableColumnsComponentSelector, | ||
); | ||
|
||
return ( | ||
<StyledTrContainer onClick={onClick}> | ||
<td aria-hidden /> | ||
<StyledIconContainer> | ||
<LeftIcon size={theme.icon.size.sm} color={theme.font.color.tertiary} /> | ||
</StyledIconContainer> | ||
<StyledRecordTableTdTextContainer colSpan={visibleColumns.length}> | ||
<StyledText>{text}</StyledText> | ||
</StyledRecordTableTdTextContainer> | ||
<StyledEmptyTd /> | ||
<StyledEmptyTd /> | ||
</StyledTrContainer> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { useCurrentRecordGroupId } from '@/object-record/record-group/hooks/useC | |
import { recordGroupDefinitionFamilyState } from '@/object-record/record-group/states/recordGroupDefinitionFamilyState'; | ||
import { RecordGroupDefinitionType } from '@/object-record/record-group/types/RecordGroupDefinition'; | ||
import { recordIndexRecordIdsByGroupComponentFamilyState } from '@/object-record/record-index/states/recordIndexRecordIdsByGroupComponentFamilyState'; | ||
import { RecordTableTd } from '@/object-record/record-table/record-table-cell/components/RecordTableTd'; | ||
import { isRecordGroupTableSectionToggledComponentState } from '@/object-record/record-table/record-table-section/states/isRecordGroupTableSectionToggledComponentState'; | ||
import { visibleTableColumnsComponentSelector } from '@/object-record/record-table/states/selectors/visibleTableColumnsComponentSelector'; | ||
import { useRecoilComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyStateV2'; | ||
|
@@ -19,8 +20,8 @@ const StyledTrContainer = styled.tr` | |
cursor: pointer; | ||
`; | ||
|
||
const StyledChevronContainer = styled.td` | ||
border-bottom: 1px solid ${({ theme }) => theme.border.color.light}; | ||
const StyledChevronContainer = styled(RecordTableTd)` | ||
border-right: none; | ||
color: ${({ theme }) => theme.font.color.secondary}; | ||
text-align: center; | ||
vertical-align: middle; | ||
|
@@ -33,10 +34,9 @@ const StyledTotalRow = styled.span` | |
vertical-align: middle; | ||
`; | ||
|
||
const StyledRecordGroupSection = styled.td` | ||
border-bottom: 1px solid ${({ theme }) => theme.border.color.light}; | ||
padding-bottom: 6px; | ||
padding-top: 6px; | ||
const StyledRecordGroupSection = styled(RecordTableTd)` | ||
border-right: none; | ||
height: 32px; | ||
`; | ||
|
||
const StyledEmptyTd = styled.td` | ||
|
@@ -79,7 +79,7 @@ export const RecordTableRecordGroupSection = () => { | |
|
||
return ( | ||
<StyledTrContainer onClick={handleDropdownToggle}> | ||
<td aria-hidden></td> | ||
<td aria-hidden /> | ||
<StyledChevronContainer> | ||
<motion.span | ||
animate={{ rotate: isRecordGroupTableSectionToggled ? 180 : 0 }} | ||
|
@@ -108,8 +108,8 @@ export const RecordTableRecordGroupSection = () => { | |
/> | ||
<StyledTotalRow>{recordIdsByGroup.length}</StyledTotalRow> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: recordIdsByGroup.length may not reflect total records when paginated. Consider showing total count instead |
||
</StyledRecordGroupSection> | ||
<StyledEmptyTd></StyledEmptyTd> | ||
<StyledEmptyTd></StyledEmptyTd> | ||
<StyledEmptyTd /> | ||
<StyledEmptyTd /> | ||
Comment on lines
+111
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: empty td elements should have aria-hidden for better accessibility |
||
</StyledTrContainer> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useCurrentRecordGroupId } from '@/object-record/record-group/hooks/useCurrentRecordGroupId'; | ||
import { recordIndexHasFetchedAllRecordsByGroupComponentState } from '@/object-record/record-index/states/recordIndexHasFetchedAllRecordsByGroupComponentState'; | ||
import { recordIndexShouldFetchMoreRecordsByGroupComponentState } from '@/object-record/record-index/states/recordIndexShouldFetchMoreRecordsByGroupComponentState'; | ||
import { RecordTableActionRow } from '@/object-record/record-table/record-table-row/components/RecordTableActionRow'; | ||
import { useRecoilComponentFamilyValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyValueV2'; | ||
import { useSetRecoilComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentFamilyStateV2'; | ||
import { IconArrowDown } from 'twenty-ui'; | ||
|
||
export const RecordTableRecordGroupSectionLoadMore = () => { | ||
const currentRecordGroupId = useCurrentRecordGroupId(); | ||
|
||
const hasFetchedAllRecords = useRecoilComponentFamilyValueV2( | ||
recordIndexHasFetchedAllRecordsByGroupComponentState, | ||
currentRecordGroupId, | ||
); | ||
|
||
const setShouldFetchMoreRecords = useSetRecoilComponentFamilyStateV2( | ||
recordIndexShouldFetchMoreRecordsByGroupComponentState, | ||
currentRecordGroupId, | ||
); | ||
|
||
const handleLoadMore = () => { | ||
setShouldFetchMoreRecords(true); | ||
}; | ||
|
||
if (hasFetchedAllRecords) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<RecordTableActionRow | ||
LeftIcon={IconArrowDown} | ||
text="Load more" | ||
onClick={handleLoadMore} | ||
/> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider making the 8 record limit configurable via a constant rather than hardcoding the value