@eeacms/volto-eea-website-theme 1.8.1 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ ### [1.8.2](https://github.com/eea/volto-eea-website-theme/compare/1.8.1...1.8.2) - 14 February 2023
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat: use removeTrailingSlash [Mimi - [`2fa8e23`](https://github.com/eea/volto-eea-website-theme/commit/2fa8e23525af589efb13f5b04e52026a97245556)]
12
+ - feat: compare pathname to contentId to show draft watermark [Mimi - [`de870d8`](https://github.com/eea/volto-eea-website-theme/commit/de870d8be85b7aa64e26697e1e19709c1c4721cb)]
13
+ - feat: show or remove the draft watermark based on the value from the ENV file [Mimi - [`e5d2ce0`](https://github.com/eea/volto-eea-website-theme/commit/e5d2ce00f865cbe5ddb95030cb8ccd8a609ebf02)]
14
+ - feat: remove draft image from control panel and login [Mimi - [`274891a`](https://github.com/eea/volto-eea-website-theme/commit/274891a0810102e445813bb59735c56403125895)]
15
+
16
+ #### :bug: Bug Fixes
17
+
18
+ - fix(search): Fix some issues in the search popup #107 from eea/fix-search-popup [ichim-david - [`07b03df`](https://github.com/eea/volto-eea-website-theme/commit/07b03df36022da21d4c80b220cf529840e00c707)]
19
+ - fix(search): Fix undefined [kreafox - [`613d358`](https://github.com/eea/volto-eea-website-theme/commit/613d35860222ede3d40fc61acc0202b95e53108b)]
20
+ - fix(search): Fix some issues in the search popup [kreafox - [`13b5e64`](https://github.com/eea/volto-eea-website-theme/commit/13b5e64b69eacffacf2e65b9c5336cbcb5a9dfa7)]
21
+
22
+ #### :house: Internal changes
23
+
24
+ - chore: clean up [Mimi - [`b80f1dc`](https://github.com/eea/volto-eea-website-theme/commit/b80f1dcc5e5cd1d369bdcea574dd8158785af6be)]
25
+ - chore: use runtimeConfig for the RAZZLE_DISABLE_DRAFT_WATERMARK variable [Mimi - [`6b6cc83`](https://github.com/eea/volto-eea-website-theme/commit/6b6cc83dd0e6a4820d75acfdc8d41e092831261d)]
26
+ - chore: clean up [Mimi - [`807ca82`](https://github.com/eea/volto-eea-website-theme/commit/807ca82820319c0d45096dcbe228eee4262b602c)]
27
+ - chore: add missing code [Mimi - [`3a93e94`](https://github.com/eea/volto-eea-website-theme/commit/3a93e944613af0ee3ca1ed25c2439d9c504d4591)]
28
+
7
29
  ### [1.8.1](https://github.com/eea/volto-eea-website-theme/compare/1.8.0...1.8.1) - 9 February 2023
8
30
 
9
31
  #### :rocket: New Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-website-theme",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "@eeacms/volto-eea-website-theme: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -2,15 +2,51 @@ import React from 'react';
2
2
  import { connect } from 'react-redux';
3
3
  import './draft.css';
4
4
  import { BodyClass } from '@plone/volto/helpers';
5
+ import { withRouter } from 'react-router-dom';
6
+ import { compose } from 'redux';
7
+ import { runtimeConfig } from '@plone/volto/runtime_config';
8
+ import { flattenToAppURL } from '@plone/volto/helpers';
5
9
 
6
- const DraftBackground = ({ review_state }) => {
7
- const draftClass = `wf-state-${review_state}`;
8
- return <BodyClass className={draftClass} />;
10
+ const removeTrailingSlash = (str) => {
11
+ return str.replace(/\/+$/, '');
9
12
  };
10
- function propsAreEqual(prevProps, nextProps) {
11
- return prevProps.review_state === nextProps.review_state;
12
- }
13
13
 
14
- export default connect((state) => ({
15
- review_state: state.content.data?.review_state,
16
- }))(React.memo(DraftBackground, propsAreEqual));
14
+ /**
15
+ * The review_state and id don't change everytime the page is changed and because of that the draft background
16
+ * will apear on pages that shouldn't have it. The RAZZLE_DISABLE_DRAFT_WATERMARK varible from ENV file should have two possible values:
17
+ * "Hide-No-Workflow" and "Hide-All". If the variable is not present, it should follow the current logic(show the draft image everywhere),
18
+ * if the value is "Hide-No-Workflow", then the draft image is not shown on pages like login or controlpanel and if the value is "Hide-All", then
19
+ * the draft image is not visible at all.
20
+ * For example, if the current page is /datatable (that has the draft background) and then we go to Content Types page,
21
+ * the review_state and id will be the same as the ones from /datatable, so the draft background will still be present. By checking
22
+ * if the pathname from (from withRouter) is different than the one from state.content.data and based on the varible from ENV,
23
+ * we decide if the draft backgound can be present or not.
24
+ * @param {Object} props
25
+ * @returns
26
+ */
27
+ const DraftBackground = (props) => {
28
+ const draftClass = `wf-state-${props.review_state}`;
29
+ const razzleDraft =
30
+ runtimeConfig['RAZZLE_DISABLE_DRAFT_WATERMARK'] || 'default';
31
+ const isReviewableStateComponent =
32
+ props.review_state &&
33
+ props.contentId === removeTrailingSlash(props.pathname);
34
+
35
+ const draftOptions = {
36
+ 'Hide-All': 'wf-state-published',
37
+ 'Hide-No-Workflow': isReviewableStateComponent
38
+ ? draftClass
39
+ : 'wf-state-published',
40
+ default: draftClass,
41
+ };
42
+
43
+ return <BodyClass className={draftOptions[razzleDraft]} />;
44
+ };
45
+
46
+ export default compose(
47
+ withRouter,
48
+ connect((state, props) => ({
49
+ review_state: state.content.data?.review_state,
50
+ contentId: flattenToAppURL(state.content.data?.['@id']),
51
+ })),
52
+ )(DraftBackground);
@@ -1,13 +1,15 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { Container, Input, List } from 'semantic-ui-react';
3
3
  import { withRouter } from 'react-router-dom';
4
4
  import { useClickOutside } from '@eeacms/volto-eea-design-system/helpers';
5
5
  import config from '@plone/volto/registry';
6
6
 
7
7
  const getRandomItems = (arr, max) => {
8
- return arr.slice(0, max).map(function () {
9
- return this.splice(Math.floor(Math.random() * this.length), 1)[0];
10
- }, arr.slice());
8
+ return (
9
+ arr?.slice(0, max).map(function () {
10
+ return this.splice(Math.floor(Math.random() * this.length), 1)[0];
11
+ }, arr.slice()) || []
12
+ );
11
13
  };
12
14
 
13
15
  function HeaderSearchPopUp({
@@ -32,10 +34,15 @@ function HeaderSearchPopUp({
32
34
  searchSuggestions,
33
35
  } = activeView;
34
36
  const { suggestionsTitle, suggestions, maxToShow } = searchSuggestions || {};
37
+
35
38
  const [text, setText] = React.useState('');
36
- const visibleSuggestions = suggestions
37
- ? getRandomItems(suggestions, maxToShow)
38
- : [];
39
+ const [visibleSuggestions, setVisibileSuggestions] = React.useState(
40
+ getRandomItems(suggestions, maxToShow),
41
+ );
42
+
43
+ useEffect(() => {
44
+ setVisibileSuggestions(getRandomItems(suggestions, maxToShow));
45
+ }, [maxToShow, suggestions]);
39
46
 
40
47
  useClickOutside({ targetRefs: [nodeRef, ...triggerRefs], callback: onClose });
41
48
 
@@ -0,0 +1,3 @@
1
+ <svg width="36" height="36" version="1.1" viewBox="0 0 36 36" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="m14.378 14.247-6.8402 6.8402 7.1774 7.1774h1.6168v-0.0028h1.6195l5.2207-5.2207zm1.954-1.9539 8.7942 8.7942 3.9079-3.9093-8.7942-8.7942zm5.5274 15.969h9.673v2.7637h-12.437l-5.5247 0.002764-8.9641-8.9641a1.3819 1.3819 0 0 1 0-1.954l14.655-14.657a1.3819 1.3819 0 0 1 1.9553 0l10.748 10.748a1.3819 1.3819 0 0 1 0 1.9539z" stroke-width="1.3819"/>
3
+ </svg>
package/src/slate.js CHANGED
@@ -3,10 +3,9 @@ import { List } from 'semantic-ui-react';
3
3
  import { MarkElementButton, ToolbarButton } from '@plone/volto-slate/editor/ui';
4
4
  import installCallout from '@plone/volto-slate/editor/plugins/Callout';
5
5
  import { Icon } from '@plone/volto/components';
6
- import { Editor, Transforms } from 'slate';
6
+ import { Editor, Transforms, Text } from 'slate';
7
7
  import { useSlate } from 'slate-react';
8
8
 
9
- import formatClearIcon from '@plone/volto/icons/format-clear.svg';
10
9
  import paintSVG from '@plone/volto/icons/paint.svg';
11
10
  import alignLeftIcon from '@plone/volto/icons/align-left.svg';
12
11
  import alignRightIcon from '@plone/volto/icons/align-right.svg';
@@ -14,6 +13,7 @@ import alignCenterIcon from '@plone/volto/icons/align-center.svg';
14
13
  import alignJustifyIcon from '@plone/volto/icons/align-justify.svg';
15
14
  import lightIcon from './icons/light.svg';
16
15
  import smallIcon from './icons/small.svg';
16
+ import clearIcon from './icons/eraser.svg';
17
17
 
18
18
  const toggleBlockClassFormat = (editor, format) => {
19
19
  const levels = Array.from(Editor.levels(editor, editor.selection));
@@ -59,6 +59,27 @@ function BlockClassButton({ format, icon, ...props }) {
59
59
  }
60
60
 
61
61
  const clearFormatting = (editor) => {
62
+ const sn = Array.from(
63
+ Editor.nodes(editor, {
64
+ mode: 'lowest',
65
+ match: (n, p) => {
66
+ // console.log('node', n, p);
67
+ return Text.isText(n);
68
+ },
69
+ at: [0], // uncomment if you want everything to be cleared
70
+ }),
71
+ );
72
+
73
+ // console.log('sn', sn);
74
+
75
+ sn.forEach(([n, at]) => {
76
+ const toRemove = Object.keys(n).filter((k) => k.startsWith('style-'));
77
+ if (toRemove.length) {
78
+ Transforms.unsetNodes(editor, toRemove, { at });
79
+ // console.log('unset', n, at, toRemove);
80
+ }
81
+ });
82
+
62
83
  Transforms.setNodes(editor, {
63
84
  type: 'p',
64
85
  styleName: null,
@@ -90,7 +111,7 @@ export default function installSlate(config) {
90
111
  config = installCallout(config);
91
112
 
92
113
  config.settings.slate.buttons.clearformatting = (props) => (
93
- <ClearFormattingButton title="Clear formatting" icon={formatClearIcon} />
114
+ <ClearFormattingButton title="Clear formatting" icon={clearIcon} />
94
115
  );
95
116
 
96
117
  // Remove blockquote, italic, strikethrough slate button from toolbarButtons