@eeacms/volto-clms-theme 1.1.182 → 1.1.183

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,15 @@ 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.1.183](https://github.com/eea/volto-clms-theme/compare/1.1.182...1.1.183) - 2 September 2024
8
+
9
+ #### :house: Internal changes
10
+
11
+ - style: Automated code fix [eea-jenkins - [`6781834`](https://github.com/eea/volto-clms-theme/commit/67818343593af201d89ac57468b8c9a686f0e424)]
12
+
13
+ #### :hammer_and_wrench: Others
14
+
15
+ - Redo faq improve [Tiberiu Ichim - [`83f225e`](https://github.com/eea/volto-clms-theme/commit/83f225e8a3d4e8181c4aa6060c99ceadf2ae29a0)]
7
16
  ### [1.1.182](https://github.com/eea/volto-clms-theme/compare/1.1.181...1.1.182) - 30 August 2024
8
17
 
9
18
  ### [1.1.181](https://github.com/eea/volto-clms-theme/compare/1.1.180...1.1.181) - 29 August 2024
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-clms-theme",
3
- "version": "1.1.182",
3
+ "version": "1.1.183",
4
4
  "description": "volto-clms-theme: Volto theme for CLMS site",
5
5
  "main": "src/index.js",
6
6
  "author": "CodeSyntax for the European Environment Agency",
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import CclFAQBlockView from './CclFAQBlockView';
3
3
 
4
4
  const CclFAQBlockEdit = (props) => {
5
- return <CclFAQBlockView props={props} isEditMode={true} />;
5
+ return <CclFAQBlockView {...props} isEditMode={true} />;
6
6
  };
7
7
 
8
8
  export default CclFAQBlockEdit;
@@ -1,3 +1,4 @@
1
+ import cx from 'classnames';
1
2
  import React, { useState } from 'react';
2
3
  import AnimateHeight from 'react-animate-height';
3
4
  import { useDispatch, useSelector } from 'react-redux';
@@ -6,18 +7,46 @@ import { Accordion, Segment } from 'semantic-ui-react';
6
7
  import { getContextNavigation } from '@plone/volto/actions';
7
8
  import { Icon, UniversalLink } from '@plone/volto/components';
8
9
  import RenderBlocks from '@plone/volto/components/theme/View/RenderBlocks';
9
- import { hasBlocksData } from '@plone/volto/helpers';
10
+ import { hasBlocksData, getBaseUrl } from '@plone/volto/helpers';
11
+
12
+ import { CclTabs } from '@eeacms/volto-clms-theme/components/CclTab';
13
+
10
14
  import penSVG from '@plone/volto/icons/pen.svg';
11
15
  import config from '@plone/volto/registry';
12
- import { CclTabs } from '@eeacms/volto-clms-theme/components/CclTab';
13
- // import { StringToHTML } from '@eeacms/volto-clms-theme/components/CclUtils';
16
+
17
+ const flattenCN = (cn_items) =>
18
+ cn_items.reduce(
19
+ (acc, curr) => [
20
+ ...acc,
21
+ curr,
22
+ ...curr.items
23
+ .filter((i) => i.type === 'document')
24
+ .map((item) => ({ ...item, isSubtab: true })),
25
+ ],
26
+ [],
27
+ );
28
+
29
+ // this is just to highlight that the way CclTabs is working is misleading
30
+ // It reads random properties from <div> children, which is unexpected
31
+ function Tab(props) {
32
+ return <div {...props} />;
33
+ }
14
34
 
15
35
  const CclFAQBlockView = (props) => {
16
- const { isEditMode } = props;
36
+ const { isEditMode, content } = props;
37
+ const pathname = getBaseUrl(props.pathname || props.path);
38
+ const cn_key = `${pathname}/@contextnavigation`;
39
+
40
+ // this are the accordions that are opened
41
+ const [activeIndex, setActiveIndex] = useState([]);
42
+
17
43
  const dispatch = useDispatch();
18
- const path = useSelector((state) => state.router.location.pathname);
19
- const contextNavigation = useSelector((state) => state.contextNavigation);
20
- const cn_key = `${path.replace('/edit', '')}/@contextnavigation`;
44
+ const contextNavigationItems = useSelector(
45
+ (state) =>
46
+ state.contextNavigation?.[cn_key]?.data?.items ||
47
+ content['@components']?.['contextnavigation']?.items,
48
+ );
49
+
21
50
  const handleClick = ({ index }) => {
22
51
  const newIndex =
23
52
  activeIndex.indexOf(index) === -1
@@ -27,128 +56,93 @@ const CclFAQBlockView = (props) => {
27
56
  setActiveIndex(newIndex);
28
57
  };
29
58
 
30
- const flattenCN = (cn_items) => {
31
- return cn_items.reduce((prev, curr) => {
32
- prev.push(curr);
33
- if (curr.items.filter((i) => i.type === 'document').length > 0) {
34
- curr.items
35
- .filter((i) => i.type === 'document')
36
- .forEach((i_i) => prev.push({ ...i_i, isSubtab: true }));
37
- }
38
- return prev;
39
- }, []);
40
- };
41
59
  const flatCN = flattenCN(
42
- contextNavigation?.[cn_key]?.data?.items
43
- ? contextNavigation?.[cn_key]?.data?.items.filter(
44
- (i) => i.type === 'document',
45
- )
46
- : [],
60
+ contextNavigationItems?.filter((i) => i.type === 'document') || [],
47
61
  );
48
- const [activeIndex, setActiveIndex] = useState([]);
62
+
49
63
  React.useEffect(() => {
50
- dispatch(getContextNavigation(path.replace('/edit', '')));
51
- }, [path, dispatch]);
64
+ isEditMode && dispatch(getContextNavigation(pathname));
65
+ }, [pathname, dispatch, isEditMode]);
66
+
52
67
  React.useEffect(() => {
53
- let indexes = [];
54
- // eslint-disable-next-line no-unused-expressions
55
- contextNavigation?.[cn_key]?.data?.items &&
56
- contextNavigation?.[cn_key]?.data?.items.forEach((i) => {
57
- if (i.items.length > 0) {
58
- indexes.push(i.items[0].normalized_id);
59
- }
60
- if (i.type === 'document') {
61
- i.items.forEach((i_i) => {
62
- if (i_i.items.length > 0) {
63
- indexes.push(i_i.items[0].normalized_id);
64
- }
65
- });
66
- }
67
- });
68
+ let indexes = (contextNavigationItems || []).reduce(
69
+ (acc, cur) => [
70
+ ...acc,
71
+ ...(cur.items?.length ? [cur.items[0].normalized_id] : []),
72
+ ...cur.items
73
+ ?.map((item) => item.items?.[0]?.normalized_id)
74
+ .filter((id) => !!id),
75
+ ],
76
+ [],
77
+ );
68
78
  setActiveIndex(indexes);
69
- // eslint-disable-next-line react-hooks/exhaustive-deps
70
- }, [contextNavigation?.[cn_key]?.data?.items]);
79
+ }, [contextNavigationItems]);
71
80
 
72
81
  const titleIcons = config.blocks?.blocksConfig?.accordion?.titleIcons;
73
82
 
74
83
  return (
75
84
  <div id="faq-listing" className="ccl-container tab-container">
76
- {contextNavigation?.[cn_key]?.loaded ? (
77
- contextNavigation?.[cn_key]?.data?.items?.length > 0 && (
78
- <CclTabs routing={true}>
79
- {flatCN
80
- .filter((cn) => cn.type === 'document')
81
- .map((cn, key) => (
82
- <div
83
- key={key}
84
- tabTitle={cn.title}
85
- className={
86
- cn.isSubtab
87
- ? 'subcard'
88
- : cn.items.filter((i) => i.type === 'document').length > 0
89
- }
90
- parent={
91
- cn.items.filter((i) => i.type === 'document').length > 0
92
- }
93
- >
94
- <div className="accordion-block">
95
- {cn.items
96
- .filter((item) => item.type === 'faq')
97
- .map((item, item_key) => {
98
- return (
99
- <Accordion fluid styled key={item_key}>
100
- <Accordion.Title
101
- as={'h2'}
102
- onClick={() =>
103
- handleClick({ index: item.normalized_id })
104
- }
105
- className={'accordion-title align-arrow-right'}
106
- >
107
- {activeIndex.includes(item.normalized_id) ? (
108
- <Icon name={titleIcons.opened.rightPosition} />
109
- ) : (
110
- <Icon name={titleIcons.closed.rightPosition} />
111
- )}
112
- {isEditMode && (
113
- <UniversalLink
114
- openLinkInNewTab={true}
115
- href={`${item['@id']}/edit`}
116
- >
117
- <Icon
118
- name={penSVG}
119
- className="circled"
120
- title={'Edit'}
121
- />
122
- </UniversalLink>
123
- )}
124
- <span>{item.title}</span>
125
- </Accordion.Title>
126
- <Accordion.Content
127
- active={activeIndex.includes(item.normalized_id)}
128
- >
129
- <AnimateHeight
130
- animateOpacity
131
- duration={500}
132
- height={'auto'}
133
- >
134
- {/* <StringToHTML
135
- string={item.text ? item.text.data : ''}
136
- /> */}
137
- {hasBlocksData(item) && (
138
- <RenderBlocks content={item} />
139
- )}
140
- </AnimateHeight>
141
- </Accordion.Content>
142
- </Accordion>
143
- );
144
- })}
145
- </div>
146
- </div>
147
- ))}
148
- </CclTabs>
149
- )
85
+ {contextNavigationItems?.length > 0 ? (
86
+ <CclTabs routing={true}>
87
+ {flatCN.map((cn, key) => (
88
+ <Tab
89
+ key={key}
90
+ tabTitle={cn.title}
91
+ className={cx({ subcard: cn.isSubtab })}
92
+ isParent={!!cn.items.filter((i) => i.type === 'document').length}
93
+ >
94
+ <div className="accordion-block">
95
+ {cn.items
96
+ .filter((item) => item.type === 'faq')
97
+ .map((item, item_key) => (
98
+ <Accordion fluid styled key={item_key}>
99
+ <Accordion.Title
100
+ as={'h2'}
101
+ onClick={() =>
102
+ handleClick({ index: item.normalized_id })
103
+ }
104
+ className={'accordion-title align-arrow-right'}
105
+ >
106
+ {activeIndex.includes(item.normalized_id) ? (
107
+ <Icon name={titleIcons.opened.rightPosition} />
108
+ ) : (
109
+ <Icon name={titleIcons.closed.rightPosition} />
110
+ )}
111
+ {isEditMode && (
112
+ <UniversalLink
113
+ openLinkInNewTab={true}
114
+ href={`${item['@id']}/edit`}
115
+ >
116
+ <Icon
117
+ name={penSVG}
118
+ className="circled"
119
+ title={'Edit'}
120
+ />
121
+ </UniversalLink>
122
+ )}
123
+ <span>{item.title}</span>
124
+ </Accordion.Title>
125
+ <Accordion.Content
126
+ active={activeIndex.includes(item.normalized_id)}
127
+ >
128
+ <AnimateHeight
129
+ animateOpacity
130
+ duration={500}
131
+ height={'auto'}
132
+ >
133
+ {hasBlocksData(item) && (
134
+ <RenderBlocks content={item} />
135
+ )}
136
+ </AnimateHeight>
137
+ </Accordion.Content>
138
+ </Accordion>
139
+ ))}
140
+ </div>
141
+ </Tab>
142
+ ))}
143
+ </CclTabs>
150
144
  ) : (
151
- <Segment loading={contextNavigation?.[cn_key]?.loading}></Segment>
145
+ <Segment loading={true}></Segment>
152
146
  )}
153
147
  </div>
154
148
  );
@@ -43,7 +43,7 @@ const CclTabs = (props) => {
43
43
  if (possible_hashes.includes(hash)) setActiveTab(hash);
44
44
  } else if (
45
45
  children.filter((item) => !!item?.props?.tabTitle).length > 1 &&
46
- firstTab.props?.parent
46
+ firstTab.props?.isParent
47
47
  ) {
48
48
  setActiveTab(
49
49
  slugify(
@@ -72,7 +72,7 @@ const CclTabs = (props) => {
72
72
  const currentTab = children.filter(
73
73
  (item) => slugify(item?.props?.tabTitle) === tabId,
74
74
  )[0];
75
- if (currentTab?.props?.parent) {
75
+ if (currentTab?.props?.isParent) {
76
76
  hasSubtab = true;
77
77
  }
78
78
  return (
package/src/index.js CHANGED
@@ -204,9 +204,18 @@ const applyConfig = (config) => {
204
204
  {
205
205
  match: '',
206
206
  GET_CONTENT: ['navigation'],
207
- querystring: (config) => ({
208
- 'expand.navigation.depth': config.settings.navDepth,
209
- }),
207
+ // TODO: this doesn't do anything as the querystring is not a callable
208
+ // querystring: (config) => ({
209
+ // 'expand.navigation.depth': config.settings.navDepth,
210
+ // }),
211
+ },
212
+ {
213
+ match: '/en/faq',
214
+ exact: false,
215
+ GET_CONTENT: ['contextnavigation'],
216
+ querystring: {
217
+ 'expand.contextnavigation.bottomLevel': 2,
218
+ },
210
219
  },
211
220
  ],
212
221
  };