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

refresh document on extractions complete #3401

Merged
merged 9 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -154,15 +154,15 @@
</template>

<script setup lang="ts">
import { computed, onUpdated, ref, watch } from 'vue';
import { computed, onUnmounted, onUpdated, ref, watch } from 'vue';
import { isEmpty } from 'lodash';
import Accordion from 'primevue/accordion';
import AccordionTab from 'primevue/accordiontab';
import { FeatureConfig } from '@/types/common';
import TeraPdfEmbed from '@/components/widgets/tera-pdf-embed.vue';
import TeraAsset from '@/components/asset/tera-asset.vue';
import type { DocumentAsset } from '@/types/Types';
import { AssetType, ExtractionAssetType } from '@/types/Types';
import type { ClientEvent, DocumentAsset, ExtractionStatusUpdate } from '@/types/Types';
import { AssetType, ClientEventType, ExtractionAssetType } from '@/types/Types';
import {
downloadDocumentAsset,
getDocumentAsset,
Expand All @@ -176,6 +176,8 @@ import { useProjects } from '@/composables/project';
import { logger } from '@/utils/logger';
import Button from 'primevue/button';
import ContextMenu from 'primevue/contextmenu';
import { subscribe, unsubscribe } from '@/services/ClientEventService';
import { getStatus } from '@/composables/notificationManager';
import TeraTextEditor from './tera-text-editor.vue';

enum DocumentView {
Expand Down Expand Up @@ -267,6 +269,9 @@ const toggleOptionsMenu = (event) => {
watch(
() => props.assetId,
async () => {
// unsub and sub to avoid multiple subscriptions when switching between document assets
await unsubscribe(ClientEventType.Extraction, subscribeToExtraction);
YohannParis marked this conversation as resolved.
Show resolved Hide resolved
await subscribe(ClientEventType.Extraction, subscribeToExtraction);
YohannParis marked this conversation as resolved.
Show resolved Hide resolved
if (props.assetId) {
view.value = DocumentView.EXTRACTIONS;
pdfLink.value = null;
Expand Down Expand Up @@ -308,6 +313,26 @@ onUpdated(() => {
emit('asset-loaded');
}
});

async function subscribeToExtraction(event: ClientEvent<ExtractionStatusUpdate>) {
if (!event.data) return;
if (event.data.documentId !== props.assetId) return;
blanchco marked this conversation as resolved.
Show resolved Hide resolved

const status = getStatus(event.data);
// FIXME: adding the 'dispatching' check since there seems to be an issue with the status of the extractions. Lets what for the Notification service to be fully integrated and then this can be removed.
if (status === 'Completed' && event.data.message.includes('Dispatching')) {
document.value = await getDocumentAsset(props.assetId);
await unsubscribe(ClientEventType.Extraction, subscribeToExtraction);
}

if (status === 'Failed') {
await unsubscribe(ClientEventType.Extraction, subscribeToExtraction);
}
}

onUnmounted(async () => {
await unsubscribe(ClientEventType.Extraction, subscribeToExtraction);
});
</script>
<style scoped>
.extracted-item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const displayToast = (
useToastService().error(toastTitle[eventType]?.error ?? 'Process Failed', error);
};

const getStatus = (data: { error: string; t: number }) => {
export const getStatus = (data: { error: string; t: number }) => {
if (data.error) return 'Failed';
if (data.t >= 1.0) return 'Completed';
return 'Running';
Expand Down
Loading