Skip to content

Commit

Permalink
fix: removed threshold from poll request and made necessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Maham Akif authored and Maham Akif committed May 3, 2024
1 parent f4a95ac commit 13c9c86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/components/aiCuration/data/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useXpertResultsWithThreshold = () => {
const { status, data: responseData, error: responseError } = response;

if (status >= 400 && status < 600) {
setError(responseError);
setError(responseError || responseData?.error);
setXpertResultsData({});
} else {
setXpertResultsData(responseData.result || defaultResult);
Expand Down
9 changes: 7 additions & 2 deletions src/components/aiCuration/data/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ class EnterpriseCatalogAiCurationApiService {
return new Promise(resolve => { setTimeout(resolve, ms); });
}

static async getXpertResults(taskId, threshold = 0) {
static async getXpertResults(taskId, threshold) {
try {
const response = await axios.get(`${EnterpriseCatalogAiCurationApiService.enterpriseCatalogAiCurationServiceUrl}?task_id=${taskId}&threshold=${threshold}`);
let url = `${EnterpriseCatalogAiCurationApiService.enterpriseCatalogAiCurationServiceUrl}?task_id=${taskId}`;
if (threshold) {
url += `&threshold=${threshold}`;
}

const response = await axios.get(url);
return {
status: response.status,
data: response.data,
Expand Down
15 changes: 3 additions & 12 deletions src/components/aiCuration/xpertResultCard/XpertResultCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { Close } from '@openedx/paragon/icons';
import askXpretImage from '../../../assets/edx-xpert-card-side-image.png';
import { useXpertResultsWithThreshold } from '../data/hooks';
import { hasNonEmptyValues } from '../../../utils/common';
import {
CONTENT_TYPE_COURSE,
CONTENT_TYPE_PROGRAM,
Expand All @@ -31,14 +30,16 @@ const XpertResultCard = ({
}, 1000), [taskId]);

useEffect(() => {
setXpertResults(xpertResultsData);
if (xpertResultsData && Object.keys(xpertResultsData).length > 0) {
setXpertResults(xpertResultsData);
const aggregationKeys = {
[CONTENT_TYPE_COURSE]: xpertResultsData.ocm_courses?.map(item => item.aggregation_key),
[EXEC_ED_TITLE]: xpertResultsData.exec_ed_courses?.map(item => item.aggregation_key),
[CONTENT_TYPE_PROGRAM]: xpertResultsData.programs?.map(item => item.aggregation_key),
};
onXpertResults(aggregationKeys);
} else if (error) {
setXpertResults({});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [thresholdValue, xpertResultsData]);
Expand Down Expand Up @@ -142,16 +143,6 @@ const XpertResultCard = ({
/>
</p>
)}
{!error && !hasNonEmptyValues(xpertResults)
&& (
<p className="text-white">
<FormattedMessage
id="catalogs.askXpert.result.card.no.data.found.error.message"
defaultMessage="No course/program found against your filter criteria, please select a broader focus to get results"
description="Error message displayed when no course/program is found against the selected filter value, on askXpert result card"
/>
</p>
)}
<div className="text-white mt-4">
<Form.Group className="">
<Form.Label className="h2 text-white mb-3 font-weight-bold">
Expand Down

0 comments on commit 13c9c86

Please sign in to comment.