diff --git a/.env b/.env new file mode 100644 index 0000000..4f65262 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +JEST_USE_SETUP=ON \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..0cbd65c --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,65 @@ +const fs = require('fs'); +const path = require('path'); +const projectRootPath = fs.realpathSync(__dirname + '/../../../'); + +let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto'); +let configFile; +if (fs.existsSync(`${projectRootPath}/tsconfig.json`)) + configFile = `${projectRootPath}/tsconfig.json`; +else if (fs.existsSync(`${projectRootPath}/jsconfig.json`)) + configFile = `${projectRootPath}/jsconfig.json`; + +if (configFile) { + const jsConfig = require(configFile).compilerOptions; + const pathsConfig = jsConfig.paths; + if (pathsConfig['@plone/volto']) + voltoPath = `./${jsConfig.baseUrl}/${pathsConfig['@plone/volto'][0]}`; +} + +const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`); +const reg = new AddonConfigurationRegistry(projectRootPath); + +// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons +const addonAliases = Object.keys(reg.packages).map((o) => [ + o, + reg.packages[o].modulePath, +]); + +const addonExtenders = reg.getEslintExtenders().map((m) => require(m)); + +const defaultConfig = { + extends: `${voltoPath}/.eslintrc`, + settings: { + 'import/resolver': { + alias: { + map: [ + ['@plone/volto', '@plone/volto/src'], + ['@plone/volto-slate', '@plone/volto/packages/volto-slate/src'], + ...addonAliases, + ['@package', `${__dirname}/src`], + ['@root', `${__dirname}/src`], + ['~', `${__dirname}/src`], + ], + extensions: ['.js', '.jsx', '.json'], + }, + 'babel-plugin-root-import': { + rootPathSuffix: 'src', + }, + }, + }, + rules: { + 'react/jsx-no-target-blank': [ + 'error', + { + allowReferrer: true, + }, + ], + } +}; + +const config = addonExtenders.reduce( + (acc, extender) => extender.modify(acc), + defaultConfig, +); + +module.exports = config; diff --git a/.project.eslintrc.js b/.project.eslintrc.js deleted file mode 100644 index a74f790..0000000 --- a/.project.eslintrc.js +++ /dev/null @@ -1,47 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -const projectRootPath = fs.existsSync('./project') - ? fs.realpathSync('./project') - : fs.realpathSync('./../../../'); -const packageJson = require(path.join(projectRootPath, 'package.json')); -const jsConfig = require(path.join(projectRootPath, 'jsconfig.json')) - .compilerOptions; - -const pathsConfig = jsConfig.paths; - -let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto'); - -Object.keys(pathsConfig).forEach((pkg) => { - if (pkg === '@plone/volto') { - voltoPath = `./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`; - } -}); -const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`); -const reg = new AddonConfigurationRegistry(projectRootPath); - -// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons -const addonAliases = Object.keys(reg.packages).map((o) => [ - o, - reg.packages[o].modulePath, -]); - -module.exports = { - extends: `${projectRootPath}/node_modules/@plone/volto/.eslintrc`, - settings: { - 'import/resolver': { - alias: { - map: [ - ['@plone/volto', '@plone/volto/src'], - ...addonAliases, - ['@package', `${__dirname}/src`], - ['~', `${__dirname}/src`], - ], - extensions: ['.js', '.jsx', '.json'], - }, - 'babel-plugin-root-import': { - rootPathSuffix: 'src', - }, - }, - }, -}; diff --git a/CHANGELOG.md b/CHANGELOG.md index ae95265..415d1f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). -### [7.2.0](https://github.com/eea/volto-tableau/compare/7.1.0...7.2.0) - 17 January 2024 +### [7.2.1](https://github.com/eea/volto-tableau/compare/7.2.0...7.2.1) - 31 January 2024 -#### :rocket: New Features +#### :hammer_and_wrench: Others -- feat: show embed error + always show sources [Razvan - [`c1df7a2`](https://github.com/eea/volto-tableau/commit/c1df7a221c427705e29bcd45d621666973e12edb)] +- fix tests [Razvan - [`e370ea4`](https://github.com/eea/volto-tableau/commit/e370ea49343f52b1a07dbe402ce48c9ef53b6a7b)] +- fix eslint [Razvan - [`82f9311`](https://github.com/eea/volto-tableau/commit/82f9311fadd7c269321c23d4a3e029c2d5a133c6)] +- test: Update jest,Jenkinsfile,lint to volto-addons-template PR30 [valentinab25 - [`6a19c5c`](https://github.com/eea/volto-tableau/commit/6a19c5ceaf229d944f3f15ee32a833ae37619d74)] +- fallbacks [Razvan - [`efcc619`](https://github.com/eea/volto-tableau/commit/efcc6196c454df58cb83801297332fd2d98edd97)] +### [7.2.0](https://github.com/eea/volto-tableau/compare/7.1.0...7.2.0) - 17 January 2024 #### :bug: Bug Fixes diff --git a/Jenkinsfile b/Jenkinsfile index 5418a15..5fe237b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -162,10 +162,16 @@ pipeline { script { try { sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' - sh '''docker run -d --shm-size=3g --link $IMAGE_NAME-plone:plone --name="$IMAGE_NAME-cypress" -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend start-ci''' + sh '''docker run -d --shm-size=4g --link $IMAGE_NAME-plone:plone --name="$IMAGE_NAME-cypress" -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend start-ci''' + frontend = sh script:'''docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress make check-ci''', returnStatus: true + if ( frontend != 0 ) { + sh '''docker logs $IMAGE_NAME-cypress; exit 1''' + } + sh '''timeout -s 9 1800 docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress make cypress-ci''' } finally { try { + if ( frontend == 0 ) { sh '''rm -rf cypress-videos cypress-results cypress-coverage cypress-screenshots''' sh '''mkdir -p cypress-videos cypress-results cypress-coverage cypress-screenshots''' videos = sh script: '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/videos cypress-videos/''', returnStatus: true @@ -189,6 +195,7 @@ pipeline { sh '''for file in $(find cypress-results -name *.xml); do if [ $(grep -E 'failures="[1-9].*"' $file | wc -l) -eq 0 ]; then testname=$(grep -E 'file=.*failures="0"' $file | sed 's#.* file=".*\\/\\(.*\\.[jsxt]\\+\\)" time.*#\\1#' ); rm -f cypress-videos/videos/$testname.mp4; fi; done''' archiveArtifacts artifacts: 'cypress-videos/**/*.mp4', fingerprint: true, allowEmptyArchive: true } + } } finally { catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true diff --git a/Makefile b/Makefile index efbf2fb..c583f3f 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ cypress-open: ## Open cypress integration tests .PHONY: cypress-run cypress-run: ## Run cypress integration tests - CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run --browser chromium + CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run .PHONY: test test: ## Run jest tests @@ -155,8 +155,11 @@ start-ci: cd ../.. yarn start +.PHONY: check-ci +check-ci: + $(NODE_MODULES)/.bin/wait-on -t 240000 http://localhost:3000 + .PHONY: cypress-ci cypress-ci: $(NODE_MODULES)/.bin/wait-on -t 240000 http://localhost:3000 - NODE_ENV=development make cypress-run - + CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run --browser chromium diff --git a/jest-addon.config.js b/jest-addon.config.js index f536e87..d91297b 100644 --- a/jest-addon.config.js +++ b/jest-addon.config.js @@ -1,3 +1,5 @@ +require('dotenv').config({ path: __dirname + '/.env' }) + module.exports = { testMatch: ['**/src/addons/**/?(*.)+(spec|test).[jt]s?(x)'], collectCoverageFrom: [ @@ -13,6 +15,8 @@ module.exports = { '@root/(.*)$': '/node_modules/@plone/volto/src/$1', '@plone/volto-quanta/(.*)$': '/src/addons/volto-quanta/src/$1', '@eeacms/(.*?)/(.*)$': '/node_modules/@eeacms/$1/src/$2', + '@plone/volto-slate$': + '/node_modules/@plone/volto/packages/volto-slate/src', '@plone/volto-slate/(.*)$': '/node_modules/@plone/volto/packages/volto-slate/src/$1', '~/(.*)$': '/src/$1', @@ -36,7 +40,9 @@ module.exports = { statements: 5, }, }, - setupFilesAfterEnv: [ - '/node_modules/@eeacms/volto-tableau/jest.setup.js', - ], -}; + ...(process.env.JEST_USE_SETUP === 'ON' && { + setupFilesAfterEnv: [ + '/node_modules/@eeacms/volto-tableau/jest.setup.js', + ], + }), +} diff --git a/package.json b/package.json index 27c1a05..6573bff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eeacms/volto-tableau", - "version": "7.2.0", + "version": "7.2.1", "description": "@eeacms/volto-tableau: Volto add-on", "main": "src/index.js", "author": "European Environment Agency: IDM2 A-Team", @@ -32,7 +32,8 @@ "babel-plugin-transform-class-properties": "^6.24.1", "husky": "^8.0.3", "lint-staged": "^14.0.1", - "md5": "^2.3.0" + "md5": "^2.3.0", + "dotenv": "^16.3.2" }, "lint-staged": { "src/**/*.{js,jsx,ts,tsx,json}": [ diff --git a/src/Blocks/EmbedTableauVisualization/__snapshots__/Edit.test.jsx.snap b/src/Blocks/EmbedTableauVisualization/__snapshots__/Edit.test.jsx.snap index cc82a22..c1d583c 100644 --- a/src/Blocks/EmbedTableauVisualization/__snapshots__/Edit.test.jsx.snap +++ b/src/Blocks/EmbedTableauVisualization/__snapshots__/Edit.test.jsx.snap @@ -82,7 +82,7 @@ Array [ > CSS height diff --git a/src/Blocks/EmbedTableauVisualization/schema.js b/src/Blocks/EmbedTableauVisualization/schema.js index 19abe0d..a1caa3b 100644 --- a/src/Blocks/EmbedTableauVisualization/schema.js +++ b/src/Blocks/EmbedTableauVisualization/schema.js @@ -155,7 +155,7 @@ export default (props) => { tableau_height: { title: ( diff --git a/src/Tableau/helpers.js b/src/Tableau/helpers.js index bc6e255..2a04d47 100644 --- a/src/Tableau/helpers.js +++ b/src/Tableau/helpers.js @@ -28,8 +28,8 @@ export function getQuery({ export function getTableauVisualization({ isBlock, data, - tableauContent, - content, + tableauContent = {}, + content = {}, }) { const mergedContent = (isBlock @@ -37,12 +37,12 @@ export function getTableauVisualization({ : { ...content, tableau_visualization: { - ...(content?.tableau_visualization || {}), + ...(content.tableau_visualization || {}), ...pickMetadata(content), }, }) || {}; const tableau_visualization = - mergedContent?.tableau_visualization || data?.tableau_visualization || {}; + mergedContent.tableau_visualization || data?.tableau_visualization || {}; return { ...tableau_visualization, ...(isBlock ? pickMetadata(mergedContent) : {}), diff --git a/src/Widgets/VisualizationWidget.jsx b/src/Widgets/VisualizationWidget.jsx index 36efc7e..825dd89 100644 --- a/src/Widgets/VisualizationWidget.jsx +++ b/src/Widgets/VisualizationWidget.jsx @@ -19,6 +19,7 @@ import '@eeacms/volto-tableau/less/tableau.less'; const VisualizationWidget = (props) => { const { location, content } = props; + const ogValue = props.value || {}; const viz = React.useRef(); const [schema, setSchema] = React.useState(null); const [vizState, setVizState] = React.useState({ @@ -27,7 +28,7 @@ const VisualizationWidget = (props) => { error: null, }); const [open, setOpen] = React.useState(false); - const [value, setValue] = React.useState(props.value); + const [value, setValue] = React.useState(ogValue); const [tableauVisualization, setTableauVisualization] = useState(() => getTableauVisualization({ @@ -57,13 +58,13 @@ const VisualizationWidget = (props) => { }; const handleClose = () => { - setValue(props.value); + setValue(ogValue); setOpen(false); }; React.useEffect(() => { - if (!open && !isEqual(props.value, value)) { - setValue(props.value); + if (!open && !isEqual(props.value || {}, value)) { + setValue(props.value || {}); } }, [props.value, value, open]);