Skip to content

Commit 33c66bc

Browse files
committed
show currently clustered record in style with others. relates to gbif/hosted-portals#263
1 parent c10d712 commit 33c66bc

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

packages/graphql-api/src/resources/gbif/occurrence/occurrence.resolver.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export default {
208208
size,
209209
from,
210210
count: response.relatedOccurrences.length,
211+
currentOccurrence: response.currentOccurrence,
211212
relatedOccurrences: response.relatedOccurrences.slice(
212213
from,
213214
from + size,
@@ -563,6 +564,13 @@ export default {
563564
}),
564565
stub: (related) => related.occurrence,
565566
},
567+
RelatedCurrentOccurrence: {
568+
occurrence: (current, _args, { dataSources }) =>
569+
dataSources.occurrenceAPI.getOccurrenceByKey({
570+
key: current.gbifId,
571+
}),
572+
stub: (current) => current,
573+
},
566574
LongitudeHistogram: {
567575
bounds: ({ buckets, interval }) => {
568576
return getLongitudeBounds(buckets, interval);

packages/graphql-api/src/resources/gbif/occurrence/occurrence.type.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ const typeDef = gql`
335335
count: Int
336336
size: Int
337337
from: Int
338+
currentOccurrence: RelatedCurrentOccurrence!
338339
relatedOccurrences: [RelatedOccurrence]
339340
}
340341
@@ -347,6 +348,14 @@ const typeDef = gql`
347348
stub: RelatedOccurrenceStub
348349
}
349350
351+
type RelatedCurrentOccurrence {
352+
occurrence: Occurrence
353+
"""
354+
The occurrence as provided by the cluster API. It only has relev
355+
"""
356+
stub: RelatedOccurrenceStub
357+
}
358+
350359
type RelatedOccurrenceStub {
351360
gbifId: ID
352361
scientificName: String

packages/react-components/src/entities/OccurrenceSidebar/details/Cluster.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
import { jsx } from '@emotion/react';
2+
import { jsx, css } from '@emotion/react';
33
import React, { useContext, useState, useEffect } from 'react';
44
import ThemeContext from '../../../style/themes/ThemeContext';
5-
import * as css from '../styles';
5+
import * as styles from '../styles';
66
import { Row, Col, Image, Properties, IconFeatures } from "../../../components";
77
import { useQuery } from '../../../dataManagement/api';
88
import { Header } from './Header';
@@ -35,8 +35,14 @@ export function Cluster({
3535
}
3636

3737
return <div style={{ padding: '12px 16px' }}>
38-
<Header data={data} />
39-
<div style={{ marginTop: 24 }}>
38+
{/* Based on feedback in https://github.com/gbif/hosted-portals/issues/263 I have removed the header and instead repeated the information in a format similar to the other clustered records */}
39+
{/* <Header data={data} /> */}
40+
<div>
41+
<RelatedOccurrence onClick={e => setActiveKey(data.occurrence.key)} related={data.occurrence} css={css`
42+
border-color: var(--primary);
43+
background: var(--paperBackground700);
44+
border-radius: var(--borderRadiusPx);
45+
`}/>
4046
{related.map(x => {
4147
if (x.occurrence) {
4248
return <RelatedOccurrence key={x.occurrence.key} onClick={e => setActiveKey(x.occurrence.key)} related={x.occurrence} reasons={x.reasons} original={data.occurrence} />;
@@ -61,17 +67,17 @@ export function Cluster({
6167

6268
export function RelatedOccurrence({ original, reasons, related, ...props }) {
6369
const theme = useContext(ThemeContext);
64-
return <article css={css.clusterCard({ theme })} {...props}>
70+
return <article css={styles.clusterCard({ theme })} {...props}>
6571
<Row wrap="nowrap" halfGutter={6} style={{ padding: 12 }}>
6672
<Col>
6773
<h4 style={{ margin: 0 }} dangerouslySetInnerHTML={{ __html: related.gbifClassification.usage.formattedName }}></h4>
68-
<div css={css.entitySummary({ theme })}>
69-
<IconFeatures css={css.features({ theme })}
74+
<div css={styles.entitySummary({ theme })}>
75+
<IconFeatures css={styles.features({ theme })}
7076
eventDate={related.eventDate}
7177
countryCode={related.countryCode}
7278
locality={related.locality}
7379
/>
74-
<IconFeatures css={css.features({ theme })}
80+
<IconFeatures css={styles.features({ theme })}
7581
stillImageCount={related.stillImageCount}
7682
movingImageCount={related.movingImageCount}
7783
soundCount={related.soundCount}
@@ -98,11 +104,12 @@ export function RelatedOccurrence({ original, reasons, related, ...props }) {
98104
</div>
99105
</Col>
100106
</Row>
101-
<div css={css.clusterFooter({ theme })}>
102-
<Properties style={{ fontSize: 12 }} horizontal dense>
107+
<div css={styles.clusterFooter({ theme })}>
108+
{!reasons && <div>Current record</div>}
109+
{reasons && <Properties style={{ fontSize: 12 }} horizontal dense>
103110
<T>Similarities</T>
104-
<V>{ reasons.map(reason => <span css={css.chip({ theme })} key={reason}>{prettifyEnum(reason)}</span>) }</V>
105-
</Properties>
111+
<V>{ reasons.map(reason => <span css={styles.chip({ theme })} key={reason}>{prettifyEnum(reason)}</span>) }</V>
112+
</Properties>}
106113
</div>
107114
</article>
108115
};

packages/react-components/src/search/OccurrenceSearch/OccurrenceSearch.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const config = {
177177
labels,
178178
getSuggests,
179179
filters,
180-
occurrenceSearchTabs: ['TABLE', 'MAP', 'DATASETS', 'GALLERY'],
180+
occurrenceSearchTabs: ['CLUSTERS', 'TABLE', 'MAP', 'DATASETS', 'GALLERY'],
181181
// highlightedFilters: ['establishmentMeans'],
182182
// excludedFilters: ['locality'],
183183
availableCatalogues: ['OCCURRENCE', 'LITERATURE', 'COLLECTION'],

0 commit comments

Comments
 (0)