From ee7db4a633c0c4b893ec433ac051a76f75f97ddc Mon Sep 17 00:00:00 2001 From: crssstha Date: Wed, 24 Jun 2026 17:02:34 +0545 Subject: [PATCH 1/2] feat(ai-summary): added ai summary --- app/views/CapacityAndResources/index.tsx | 2 +- app/views/DataAndReport/AIsummary/index.tsx | 51 ++++++--------- .../DataAndReport/AIsummary/styles.module.css | 2 + .../DataAndReport/ReportDetail/index.tsx | 62 ++++++++++++++++--- app/views/DataAndReport/index.tsx | 5 +- app/views/OurWork/EmergencyResponse/index.tsx | 2 +- .../Preparedness/DisasterResponse/index.tsx | 2 +- .../Preparedness/EmergencyAlert/index.tsx | 2 +- app/views/TeamList/Members/index.tsx | 4 +- backend | 2 +- 10 files changed, 83 insertions(+), 51 deletions(-) diff --git a/app/views/CapacityAndResources/index.tsx b/app/views/CapacityAndResources/index.tsx index 381f494..9a5eca0 100644 --- a/app/views/CapacityAndResources/index.tsx +++ b/app/views/CapacityAndResources/index.tsx @@ -76,7 +76,7 @@ function CapacityAndResourcesList() { const [{ data, fetching }] = useCapacityAndResourcesQuery({ variables: { filters: { - regions: [regionId ?? ''], + regions: regionId ? [regionId] : null, isActive: true, search: filter.searchText, }, diff --git a/app/views/DataAndReport/AIsummary/index.tsx b/app/views/DataAndReport/AIsummary/index.tsx index 9f1fa17..e33ab89 100644 --- a/app/views/DataAndReport/AIsummary/index.tsx +++ b/app/views/DataAndReport/AIsummary/index.tsx @@ -1,5 +1,6 @@ import { StarLineIcon } from '@ifrc-go/icons'; import { + BlockLoading, Description, Heading, InlineView, @@ -8,8 +9,13 @@ import { import styles from './styles.module.css'; -function AIsummary() { - // TODO: fetch ai summary data from backend and display here +interface AISummaryProps { + loading? : boolean, + summary: string +} + +function AIsummary(props: AISummaryProps) { + const { loading, summary } = props; return ( AI Summary - - A cholera outbreak was declared in Arsi Zone, - Ethiopia on 17 May 2025 and is spreading to nearby areas. - By mid-June, 201 cases (92% severe) and 2 deaths were reported. - The outbreak is rapidly increasing, with over 62,000 people in need of assistance. - - - A cholera outbreak was declared in Arsi Zone, - Ethiopia on 17 May 2025 and is spreading to nearby areas. - By mid-June, 201 cases (92% severe) and 2 deaths were reported. - The outbreak is rapidly increasing, with over 62,000 people in need of assistance. - - - A cholera outbreak was declared in Arsi Zone, - Ethiopia on 17 May 2025 and is spreading to nearby areas. - By mid-June, 201 cases (92% severe) and 2 deaths were reported. - The outbreak is rapidly increasing, with over 62,000 people in need of assistance. - - - A cholera outbreak was declared in Arsi Zone, - Ethiopia on 17 May 2025 and is spreading to nearby areas. - By mid-June, 201 cases (92% severe) and 2 deaths were reported. - The outbreak is rapidly increasing, with over 62,000 people in need of assistance. - - - A cholera outbreak was declared in Arsi Zone, - Ethiopia on 17 May 2025 and is spreading to nearby areas. - By mid-June, 201 cases (92% severe) and 2 deaths were reported. - The outbreak is rapidly increasing, with over 62,000 people in need of assistance. - - + {loading ? ( + + ) : ( + + {summary} + + ) } ); } diff --git a/app/views/DataAndReport/AIsummary/styles.module.css b/app/views/DataAndReport/AIsummary/styles.module.css index f5012ec..634fa2a 100644 --- a/app/views/DataAndReport/AIsummary/styles.module.css +++ b/app/views/DataAndReport/AIsummary/styles.module.css @@ -2,5 +2,7 @@ background: var(--go-ui-color-primary-red) ; padding-top: var(--go-ui-spacing-4xl) !important; height: 100%; + white-space: pre-line; color: var(--go-ui-color-white); + } \ No newline at end of file diff --git a/app/views/DataAndReport/ReportDetail/index.tsx b/app/views/DataAndReport/ReportDetail/index.tsx index a55af93..f7161ce 100644 --- a/app/views/DataAndReport/ReportDetail/index.tsx +++ b/app/views/DataAndReport/ReportDetail/index.tsx @@ -12,7 +12,12 @@ import { gql } from 'urql'; import PdfViewer from '#components/PdfViewer'; import PowerBIEmbed from '#components/PowerBiEmbed'; -import { useReportQuery } from '#generated/types/graphql'; +import { + DocumentExtractionStatus, + ExtractionType, + useReportQuery, + useReportSummaryQuery, +} from '#generated/types/graphql'; import AIsummary from '#views/DataAndReport/AIsummary'; import styles from './styles.module.css'; @@ -39,6 +44,33 @@ const REPORT_QUERY = gql` } `; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const REPORT_SUMMARY_QUERY = gql` + query ReportSummary( + $pagination: OffsetPaginationInput, + $filters: ReportSummaryFilter + ) { + reportSummaries( + filters: $filters + pagination: $pagination + ) { + totalCount + results { + id + chunkType + text + pageNumber + status + } + totalCount + pageInfo { + offset + limit + } + } + } +`; + function ReportDetail() { const { id } = useParams<{ id: string }>(); @@ -47,10 +79,21 @@ function ReportDetail() { pause: !id, }); - const reportData = data?.report; + const [{ fetching: summaryLoading, data: summaryData }] = useReportSummaryQuery({ + variables: { + filters: { + report: id, + status: DocumentExtractionStatus.Success, + chunkType: ExtractionType.DocumentSummary, + }, + }, + pause: !id, + }); - // TODO: add condition or ai summary - const aiSummaryAvailable = !reportData?.iframeUrl; + const reportData = data?.report; + const aiSummary = summaryData?.reportSummaries.results + .map((summary) => summary.text) + .join('\n \n'); const publishedDate = new Date(reportData?.publishedAt); const encodedPublishedDate = encodeDate(publishedDate); @@ -63,13 +106,13 @@ function ReportDetail() { > ) } - {aiSummaryAvailable && ( + {aiSummary && (
- +
)} diff --git a/app/views/DataAndReport/index.tsx b/app/views/DataAndReport/index.tsx index eb2d809..b5946a9 100644 --- a/app/views/DataAndReport/index.tsx +++ b/app/views/DataAndReport/index.tsx @@ -105,9 +105,8 @@ function DataAndReport() { filters: { thematicAreaId: rawFilter.thematicAreaId, reportType: ReportTypeEnum.Report, - // TODO: add search filter in backend and uncomment below line - // search: rawFilter.search, - regions: [regionId ?? ''], + search: rawFilter.searchText ?? '', + regions: regionId ? [regionId] : null, }, pagination: { limit, diff --git a/app/views/OurWork/EmergencyResponse/index.tsx b/app/views/OurWork/EmergencyResponse/index.tsx index ee60ed1..6ad90a9 100644 --- a/app/views/OurWork/EmergencyResponse/index.tsx +++ b/app/views/OurWork/EmergencyResponse/index.tsx @@ -22,7 +22,7 @@ function EmergencyResponse() { filters: { page: DashboardPage.EmergencyResponse, isActive: true, - regions: [regionId ?? ''], + regions: regionId ? [regionId] : null, }, }, }); diff --git a/app/views/Preparedness/DisasterResponse/index.tsx b/app/views/Preparedness/DisasterResponse/index.tsx index 3670668..7f976c9 100644 --- a/app/views/Preparedness/DisasterResponse/index.tsx +++ b/app/views/Preparedness/DisasterResponse/index.tsx @@ -21,7 +21,7 @@ function DisasterResponse() { filters: { page: DashboardPage.DisasterResponse, isActive: true, - regions: [regionId ?? ''], + regions: regionId ? [regionId] : null, }, }, }); diff --git a/app/views/Preparedness/EmergencyAlert/index.tsx b/app/views/Preparedness/EmergencyAlert/index.tsx index b4c9cca..2afdc48 100644 --- a/app/views/Preparedness/EmergencyAlert/index.tsx +++ b/app/views/Preparedness/EmergencyAlert/index.tsx @@ -22,7 +22,7 @@ function EmergencyAlert() { filters: { page: DashboardPage.EmergencyAlerts, isActive: true, - regions: [regionId ?? ''], + regions: regionId ? [regionId] : null, }, }, }); diff --git a/app/views/TeamList/Members/index.tsx b/app/views/TeamList/Members/index.tsx index 105ebba..9433724 100644 --- a/app/views/TeamList/Members/index.tsx +++ b/app/views/TeamList/Members/index.tsx @@ -47,12 +47,12 @@ const TEAM_MEMBERS_QUERY = gql` ) { totalCount results { - woredaId + woreda updatedAt training teamId sex - regionId + region position phoneNumber order diff --git a/backend b/backend index 60042c6..1650594 160000 --- a/backend +++ b/backend @@ -1 +1 @@ -Subproject commit 60042c6d8854426c0b5557fd1ee1f786ec7d7f95 +Subproject commit 165059487a2ed41fcbc9fea2949c8e10c801619b From ab04187a1ad16c5d625d906311a91d46347e850b Mon Sep 17 00:00:00 2001 From: crssstha Date: Fri, 26 Jun 2026 11:58:38 +0545 Subject: [PATCH 2/2] fix(report): semantic search --- app/components/ReportCard/index.tsx | 22 +++++++++++++++++-- .../DataAndReport/ReportDetail/index.tsx | 16 +++++++++----- app/views/DataAndReport/index.tsx | 4 +++- backend | 2 +- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/components/ReportCard/index.tsx b/app/components/ReportCard/index.tsx index ab11230..e194fef 100644 --- a/app/components/ReportCard/index.tsx +++ b/app/components/ReportCard/index.tsx @@ -7,8 +7,12 @@ import { InlineLayout, ListView, } from '@ifrc-go/ui'; +import { isDefined } from '@togglecorp/fujs'; -import type { ReportsQuery } from '#generated/types/graphql'; +import { + ReportContentType, + type ReportsQuery, +} from '#generated/types/graphql'; import styles from './styles.module.css'; @@ -21,12 +25,13 @@ function ReportCard({ report }: ReportCardProps) { coverImage, title, description, + contentType, } = report; return ( + {contentType === ReportContentType.Iframe && ( + + } + > + External Dashboard + + + )} + diff --git a/app/views/DataAndReport/ReportDetail/index.tsx b/app/views/DataAndReport/ReportDetail/index.tsx index f7161ce..e4fe497 100644 --- a/app/views/DataAndReport/ReportDetail/index.tsx +++ b/app/views/DataAndReport/ReportDetail/index.tsx @@ -7,7 +7,10 @@ import { ListView, PageContainer, } from '@ifrc-go/ui'; -import { encodeDate } from '@togglecorp/fujs'; +import { + encodeDate, + isDefined, +} from '@togglecorp/fujs'; import { gql } from 'urql'; import PdfViewer from '#components/PdfViewer'; @@ -15,6 +18,7 @@ import PowerBIEmbed from '#components/PowerBiEmbed'; import { DocumentExtractionStatus, ExtractionType, + ReportContentType, useReportQuery, useReportSummaryQuery, } from '#generated/types/graphql'; @@ -78,6 +82,7 @@ function ReportDetail() { variables: { id: id! }, pause: !id, }); + const reportData = data?.report; const [{ fetching: summaryLoading, data: summaryData }] = useReportSummaryQuery({ variables: { @@ -87,10 +92,9 @@ function ReportDetail() { chunkType: ExtractionType.DocumentSummary, }, }, - pause: !id, + pause: !id || !reportData || reportData.contentType === ReportContentType.Iframe, }); - const reportData = data?.report; const aiSummary = summaryData?.reportSummaries.results .map((summary) => summary.text) .join('\n \n'); @@ -106,7 +110,7 @@ function ReportDetail() { > @@ -160,7 +164,7 @@ function ReportDetail() {
- {reportData?.file?.url + {isDefined(reportData?.file?.url) ? : ( ) }
- {aiSummary && ( + {isDefined(aiSummary) && (