Skip to content

Commit

Permalink
Merge pull request #27 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea authored Jun 12, 2023
2 parents f67137f + 8eb4064 commit 1dc6d91
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 4 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ 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).

### [5.1.2](https://github.com/eea/volto-object-widget/compare/5.1.1...5.1.2) - 12 June 2023

#### :rocket: New Features

- feat: File picker object browser - refs #253430 [dobri1408 - [`62fb1d0`](https://github.com/eea/volto-object-widget/commit/62fb1d01ea85cab458e496ecb011f114d9ffa88a)]

#### :house: Internal changes

- chore: [JENKINS] Deprecate circularity website [valentinab25 - [`da1cf7d`](https://github.com/eea/volto-object-widget/commit/da1cf7d96f01e677293eeba2602804727a360571)]

#### :hammer_and_wrench: Others

- test: jest should look for addons in node_modules Refs #253277 [valentinab25 - [`6a639c5`](https://github.com/eea/volto-object-widget/commit/6a639c5917f66e6addb614d629988b195cda4ad7)]
- test: Fix test config, coverage Refs #253277 [valentinab25 - [`12f23fc`](https://github.com/eea/volto-object-widget/commit/12f23fc78fffd8ffde62f24321022d20fd704725)]
### [5.1.1](https://github.com/eea/volto-object-widget/compare/5.1.0...5.1.1) - 26 April 2023

#### :rocket: New Features
Expand All @@ -20,11 +34,19 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- * version [andreiggr - [`052c684`](https://github.com/eea/volto-object-widget/commit/052c684180dd1f46af435e4cbc9e7e8641abebe7)]
- Revert changes on AttachedImageWidget [Miu Razvan - [`88eafeb`](https://github.com/eea/volto-object-widget/commit/88eafeb363f495faae7d915aa1f8867c86a5f1d6)]
- Revert fc658b5 [Miu Razvan - [`669d06f`](https://github.com/eea/volto-object-widget/commit/669d06f8b8856599feab29f96981eb67e21dc2b0)]
- Revert "Add Sonarqube tag using eea-website-frontend addons list" [Miu Razvan - [`fc658b5`](https://github.com/eea/volto-object-widget/commit/fc658b5291c1c4fdebd21da609463f85841b38ce)]
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`45e4f91`](https://github.com/eea/volto-object-widget/commit/45e4f9134390f4ee2f1636edc17320365d2f13d7)]
### [5.1.0](https://github.com/eea/volto-object-widget/compare/5.0.1...5.1.0) - 27 March 2023

#### :hammer_and_wrench: Others

- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`38ae79f`](https://github.com/eea/volto-object-widget/commit/38ae79f2d63a0240885a9685ce9a0e5f698ef957)]
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`ea09d1e`](https://github.com/eea/volto-object-widget/commit/ea09d1ec24dc6e46c79d57d8b90f2b943e3b41e3)]
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`48e235e`](https://github.com/eea/volto-object-widget/commit/48e235e0a1f3aa6fcf6fe6b8021cbf57d89f3bff)]
- test(Jenkins): Run tests and cypress with latest canary @plone/volto [Alin Voinea - [`33ab4d9`](https://github.com/eea/volto-object-widget/commit/33ab4d94a61939763e245c721acc9c300e8deba6)]
- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`e95a916`](https://github.com/eea/volto-object-widget/commit/e95a91628659c5447ceea8668162109ac10a67ff)]
- yarn 3 [Alin Voinea - [`aabc72c`](https://github.com/eea/volto-object-widget/commit/aabc72cb720dced56f7888bfaaf6d9b7668392b8)]
- Add Sonarqube tag using demo-kitkat-frontend addons list [EEA Jenkins - [`bcbaa9e`](https://github.com/eea/volto-object-widget/commit/bcbaa9e6644bdd53cf9d269ef9eede823706d2ae)]
### [5.0.1](https://github.com/eea/volto-object-widget/compare/5.0.0...5.0.1) - 16 November 2022

#### :hammer_and_wrench: Others
Expand All @@ -39,11 +61,14 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Typo [Miu Razvan - [`0eac194`](https://github.com/eea/volto-object-widget/commit/0eac194761c04db9807ca63381b25c13c7a854bd)]
- Prepare 5.0.0 release [Miu Razvan - [`2a12c37`](https://github.com/eea/volto-object-widget/commit/2a12c377a7bf5a1a51966ab1e1c867f1b55ccb95)]
- Update babel & jest config [Miu Razvan - [`8269b4a`](https://github.com/eea/volto-object-widget/commit/8269b4ac4aa9d487579b35ff41d0fea9dce5fc45)]
- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`2b550d7`](https://github.com/eea/volto-object-widget/commit/2b550d76313569397fda8967147e0052176f823e)]
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`08aa211`](https://github.com/eea/volto-object-widget/commit/08aa211cdfa1b48817a4af6a21c3b033ef6642ea)]
- update(jest): add @plone/volto-slate resolver refs- #153447 [nileshgulia1 - [`6963a87`](https://github.com/eea/volto-object-widget/commit/6963a87a0c84910c0ef695652d944115d487b24e)]
### [4.0.2](https://github.com/eea/volto-object-widget/compare/4.0.1...4.0.2) - 30 June 2022

#### :hammer_and_wrench: Others

- Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`f7e9285`](https://github.com/eea/volto-object-widget/commit/f7e928506f881dcf6bcd5f1bd5897148af2c4c38)]
### [4.0.1](https://github.com/eea/volto-object-widget/compare/4.0.0...4.0.1) - 20 May 2022

## [4.0.0](https://github.com/eea/volto-object-widget/compare/3.0.3...4.0.0) - 19 May 2022
Expand All @@ -57,23 +82,33 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Release 4.0.0 [Alin Voinea - [`553e4ab`](https://github.com/eea/volto-object-widget/commit/553e4ab8b5888a2af43dcaf8be6d955cc3949513)]
- Improved style for attached image widget [Miu Razvan - [`8c770cd`](https://github.com/eea/volto-object-widget/commit/8c770cdeb6af776208bd9a3936f33f5370d70fd7)]
- Release 3.1.0 [Alin Voinea - [`61dd13b`](https://github.com/eea/volto-object-widget/commit/61dd13b20b2e00305af00b762e3e4d734a03cf0d)]
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`0912594`](https://github.com/eea/volto-object-widget/commit/09125945f04192d8af200c6828c9388a29f4e8ff)]
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`beb8f0b`](https://github.com/eea/volto-object-widget/commit/beb8f0ba5091911428b885e39b2bcdcdf390104c)]
### [3.0.3](https://github.com/eea/volto-object-widget/compare/3.0.2...3.0.3) - 3 January 2022

### [3.0.2](https://github.com/eea/volto-object-widget/compare/3.0.1...3.0.2) - 18 December 2021

#### :hammer_and_wrench: Others

- Add Sonarqube tag using freshwater-frontend addons list [EEA Jenkins - [`5f6c212`](https://github.com/eea/volto-object-widget/commit/5f6c212134fee7d1096c9733e215a517d9842279)]
### [3.0.1](https://github.com/eea/volto-object-widget/compare/3.0.0...3.0.1) - 10 December 2021

#### :hammer_and_wrench: Others

- Refs #142010 - Optimize Volto-addons gitflow pipelines [valentinab25 - [`0598f50`](https://github.com/eea/volto-object-widget/commit/0598f50fd11e720e3b78d039987d92580ad6c7d6)]
- Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`0eb9ee2`](https://github.com/eea/volto-object-widget/commit/0eb9ee20b47872dcd13fbd016443226968b93e6b)]
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`da90a9b`](https://github.com/eea/volto-object-widget/commit/da90a9bcd52894ca8e2303e9f4d6f39f6e7c727a)]
- Add Sonarqube tag using sustainability-frontend addons list [EEA Jenkins - [`b9f9262`](https://github.com/eea/volto-object-widget/commit/b9f9262a51f8c7b21081ed7a3c471ed1f54d600d)]
- Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`5374fa5`](https://github.com/eea/volto-object-widget/commit/5374fa5d6fb973c1534d1608a623f1e0a1ec5266)]
- Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`c954416`](https://github.com/eea/volto-object-widget/commit/c9544161ee8717e6568535527d720f884347160c)]
## [3.0.0](https://github.com/eea/volto-object-widget/compare/2.2.3...3.0.0) - 3 September 2021

#### :hammer_and_wrench: Others

- Fix ObjectListWidget tests [Alin Voinea - [`149c3ae`](https://github.com/eea/volto-object-widget/commit/149c3aee0fe40c5a80d58cc8a12bd1b67a66366f)]
- Remove DEPRECATED ObjectWidget. Moved to Volto core. [Alin Voinea - [`415e7a9`](https://github.com/eea/volto-object-widget/commit/415e7a91652d7fc68e0c0dd6648f9bc5a50170f9)]
- Add Sonarqube tag using frontend addons list [EEA Jenkins - [`49e4e6e`](https://github.com/eea/volto-object-widget/commit/49e4e6e6376bbacbf657925811ae087da3bd2d30)]
- Add Sonarqube tag using frontend addons list [EEA Jenkins - [`4c3c118`](https://github.com/eea/volto-object-widget/commit/4c3c118290cbd25432111c60090f6aade1bac1d2)]
### [2.2.3](https://github.com/eea/volto-object-widget/compare/2.2.2...2.2.3) - 4 June 2021

#### :hammer_and_wrench: Others
Expand Down
3 changes: 2 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pipeline {
environment {
GIT_NAME = "volto-object-widget"
NAMESPACE = "@eeacms"
SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,biodiversity.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,circularity.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en"
SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,biodiversity.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en"
DEPENDENCIES = ""
VOLTO = ""
}
Expand Down Expand Up @@ -188,6 +188,7 @@ pipeline {
def nodeJS = tool 'NodeJS';
withSonarQubeEnv('Sonarqube') {
sh '''sed -i "s#/opt/frontend/my-volto-project/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info'''
sh '''sed -i "s#src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info'''
sh "export PATH=${scannerHome}/bin:${nodeJS}/bin:$PATH; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info,./cypress-coverage/coverage/lcov.info -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done'''
}
Expand Down
4 changes: 2 additions & 2 deletions jest-addon.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ module.exports = {
'!src/**/*.d.ts',
],
moduleNameMapper: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
'@plone/volto/cypress': '<rootDir>/node_modules/@plone/volto/cypress',
'@plone/volto/babel': '<rootDir>/node_modules/@plone/volto/babel',
'@plone/volto/(.*)$': '<rootDir>/node_modules/@plone/volto/src/$1',
'@package/(.*)$': '<rootDir>/src/$1',
'@root/(.*)$': '<rootDir>/src/$1',
'@plone/volto-quanta/(.*)$': '<rootDir>/src/addons/volto-quanta/src/$1',
'@eeacms/(.*?)/(.*)$': '<rootDir>/src/addons/$1/src/$2',
'@eeacms/(.*?)/(.*)$': '<rootDir>/node_modules/@eeacms/$1/src/$2',
'@plone/volto-slate':
'<rootDir>/node_modules/@plone/volto/packages/volto-slate/src',
'~/(.*)$': '<rootDir>/src/$1',
'load-volto-addons':
'<rootDir>/node_modules/@plone/volto/jest-addons-loader.js',
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
},
transform: {
'^.+\\.js(x)?$': 'babel-jest',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-object-widget",
"version": "5.1.1",
"version": "5.1.2",
"description": "volto-object-widget: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
206 changes: 206 additions & 0 deletions src/Widget/AttachedFileWidget.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Dimmer, Input } from 'semantic-ui-react';
import { readAsDataURL } from 'promise-file-reader';
import { injectIntl } from 'react-intl';
import deleteSVG from '@plone/volto/icons/delete.svg';
import { Icon, FormFieldWrapper } from '@plone/volto/components';
import loadable from '@loadable/component';
import { flattenToAppURL, isInternalURL } from '@plone/volto/helpers';
import { useSelector } from 'react-redux';
import withObjectBrowser from '@plone/volto/components/manage/Sidebar/ObjectBrowser';
import { defineMessages, useIntl } from 'react-intl';
import navTreeSVG from '@plone/volto/icons/nav.svg';
import aheadSVG from '@plone/volto/icons/ahead.svg';
import './style.css';

const Dropzone = loadable(() => import('react-dropzone'));

const messages = defineMessages({
dragOrUpload: {
id: 'Drop files here or click to upload',
defaultMessage: 'Drop files here or click to upload',
},
editFile: {
id: 'Drop files here or click to upload',
defaultMessage: 'Drop files here or click to upload',
},
FilePickerWidgetInputPlaceholder: {
id: 'Browse the site',
defaultMessage: 'Browse the site',
},
});

const FileWidget = (props) => {
const { id, value, onChange, isDisabled, openObjectBrowser } = props;
const [nameOfFile, setNameOfFile] = React.useState('');
const intl = useIntl();
const [url, setUrl] = React.useState(
typeof props.value === 'string' ? props.value : '',
);
const placeholder =
props.placeholder ||
intl.formatMessage(messages.FilePickerWidgetInputPlaceholder);
const pathname = useSelector((state) => state.router.location.pathname);

/**
* Submit url handler
* @method onSubmitUrl
* @param {object} e Event
* @returns {undefined}
*/
const onSubmitUrl = () => {
onChange(id, flattenToAppURL(url));
};

const onChangeUrl = ({ target }) => {
setUrl(target.value);
};

/**
* Drop handler
* @method onDrop
* @param {array} files File objects
* @returns {undefined}
*/
const onDrop = (files) => {
const file = files[0];
readAsDataURL(file).then((data) => {
const fields = data.match(/^data:(.*);(.*),(.*)$/);
onChange(id, {
data: fields[3],
encoding: fields[2],
'content-type': fields[1],
filename: file.name,
});
});
let reader = new FileReader();
reader.readAsDataURL(files[0]);
};

React.useEffect(() => {
if (typeof value === 'string' && isInternalURL(value)) {
setNameOfFile(value.split('/').at(-1));
} else if (value) setNameOfFile(value.filename);
}, [value]);

return (
<FormFieldWrapper {...props}>
{value !== undefined && value !== null ? (
<div className="field-file-name">
{nameOfFile}
<Button
icon
basic
className="delete-button"
aria-label="delete file"
disabled={isDisabled}
onClick={() => {
onChange(id, null);
}}
>
<Icon name={deleteSVG} size="20px" />
</Button>
</div>
) : (
<>
<Dropzone onDrop={onDrop}>
{({ getRootProps, getInputProps, isDragActive }) => (
<>
<div className="file-widget-dropzone" {...getRootProps()}>
{isDragActive && <Dimmer active></Dimmer>}

<div className="dropzone-placeholder">
<p className="dropzone-text">
{intl.formatMessage(messages.dragOrUpload)}
</p>
<input
{...getInputProps({
type: 'file',
style: { display: 'none' },
})}
id={`field-${id}`}
name={id}
type="file"
disabled={isDisabled}
/>
</div>
</div>
</>
)}
</Dropzone>
<div className="file-picker-toolbar">
<Button
basic
icon
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
openObjectBrowser({
mode: 'link',
currentPath: pathname,
onSelectItem: (url) => {
setUrl(url);
},
});
}}
>
<Icon name={navTreeSVG} size="24px" />
</Button>

<Input
className="input-toolbar"
onChange={onChangeUrl}
placeholder={placeholder}
value={url}
/>

<Button
basic
icon
primary
disabled={!url}
onClick={(e) => {
e.stopPropagation();
onSubmitUrl();
}}
>
<Icon name={aheadSVG} size="24px" />
</Button>
</div>
</>
)}
</FormFieldWrapper>
);
};

/**
* Property types.
* @property {Object} propTypes Property types.
* @static
*/
FileWidget.propTypes = {
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string,
required: PropTypes.bool,
error: PropTypes.arrayOf(PropTypes.string),
onChange: PropTypes.func.isRequired,
wrapped: PropTypes.bool,
openObjectBrowser: PropTypes.func.isRequired,
value: PropTypes.any,
};

/**
* Default properties.
* @property {Object} defaultProps Default properties.
* @static
*/
FileWidget.defaultProps = {
description: null,
required: false,
error: [],
value: null,
};

export default withObjectBrowser(injectIntl(FileWidget));
1 change: 1 addition & 0 deletions src/Widget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export ObjectListInlineWidget from './ObjectListInlineWidget';
export ObjectByTypeWidget from './ObjectByTypeWidget';
export MappingWidget from './MappingWidget';
export ObjectTypesWidget from './ObjectTypesWidget';
export AttachedFileWidget from './AttachedFileWidget';
9 changes: 9 additions & 0 deletions src/Widget/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
}
}

.file-picker-toolbar {
display: flex;
justify-content: space-between;
}

.input-toolbar {
width: 60% !important;
}

.field-just-changed {
animation: field-just-changed-anim 0.5s;
}
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ObjectListInlineWidget,
ObjectByTypeWidget,
MappingWidget,
AttachedFileWidget,
ObjectTypesWidget,
} from './Widget';

Expand All @@ -13,6 +14,7 @@ export {
ObjectByTypeWidget,
MappingWidget,
ObjectTypesWidget,
AttachedFileWidget,
} from './Widget';

export installDemo from './demo';
Expand All @@ -24,6 +26,7 @@ const applyConfig = (config) => {
config.widgets.widget.object_by_type = ObjectByTypeWidget;
config.widgets.widget.option_mapping = MappingWidget;
config.widgets.widget.attachedimage = AttachedImageWidget;
config.widgets.widget.attachedfile = AttachedFileWidget;
config.widgets.widget.object_types_widget = ObjectTypesWidget;
}

Expand Down

0 comments on commit 1dc6d91

Please sign in to comment.