Skip to content

Commit

Permalink
fix: fixed ai curation bugs (#414)
Browse files Browse the repository at this point in the history
Co-authored-by: Maham Akif <maham.akif@A006-00821.local>
  • Loading branch information
mahamakifdar19 and Maham Akif authored Apr 29, 2024
1 parent 1fe1e53 commit 8cc8983
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
22 changes: 11 additions & 11 deletions src/components/aiCuration/AskXpert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ const AskXpert = ({ catalogName, onClose, onXpertData }) => {
const defaultErrorMessage = 'An error occurred. Please try again.';

if (status < 400 || status === 429) {
if (!XPERT_RESULT_STATUSES.includes(finalResponse.status)) {
if (finalResponse.status && !XPERT_RESULT_STATUSES.includes(finalResponse.status)) {
setResults(finalResponse.result);
if (finalResponse.result) {
setShowXpertResultCard(hasNonEmptyValues(finalResponse.result));

const aggregationKeys = {
[CONTENT_TYPE_COURSE]: finalResponse?.result?.ocm_courses.map(item => item.aggregation_key),
[EXEC_ED_TITLE]: finalResponse?.result?.exec_ed_courses.map(item => item.aggregation_key),
[CONTENT_TYPE_PROGRAM]: finalResponse?.result?.programs.map(item => item.aggregation_key),
};

onXpertData(aggregationKeys); // Pass aggregationKeys to CatalogSearch
if (hasNonEmptyValues(finalResponse.result)) {
setShowXpertResultCard(finalResponse.result);
} else {
// Handles the scenario where request is successful but no data is returned.
setErrorMessage('Hm, I didnt find anything. Try telling me about the subjects, jobs, or skills you are trying to train in your organization.');
}
const aggregationKeys = {
[CONTENT_TYPE_COURSE]: finalResponse?.result?.ocm_courses.map(item => item.aggregation_key),
[EXEC_ED_TITLE]: finalResponse?.result?.exec_ed_courses.map(item => item.aggregation_key),
[CONTENT_TYPE_PROGRAM]: finalResponse?.result?.programs.map(item => item.aggregation_key),
};

onXpertData(aggregationKeys); // Pass aggregationKeys to CatalogSearch for Algolia filter

setIsLoading(false);
setDelay(null);
}
Expand Down
9 changes: 6 additions & 3 deletions src/components/aiCuration/xpertResultCard/XpertResultCard.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useMemo } from 'react';
import React, { useState, useMemo, useEffect } from 'react';
import PropTypes from 'prop-types';
import {
Icon, Card, Stack, Form, Button, Spinner, Image,
Expand Down Expand Up @@ -27,8 +27,10 @@ const XpertResultCard = ({

const debouncedHandleChange = debounce(async (threshold) => {
getXpertResultsWithThreshold(taskId, threshold);
}, 1000);

if (xpertResultsData) {
useEffect(() => {
if (hasNonEmptyValues(xpertResultsData)) {
setXpertResults(xpertResultsData);
const aggregationKeys = {
[CONTENT_TYPE_COURSE]: xpertResultsData.ocm_courses?.map(item => item.aggregation_key),
Expand All @@ -37,7 +39,8 @@ const XpertResultCard = ({
};
onXpertResults(aggregationKeys);
}
}, 1000);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [thresholdValue, xpertResultsData]);

const handleChange = async (e) => {
const threshold = Number(e.target.value);
Expand Down
5 changes: 4 additions & 1 deletion src/components/catalogs/CatalogSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { Image } from '@openedx/paragon';
import { useAlgoliaIndex } from './data/hooks';
import PageWrapper from '../PageWrapper';
import { getSelectedCatalogFromURL } from '../../utils/common';

import {
CONTENT_TYPE_COURSE,
Expand All @@ -26,6 +27,7 @@ import {
NUM_RESULTS_COURSE,
NUM_RESULTS_PROGRAM,
NUM_RESULTS_PER_PAGE,
QUERY_TITLE_REFINEMENT,
} from '../../constants';
import CatalogSearchResults from '../catalogSearchResults/CatalogSearchResults';
import CatalogInfoModal from '../catalogInfoModal/CatalogInfoModal';
Expand Down Expand Up @@ -198,12 +200,13 @@ const CatalogSearch = (intl) => {

// Take a list of learning types and render a search results component for each item
const contentToRender = (items) => {
const selectedCatalog = getSelectedCatalogFromURL();
const itemsWithResultsList = items.map((item) => {
let filters = contentData[item].filter;

if (features.ENABLE_AI_CURATION) {
if (xpertData[item]?.length > 0) {
filters += ` AND (${xpertData[item]?.map(key => `aggregation_key:'${key}'`).join(' OR ')})`;
filters += ` AND ${QUERY_TITLE_REFINEMENT}:"${selectedCatalog}" AND (${xpertData[item]?.map(key => `aggregation_key:'${key}'`).join(' OR ')})`;
} else if (xpertData[item]?.length === 0) {
filters = 'aggregation_key: null';
}
Expand Down

0 comments on commit 8cc8983

Please sign in to comment.