-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDP #33 - Adding model side panels; Adding handling for user-defined …
…fields
- Loading branch information
1 parent
1beeabb
commit 4d72271
Showing
21 changed files
with
421 additions
and
91 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import RecordPanel from '@apps/search/panels/RecordPanel'; | ||
import { BaseService, CoreData as CoreDataUtils, useLoader } from '@performant-software/core-data'; | ||
import { useCurrentRoute, useNavigate } from '@peripleo/peripleo'; | ||
import { getPreviewImage } from '@utils/Media'; | ||
import { getCurrentId } from '@utils/router'; | ||
import React, { useCallback, useMemo } from 'react'; | ||
import _ from 'underscore'; | ||
|
||
interface Props { | ||
name: string; | ||
renderItem?: (item: any) => JSX.Element; | ||
renderName?: (item: any) => string; | ||
useServiceHook: () => typeof BaseService; | ||
} | ||
|
||
const BasePanel = (props: Props) => { | ||
const Service = props.useServiceHook(); | ||
const navigate = useNavigate(); | ||
|
||
const route = useCurrentRoute(); | ||
const id = getCurrentId(route); | ||
|
||
/** | ||
* Loads the instance record from the Core Data API. | ||
*/ | ||
const onLoad = useCallback(() => Service.fetchOne(id), [id]); | ||
const { data } = useLoader(onLoad); | ||
|
||
const item = useMemo(() => data && data[props.name], [data, props.name]); | ||
|
||
/** | ||
* Loads the first related media record from the Core Data API. | ||
*/ | ||
const onLoadMedia = useCallback(() => Service.fetchRelatedMedia(id, { limit: 1 }), [id]); | ||
const { data: { media_contents: mediaContents = [] } = {} } = useLoader(onLoadMedia); | ||
|
||
/** | ||
* Loads the related place records from the Core Data API. | ||
*/ | ||
const onLoadPlaces = useCallback(() => Service.fetchRelatedPlaces(id), [id]); | ||
const { data: { places = [] } = {} } = useLoader(onLoadPlaces); | ||
|
||
/** | ||
* Memo-izes the geometry. | ||
*/ | ||
const geometry = useMemo(() => !_.isEmpty(places) && CoreDataUtils.toFeatureCollection(places), [places]); | ||
|
||
/** | ||
* Memo-izes the image. | ||
*/ | ||
const image = useMemo(() => getPreviewImage(mediaContents), [mediaContents]); | ||
|
||
/** | ||
* Memo-izes the name. | ||
*/ | ||
const name = useMemo(() => (item && props.renderName && props.renderName(item)) || item?.name, [item]); | ||
|
||
return ( | ||
<RecordPanel | ||
geometry={geometry} | ||
id={id} | ||
image={image} | ||
name={name} | ||
onClose={() => navigate('/')} | ||
onLoadMedia={() => Service.fetchRelatedManifests(id)} | ||
onLoadOrganizations={() => Service.fetchRelatedOrganizations(id)} | ||
onLoadPeople={() => Service.fetchRelatedPeople(id)} | ||
onLoadPlaces={() => Service.fetchRelatedPlaces(id)} | ||
onLoadTaxonomies={() => Service.fetchRelatedTaxonomies(id)} | ||
userDefined={item?.user_defined} | ||
> | ||
{ item && props.renderItem && props.renderItem(item) } | ||
</RecordPanel> | ||
) | ||
}; | ||
|
||
export default BasePanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import BasePanel from '@apps/search/panels/BasePanel'; | ||
import { useTranslations } from '@i18n/client'; | ||
import { useEventsService } from '@performant-software/core-data'; | ||
import { FuzzyDate as FuzzyDateUtils } from '@performant-software/shared-components'; | ||
import React, { useCallback } from 'react'; | ||
|
||
const Event = () => { | ||
const { t } = useTranslations(); | ||
|
||
/** | ||
* Returns the start date label for the passed event. | ||
*/ | ||
const getStartDateLabel = useCallback((event) => event.end_date ? t('startDate') : t('date'), [t]); | ||
|
||
/** | ||
* Renders the label and value for the passed date. | ||
*/ | ||
const renderDate = useCallback((date, label) => ( | ||
<div> | ||
<div | ||
className='text-muted' | ||
> | ||
{ label } | ||
</div> | ||
<div | ||
className='font-medium overflow-hidden text-ellipsis' | ||
> | ||
{ FuzzyDateUtils.getDateView(date) } | ||
</div> | ||
</div> | ||
), []); | ||
|
||
return ( | ||
<BasePanel | ||
name='event' | ||
renderItem={(event) => ( | ||
<> | ||
{ event.start_date && renderDate(event.start_date, getStartDateLabel(event)) } | ||
{ event.end_date && renderDate(event.end_date, t('endDate')) } | ||
{ event.description && ( | ||
<p | ||
className='py-2' | ||
> | ||
{ event.description } | ||
</p> | ||
)} | ||
</> | ||
)} | ||
useServiceHook={useEventsService} | ||
/> | ||
); | ||
}; | ||
|
||
export default Event; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import BasePanel from '@apps/search/panels/BasePanel'; | ||
import { useInstancesService } from '@performant-software/core-data'; | ||
import React from 'react'; | ||
|
||
const Instance = () => ( | ||
<BasePanel | ||
name='instance' | ||
useServiceHook={useInstancesService} | ||
/> | ||
); | ||
|
||
export default Instance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import BasePanel from '@apps/search/panels/BasePanel'; | ||
import { useItemsService } from '@performant-software/core-data'; | ||
import React from 'react'; | ||
|
||
const Item = () => ( | ||
<BasePanel | ||
name='item' | ||
useServiceHook={useItemsService} | ||
/> | ||
); | ||
|
||
export default Item; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import BasePanel from '@apps/search/panels/BasePanel'; | ||
import { useOrganizationsService } from '@performant-software/core-data'; | ||
import React from 'react'; | ||
|
||
const Organization = () => ( | ||
<BasePanel | ||
name='organization' | ||
useServiceHook={useOrganizationsService} | ||
/> | ||
); | ||
|
||
export default Organization; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import BasePanel from '@apps/search/panels/BasePanel'; | ||
import { usePeopleService } from '@performant-software/core-data'; | ||
import { getNameView } from '@utils/Person'; | ||
import React, { useCallback } from 'react'; | ||
|
||
const Person = () => { | ||
/** | ||
* Returns a concatenation of the person's name attributes. | ||
* | ||
* @type {function(*): *} | ||
*/ | ||
const renderName = useCallback((person) => getNameView(person), []); | ||
|
||
return ( | ||
<BasePanel | ||
name='person' | ||
renderName={renderName} | ||
useServiceHook={usePeopleService} | ||
/> | ||
); | ||
}; | ||
|
||
export default Person; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.