Skip to content

Commit

Permalink
Merge pull request #2968 from the-deep/feature/automatic-analytical-i…
Browse files Browse the repository at this point in the history
…nformation-summary

Automatic Analytical statement
  • Loading branch information
subinasr authored Jul 22, 2024
2 parents eadfb75 + 99216b8 commit c8f5f58
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,81 +1,31 @@
import React, { useEffect } from 'react';
import React from 'react';
import { isDefined } from '@togglecorp/fujs';
import { gql, useQuery } from '@apollo/client';
import {
Kraken,
Message,
PendingMessage,
} from '@the-deep/deep-ui';
import {
AutomaticSummaryQuery,
AutomaticSummaryQueryVariables,
type ApolloError,
} from '@apollo/client';
import {
AnalyticalInformationSummaryQuery,
} from '#generated/types';

import styles from './styles.css';

const AUTOMATIC_SUMMARY = gql`
query AutomaticSummary($projectId: ID!, $summaryId: ID!) {
project(id: $projectId) {
id
analysisAutomaticSummary(id: $summaryId) {
id
status
summary
}
}
}
`;

interface Props {
projectId: string;
summaryId: string | undefined;
summaryData: AnalyticalInformationSummaryQuery | undefined;
error: ApolloError | undefined;
}

function Summary(props: Props) {
const {
projectId,
summaryId,
} = props;

const {
data,
loading,
startPolling,
stopPolling,
summaryData,
error,
} = useQuery<AutomaticSummaryQuery, AutomaticSummaryQueryVariables>(
AUTOMATIC_SUMMARY,
{
skip: !summaryId,
variables: summaryId ? {
projectId,
summaryId,
} : undefined,
},
);

useEffect(
() => {
const shouldPoll = data?.project?.analysisAutomaticSummary?.status === 'PENDING'
|| data?.project?.analysisAutomaticSummary?.status === 'STARTED';

if (shouldPoll) {
startPolling(5000);
} else {
stopPolling();
}
return (() => {
stopPolling();
});
},
[
data?.project?.analysisAutomaticSummary?.status,
startPolling,
stopPolling,
],
);
} = props;

if (data?.project?.analysisAutomaticSummary?.status === 'SEND_FAILED') {
if (summaryData?.project?.analysisAutomaticSummary?.status === 'SEND_FAILED') {
return (
<div className={styles.message}>
<Message
Expand All @@ -86,7 +36,7 @@ function Summary(props: Props) {
);
}

if (isDefined(error) || data?.project?.analysisAutomaticSummary?.status === 'FAILED') {
if (isDefined(error) || summaryData?.project?.analysisAutomaticSummary?.status === 'FAILED') {
return (
<div className={styles.message}>
<Message
Expand All @@ -97,9 +47,8 @@ function Summary(props: Props) {
);
}

const pending = loading
|| data?.project?.analysisAutomaticSummary?.status === 'STARTED'
|| data?.project?.analysisAutomaticSummary?.status === 'PENDING';
const pending = summaryData?.project?.analysisAutomaticSummary?.status === 'STARTED'
|| summaryData?.project?.analysisAutomaticSummary?.status === 'PENDING';

if (pending) {
return (
Expand All @@ -109,9 +58,9 @@ function Summary(props: Props) {

return (
<div className={styles.summary}>
{(data?.project?.analysisAutomaticSummary?.summary?.length ?? 0) > 0 ? (
{(summaryData?.project?.analysisAutomaticSummary?.summary?.length ?? 0) > 0 ? (
<p className={styles.summaryText}>
{data?.project?.analysisAutomaticSummary?.summary}
{summaryData?.project?.analysisAutomaticSummary?.summary}
</p>
) : (
<div className={styles.message}>
Expand Down
Loading

0 comments on commit c8f5f58

Please sign in to comment.