Skip to content

Commit a1d2549

Browse files
authored
Merge pull request #66 from mapswipe/fix/validate-image-datase-upload
2 parents 402cd27 + 035b772 commit a1d2549

File tree

20 files changed

+356
-166
lines changed

20 files changed

+356
-166
lines changed

app/components/domain/BaseMap/index.tsx

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import {
33
useMemo,
44
} from 'react';
55
import {
6+
isDefined,
67
isNotDefined,
78
listToMap,
9+
randomString,
810
} from '@togglecorp/fujs';
911
import Map from '@togglecorp/re-map';
1012
import { removeNull } from '@togglecorp/toggle-form';
@@ -47,49 +49,62 @@ function BaseMap(props: Props) {
4749

4850
const { raster: rasterTileServers } = useContext(TileServerContext);
4951

50-
const mapInfo = useMemo(() => {
51-
const rasterTileServerMapping = listToMap(
52-
rasterTileServers,
53-
({ type: tileType }) => tileType,
54-
);
52+
const rasterTileServerMapping = useMemo(() => listToMap(
53+
rasterTileServers,
54+
({ type: tileType }) => tileType,
55+
), [rasterTileServers]);
56+
57+
const name = baseTileServer?.name;
58+
const custom = name === RasterTileServerNameEnum.Custom
59+
? baseTileServer?.custom
60+
: undefined;
61+
62+
const tileUrl = isDefined(name) ? rasterTileServerMapping[name]?.url : undefined;
63+
const tileCredits = isDefined(name) ? rasterTileServerMapping[name]?.credits : undefined;
64+
const minZoom = isDefined(name) ? rasterTileServerMapping[name]?.minZoom : undefined;
65+
const maxZoom = isDefined(name) ? rasterTileServerMapping[name]?.maxZoom : undefined;
66+
67+
const baseTileServerDefined = isDefined(baseTileServer);
5568

56-
if (isNotDefined(baseTileServer)) {
69+
const mapInfo = useMemo(() => {
70+
if (!baseTileServerDefined) {
5771
return FALLBACK_TILE_URL;
5872
}
5973

60-
const { name } = baseTileServer;
61-
6274
if (isNotDefined(name)) {
63-
return {
64-
url: undefined,
65-
credits: undefined,
66-
minzoom: undefined,
67-
maxzoom: undefined,
68-
};
75+
return undefined;
6976
}
7077

7178
if (name === RasterTileServerNameEnum.Custom) {
79+
if (isNotDefined(custom)) {
80+
return undefined;
81+
}
82+
7283
return {
73-
url: baseTileServer.custom?.url,
74-
credits: baseTileServer.custom?.credits,
75-
minzoom: baseTileServer.custom?.minZoom,
76-
maxzoom: baseTileServer.custom?.maxZoom,
84+
url: custom.url,
85+
credits: custom.credits,
86+
minzoom: custom.minZoom,
87+
maxzoom: custom.maxZoom,
7788
};
7889
}
7990

8091
return {
81-
url: rasterTileServerMapping[name]?.url,
82-
credits: rasterTileServerMapping[name]?.credits,
83-
minzoom: baseTileServer.custom?.minZoom,
84-
maxzoom: baseTileServer.custom?.maxZoom,
92+
url: tileUrl,
93+
credits: tileCredits,
94+
minzoom: minZoom,
95+
maxzoom: maxZoom,
8596
};
86-
}, [baseTileServer, rasterTileServers]);
97+
}, [baseTileServerDefined, custom, maxZoom, minZoom, name, tileCredits, tileUrl]);
8798

8899
const mapStyle = useMemo(() => {
89100
if (typeof mapInfo === 'string') {
90101
return mapInfo;
91102
}
92103

104+
if (isNotDefined(mapInfo)) {
105+
return undefined;
106+
}
107+
93108
const result = type('string.url')(mapInfo.url);
94109

95110
if (result instanceof type.errors) {
@@ -128,8 +143,21 @@ function BaseMap(props: Props) {
128143
dragPan: !disablePan,
129144
}), [disablePan]);
130145

146+
const mapKey = useMemo(() => (
147+
// FIXME(frozenhelium): map key is added here
148+
// to completely destroy and create a new map
149+
// to avoid race condition while recreating layers and sources
150+
randomString()
151+
// eslint-disable-next-line react-hooks/exhaustive-deps
152+
), [mapStyle]);
153+
154+
if (isNotDefined(mapStyle)) {
155+
return null;
156+
}
157+
131158
return (
132159
<Map
160+
key={mapKey}
133161
mapStyle={mapStyle}
134162
mapOptions={mapOptions}
135163
>

app/components/domain/GeoJsonMapSource/index.tsx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {
22
ComponentProps,
3-
useEffect,
43
useMemo,
5-
useState,
64
} from 'react';
75
import { pointToTileFraction } from '@mapbox/tilebelt';
86
import {
@@ -16,7 +14,6 @@ import {
1614
MapSource,
1715
} from '@togglecorp/re-map';
1816

19-
import useDebouncedValue from '#hooks/useDebouncedValue';
2017
import {
2118
BoundingBox,
2219
getBbox,
@@ -102,16 +99,6 @@ function GeoJsonMapSource(props: Props) {
10299
fit = 'default',
103100
} = props;
104101

105-
// FIXME(frozenhelium): This is a hack to fix cases when layer is added before source
106-
const [mountLayer, setMountLayer] = useState(false);
107-
useEffect(
108-
() => {
109-
setMountLayer(isDefined(geoJson));
110-
},
111-
[geoJson],
112-
);
113-
const debouncedMounted = useDebouncedValue(mountLayer);
114-
115102
const bounds = useMemo(
116103
() => {
117104
if (isDefined(overrideBounds)) {
@@ -167,13 +154,11 @@ function GeoJsonMapSource(props: Props) {
167154
sourceOptions={geoJsonSourceOptions}
168155
geoJson={geoJson as GeoJSON.FeatureCollection}
169156
>
170-
{debouncedMounted && (
171-
<MapLayer
172-
key={layerKey}
173-
layerKey={layerKey}
174-
layerOptions={layerOptions}
175-
/>
176-
)}
157+
<MapLayer
158+
key={layerKey}
159+
layerKey={layerKey}
160+
layerOptions={layerOptions}
161+
/>
177162
</MapSource>
178163
)}
179164
{isNotDefined(zoomLevel) && isDefined(bounds) && (

app/components/domain/ProjectSpecificDetails/CompareDetails/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function CompareDetails(props: Props) {
4040
<DefaultMapContainer compact />
4141
<GeoJsonAssetMapSource
4242
geoJsonAssetId={data.aoiGeometry}
43-
zoomLevel={zoomView === 'zoomLevel' ? tileZ - 1 : undefined}
43+
zoomLevel={zoomView === 'zoomLevel' ? tileZ : undefined}
4444
withPadding={zoomView === 'aoiBounds'}
4545
defaultBounds={defaultBounds}
4646
/>
@@ -56,7 +56,7 @@ function CompareDetails(props: Props) {
5656
<DefaultMapContainer compact />
5757
<GeoJsonAssetMapSource
5858
geoJsonAssetId={data.aoiGeometry}
59-
zoomLevel={zoomView === 'zoomLevel' ? tileZ - 1 : undefined}
59+
zoomLevel={zoomView === 'zoomLevel' ? tileZ : undefined}
6060
withPadding={zoomView === 'aoiBounds'}
6161
defaultBounds={defaultBounds}
6262
/>

app/components/domain/ProjectSpecificDetails/CompletenessDetails/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function CompletenessDetails(props: Props) {
5151
/>
5252
<GeoJsonAssetMapSource
5353
geoJsonAssetId={data.aoiGeometry}
54-
zoomLevel={zoomView === 'zoomLevel' ? tileZ - 1 : undefined}
54+
zoomLevel={zoomView === 'zoomLevel' ? tileZ : undefined}
5555
withPadding={zoomView === 'aoiBounds'}
5656
defaultBounds={defaultBounds}
5757
/>

app/components/domain/ProjectSpecificDetails/FindDetails/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function FindDetails(props: Props) {
4343
<GeoJsonAssetMapSource
4444
geoJsonAssetId={data?.aoiGeometry}
4545
defaultBounds={defaultBounds}
46-
zoomLevel={zoomView === 'zoomLevel' ? tileZ - 1 : undefined}
46+
zoomLevel={zoomView === 'zoomLevel' ? tileZ : undefined}
4747
withPadding={zoomView === 'aoiBounds'}
4848
/>
4949
</BaseMap>

app/components/domain/RasterTileMapSource/index.tsx

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import {
22
ComponentProps,
33
useContext,
4-
useEffect,
54
useMemo,
6-
useState,
75
} from 'react';
86
import {
9-
isDefined,
107
isNotDefined,
118
listToMap,
129
} from '@togglecorp/fujs';
@@ -21,7 +18,6 @@ import {
2118
ProjectOverlayRasterTileServerConfig,
2219
RasterTileServerNameEnum,
2320
} from '#generated/types/graphql';
24-
import useDebouncedValue from '#hooks/useDebouncedValue';
2521
import { standardizeQuadKey } from '#utils/geo';
2622

2723
interface Props {
@@ -71,16 +67,6 @@ function RasterTileMapSource(props: Props) {
7167
};
7268
}, [tileConfig, rasterTileServers]);
7369

74-
// FIXME(frozenhelium): This is a hack to fix cases when layer is added before source
75-
const [mountLayer, setMountLayer] = useState(false);
76-
useEffect(
77-
() => {
78-
setMountLayer(isDefined(url));
79-
},
80-
[url],
81-
);
82-
const debouncedMounted = useDebouncedValue(mountLayer, 1000);
83-
8470
const sourceOptions = useMemo<ComponentProps<typeof MapSource>['sourceOptions']>(() => {
8571
if (isNotDefined(url)) {
8672
return undefined;
@@ -126,13 +112,11 @@ function RasterTileMapSource(props: Props) {
126112
sourceKey={sourceKey}
127113
sourceOptions={sourceOptions}
128114
>
129-
{debouncedMounted && (
130-
<MapLayer
131-
key={rasterLayerKey}
132-
layerKey={rasterLayerKey}
133-
layerOptions={rasterLayerOptions}
134-
/>
135-
)}
115+
<MapLayer
116+
key={rasterLayerKey}
117+
layerKey={rasterLayerKey}
118+
layerOptions={rasterLayerOptions}
119+
/>
136120
</MapSource>
137121
);
138122
}

app/components/domain/VectorTileMapSource/index.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {
22
ComponentProps,
33
useContext,
4-
useEffect,
54
useMemo,
6-
useState,
75
} from 'react';
86
import {
97
isDefined,
@@ -22,7 +20,6 @@ import {
2220
ProjectOverlayVectorTileServerConfig,
2321
VectorTileServerNameEnum,
2422
} from '#generated/types/graphql';
25-
import useDebouncedValue from '#hooks/useDebouncedValue';
2623

2724
interface Props {
2825
tileConfig: ProjectOverlayVectorTileServerConfig | undefined;
@@ -77,16 +74,6 @@ function VectorTileMapSource(props: Props) {
7774
};
7875
}, [tileConfig, vectorTileServers]);
7976

80-
// FIXME(frozenhelium): This is a hack to fix cases when layer is added before source
81-
const [mountLayer, setMountLayer] = useState(false);
82-
useEffect(
83-
() => {
84-
setMountLayer(isDefined(url));
85-
},
86-
[url],
87-
);
88-
const debouncedMounted = useDebouncedValue(mountLayer, 1000);
89-
9077
const sourceOptions = useMemo<ComponentProps<typeof MapSource>['sourceOptions']>(() => {
9178
if (isNotDefined(url)) {
9279
return undefined;
@@ -151,14 +138,14 @@ function VectorTileMapSource(props: Props) {
151138
sourceKey={sourceKey}
152139
sourceOptions={sourceOptions}
153140
>
154-
{debouncedMounted && isDefined(fillLayerOptions) && (
141+
{isDefined(fillLayerOptions) && (
155142
<MapLayer
156143
key={fillLayerKey}
157144
layerKey={fillLayerKey}
158145
layerOptions={fillLayerOptions}
159146
/>
160147
)}
161-
{debouncedMounted && isDefined(lineLayerOptions) && (
148+
{isDefined(lineLayerOptions) && (
162149
<MapLayer
163150
key={lineLayerKey}
164151
layerKey={lineLayerKey}

app/views/EditProject/ProjectActions/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function ProjectActions(props: Props) {
7777
alert.show(
7878
'Failed to update the Project status!',
7979
{
80-
description: 'Unexpectected response from the server!',
80+
description: 'Unexpected response from the server!',
8181
variant: 'danger',
8282
},
8383
);

app/views/EditProject/UpdateProcessedProjectForm/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ function UpdateProcessedProjectForm(props: Props) {
348348
)}
349349
<NonFieldError error={error} />
350350
<ProjectGeneralInputs
351-
name={projectData.project.name}
352351
projectType={projectData.project.projectType}
353352
value={value}
354353
setFieldValue={setFieldValue}

app/views/EditProject/UpdateProjectForm/CompareProjectSpecifics/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function CompareProjectSpecifics(props: Props) {
6969
setFieldValue={setTileServerInputFieldValue}
7070
disabled={disabled}
7171
aoiGeoJsonAssetId={value?.aoiGeometry}
72-
zoomLevel={isDefined(value?.zoomLevel) ? value.zoomLevel - 1 : undefined}
72+
zoomLevel={isDefined(value?.zoomLevel) ? value.zoomLevel : undefined}
7373
/>
7474
<RasterTileServerInput
7575
label="Tile server B"
@@ -78,7 +78,7 @@ function CompareProjectSpecifics(props: Props) {
7878
setFieldValue={setTileServerBInputFieldValue}
7979
disabled={disabled}
8080
aoiGeoJsonAssetId={value?.aoiGeometry}
81-
zoomLevel={isDefined(value?.zoomLevel) ? value.zoomLevel - 1 : undefined}
81+
zoomLevel={isDefined(value?.zoomLevel) ? value.zoomLevel : undefined}
8282
/>
8383
<ZoomLevelSelectInput
8484
name="zoomLevel"

0 commit comments

Comments
 (0)