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

Add pagination in automatic entries #2802

Merged
merged 2 commits into from
Dec 21, 2023
Merged
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
86 changes: 55 additions & 31 deletions app/views/EntryEdit/LeftPane/AutoEntriesModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import {
useMutation,
} from '@apollo/client';
import {
Modal,
ListView,
Modal,
Pager,
Tab,
Tabs,
TabPanel,
TabList,
TabPanel,
Tabs,
useAlert,
Button,
} from '@the-deep/deep-ui';
Expand Down Expand Up @@ -82,33 +83,41 @@ const AUTO_ENTRIES_FOR_LEAD = gql`
$projectId: ID!,
$leadId: ID!,
$isDiscarded: Boolean,
$page: Int,
$pageSize: Int,
) {
project(id: $projectId) {
id
assistedTagging {
draftEntryByLeads(
filter: {
draftEntries(
draftEntryTypes: AUTO,
leads: $leadId,
lead: $leadId,
isDiscarded: $isDiscarded,
}) {
id
excerpt
predictionReceivedAt
predictionStatus
predictions {
page: $page,
pageSize: $pageSize,
) {
page
pageSize
totalCount
results {
id
draftEntry
tag
dataTypeDisplay
dataType
category
isSelected
modelVersion
modelVersionDeeplModelId
prediction
threshold
value
excerpt
predictionReceivedAt
predictionStatus
predictions {
id
draftEntry
tag
dataTypeDisplay
dataType
category
isSelected
modelVersion
modelVersionDeeplModelId
prediction
threshold
value
}
}
}
}
Expand Down Expand Up @@ -140,10 +149,10 @@ const AUTO_DRAFT_ENTRIES_STATUS = gql`
) {
project(id: $projectId) {
id
assistedTagging {
extractionStatusByLead(leadId: $leadId) {
autoEntryExtractionStatus
}
lead(
id: $leadId,
) {
autoEntryExtractionStatus
}
}
}
Expand Down Expand Up @@ -354,6 +363,8 @@ function handleMappingsFetch(entryAttributes: EntryAttributes) {
};
}

const MAX_ITEMS_PER_PAGE = 20;

const entryKeySelector = (entry: PartialEntryType) => entry.clientId;

type EntriesTabType = 'extracted' | 'discarded';
Expand Down Expand Up @@ -393,6 +404,8 @@ function AutoEntriesModal(props: Props) {
setSelectedTab,
] = useState<EntriesTabType | undefined>('extracted');

const [activePage, setActivePage] = useState<number>(1);

const {
allWidgets,
filteredWidgets,
Expand Down Expand Up @@ -468,7 +481,7 @@ function AutoEntriesModal(props: Props) {
notifyOnNetworkStatusChange: true,
onCompleted: (response) => {
const status = response?.project
?.assistedTagging?.extractionStatusByLead?.autoEntryExtractionStatus;
?.lead?.autoEntryExtractionStatus;
if (status === 'SUCCESS') {
setDraftEntriesLoading(false);
}
Expand All @@ -477,11 +490,11 @@ function AutoEntriesModal(props: Props) {
);

const extractionStatus = autoEntryExtractionStatus?.project
?.assistedTagging?.extractionStatusByLead?.autoEntryExtractionStatus;
?.lead?.autoEntryExtractionStatus;

useEffect(() => {
const extractionStatusInternal = autoEntryExtractionStatus?.project
?.assistedTagging?.extractionStatusByLead?.autoEntryExtractionStatus;
?.lead?.autoEntryExtractionStatus;

const shouldPoll = extractionStatusInternal === 'PENDING' || extractionStatusInternal === 'STARTED';
if (shouldPoll) {
Expand Down Expand Up @@ -560,13 +573,17 @@ function AutoEntriesModal(props: Props) {
projectId,
leadId,
isDiscarded: selectedTab === 'discarded',
page: activePage,
pageSize: MAX_ITEMS_PER_PAGE,
}), [
projectId,
leadId,
selectedTab,
activePage,
]);

const {
data: autoEntries,
loading: autoEntriesLoading,
refetch: retriggerAutoEntriesFetch,
} = useQuery<AutoEntriesForLeadQuery, AutoEntriesForLeadQueryVariables>(
Expand All @@ -579,7 +596,7 @@ function AutoEntriesModal(props: Props) {
// TODO: This is due to caching issue in apollo.
notifyOnNetworkStatusChange: true,
onCompleted: (response) => {
const entries = response.project?.assistedTagging?.draftEntryByLeads;
const entries = response.project?.assistedTagging?.draftEntries?.results;
const transformedEntries = (entries ?? [])?.map((entry) => {
const validPredictions = entry.predictions?.filter(isDefined);
const categoricalTags = validPredictions?.filter(
Expand Down Expand Up @@ -1005,6 +1022,13 @@ function AutoEntriesModal(props: Props) {
/>
</TabPanel>
</Tabs>
<Pager
activePage={activePage}
itemsCount={autoEntries?.project?.assistedTagging?.draftEntries?.totalCount ?? 0}
onActivePageChange={setActivePage}
maxItemsPerPage={MAX_ITEMS_PER_PAGE}
itemsPerPageControlHidden
/>
</Modal>
);
}
Expand Down
Loading