Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
turban committed Jun 22, 2024
2 parents 776cbd3 + 9f9fddf commit 52cb21d
Show file tree
Hide file tree
Showing 19 changed files with 2,601 additions and 1,981 deletions.
19 changes: 15 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
- package-ecosystem: npm
directory: /
schedule:
interval: 'weekly'
interval: weekly
open-pull-requests-limit: 5
versioning-strategy: 'increase'
versioning-strategy: increase
groups:
security:
applies-to: security-updates
update-types:
- minor
- patch
dependencies:
applies-to: version-updates
update-types:
- minor
- patch
39 changes: 39 additions & 0 deletions .github/workflows/copy-to-d2-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Copy build to d2-ci

on:
push:
branches-ignore:
- master
- dependabot/**

env:
GH_TOKEN: ${{secrets.DHIS2_BOT_GITHUB_TOKEN}}

jobs:
copy-to-d2-ci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
token: ${{env.GH_TOKEN}}

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build package
run: yarn build

- name: Pack and unpack the build to a directory named 'package'
run: yarn pack --filename output.tgz && tar -xzf output.tgz

- name: Copy package to d2-ci
uses: dhis2/deploy-build@master
with:
build-dir: package
github-token: ${{env.GH_TOKEN}}
6 changes: 3 additions & 3 deletions .github/workflows/node-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x

- name: Install
run: yarn install --frozen-lockfile
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
package-lock.json
build
build

# IDE
.vscode
4 changes: 0 additions & 4 deletions .hooks/commit-msg

This file was deleted.

4 changes: 0 additions & 4 deletions .hooks/pre-commit

This file was deleted.

1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn d2-style check --staged
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [3.9.2](https://github.com/dhis2/maps-gl/compare/v3.9.1...v3.9.2) (2024-06-06)


### Bug Fixes

* unclear 'show no data' ([#573](https://github.com/dhis2/maps-gl/issues/573)) ([1c31fcc](https://github.com/dhis2/maps-gl/commit/1c31fcc20b700e5dadeec1d6c6e4f82484f262f5))

## [3.9.1](https://github.com/dhis2/maps-gl/compare/v3.9.0...v3.9.1) (2024-03-13)


Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ Both of these commands will run the javascript files in the `src` directory thro

Publication is done automatically by a GitHub action for all commits on the `master` branch. Commits (including pull-request squashed commits) should follow the [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/) guidelines so that the release bot can determine which version to cut - breaking, feature, or bug

## Publishing pre-release versions during app development

Builds for all non-production branches are automatically copied to [d2-ci/maps-gl](https://github.com/d2-ci/maps-gl) for use during development and testing, prior to production release.

To test changes in a development branch, change the maps-gl dependency of package.json of the app you are testing with. There are a few options:

1. point to a specific commit:

```
"dependencies": {
"@dhis2/maps-gl": "git+https://github.com/d2-ci/maps-gl.git#70249ebe8be39051fa10142f850de449e1ec488c",
...
}
```

2. point to a branch:

```
"dependencies": {
"@dhis2/maps-gl": "git+https://github.com/d2-ci/maps-gl.git#chore/some-chore",
...
}
```

## Report an issue

The issue tracker can be found in [DHIS2 JIRA](https://jira.dhis2.org)
Expand Down
1 change: 1 addition & 0 deletions jest.stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ global.mockMapGL = {
getLayer: jest.fn(),
getSource: jest.fn(),
setFeatureState: jest.fn(),
_getUIString: jest.fn(),
}

global.mockMap = {
Expand Down
33 changes: 14 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/maps-gl",
"version": "3.9.1",
"version": "3.9.2",
"description": "A WebGL rendering engine for DHIS2 maps based on Mapbox GL JS.",
"publishConfig": {
"access": "public"
Expand All @@ -18,7 +18,7 @@
],
"license": "BSD-3-Clause",
"dependencies": {
"@google/earthengine": "^0.1.402",
"@google/earthengine": "^0.1.408",
"@mapbox/sphericalmercator": "^1.2.0",
"@turf/area": "^6.5.0",
"@turf/bbox": "^6.5.0",
Expand All @@ -27,32 +27,32 @@
"@turf/circle": "^6.5.0",
"@turf/length": "^6.5.0",
"comlink": "^4.4.1",
"fetch-jsonp": "^1.2.3",
"fetch-jsonp": "^1.3.0",
"lodash.throttle": "^4.1.1",
"maplibre-gl": "^2.4.0",
"polylabel": "^1.1.0",
"suggestions": "^1.7.1",
"uuid": "^9.0.0"
},
"devDependencies": {
"@babel/cli": "^7.21.0",
"@babel/core": "^7.21.0",
"@babel/cli": "^7.24.7",
"@babel/core": "^7.24.7",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-transform-runtime": "^7.21.0",
"@babel/preset-env": "^7.22.2",
"@babel/runtime": "^7.21.0",
"@dhis2/cli-style": "^10.5.1",
"@babel/plugin-transform-runtime": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/runtime": "^7.24.7",
"@dhis2/cli-style": "^10.7.3",
"@types/jest": "^29.4.0",
"babel-jest": "^29.5.0",
"babel-jest": "^29.7.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"concurrently": "^7.6.0",
"husky": "^8.0.3",
"husky": "^9.0.11",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.5.1",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"rimraf": "^5.0.1"
"rimraf": "^5.0.7"
},
"scripts": {
"format": "d2-style apply js --all --no-stage",
Expand All @@ -62,13 +62,8 @@
"build": "NODE_ENV=production yarn clean && yarn build:commonjs && yarn build:modules",
"watch": "NODE_ENV=development yarn clean && concurrently -n watch-cjs,watch-es \"yarn build:commonjs --watch\" \"yarn build:modules --watch\"",
"postinstall": "patch-package",
"test": "jest src/*"
},
"husky": {
"hooks": {
"commit-msg": "d2-style commit check",
"pre-commit": "d2-style apply js"
}
"test": "jest src/*",
"prepare": "husky"
},
"jest": {
"setupFiles": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/node_modules/@google/earthengine/build/browser.js b/node_modules/@google/earthengine/build/browser.js
index 1513223..18b6d65 100644
index 99457a7..e371e77 100644
--- a/node_modules/@google/earthengine/build/browser.js
+++ b/node_modules/@google/earthengine/build/browser.js
@@ -26821,6 +26821,12 @@ ee.data.Profiler.Format.JSON = new ee.data.Profiler.Format("json");
@@ -26828,6 +26828,12 @@ ee.data.Profiler.Format.JSON = new ee.data.Profiler.Format("json");
goog.global.EXPORTED_FN_INFO = exportedFnInfo;
})();

Expand Down
1 change: 1 addition & 0 deletions src/controls/controlsLocale.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const controlsLocale = {
'SearchControl.SearchForPlace': 'Search for place or address',
'FitBoundsControl.ZoomToContent': 'Zoom to content',
'HoverLabel.NoData': 'No data',
'MeasureControl.MeasureDistancesAndAreas': 'Measure distances and areas',
'MeasureControl.ClickStartMeasurement':
'Click where you want to start the measurement',
Expand Down
5 changes: 1 addition & 4 deletions src/earthengine/ee_worker_utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import ee from '@google/earthengine/build/browser.js' // this is a patched version of the ee module

const squareMetersToHectares = value => value / 10000

const squareMetersToAcres = value => value / 4046.8564224
import { squareMetersToHectares, squareMetersToAcres } from '../utils/numbers'

const classAggregation = ['percentage', 'hectares', 'acres']

Expand Down
1 change: 0 additions & 1 deletion src/layers/BingLayer.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/layers/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Layer extends Evented {
const layers = this.getLayers()
const beforeId = map.getBeforeLayerId()

this.locale = mapgl._getUIString.bind(mapgl)

if (images) {
try {
await addImages(mapgl, images)
Expand Down Expand Up @@ -343,7 +345,9 @@ class Layer extends Evented {
const { properties } = feature
const content = (hoverLabel || label).replace(
/\{ *([\w_-]+) *\}/g,
(str, key) => properties[key] || ''
(str, key) =>
properties[key] ||
(key === 'value' ? this.locale('HoverLabel.NoData') : '')
)

this._map.showLabel(content, evt.lngLat)
Expand Down
27 changes: 25 additions & 2 deletions src/utils/__tests__/numbers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import {
} from '../numbers'

describe('numbers', () => {
it('Should round number to x decimals', () => {
it('numberPrecision should round number to x decimals', () => {
const formatNumber = numberPrecision(3)

expect(formatNumber(123.342342342)).toBe(123.342)
expect(formatNumber(123.3456)).toBe(123.346)
expect(formatNumber(123.39)).toBe(123.39)
})

it('Should return decimal precision based on value', () => {
it('getPrecision should return decimal precision based on value', () => {
expect(getPrecision(542.312321312)).toBe(0)
expect(getPrecision(78.312321312)).toBe(1)
expect(getPrecision(8.312321312)).toBe(2)
Expand All @@ -40,4 +40,27 @@ describe('numbers', () => {
it('Should convert km to miles', () => {
expect(kmToMiles(1)).toBe(0.621371192)
})

describe('setPrecision', () => {
it('should set precision when no "precision" value provided', () => {
expect(setPrecision(542.312321312)).toBe(542)
expect(setPrecision(78.312321312)).toBe(78.3)
expect(setPrecision(8.312321312)).toBe(8.31)
expect(setPrecision(0.312321312)).toBe(0.312)
})
it('should set the precision of a positive number correctly', () => {
const result = setPrecision(123.456, 2)
expect(result).toEqual(123.46)
})

it('should set the precision of a negative number correctly', () => {
const result = setPrecision(-123.456, 2)
expect(result).toEqual(-123.46)
})

it('should handle zero correctly', () => {
const result = setPrecision(0, 2)
expect(result).toEqual(0)
})
})
})
6 changes: 4 additions & 2 deletions src/utils/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export const numberPrecision = d => {

const m = Math.pow(10, d)

console.log('numberPrecision', d, m)

return n => Math.round(n * m) / m
}

Expand All @@ -23,3 +21,7 @@ export const setPrecision = (value, precision) =>
)(value)

export const kmToMiles = value => value * 0.621371192

export const squareMetersToHectares = value => value / 10000

export const squareMetersToAcres = value => value / 4046.8564224
Loading

0 comments on commit 52cb21d

Please sign in to comment.