From a215c29cff235c8364cc27163b48d91f24a75aee Mon Sep 17 00:00:00 2001 From: Suren Date: Mon, 21 Oct 2024 07:13:03 -0700 Subject: [PATCH] #193: Update to the latest MapStore 2024.02 (#194) * #193: Update to the latest MapStore 2024.02 * fix workflow yaml * index.html updated * Update build and tests files to work properly * Update cadastrapp.yml --------- Co-authored-by: Lorenzo Natali --- .github/workflows/cadastrapp.yml | 9 +-- .npmrc | 2 + MapStore2 | 2 +- build/extension/prod-webpack.config.js | 11 ++- index.html | 5 -- js/extension/epics/__tests__/events-test.js | 15 ++-- js/extension/epics/events.js | 13 ++-- js/extension/utils/__tests__/download-test.js | 8 ++- js/extension/utils/download.js | 71 ++++++++++--------- package.json | 22 +++--- proxyConfig.js | 9 +-- version.txt | 2 +- webpack.config.js | 2 +- 13 files changed, 91 insertions(+), 80 deletions(-) create mode 100644 .npmrc diff --git a/.github/workflows/cadastrapp.yml b/.github/workflows/cadastrapp.yml index 7ba86f2..d14d04b 100644 --- a/.github/workflows/cadastrapp.yml +++ b/.github/workflows/cadastrapp.yml @@ -16,7 +16,7 @@ jobs: - name: "setting up npm" uses: actions/setup-node@v1 with: - node-version: '12.x' + node-version: '16.x' - name: "cache node modules" uses: actions/cache@v1 @@ -37,19 +37,20 @@ jobs: run: npm run ext:build - name: "publish zip as artifact" - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v4 with: name: Cadastrapp-${{ github.sha }} path: dist/Cadastrapp.zip - name: "change webpack config to avoid minification" - run: sed -i -e 's/prod: true/prod: false/' build/extension/prod-webpack.config.js + run: | + sed -i -e 's/prod: true/prod: false/' build/extension/prod-webpack.config.js - name: "build unminified" run: npm run ext:build - name: "publish zip as artifact" - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v4 with: name: Cadastrapp-unminified-${{ github.sha }} path: dist/Cadastrapp.zip diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..2051cce --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +# add legacy peer dependency flag on npm install +legacy-peer-deps=true \ No newline at end of file diff --git a/MapStore2 b/MapStore2 index b81c200..453cd13 160000 --- a/MapStore2 +++ b/MapStore2 @@ -1 +1 @@ -Subproject commit b81c200fdb11ed8690625df96065066084e9fbd0 +Subproject commit 453cd13c1e6319ddc083f09528650a3934ae0cbf diff --git a/build/extension/prod-webpack.config.js b/build/extension/prod-webpack.config.js index 0e4629d..bf61990 100644 --- a/build/extension/prod-webpack.config.js +++ b/build/extension/prod-webpack.config.js @@ -37,6 +37,15 @@ const fileLoader = { } }] }; +const urlLoader = { + test: /\.woff(2)?(\?v=[0-9].[0-9].[0-9])?$/, + use: [{ + loader: 'url-loader', + options: { + mimetype: "application/font-woff" + } + }] +}; const {module: moduleObj, ...extensionConfig} = createExtensionWebpackConfig({ prod: true, name, ...commons, plugins}); // Temp fix to return errors for leaflet // TODO: wait for a fix on mapstore createExtensionWebpackConfig @@ -50,4 +59,4 @@ const rules = [{ }, ...moduleObj.rules[0].use.slice(1)] }, ...moduleObj.rules.slice(1)]; -module.exports = { ...extensionConfig, module: { ...moduleObj, rules: [...rules, fileLoader] } }; +module.exports = { ...extensionConfig, module: { ...moduleObj, rules: [...rules, fileLoader, urlLoader] } }; diff --git a/index.html b/index.html index daee87d..f21ce6f 100644 --- a/index.html +++ b/index.html @@ -83,14 +83,9 @@ } - - - - - diff --git a/js/extension/epics/__tests__/events-test.js b/js/extension/epics/__tests__/events-test.js index 907974b..e6bf06d 100644 --- a/js/extension/epics/__tests__/events-test.js +++ b/js/extension/epics/__tests__/events-test.js @@ -10,8 +10,8 @@ import { testEpic } from "@mapstore/epics/__tests__/epicTestUtils"; import {saveAsAnnotation} from "../../actions/cadastrapp"; import {CADASTRAPP_VECTOR_LAYER_ID} from "@js/extension/constants"; import {cadastrappSaveAsAnnotation} from "@js/extension/epics/events"; -import {SET_CONTROL_PROPERTY} from "@mapstore/actions/controls"; -import {NEW_ANNOTATION, SET_EDITING_FEATURE} from "@mapstore/actions/annotations"; +import { ADD_LAYER } from "@mapstore/actions/layers"; +import { EDIT_ANNOTATION } from "@mapstore/plugins/Annotations/actions/annotations"; describe("download Epics", () => { const state = { @@ -86,17 +86,16 @@ describe("download Epics", () => { it("cadastrappSaveAsAnnotation", done => { testEpic( cadastrappSaveAsAnnotation, - 3, + 2, saveAsAnnotation(), actions => { - expect(actions.length).toBe(3); + expect(actions.length).toBe(2); actions.map(action=>{ switch (action.type) { - case SET_CONTROL_PROPERTY: - case NEW_ANNOTATION: + case ADD_LAYER: break; - case SET_EDITING_FEATURE: - expect(action.feature.features.length).toBe(2); + case EDIT_ANNOTATION: + expect(action.id).toBeTruthy(); break; default: expect(false).toBe(true); diff --git a/js/extension/epics/events.js b/js/extension/epics/events.js index 34ef8fd..13c82eb 100644 --- a/js/extension/epics/events.js +++ b/js/extension/epics/events.js @@ -3,9 +3,9 @@ import {SAVE_AS_ANNOTATION, ZOOM_TO_SELECTION} from '../actions/cadastrapp'; import {getCadastrappVectorLayer, getCurrentPlotFeatures, getSelectedFeatures} from '../selectors/cadastrapp'; import { zoomToExtent } from '@mapstore/actions/map'; import bbox from '@turf/bbox'; -import {convertFeaturesToAnnotation} from "@js/extension/utils/download"; -import {setControlProperty} from "@mapstore/actions/controls"; -import {newAnnotation, setEditingFeature} from "@mapstore/actions/annotations"; +import { convertFeaturesToAnnotationLayer } from "@js/extension/utils/download"; +import { editAnnotation } from "@mapstore/plugins/Annotations/actions/annotations"; +import { addLayer } from '@mapstore/actions/layers'; /** @@ -30,11 +30,10 @@ export function cadastrappZoomToSelection(action$, store) { export function cadastrappSaveAsAnnotation(action$, store) { return action$.ofType(SAVE_AS_ANNOTATION).switchMap(() => { const state = store.getState(); - const collection = convertFeaturesToAnnotation(getCadastrappVectorLayer(state), state); + const layer = convertFeaturesToAnnotationLayer(getCadastrappVectorLayer(state), state); return Rx.Observable.of( - setControlProperty('annotations', 'enabled', true), - newAnnotation(), - setEditingFeature(collection) + addLayer(layer), + editAnnotation(layer.id) ); }); } diff --git a/js/extension/utils/__tests__/download-test.js b/js/extension/utils/__tests__/download-test.js index fea20a0..f52b0ab 100644 --- a/js/extension/utils/__tests__/download-test.js +++ b/js/extension/utils/__tests__/download-test.js @@ -1,8 +1,9 @@ import expect from 'expect'; -import {convertFeaturesToAnnotation} from "@js/extension/utils/download"; +import {convertFeaturesToAnnotationLayer} from "@js/extension/utils/download"; +import { ANNOTATIONS } from '@mapstore/utils/LegacyAnnotationsUtils'; describe('download utils', () => { - it("convertFeaturesToAnnotation", () => { + it("convertFeaturesToAnnotationLayer", () => { const state = { cadastrapp: { configuration: @@ -67,10 +68,11 @@ describe('download utils', () => { ] }; - const converted = convertFeaturesToAnnotation(layer, state); + const converted = convertFeaturesToAnnotationLayer(layer, state); expect(converted.features[0].geometry.type).toBe('Polygon'); expect(converted.features[1].geometry.type).toBe(layer.features[1].geometry.type); expect(converted.features[0].properties.geometryTitle).toBe('SomeTitle'); expect(converted.features[1].properties.geometryTitle).toBe('SomeTitle2'); + expect(converted.rowViewer).toBe(ANNOTATIONS); }); }); diff --git a/js/extension/utils/download.js b/js/extension/utils/download.js index a6b58e6..2712fdc 100644 --- a/js/extension/utils/download.js +++ b/js/extension/utils/download.js @@ -4,6 +4,7 @@ import {validateFeatureCoordinates} from "@mapstore/utils/MeasureUtils"; import {cadastreLayerIdParcelle} from "@js/extension/selectors/cadastrapp"; import {getMessageById} from "@mapstore/utils/LocaleUtils"; import {currentMessagesSelector} from "@mapstore/selectors/locale"; +import {ANNOTATIONS, createAnnotationId} from '@mapstore/plugins/Annotations/utils/AnnotationsUtils'; export const toDownload = ({ fileName, mimeType }) => (response) => { const dataUrl = window.URL.createObjectURL(new Blob([response.data], { type: mimeType })); @@ -48,46 +49,46 @@ export function downloadResponse(response, { fileName = 'unknown' } = {}) { * @param state * @returns object */ -export const convertFeaturesToAnnotation = (vectorLayer, state) => { - const id = uuidv1(); +export const convertFeaturesToAnnotationLayer = (vectorLayer, state) => { + const id = createAnnotationId(uuidv1()); return { - type: "FeatureCollection", + type: "vector", features: [ - ...(vectorLayer?.features ?? []).map(feature => ({ - type: 'Feature', - geometry: { - type: feature.geometry.type === 'MultiPolygon' ? 'Polygon' : feature.geometry.type, - coordinates: feature.geometry.type === 'MultiPolygon' - ? validateFeatureCoordinates({coordinates: feature.geometry.coordinates[0], type: 'Polygon'}) - : validateFeatureCoordinates(feature.geometry), - textLabels: feature.geometry.textLabels - }, - properties: { - id: uuidv1(), - isValidFeature: true, - geometryTitle: feature.properties[cadastreLayerIdParcelle(state)], - values: feature.properties?.values || [] - }, - style: [{ - ...feature.style, - type: feature.geometry.type, - id: uuidv1(), - geometry: null, - title: `${feature.geometry.type} Style`, - filtering: true - }] - })) + ...(vectorLayer?.features ?? []).map(feature => { + const geomType = feature.geometry.type === 'MultiPolygon' ? 'Polygon' : feature.geometry.type; + return { + type: 'Feature', + geometry: { + type: geomType, + coordinates: feature.geometry.type === 'MultiPolygon' + ? validateFeatureCoordinates({coordinates: feature.geometry.coordinates[0], type: 'Polygon'}) + : validateFeatureCoordinates(feature.geometry), + textLabels: feature.geometry.textLabels + }, + properties: { + id: uuidv1(), + isValidFeature: true, + geometryTitle: feature.properties[cadastreLayerIdParcelle(state)], + values: feature.properties?.values || [], + annotationType: geomType, + name: geomType + }, + style: [{ + ...feature.style, + type: feature.geometry.type, + id: uuidv1(), + geometry: null, + title: `${feature.geometry.type} Style`, + filtering: true + }] + }; + }) ], - properties: { - id, - description: '', - type: 'Cadastrapp', - title: getMessageById(currentMessagesSelector(state), "cadastrapp.result.parcelle.selectedPlots"), - iconGlyph: 'geometry-collection' - }, id, + description: '', + title: getMessageById(currentMessagesSelector(state), "cadastrapp.result.parcelle.selectedPlots"), style: {}, - newFeature: true, + rowViewer: ANNOTATIONS, visibility: true }; }; diff --git a/package.json b/package.json index 767e550..7079f19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "CadastrappExtension", - "version": "1.0.0", + "version": "2.2.0", "description": "Cadastrapp plugin for mapstore2", "main": "index.js", "eslintConfig": { @@ -31,7 +31,8 @@ "@geosolutions/acorn-jsx": "4.0.2", "@geosolutions/jsdoc": "3.4.4", "@geosolutions/mocha": "6.2.1-3", - "@mapstore/eslint-config-mapstore": "1.0.3", + "@mapstore/eslint-config-mapstore": "1.0.5", + "@testing-library/react": "12.1.5", "axios-mock-adapter": "1.16.0", "babel-loader": "8.0.5", "babel-plugin-add-module-exports": "0.1.4", @@ -39,7 +40,7 @@ "babel-plugin-object-assign": "1.2.1", "babel-plugin-react-transform": "2.0.2", "babel-plugin-transform-imports": "2.0.0", - "copy-webpack-plugin": "^5.1.2", + "copy-webpack-plugin": "5.0.2", "css-loader": "5.1.2", "css-minimizer-webpack-plugin": "3.0.2", "denodeify": "1.2.1", @@ -54,8 +55,8 @@ "expect": "1.20.1", "file-loader": "2.0.0", "glob": "7.1.1", - "html-loader": "0.5.1", - "html-webpack-plugin": "4.5.0", + "html-loader": "2.0.0", + "html-webpack-plugin": "5.2.0", "jsdoc-jsx": "0.1.0", "karma": "6.4.0", "karma-chrome-launcher": "3.1.1", @@ -68,9 +69,10 @@ "karma-mocha": "2.0.1", "karma-mocha-reporter": "2.2.5", "karma-sourcemap-loader": "0.3.8", - "karma-webpack": "^5.0.0-alpha.5", + "karma-webpack": "5.0.0", "less": "4.1.1", "less-loader": "8.0.0", + "markdownlint-cli": "0.34.0", "mini-css-extract-plugin": "1.3.9", "mkdirp": "0.5.1", "ncp": "2.0.0", @@ -92,14 +94,14 @@ "rimraf": "2.5.2", "simple-git": "2.20.1", "style-loader": "2.0.0", + "terser": "5.18.1", "url-loader": "0.5.7", "vusion-webfonts-generator": "0.4.1", - "webpack": "5.9.0", + "webpack": "5.54.0", "webpack-bundle-size-analyzer": "2.0.2", "webpack-cli": "4.10.0", "webpack-dev-server": "3.11.0", - "zip-webpack-plugin": "^3.0.0", - "git-revision-webpack-plugin": "5.0.0" + "zip-webpack-plugin": "3.0.0" }, "dependencies": { "mapstore2": "file:MapStore2" @@ -119,4 +121,4 @@ }, "author": "GeoSolutions", "license": "BSD-2-Clause" -} +} \ No newline at end of file diff --git a/proxyConfig.js b/proxyConfig.js index 1797c27..6778234 100644 --- a/proxyConfig.js +++ b/proxyConfig.js @@ -2,7 +2,7 @@ const DEV_PROTOCOL = "http"; const DEV_HOST = "localhost:8080"; -const cookie = "_hp2_props.2826793817=%7B%22account_state%22%3A%22active%22%7D; _hp2_id.2826793817=%7B%22userId%22%3A%221499114905535127%22%2C%22pageviewId%22%3A%222428177607153135%22%2C%22sessionId%22%3A%222201495479166025%22%2C%22identity%22%3A%223635521%22%2C%22trackerVersion%22%3A%224.0%22%2C%22identityField%22%3Anull%2C%22isIdentified%22%3A1%7D; _ga=GA1.2.418248975.1607951243; JSESSIONID=node0zn0cohqg5jw2qn4nddqynxiw70196.node0"; +const cookie = "JSESSIONID=node0fieai9vvjzcv1uhtlkbbmp7jt4043608.node0"; module.exports = { "/rest": { target: `${DEV_PROTOCOL}://${DEV_HOST}/mapstore`, @@ -26,11 +26,12 @@ module.exports = { } }, "/proxy": { - target: `https://dev.mapstore.geo-solutions.it/mapstore`, + target: `${DEV_PROTOCOL}://${DEV_HOST}/mapstore/`, secure: false }, "/mapstore/proxy": { - target: `https://dev.mapstore.geo-solutions.it`, + target: `${DEV_PROTOCOL}://${DEV_HOST}`, + secure: false }, "/geonetwork": { @@ -60,4 +61,4 @@ module.exports = { } } -}; \ No newline at end of file +}; diff --git a/version.txt b/version.txt index 81f8c9d..632e483 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -MapStoreExtension-1.0.0 \ No newline at end of file +MapStoreExtension-2.2.0 \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 12df863..606e1ac 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -34,6 +34,6 @@ const cfg = buildConfig( proxyConfig ); // stream are needed here in code -cfg.resolve.fallback = {timers: false}; +cfg.resolve.fallback = {timers: false, http: false, https: false, stream: false, zlib: false}; cfg.devtool = "eval-source-map"; module.exports = cfg;