|
1 | 1 | import forEach from 'lodash/forEach';
|
2 | 2 | import { atom, atomFamily, selector, selectorFamily } from 'recoil';
|
3 | 3 |
|
4 |
| -import { InteractionLayer } from 'lib/data-map/types'; |
| 4 | +import { InteractionLayer, VectorTarget } from 'lib/data-map/types'; |
5 | 5 | import { isReset } from 'lib/recoil/is-reset';
|
6 | 6 | import { ApiClient } from 'lib/api-client';
|
7 | 7 |
|
@@ -90,6 +90,45 @@ export const selectedAssetDetails = selectorFamily({
|
90 | 90 | },
|
91 | 91 | });
|
92 | 92 |
|
| 93 | +export const protectedFeatureDetailsState = selector({ |
| 94 | + key: 'protectedFeatureDetails', |
| 95 | + get: async ({ get }) => { |
| 96 | + const selection = get(selectionState('assets')); |
| 97 | + const target = selection?.target as VectorTarget; |
| 98 | + if (!target?.feature?.id) { |
| 99 | + return null; |
| 100 | + } |
| 101 | + const featureDetails = await apiClient.features.featuresReadProtectedFeatures({ |
| 102 | + protectorId: target.feature.id, |
| 103 | + }); |
| 104 | + return featureDetails; |
| 105 | + }, |
| 106 | +}); |
| 107 | + |
| 108 | +export const protectedFeatureRCPState = selector({ |
| 109 | + key: 'protectedFeatureRCP', |
| 110 | + get: ({ get }) => new Set(get(protectedFeatureDetailsState)?.map((feature) => feature.rcp)), |
| 111 | +}); |
| 112 | + |
| 113 | +export const protectedFeatureProtectionLevelState = selector({ |
| 114 | + key: 'protectedFeatureProtectionLevel', |
| 115 | + get: ({ get }) => |
| 116 | + new Set( |
| 117 | + get(protectedFeatureDetailsState)?.map((feature) => feature.adaptation_protection_level), |
| 118 | + ), |
| 119 | +}); |
| 120 | + |
| 121 | +type ProtectedFeatureDetailsQuery = { rcp: number; protectionLevel: number }; |
| 122 | +export const protectedFeatureDetailsQuery = selectorFamily({ |
| 123 | + key: 'protectedFeatureDetailsQuery', |
| 124 | + get: |
| 125 | + ({ rcp, protectionLevel }: ProtectedFeatureDetailsQuery) => |
| 126 | + ({ get }) => |
| 127 | + get(protectedFeatureDetailsState).filter( |
| 128 | + (item) => item.rcp === rcp && item.adaptation_protection_level === protectionLevel, |
| 129 | + ), |
| 130 | +}); |
| 131 | + |
93 | 132 | type AllowedGroupLayers = Record<string, string[]>;
|
94 | 133 |
|
95 | 134 | const allowedGroupLayersImpl = atom<AllowedGroupLayers>({
|
|
0 commit comments