Skip to content

Commit

Permalink
Merge pull request #10 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea authored Jan 25, 2023
2 parents 186ee6f + 42cf7f2 commit 182ef74
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ 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).

### [2.0.0](https://github.com/eea/volto-call-to-action-block/compare/1.0.0...2.0.0) - 15 November 2022
### [3.0.0](https://github.com/eea/volto-call-to-action-block/compare/2.0.0...3.0.0) - 24 January 2023

#### :hammer_and_wrench: Others

- test(Jenkins): Run tests and cypress with latest canary @plone/volto [Alin Voinea - [`d1ba7b8`](https://github.com/eea/volto-call-to-action-block/commit/d1ba7b844f114305604e7f8c8b3158746dd59a7b)]
## [2.0.0](https://github.com/eea/volto-call-to-action-block/compare/1.0.0...2.0.0) - 16 November 2022

#### :nail_care: Enhancements

Expand Down
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pipeline {
environment {
GIT_NAME = "volto-call-to-action-block"
NAMESPACE = "@eeacms"
SONARQUBE_TAGS = "volto.eea.europa.eu,demo-www.eea.europa.eu,prod-www.eea.europa.eu,circularity.eea.europa.eu"
SONARQUBE_TAGS = "volto.eea.europa.eu,demo-www.eea.europa.eu,prod-www.eea.europa.eu,circularity.eea.europa.eu,forest.eea.europa.eu,demo-kitkat.dev2aws.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,biodiversity.europa.eu,climate-adapt.eea.europa.eu,climate-energy.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu"
DEPENDENCIES = ""
VOLTO = "alpha"
VOLTO = ""
}

stages {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-call-to-action-block",
"version": "2.0.0",
"version": "3.0.0",
"description": "@eeacms/volto-call-to-action-block: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand All @@ -16,10 +16,9 @@
"type": "git",
"url": "[email protected]:eea/volto-call-to-action-block.git"
},
"dependencies": {},
"devDependencies": {
"@plone/scripts": "*",
"@cypress/code-coverage": "^3.10.0",
"@plone/scripts": "*",
"babel-plugin-transform-class-properties": "^6.24.1",
"md5": "^2.3.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const EditSchema = ({ intl }) => ({
},
href: {
title: intl.formatMessage(messages.Link),
widget: 'object_browser',
widget: 'call_to_action',
mode: 'link',
selectedItemAttrs: ['Title', 'Description', 'hasPreviewImage'],
allowExternals: true,
Expand Down
9 changes: 5 additions & 4 deletions src/components/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const View = ({ data, isEditMode }) => {
}
}, [isEditMode, data.href]);

const As = hasLink && isInternalURL(data.href[0]['@id']) ? Link : 'a';
const url = flattenToAppURL(data.href?.[0]?.['@id'] || data.href);
const As = hasLink && isInternalURL(url) ? Link : 'a';
return (
<div className={cx('block call-to-action align', data.styles?.align)}>
<As
Expand All @@ -49,9 +50,9 @@ const View = ({ data, isEditMode }) => {
: '',
data.styles?.theme,
)}
href={hasLink ? flattenToAppURL(data.href[0]['@id']) : null}
to={hasLink ? flattenToAppURL(data.href[0]['@id']) : null}
title={hasLink ? data.href[0]['title'] : ''}
href={hasLink ? url : null}
to={hasLink ? url : null}
title={hasLink ? data.text : ''}
target={data.target}
>
<Content data={data} />
Expand Down
186 changes: 186 additions & 0 deletions src/components/Widget.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/**
* CallToActionWidget component.
* @module components/Widget
*/

import React, { useState } from 'react';
import { compose } from 'redux';
import PropTypes from 'prop-types';
import { Input, Button } from 'semantic-ui-react';
import { FormFieldWrapper, Icon } from '@plone/volto/components';
import {
addAppURL,
isInternalURL,
flattenToAppURL,
URLUtils,
} from '@plone/volto/helpers';
import withObjectBrowser from '@plone/volto/components/manage/Sidebar/ObjectBrowser';
import clearSVG from '@plone/volto/icons/clear.svg';
import navTreeSVG from '@plone/volto/icons/nav.svg';

/** Widget to edit urls
*
* This is the default widget used for the `remoteUrl` field. You can also use
* it by declaring a field like:
*
* ```jsx
* {
* title: "URL",
* widget: 'url',
* }
* ```
*/
export const CallToActionWidget = (props) => {
const {
id,
onChange,
onBlur,
onClick,
minLength,
maxLength,
placeholder,
isDisabled,
} = props;
const inputId = `field-${id}`;

const [value, setValue] = useState(
flattenToAppURL(props.value?.[0]?.['@id'] || props.value),
);
const [isInvalid, setIsInvalid] = useState(false);
/**
* Clear handler
* @method clear
* @param {Object} value Value
* @returns {undefined}
*/
const clear = () => {
setValue('');
onChange(id, undefined);
};

const onChangeValue = (_value) => {
let newValue = _value;
if (newValue?.length > 0) {
if (isInvalid && URLUtils.isUrl(URLUtils.normalizeUrl(newValue))) {
setIsInvalid(false);
}

if (isInternalURL(newValue)) {
newValue = flattenToAppURL(newValue);
}
}

setValue(newValue);

newValue = isInternalURL(newValue) ? addAppURL(newValue) : newValue;

if (!isInternalURL(newValue) && newValue.length > 0) {
const checkedURL = URLUtils.checkAndNormalizeUrl(newValue);
newValue = checkedURL.url;
if (!checkedURL.isValid) {
setIsInvalid(true);
}
}

onChange(id, newValue === '' ? undefined : newValue);
};

return (
<FormFieldWrapper {...props} className="url wide">
<div className="wrapper">
<Input
id={inputId}
name={id}
type="url"
value={value || ''}
disabled={isDisabled}
placeholder={placeholder || 'mailto: tel: href:...'}
onChange={({ target }) => onChangeValue(target.value)}
onBlur={({ target }) =>
onBlur(id, target.value === '' ? undefined : target.value)
}
onClick={() => onClick()}
minLength={minLength || null}
maxLength={maxLength || null}
error={isInvalid}
/>
{value?.length > 0 ? (
<Button.Group>
<Button
basic
className="cancel"
aria-label="clearUrlBrowser"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
clear();
}}
>
<Icon name={clearSVG} size="30px" />
</Button>
</Button.Group>
) : (
<Button.Group>
<Button
basic
icon
aria-label="openUrlBrowser"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
props.openObjectBrowser({
mode: 'link',
overlay: true,
onSelectItem: (url) => {
onChangeValue(url);
},
});
}}
>
<Icon name={navTreeSVG} size="24px" />
</Button>
</Button.Group>
)}
</div>
</FormFieldWrapper>
);
};

/**
* Property types
* @property {Object} propTypes Property types.
* @static
*/
CallToActionWidget.propTypes = {
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string,
required: PropTypes.bool,
error: PropTypes.arrayOf(PropTypes.string),
onChange: PropTypes.func.isRequired,
onBlur: PropTypes.func,
onClick: PropTypes.func,
minLength: PropTypes.number,
maxLength: PropTypes.number,
openObjectBrowser: PropTypes.func.isRequired,
placeholder: PropTypes.string,
};

/**
* Default properties.
* @property {Object} defaultProps Default properties.
* @static
*/
CallToActionWidget.defaultProps = {
description: null,
required: false,
error: [],
value: null,
onChange: () => {},
onBlur: () => {},
onClick: () => {},
minLength: null,
maxLength: null,
};

export default compose(withObjectBrowser)(CallToActionWidget);
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import callToActionSVG from '@plone/volto/icons/circle-right.svg';
import Edit from './components/Edit';
import View from './components/View';
import Widget from './components/Widget';
import { StylingSchema, EditSchema } from './components/Schema';

import './theme/main.less';

const applyConfig = (config) => {
// Custom Call to Action URL Widget
config.widgets.widget.call_to_action = Widget;

// Call to Action Block
config.blocks.blocksConfig.callToActionBlock = {
id: 'callToActionBlock',
title: 'Call to Action',
Expand All @@ -23,6 +28,7 @@ const applyConfig = (config) => {
view: [],
},
};

return config;
};

Expand Down

0 comments on commit 182ef74

Please sign in to comment.