Date: Tue, 28 Nov 2023 17:55:12 +0530
Subject: [PATCH 3/4] feat: added search api changes to search place,orgs
create place,event
---
src/pages/Dashboard/AddEvent/AddEvent.jsx | 407 ++++++++++++------
.../CreateNewPlace/CreateNewPlace.jsx | 195 ++++++---
.../SearchOrganizations.jsx | 184 ++++----
.../Dashboard/SearchPerson/SearchPerson.jsx | 4 +-
.../Dashboard/SearchPlaces/SearchPlaces.jsx | 196 +++++----
5 files changed, 620 insertions(+), 366 deletions(-)
diff --git a/src/pages/Dashboard/AddEvent/AddEvent.jsx b/src/pages/Dashboard/AddEvent/AddEvent.jsx
index 7f2e7de6b..e224845bc 100644
--- a/src/pages/Dashboard/AddEvent/AddEvent.jsx
+++ b/src/pages/Dashboard/AddEvent/AddEvent.jsx
@@ -84,6 +84,7 @@ import QuickCreatePlace from '../../../components/Modal/QuickCreatePlace';
import { useDebounce } from '../../../hooks/debounce';
import { SEARCH_DELAY } from '../../../constants/search';
import { sourceOptions } from '../../../constants/sourceOptions';
+import { useGetExternalSourceQuery, useLazyGetExternalSourceQuery } from '../../../services/externalSource';
const { TextArea } = Input;
function AddEvent() {
@@ -123,10 +124,16 @@ function AddEvent() {
searchKey: '',
classes: decodeURIComponent(query.toString()),
sessionId: timestampRef,
- includeArtsdata: true,
+ });
+ const { currentData: initialExternalSource, isFetching: initialExternalSourceLoading } = useGetExternalSourceQuery({
+ calendarId,
+ searchKey: '',
+ classes: decodeURIComponent(query.toString()),
+ sessionId: timestampRef,
});
const [addEvent, { isLoading: addEventLoading }] = useAddEventMutation();
- const [getEntities] = useLazyGetEntitiesQuery({ sessionId: timestampRef });
+ const [getEntities, { isFetching: isEntitiesFetching }] = useLazyGetEntitiesQuery({ sessionId: timestampRef });
+ const [getExternalSource, { isFetching: isExternalSourceFetching }] = useLazyGetExternalSourceQuery();
const [updateEventState, { isLoading: updateEventStateLoading }] = useUpdateEventStateMutation();
const [updateEvent, { isLoading: updateEventLoading }] = useUpdateEventMutation();
const [addImage, { error: isAddImageError, isLoading: addImageLoading }] = useAddImageMutation();
@@ -820,11 +827,20 @@ function AddEvent() {
searchKey: inputValue,
classes: decodeURIComponent(query.toString()),
calendarId,
- includeArtsdata: true,
})
.unwrap()
.then((response) => {
- setAllPlacesList(placesOptions(response?.cms, user, calendarContentLanguage, sourceOptions.CMS));
+ setAllPlacesList(placesOptions(response, user, calendarContentLanguage, sourceOptions.CMS));
+ })
+ .catch((error) => console.log(error));
+ getExternalSource({
+ searchKey: inputValue,
+ classes: decodeURIComponent(query.toString()),
+ calendarId,
+ excludeExistingCMS: true,
+ })
+ .unwrap()
+ .then((response) => {
setAllPlacesArtsdataList(
placesOptions(response?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
);
@@ -836,21 +852,35 @@ function AddEvent() {
let query = new URLSearchParams();
query.append('classes', entitiesClass.organization);
query.append('classes', entitiesClass.person);
- getEntities({ searchKey: value, classes: decodeURIComponent(query.toString()), calendarId, includeArtsdata: true })
+ getEntities({ searchKey: value, classes: decodeURIComponent(query.toString()), calendarId })
+ .unwrap()
+ .then((response) => {
+ if (type == 'organizers') {
+ setOrganizersList(treeEntitiesOption(response, user, calendarContentLanguage, sourceOptions.CMS));
+ } else if (type == 'performers') {
+ setPerformerList(treeEntitiesOption(response, user, calendarContentLanguage, sourceOptions.CMS));
+ } else if (type == 'supporters') {
+ setSupporterList(treeEntitiesOption(response, user, calendarContentLanguage, sourceOptions.CMS));
+ }
+ })
+ .catch((error) => console.log(error));
+ getExternalSource({
+ searchKey: value,
+ classes: decodeURIComponent(query.toString()),
+ calendarId,
+ excludeExistingCMS: true,
+ })
.unwrap()
.then((response) => {
if (type == 'organizers') {
- setOrganizersList(treeEntitiesOption(response?.cms, user, calendarContentLanguage, sourceOptions.CMS));
setOrganizersArtsdataList(
treeEntitiesOption(response?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
);
} else if (type == 'performers') {
- setPerformerList(treeEntitiesOption(response?.cms, user, calendarContentLanguage, sourceOptions.CMS));
setPerformerArtsdataList(
treeEntitiesOption(response?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
);
} else if (type == 'supporters') {
- setSupporterList(treeEntitiesOption(response?.cms, user, calendarContentLanguage, sourceOptions.CMS));
setSupporterArtsdataList(
treeEntitiesOption(response?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
);
@@ -1271,22 +1301,22 @@ function AddEvent() {
}, [currentCalendarData]);
useEffect(() => {
- if (initialEntities && currentCalendarData) {
- setOrganizersList(treeEntitiesOption(initialEntities?.cms, user, calendarContentLanguage, sourceOptions.CMS));
- setPerformerList(treeEntitiesOption(initialEntities?.cms, user, calendarContentLanguage, sourceOptions.CMS));
- setSupporterList(treeEntitiesOption(initialEntities?.cms, user, calendarContentLanguage, sourceOptions.CMS));
+ if (initialEntities && currentCalendarData && initialExternalSourceLoading) {
+ setOrganizersList(treeEntitiesOption(initialEntities, user, calendarContentLanguage, sourceOptions.CMS));
+ setPerformerList(treeEntitiesOption(initialEntities, user, calendarContentLanguage, sourceOptions.CMS));
+ setSupporterList(treeEntitiesOption(initialEntities, user, calendarContentLanguage, sourceOptions.CMS));
setPerformerArtsdataList(
- treeEntitiesOption(initialEntities?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
+ treeEntitiesOption(initialExternalSource?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
);
setSupporterArtsdataList(
- treeEntitiesOption(initialEntities?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
+ treeEntitiesOption(initialExternalSource?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
);
setOrganizersArtsdataList(
- treeEntitiesOption(initialEntities?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
+ treeEntitiesOption(initialExternalSource?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
),
placesSearch();
}
- }, [initialEntityLoading, currentCalendarData]);
+ }, [initialEntityLoading, currentCalendarData, initialExternalSourceLoading]);
return !isLoading &&
!taxonomyLoading &&
@@ -1294,7 +1324,8 @@ function AddEvent() {
currentCalendarData &&
!updateEventLoading &&
!addEventLoading &&
- !updateEventStateLoading ? (
+ !updateEventStateLoading &&
+ !initialExternalSourceLoading ? (
- {organizersList?.length > 0 ? (
- organizersList?.map((organizer, index) => (
-
{
- setSelectedOrganizers([...selectedOrganizers, organizer]);
- setIsPopoverOpen({
- ...isPopoverOpen,
- organizer: false,
- });
- }}
- data-cy={`div-select-organizer-${index}`}>
- {organizer?.label}
-
- ))
- ) : (
-
+ {isEntitiesFetching && (
+
+
+
)}
-
- >
- {quickCreateKeyword !== '' && (
- <>
-
- {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
-
-
- {organizersArtsdataList?.length > 0 ? (
- organizersArtsdataList?.map((organizer, index) => (
+ {!isEntitiesFetching &&
+ (organizersList?.length > 0 ? (
+ organizersList?.map((organizer, index) => (
+ data-cy={`div-select-organizer-${index}`}>
{organizer?.label}
))
) : (
+ ))}
+
+ >
+ {quickCreateKeyword !== '' && (
+ <>
+
+ {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
+
+
+ {isExternalSourceFetching && (
+
+
+
)}
+ {!isExternalSourceFetching &&
+ (organizersArtsdataList?.length > 0 ? (
+ organizersArtsdataList?.map((organizer, index) => (
+
{
+ setSelectedOrganizers([...selectedOrganizers, organizer]);
+ setIsPopoverOpen({
+ ...isPopoverOpen,
+ organizer: false,
+ });
+ }}
+ data-cy={`div-select-artsdata-organizer-${index}`}>
+ {organizer?.label}
+
+ ))
+ ) : (
+
+ ))}
>
)}
@@ -2608,36 +2687,20 @@ function AddEvent() {
{t('dashboard.organization.createNew.search.footlightSectionHeading')}
- {performerList?.length > 0 ? (
- performerList?.map((performer, index) => (
-
{
- setSelectedPerformers([...selectedPerformers, performer]);
- setIsPopoverOpen({
- ...isPopoverOpen,
- performer: false,
- });
- }}
- data-cy={`div-select-performer-${index}`}>
- {performer?.label}
-
- ))
- ) : (
-
+ {isEntitiesFetching && (
+
+
+
)}
-
- >
-
- {quickCreateKeyword !== '' && (
- <>
-
- {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
-
-
- {performerArtsdataList?.length > 0 ? (
- performerArtsdataList?.map((performer, index) => (
+ {!isEntitiesFetching &&
+ (performerList?.length > 0 ? (
+ performerList?.map((performer, index) => (
+ data-cy={`div-select-performer-${index}`}>
{performer?.label}
))
) : (
+ ))}
+
+ >
+
+ {quickCreateKeyword !== '' && (
+ <>
+
+ {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
+
+
+ {isExternalSourceFetching && (
+
+
+
)}
+ {!isExternalSourceFetching &&
+ (performerArtsdataList?.length > 0 ? (
+ performerArtsdataList?.map((performer, index) => (
+
{
+ setSelectedPerformers([...selectedPerformers, performer]);
+ setIsPopoverOpen({
+ ...isPopoverOpen,
+ performer: false,
+ });
+ }}
+ data-cy={`div-select-artsdata-performer-${index}`}>
+ {performer?.label}
+
+ ))
+ ) : (
+
+ ))}
>
)}
@@ -2750,36 +2853,20 @@ function AddEvent() {
{t('dashboard.organization.createNew.search.footlightSectionHeading')}
- {supporterList?.length > 0 ? (
- supporterList?.map((supporter, index) => (
-
{
- setSelectedSupporters([...selectedSupporters, supporter]);
- setIsPopoverOpen({
- ...isPopoverOpen,
- supporter: false,
- });
- }}
- data-cy={`div-select-supporter-${index}`}>
- {supporter?.label}
-
- ))
- ) : (
-
+ {isEntitiesFetching && (
+
+
+
)}
-
- >
-
- {quickCreateKeyword !== '' && (
- <>
-
- {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
-
-
- {supporterArtsdataList?.length > 0 ? (
- supporterArtsdataList?.map((supporter, index) => (
+ {!isEntitiesFetching &&
+ (supporterList?.length > 0 ? (
+ supporterList?.map((supporter, index) => (
+ data-cy={`div-select-supporter-${index}`}>
{supporter?.label}
))
) : (
+ ))}
+
+ >
+
+ {quickCreateKeyword !== '' && (
+ <>
+
+ {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
+
+
+ {isExternalSourceFetching && (
+
+
+
)}
+ {!isExternalSourceFetching &&
+ (supporterArtsdataList?.length > 0 ? (
+ supporterArtsdataList?.map((supporter, index) => (
+
{
+ setSelectedSupporters([...selectedSupporters, supporter]);
+ setIsPopoverOpen({
+ ...isPopoverOpen,
+ supporter: false,
+ });
+ }}
+ data-cy={`div-select-artsdata-supporter-${index}`}>
+ {supporter?.label}
+
+ ))
+ ) : (
+
+ ))}
>
)}
diff --git a/src/pages/Dashboard/CreateNewPlace/CreateNewPlace.jsx b/src/pages/Dashboard/CreateNewPlace/CreateNewPlace.jsx
index 86fcfb8cc..13993072d 100644
--- a/src/pages/Dashboard/CreateNewPlace/CreateNewPlace.jsx
+++ b/src/pages/Dashboard/CreateNewPlace/CreateNewPlace.jsx
@@ -70,6 +70,7 @@ import { SEARCH_DELAY } from '../../../constants/search';
import { userRoles } from '../../../constants/userRoles';
import { getExternalSourceId } from '../../../utils/getExternalSourceId';
import { sourceOptions } from '../../../constants/sourceOptions';
+import { useLazyGetExternalSourceQuery } from '../../../services/externalSource';
const { TextArea } = Input;
@@ -134,7 +135,8 @@ function CreateNewPlace() {
includeConcepts: true,
sessionId: timestampRef,
});
- const [getEntities] = useLazyGetEntitiesQuery({ sessionId: timestampRef });
+ const [getEntities, { isFetching: isEntitiesFetching }] = useLazyGetEntitiesQuery({ sessionId: timestampRef });
+ const [getExternalSource, { isFetching: isExternalSourceFetching }] = useLazyGetExternalSourceQuery();
const [addImage, { error: isAddImageError, isLoading: addImageLoading }] = useAddImageMutation();
const [addPlace, { isLoading: addPlaceLoading }] = useAddPlaceMutation();
const [updatePlace, { isLoading: updatePlaceLoading }] = useUpdatePlaceMutation();
@@ -626,15 +628,24 @@ function CreateNewPlace() {
searchKey: inputValue,
classes: decodeURIComponent(query.toString()),
calendarId,
- includeArtsdata: true,
})
.unwrap()
.then((response) => {
let containedInPlaceFilter = [];
- if (placeId) containedInPlaceFilter = response?.cms?.filter((place) => place?.id != placeId);
- else containedInPlaceFilter = response?.cms;
+ if (placeId) containedInPlaceFilter = response?.filter((place) => place?.id != placeId);
+ else containedInPlaceFilter = response;
setAllPlacesList(placesOptions(containedInPlaceFilter, user, calendarContentLanguage, sourceOptions.CMS));
+ })
+ .catch((error) => console.log(error));
+ getExternalSource({
+ searchKey: inputValue,
+ classes: decodeURIComponent(query.toString()),
+ calendarId,
+ excludeExistingCMS: true,
+ })
+ .unwrap()
+ .then((response) => {
setAllPlacesArtsdataList(
placesOptions(response?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
);
@@ -1700,38 +1711,23 @@ function CreateNewPlace() {
{t('dashboard.organization.createNew.search.footlightSectionHeading')}
- {allPlacesList?.length > 0 ? (
- allPlacesList?.map((place, index) => (
-
{
- setSelectedContainsPlaces([...selectedContainsPlaces, place]);
- setIsPopoverOpen({
- ...isPopoverOpen,
- containsPlace: false,
- });
- }}
- data-cy="div-place-footlight">
- {place?.label}
-
- ))
- ) : (
-
+ {isEntitiesFetching && (
+
+
+
)}
-
- >
- {quickCreateKeyword !== '' && (
- <>
-
- {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
-
-
- {allPlacesArtsdataList?.length > 0 ? (
- allPlacesArtsdataList?.map((place, index) => (
+ {!isEntitiesFetching &&
+ (allPlacesList?.length > 0 ? (
+ allPlacesList?.map((place, index) => (
{
setSelectedContainsPlaces([...selectedContainsPlaces, place]);
setIsPopoverOpen({
@@ -1739,13 +1735,52 @@ function CreateNewPlace() {
containsPlace: false,
});
}}
- data-cy="div-place-artsdata">
+ data-cy="div-place-footlight">
{place?.label}
))
) : (
+ ))}
+
+ >
+ {quickCreateKeyword !== '' && (
+ <>
+
+ {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
+
+
+ {isExternalSourceFetching && (
+
+
+
)}
+ {!isExternalSourceFetching &&
+ (allPlacesArtsdataList?.length > 0 ? (
+ allPlacesArtsdataList?.map((place, index) => (
+
{
+ setSelectedContainsPlaces([...selectedContainsPlaces, place]);
+ setIsPopoverOpen({
+ ...isPopoverOpen,
+ containsPlace: false,
+ });
+ }}
+ data-cy="div-place-artsdata">
+ {place?.label}
+
+ ))
+ ) : (
+
+ ))}
>
)}
@@ -1825,45 +1860,29 @@ function CreateNewPlace() {
{t('dashboard.organization.createNew.search.footlightSectionHeading')}
- {allPlacesList?.length > 0 ? (
- allPlacesList?.map((place, index) => (
-
{
- setContainedInPlace(place);
- form.setFieldValue(formFieldNames.CONTAINED_IN_PLACE, place?.value);
- setIsPopoverOpen({
- ...isPopoverOpen,
- containedInPlace: false,
- });
- }}>
- {place?.label}
-
- ))
- ) : (
-
+ {isEntitiesFetching && (
+
+
+
)}
-
- >
- {quickCreateKeyword !== '' && (
- <>
-
- {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
-
-
- {allPlacesArtsdataList?.length > 0 ? (
- allPlacesArtsdataList?.map((place, index) => (
+ {!isEntitiesFetching &&
+ (allPlacesList?.length > 0 ? (
+ allPlacesList?.map((place, index) => (
{
setContainedInPlace(place);
- form.setFieldValue(formFieldNames.CONTAINED_IN_PLACE, place?.uri);
+ form.setFieldValue(formFieldNames.CONTAINED_IN_PLACE, place?.value);
setIsPopoverOpen({
...isPopoverOpen,
containedInPlace: false,
@@ -1874,7 +1893,47 @@ function CreateNewPlace() {
))
) : (
+ ))}
+
+ >
+ {quickCreateKeyword !== '' && (
+ <>
+
+ {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
+
+
+ {isExternalSourceFetching && (
+
+
+
)}
+ {!isExternalSourceFetching &&
+ (allPlacesArtsdataList?.length > 0 ? (
+ allPlacesArtsdataList?.map((place, index) => (
+
{
+ setContainedInPlace(place);
+ form.setFieldValue(formFieldNames.CONTAINED_IN_PLACE, place?.uri);
+ setIsPopoverOpen({
+ ...isPopoverOpen,
+ containedInPlace: false,
+ });
+ }}>
+ {place?.label}
+
+ ))
+ ) : (
+
+ ))}
>
)}
diff --git a/src/pages/Dashboard/SearchOrganizations/SearchOrganizations.jsx b/src/pages/Dashboard/SearchOrganizations/SearchOrganizations.jsx
index 450d50b7d..98e79c0b3 100644
--- a/src/pages/Dashboard/SearchOrganizations/SearchOrganizations.jsx
+++ b/src/pages/Dashboard/SearchOrganizations/SearchOrganizations.jsx
@@ -19,6 +19,8 @@ import { Popover } from 'antd';
import { routinghandler } from '../../../utils/roleRoutingHandler';
import { useDebounce } from '../../../hooks/debounce';
import { SEARCH_DELAY } from '../../../constants/search';
+import { useGetExternalSourceQuery, useLazyGetExternalSourceQuery } from '../../../services/externalSource';
+import LoadingIndicator from '../../../components/LoadingIndicator';
function SearchOrganizations() {
const { t } = useTranslation();
@@ -35,7 +37,8 @@ function SearchOrganizations() {
const [organizationListArtsData, setOrganizationListArtsData] = useState([]);
const [quickCreateKeyword, setQuickCreateKeyword] = useState('');
- const [getEntities] = useLazyGetEntitiesQuery({ sessionId: timestampRef });
+ const [getEntities, { isFetching: isEntitiesFetching }] = useLazyGetEntitiesQuery({ sessionId: timestampRef });
+ const [getExternalSource, { isFetching: isExternalSourceFetching }] = useLazyGetExternalSourceQuery();
let query = new URLSearchParams();
query.append('classes', entitiesClass.organization);
@@ -46,13 +49,19 @@ function SearchOrganizations() {
includeArtsdata: true,
sessionId: timestampRef,
});
+ const { currentData: initialExternalSource, isFetching: initialExternalSourceLoading } = useGetExternalSourceQuery({
+ calendarId,
+ searchKey: '',
+ classes: decodeURIComponent(query.toString()),
+ sessionId: timestampRef,
+ });
// effects
useEffect(() => {
- if (initialEntities && currentCalendarData) {
- setOrganizationList(initialEntities?.cms);
- setOrganizationListArtsData(initialEntities?.artsdata);
+ if (initialEntities && currentCalendarData && initialExternalSourceLoading) {
+ setOrganizationList(initialEntities);
+ setOrganizationListArtsData(initialExternalSource?.artsdata);
}
}, [initialOrganizersLoading]);
@@ -67,10 +76,20 @@ function SearchOrganizations() {
const searchHandler = (value) => {
let query = new URLSearchParams();
query.append('classes', entitiesClass.organization);
- getEntities({ searchKey: value, classes: decodeURIComponent(query.toString()), calendarId, includeArtsdata: true })
+ getEntities({ searchKey: value, classes: decodeURIComponent(query.toString()), calendarId })
+ .unwrap()
+ .then((response) => {
+ setOrganizationList(response);
+ })
+ .catch((error) => console.log(error));
+ getExternalSource({
+ searchKey: value,
+ classes: decodeURIComponent(query.toString()),
+ calendarId,
+ excludeExistingCMS: true,
+ })
.unwrap()
.then((response) => {
- setOrganizationList(response?.cms);
setOrganizationListArtsData(response?.artsdata);
})
.catch((error) => console.log(error));
@@ -104,51 +123,59 @@ function SearchOrganizations() {
{t('dashboard.organization.createNew.search.footlightSectionHeading')}
- {organizationList?.length > 0 ? (
- organizationList?.map((organizer, index) => (
-
{
- setIsPopoverOpen(false);
- }}
- data-cy={`div-organization-footlight-${index}`}>
-
- ) : (
-
- )
- }
- linkText={t('dashboard.organization.createNew.search.linkText')}
+ {isEntitiesFetching && (
+
+
+
+ )}
+ {!isEntitiesFetching &&
+ (organizationList?.length > 0 ? (
+ organizationList?.map((organizer, index) => (
+
{
- if (routinghandler(user, calendarId, organizer?.creator?.userId, null, true)) {
- navigate(
- `${PathName.Dashboard}/${calendarId}${PathName.Organizations}${PathName.AddOrganization}?id=${organizer?.id}`,
- );
- } else
- navigate(`${PathName.Dashboard}/${calendarId}${PathName.Organizations}/${organizer?.id}`);
+ setIsPopoverOpen(false);
}}
- />
-
- ))
- ) : (
-
- )}
+ data-cy={`div-organization-footlight-${index}`}>
+
+ ) : (
+
+ )
+ }
+ linkText={t('dashboard.organization.createNew.search.linkText')}
+ onClick={() => {
+ if (routinghandler(user, calendarId, organizer?.creator?.userId, null, true)) {
+ navigate(
+ `${PathName.Dashboard}/${calendarId}${PathName.Organizations}${PathName.AddOrganization}?id=${organizer?.id}`,
+ );
+ } else
+ navigate(
+ `${PathName.Dashboard}/${calendarId}${PathName.Organizations}/${organizer?.id}`,
+ );
+ }}
+ />
+
+ ))
+ ) : (
+
+ ))}
{quickCreateKeyword !== '' && (
<>
@@ -156,33 +183,40 @@ function SearchOrganizations() {
{t('dashboard.organization.createNew.search.artsDataSectionHeading')}
- {organizationListArtsData?.length > 0 ? (
- organizationListArtsData?.map((organizer, index) => (
-
{
- setIsPopoverOpen(false);
- }}>
- : }
- linkText={t('dashboard.organization.createNew.search.linkText')}
- onClick={() => artsDataClickHandler(organizer)}
- />
-
- ))
- ) : (
-
+ {isExternalSourceFetching && (
+
+
+
)}
+ {!isExternalSourceFetching &&
+ (organizationListArtsData?.length > 0 ? (
+ organizationListArtsData?.map((organizer, index) => (
+
{
+ setIsPopoverOpen(false);
+ }}>
+ : }
+ linkText={t('dashboard.organization.createNew.search.linkText')}
+ onClick={() => artsDataClickHandler(organizer)}
+ />
+
+ ))
+ ) : (
+
+ ))}
>
)}
diff --git a/src/pages/Dashboard/SearchPerson/SearchPerson.jsx b/src/pages/Dashboard/SearchPerson/SearchPerson.jsx
index bca55284e..6fde8e9a3 100644
--- a/src/pages/Dashboard/SearchPerson/SearchPerson.jsx
+++ b/src/pages/Dashboard/SearchPerson/SearchPerson.jsx
@@ -39,7 +39,8 @@ function SearchPerson() {
const [selectedPeople, setSelectedPeople] = useState([]);
const [getEntities, { isFetching: isEntitiesFetching }] = useLazyGetEntitiesQuery({ sessionId: timestampRef });
- const [getExternalSource, { isFetching: isExternalSourceFetching }] = useLazyGetExternalSourceQuery();
+ const [getExternalSource, { isFetching: isExternalSourceFetching, isSuccess: isExternalSourceSuccess }] =
+ useLazyGetExternalSourceQuery();
let query = new URLSearchParams();
query.append('classes', entitiesClass.person);
@@ -185,6 +186,7 @@ function SearchPerson() {
)}
{!isExternalSourceFetching &&
+ isExternalSourceSuccess &&
(peopleListArtsData?.length > 0 ? (
peopleListArtsData?.map((person, index) => (
{
- if (initialEntities && currentCalendarData) {
- setPlacesList(initialEntities?.cms);
- setPlacesListArtsData(initialEntities?.artsdata);
+ if (initialEntities && currentCalendarData && initialExternalSourceLoading) {
+ setPlacesList(initialEntities);
+ setPlacesListArtsData(initialExternalSource?.artsdata);
}
}, [initialPlacesLoading]);
@@ -64,10 +73,20 @@ function SearchPlaces() {
const searchHandler = (value) => {
let query = new URLSearchParams();
query.append('classes', entitiesClass.place);
- getEntities({ searchKey: value, classes: decodeURIComponent(query.toString()), calendarId, includeArtsdata: true })
+ getEntities({ searchKey: value, classes: decodeURIComponent(query.toString()), calendarId })
+ .unwrap()
+ .then((response) => {
+ setPlacesList(response);
+ })
+ .catch((error) => console.log(error));
+ getExternalSource({
+ searchKey: value,
+ classes: decodeURIComponent(query.toString()),
+ calendarId,
+ excludeExistingCMS: true,
+ })
.unwrap()
.then((response) => {
- setPlacesList(response?.cms);
setPlacesListArtsData(response?.artsdata);
})
.catch((error) => console.log(error));
@@ -101,51 +120,57 @@ function SearchPlaces() {
{t('dashboard.places.createNew.search.footlightSectionHeading')}
- {placesList?.length > 0 ? (
- placesList?.map((place, index) => (
-
{
- setSelectedPlaces([...selectedPlaces, place]);
- setIsPopoverOpen(false);
- }}
- data-cy={`div-place-footlight-${index}`}>
-
- )
- }
- linkText={t('dashboard.places.createNew.search.linkText')}
+ {isEntitiesFetching && (
+
+
+
+ )}
+ {!isEntitiesFetching &&
+ (placesList?.length > 0 ? (
+ placesList?.map((place, index) => (
+
{
- if (routinghandler(user, calendarId, place?.creator?.userId, null, true)) {
- navigate(
- `${PathName.Dashboard}/${calendarId}${PathName.Places}${PathName.AddPlace}?id=${place?.id}`,
- );
- } else navigate(`${PathName.Dashboard}/${calendarId}${PathName.Places}/${place?.id}`);
+ setSelectedPlaces([...selectedPlaces, place]);
+ setIsPopoverOpen(false);
}}
- />
-
- ))
- ) : (
-
- )}
+ data-cy={`div-place-footlight-${index}`}>
+
+ )
+ }
+ linkText={t('dashboard.places.createNew.search.linkText')}
+ onClick={() => {
+ if (routinghandler(user, calendarId, place?.creator?.userId, null, true)) {
+ navigate(
+ `${PathName.Dashboard}/${calendarId}${PathName.Places}${PathName.AddPlace}?id=${place?.id}`,
+ );
+ } else navigate(`${PathName.Dashboard}/${calendarId}${PathName.Places}/${place?.id}`);
+ }}
+ />
+
+ ))
+ ) : (
+
+ ))}
{quickCreateKeyword.length > 0 && (
@@ -154,39 +179,46 @@ function SearchPlaces() {
{t('dashboard.places.createNew.search.artsDataSectionHeading')}
- {placesListArtsData?.length > 0 ? (
- placesListArtsData?.map((place, index) => (
-
{
- setIsPopoverOpen(false);
- }}
- data-cy={`div-place-artsdata-${index}`}>
-
- )
- }
- linkText={t('dashboard.places.createNew.search.linkText')}
- onClick={() => artsDataClickHandler(place)}
- />
-
- ))
- ) : (
-
+ {isExternalSourceFetching && (
+
+
+
)}
+ {!isExternalSourceFetching &&
+ (placesListArtsData?.length > 0 ? (
+ placesListArtsData?.map((place, index) => (
+
{
+ setIsPopoverOpen(false);
+ }}
+ data-cy={`div-place-artsdata-${index}`}>
+
+ )
+ }
+ linkText={t('dashboard.places.createNew.search.linkText')}
+ onClick={() => artsDataClickHandler(place)}
+ />
+
+ ))
+ ) : (
+
+ ))}
>
)}
From ca88b0e22447bc152d547a8b47a6d0262ae53145 Mon Sep 17 00:00:00 2001
From: Abhishek P Anil
Date: Wed, 29 Nov 2023 10:13:40 +0530
Subject: [PATCH 4/4] feat: added support for changes in search api for search
fields in data centric approach
---
src/constants/formFields.js | 84 ++++++++++++-------
.../CreateNewOrganization.jsx | 19 ++++-
2 files changed, 68 insertions(+), 35 deletions(-)
diff --git a/src/constants/formFields.js b/src/constants/formFields.js
index 2bfc80852..4b8427e70 100644
--- a/src/constants/formFields.js
+++ b/src/constants/formFields.js
@@ -18,6 +18,7 @@ import SelectionItem from '../components/List/SelectionItem';
import BilingualTextEditor from '../components/BilingualTextEditor';
import Outlined from '../components/Button/Outlined';
import { sourceOptions } from './sourceOptions';
+import LoadingIndicator from '../components/LoadingIndicator';
const { TextArea } = Input;
@@ -359,6 +360,8 @@ export const formFieldValue = [
allPlacesArtsdataList,
placeNavigationHandler,
mappedField,
+ isEntitiesFetching,
+ isExternalSourceFetching,
}) => {
return (
<>
@@ -379,49 +382,62 @@ export const formFieldValue = [
{t('dashboard.organization.createNew.search.footlightSectionHeading')}
- {allPlacesList?.length > 0 ? (
- allPlacesList?.map((place, index) => (
+ {isEntitiesFetching && (
+
+
+
+ )}
+ {!isEntitiesFetching &&
+ (allPlacesList?.length > 0 ? (
+ allPlacesList?.map((place, index) => (
+
{
+ setLocationPlace(place);
+ form.setFieldValue(name, place?.value);
+ setIsPopoverOpen(false);
+ }}
+ data-cy={`div-${mappedField}-footlight-place-${index}`}>
+ {place?.label}
+
+ ))
+ ) : (
+
+ ))}
+
+ >
+
+
+ {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
+
+
+ {isExternalSourceFetching && (
+
+
+
+ )}
+ {!isExternalSourceFetching &&
+ (allPlacesArtsdataList?.length > 0 ? (
+ allPlacesArtsdataList?.map((place, index) => (
{
setLocationPlace(place);
- form.setFieldValue(name, place?.value);
+ form.setFieldValue(name, place?.uri);
setIsPopoverOpen(false);
}}
- data-cy={`div-${mappedField}-footlight-place-${index}`}>
+ data-cy={`div-${mappedField}-artsdata-place-${index}`}>
{place?.label}
))
) : (
- )}
-
- >
-
-
- {t('dashboard.organization.createNew.search.artsDataSectionHeading')}
-
-
- {allPlacesArtsdataList?.length > 0 ? (
- allPlacesArtsdataList?.map((place, index) => (
-
{
- setLocationPlace(place);
- form.setFieldValue(name, place?.uri);
- setIsPopoverOpen(false);
- }}
- data-cy={`div-${mappedField}-artsdata-place-${index}`}>
- {place?.label}
-
- ))
- ) : (
-
- )}
+ ))}
@@ -570,6 +586,8 @@ export const returnFormDataWithFields = ({
form,
style,
placeNavigationHandler,
+ isExternalSourceFetching,
+ isEntitiesFetching,
}) => {
return renderFormFields({
name: [field?.mappedField],
@@ -638,6 +656,8 @@ export const returnFormDataWithFields = ({
form,
taxonomyAlias: field?.taxonomyAlias,
placeNavigationHandler,
+ isExternalSourceFetching,
+ isEntitiesFetching,
}),
key: index,
initialValue: formInitialValueHandler(field?.type, field?.mappedField, field?.datatype, entityData),
diff --git a/src/pages/Dashboard/CreateNewOrganization/CreateNewOrganization.jsx b/src/pages/Dashboard/CreateNewOrganization/CreateNewOrganization.jsx
index 8f4b300df..380c0ab3d 100644
--- a/src/pages/Dashboard/CreateNewOrganization/CreateNewOrganization.jsx
+++ b/src/pages/Dashboard/CreateNewOrganization/CreateNewOrganization.jsx
@@ -45,6 +45,7 @@ import { useDebounce } from '../../../hooks/debounce';
import { SEARCH_DELAY } from '../../../constants/search';
import { sourceOptions } from '../../../constants/sourceOptions';
import { getExternalSourceId } from '../../../utils/getExternalSourceId';
+import { useLazyGetExternalSourceQuery } from '../../../services/externalSource';
function CreateNewOrganization() {
const timestampRef = useRef(Date.now()).current;
@@ -75,7 +76,8 @@ function CreateNewOrganization() {
});
const [getPlace] = useLazyGetPlaceQuery();
const [getAllTaxonomy] = useLazyGetAllTaxonomyQuery({ sessionId: timestampRef });
- const [getEntities] = useLazyGetEntitiesQuery({ sessionId: timestampRef });
+ const [getEntities, { isFetching: isEntitiesFetching }] = useLazyGetEntitiesQuery();
+ const [getExternalSource, { isFetching: isExternalSourceFetching }] = useLazyGetExternalSourceQuery();
const [addOrganization, { isLoading: addOrganizationLoading }] = useAddOrganizationMutation();
const [updateOrganization, { isLoading: updateOrganizationLoading }] = useUpdateOrganizationMutation();
const [addImage, { isLoading: imageUploadLoading }] = useAddImageMutation();
@@ -518,11 +520,20 @@ function CreateNewOrganization() {
searchKey: inputValue,
classes: decodeURIComponent(query.toString()),
calendarId,
- includeArtsdata: true,
})
.unwrap()
.then((response) => {
- setAllPlacesList(placesOptions(response?.cms, user, calendarContentLanguage, sourceOptions.CMS));
+ setAllPlacesList(placesOptions(response, user, calendarContentLanguage, sourceOptions.CMS));
+ })
+ .catch((error) => console.log(error));
+ getExternalSource({
+ searchKey: inputValue,
+ classes: decodeURIComponent(query.toString()),
+ calendarId,
+ excludeExistingCMS: true,
+ })
+ .unwrap()
+ .then((response) => {
setAllPlacesArtsdataList(
placesOptions(response?.artsdata, user, calendarContentLanguage, sourceOptions.ARTSDATA),
);
@@ -835,6 +846,8 @@ function CreateNewOrganization() {
: '',
},
placeNavigationHandler,
+ isEntitiesFetching,
+ isExternalSourceFetching,
});
}
});