Skip to content

Commit f860c72

Browse files
committed
chore(gadm): replace parseGadm36Id method name to parseGadmId
Let the method more version agnostic
1 parent 6a8efa2 commit f860c72

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

pages/dashboards/[[...location]].js

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import uniqBy from 'lodash/uniqBy';
77

88
import useRouter from 'utils/router';
99
import { decodeQueryParams } from 'utils/url';
10-
import { parseGadm36Id } from 'utils/gadm';
10+
import { parseGadmId } from 'utils/gadm';
1111
import { parseStringWithVars } from 'utils/strings';
1212

1313
import { getLocationData } from 'services/location';
@@ -183,8 +183,8 @@ export const getServerSideProps = async ({ params, query, req }) => {
183183
countryData = {
184184
...countryData,
185185
regions: uniqBy(regions.data).map((row) => ({
186-
id: parseGadm36Id(row.id).adm1,
187-
value: parseGadm36Id(row.id).adm1,
186+
id: parseGadmId(row.id).adm1,
187+
value: parseGadmId(row.id).adm1,
188188
label: row.name,
189189
name: row.name,
190190
})),
@@ -197,8 +197,8 @@ export const getServerSideProps = async ({ params, query, req }) => {
197197
countryData = {
198198
...countryData,
199199
subRegions: uniqBy(subRegions.data).map((row) => ({
200-
id: parseGadm36Id(row.id).adm2,
201-
value: parseGadm36Id(row.id).adm2,
200+
id: parseGadmId(row.id).adm2,
201+
value: parseGadmId(row.id).adm2,
202202
label: row.name,
203203
name: row.name,
204204
})),

pages/embed/sentence/[[...location]].js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
22
import PropTypes from 'prop-types';
33
import uniqBy from 'lodash/uniqBy';
44

5-
import { parseGadm36Id } from 'utils/gadm';
5+
import { parseGadmId } from 'utils/gadm';
66

77
import { getLocationData } from 'services/location';
88
import {
@@ -91,8 +91,8 @@ export const getServerSideProps = async ({ params }) => {
9191
countryData = {
9292
...countryData,
9393
regions: uniqBy(regions.data).map((row) => ({
94-
id: parseGadm36Id(row.id).adm1,
95-
value: parseGadm36Id(row.id).adm1,
94+
id: parseGadmId(row.id).adm1,
95+
value: parseGadmId(row.id).adm1,
9696
label: row.name,
9797
name: row.name,
9898
})),
@@ -105,8 +105,8 @@ export const getServerSideProps = async ({ params }) => {
105105
countryData = {
106106
...countryData,
107107
subRegions: uniqBy(subRegions.data).map((row) => ({
108-
id: parseGadm36Id(row.id).adm2,
109-
value: parseGadm36Id(row.id).adm2,
108+
id: parseGadmId(row.id).adm2,
109+
value: parseGadmId(row.id).adm2,
110110
label: row.name,
111111
name: row.name,
112112
})),

providers/country-data-provider/actions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createAction, createThunkAction } from 'redux/actions';
2-
import { parseGadm36Id } from 'utils/gadm';
2+
import { parseGadmId } from 'utils/gadm';
33
import uniqBy from 'lodash/uniqBy';
44

55
import {
@@ -49,7 +49,7 @@ export const getRegions = createThunkAction(
4949
const parsedResponse = [];
5050
uniqBy(response.data).forEach((row) => {
5151
parsedResponse.push({
52-
id: parseGadm36Id(row.id).adm1,
52+
id: parseGadmId(row.id).adm1,
5353
name: row.name,
5454
});
5555
});
@@ -73,7 +73,7 @@ export const getSubRegions = createThunkAction(
7373
const parsedResponse = [];
7474
uniqBy(rows).forEach((row) => {
7575
parsedResponse.push({
76-
id: parseGadm36Id(row.id).adm2,
76+
id: parseGadmId(row.id).adm2,
7777
name: row.name,
7878
});
7979
});

utils/gadm.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const getGadm36Id = (country, region, subRegion) =>
33
subRegion ? `.${subRegion}_1` : '_1'
44
}`;
55

6-
export const parseGadm36Id = (gid) => {
6+
export const parseGadmId = (gid) => {
77
if (!gid) return null;
88

99
const ids = gid.split('.');
@@ -26,6 +26,6 @@ export const parseGadm36Id = (gid) => {
2626
export const getGadmLocationByLevel = ({ adm_level, ...location }) => ({
2727
type: 'country',
2828
...(location?.gid_0 && {
29-
...parseGadm36Id(location[`gid_${adm_level || '0'}`]),
29+
...parseGadmId(location[`gid_${adm_level || '0'}`]),
3030
}),
3131
});

0 commit comments

Comments
 (0)