forked from 52North/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detailviewer.js
44 lines (41 loc) · 1.43 KB
/
detailviewer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Copyright 2023, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import { Observable } from 'rxjs';
import isEmpty from 'lodash/isEmpty';
import { getLinkedResourcesByPk } from '@js/api/geonode/v2';
import {
updateResourceProperties,
SET_RESOURCE
} from '@js/actions/gnresource';
import { getResourceData } from '@js/selectors/resource';
/**
* Get linked resources
*/
export const gnGetLinkedResources = (action$, store) =>
action$.ofType(SET_RESOURCE)
.filter((action) =>
!action.pending && action.data?.pk && isEmpty(getResourceData(store.getState())?.linkedResources)
)
.switchMap((action) =>
Observable.defer(() =>
getLinkedResourcesByPk(action.data.pk)
.then((linkedResources) => {
const linkedTo = linkedResources.linked_to ?? [];
const linkedBy = linkedResources.linked_by ?? [];
return isEmpty(linkedTo) && isEmpty(linkedBy) ? {} : ({ linkedTo, linkedBy });
})
.catch(() => {})
).switchMap((linkedResources) =>
Observable.of(
updateResourceProperties({linkedResources})
)
)
);
export default {
gnGetLinkedResources
};