@eeacms/volto-tabs-block 8.0.0 → 8.1.0
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 +24 -1
- package/package.json +2 -1
- package/src/components/EditBlockWrapper.jsx +3 -3
- package/src/components/View.jsx +7 -2
- package/src/components/schema.js +15 -1
- package/src/components/templates/default/Edit.jsx +1 -0
- package/src/components/templates/horizontal-responsive/Edit.jsx +1 -0
- package/src/helpers.js +25 -1
- package/src/helpers.test.js +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,30 @@ 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
|
-
### [8.
|
|
7
|
+
### [8.1.0](https://github.com/eea/volto-tabs-block/compare/8.0.1...8.1.0) - 26 August 2024
|
|
8
|
+
|
|
9
|
+
#### :rocket: New Features
|
|
10
|
+
|
|
11
|
+
- feat(tabs): hide empty tabs, ref #273963 [Miu Razvan - [`39c0af7`](https://github.com/eea/volto-tabs-block/commit/39c0af75e530f0c21a9a3b2a2a9117002473d3b8)]
|
|
12
|
+
|
|
13
|
+
#### :house: Internal changes
|
|
14
|
+
|
|
15
|
+
- chore: package.json [Alin Voinea - [`244a1de`](https://github.com/eea/volto-tabs-block/commit/244a1de20a7e9a8a2282f91715b26990a83454a8)]
|
|
16
|
+
|
|
17
|
+
#### :hammer_and_wrench: Others
|
|
18
|
+
|
|
19
|
+
- test isTabEmpty function [Miu Razvan - [`d3e569c`](https://github.com/eea/volto-tabs-block/commit/d3e569c6dcd244b31349616dc97b47566ac053c1)]
|
|
20
|
+
- clean up [Miu Razvan - [`4cf2260`](https://github.com/eea/volto-tabs-block/commit/4cf2260a9bb9e8ed1743ca7f9db4c6c6c6fd710f)]
|
|
21
|
+
- update empty tab logic [Miu Razvan - [`f859684`](https://github.com/eea/volto-tabs-block/commit/f859684cfce0508cf5122ad82af958ad4f035871)]
|
|
22
|
+
- fix [Miu Razvan - [`d532df2`](https://github.com/eea/volto-tabs-block/commit/d532df2ba65603ccc40a6f6c713129a4d84bc58a)]
|
|
23
|
+
- bump version [Miu Razvan - [`93e4894`](https://github.com/eea/volto-tabs-block/commit/93e48949777d970793665edb782705e0d3ac66b1)]
|
|
24
|
+
### [8.0.1](https://github.com/eea/volto-tabs-block/compare/8.0.0...8.0.1) - 6 August 2024
|
|
25
|
+
|
|
26
|
+
#### :bug: Bug Fixes
|
|
27
|
+
|
|
28
|
+
- fix: Pass all errors to BlocksForm - refs #269086 [dobri1408 - [`186d795`](https://github.com/eea/volto-tabs-block/commit/186d79542ae089146d1b562024cd059b4fcbf1f2)]
|
|
29
|
+
|
|
30
|
+
## [8.0.0](https://github.com/eea/volto-tabs-block/compare/7.5.1...8.0.0) - 22 April 2024
|
|
8
31
|
|
|
9
32
|
#### :rocket: New Features
|
|
10
33
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eeacms/volto-tabs-block",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "volto-tabs-block: Volto add-on",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "European Environment Agency: IDM2 A-Team",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@cypress/code-coverage": "^3.10.0",
|
|
32
32
|
"@plone/scripts": "*",
|
|
33
33
|
"babel-plugin-transform-class-properties": "^6.24.1",
|
|
34
|
+
"cypress": "13.1.0",
|
|
34
35
|
"dotenv": "^16.3.2",
|
|
35
36
|
"husky": "^8.0.3",
|
|
36
37
|
"lint-staged": "^14.0.1",
|
|
@@ -122,9 +122,9 @@ class EditBlockWrapper extends React.Component {
|
|
|
122
122
|
basic
|
|
123
123
|
title="Add block"
|
|
124
124
|
onClick={() => {
|
|
125
|
-
this.setState({
|
|
126
|
-
addNewBlockOpened: !
|
|
127
|
-
});
|
|
125
|
+
this.setState((prevState) => ({
|
|
126
|
+
addNewBlockOpened: !prevState.addNewBlockOpened,
|
|
127
|
+
}));
|
|
128
128
|
}}
|
|
129
129
|
className="column-block-add-button"
|
|
130
130
|
>
|
package/src/components/View.jsx
CHANGED
|
@@ -4,7 +4,10 @@ import { compose } from 'redux';
|
|
|
4
4
|
import { withRouter } from 'react-router';
|
|
5
5
|
import { StyleWrapperView } from '@eeacms/volto-block-style/StyleWrapper';
|
|
6
6
|
import { TABS_BLOCK } from '@eeacms/volto-tabs-block/constants';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
isTabEmpty,
|
|
9
|
+
getParentTabFromHash,
|
|
10
|
+
} from '@eeacms/volto-tabs-block/helpers';
|
|
8
11
|
import { DefaultView } from './templates/default';
|
|
9
12
|
import { withScrollToTarget } from '@eeacms/volto-tabs-block/hocs';
|
|
10
13
|
|
|
@@ -19,8 +22,10 @@ const View = (props) => {
|
|
|
19
22
|
const metadata = props.metadata || props.properties;
|
|
20
23
|
const template = data.variation || 'default';
|
|
21
24
|
const tabsData = data.data || {};
|
|
22
|
-
const tabsList = tabsData.blocks_layout?.items || [];
|
|
23
25
|
const tabs = tabsData.blocks || {};
|
|
26
|
+
const tabsList = (tabsData.blocks_layout?.items || []).filter((tab) => {
|
|
27
|
+
return data.hideEmptyTabs ? !isTabEmpty(tabs[tab]) : true;
|
|
28
|
+
});
|
|
24
29
|
const [activeTab, setActiveTab] = React.useState(tabsList?.[0]);
|
|
25
30
|
const activeTabIndex = tabsList.indexOf(activeTab);
|
|
26
31
|
const tabData = tabs[activeTab] || {};
|
package/src/components/schema.js
CHANGED
|
@@ -86,6 +86,10 @@ const messages = defineMessages({
|
|
|
86
86
|
id: 'hideTitle',
|
|
87
87
|
defaultMessage: 'Hide tab title?',
|
|
88
88
|
},
|
|
89
|
+
HideEmptyTabs: {
|
|
90
|
+
id: 'hideEmptyTabs',
|
|
91
|
+
defaultMessage: 'Hide empty tabs in view?',
|
|
92
|
+
},
|
|
89
93
|
Large: {
|
|
90
94
|
id: 'large',
|
|
91
95
|
defaultMessage: 'Large',
|
|
@@ -191,7 +195,13 @@ export const blockSchema = (props) => {
|
|
|
191
195
|
{
|
|
192
196
|
id: 'default',
|
|
193
197
|
title: intl.formatMessage(messages.Default),
|
|
194
|
-
fields: [
|
|
198
|
+
fields: [
|
|
199
|
+
'title',
|
|
200
|
+
'description',
|
|
201
|
+
'verticalAlign',
|
|
202
|
+
'hideEmptyTabs',
|
|
203
|
+
'data',
|
|
204
|
+
],
|
|
195
205
|
},
|
|
196
206
|
],
|
|
197
207
|
properties: {
|
|
@@ -216,6 +226,10 @@ export const blockSchema = (props) => {
|
|
|
216
226
|
],
|
|
217
227
|
default: 'flex-start',
|
|
218
228
|
},
|
|
229
|
+
hideEmptyTabs: {
|
|
230
|
+
title: intl.formatMessage(messages.HideEmptyTabs),
|
|
231
|
+
type: 'boolean',
|
|
232
|
+
},
|
|
219
233
|
},
|
|
220
234
|
required: [],
|
|
221
235
|
};
|
|
@@ -347,6 +347,7 @@ const Edit = (props) => {
|
|
|
347
347
|
<Tab.Pane key={tab} as={isContainer ? Container : undefined}>
|
|
348
348
|
<div tabIndex={0} role="tabpanel" id={'tab-pane-' + tab}>
|
|
349
349
|
<BlocksForm
|
|
350
|
+
errors={props.errors}
|
|
350
351
|
allowedBlocks={data?.allowedBlocks}
|
|
351
352
|
description={data?.instructions?.data}
|
|
352
353
|
manage={manage}
|
package/src/helpers.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { v4 as uuid } from 'uuid';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
emptyBlocksForm,
|
|
4
|
+
applySchemaDefaults,
|
|
5
|
+
getBlocksFieldname,
|
|
6
|
+
getBlocksLayoutFieldname,
|
|
7
|
+
} from '@plone/volto/helpers';
|
|
3
8
|
import { visitBlocks, toSlug } from '@eeacms/volto-anchors/helpers';
|
|
4
9
|
|
|
5
10
|
export const empty = ({ schema, intl }) => {
|
|
@@ -56,3 +61,22 @@ export const getParentTabFromHash = (tabsBlockData, urlHash) => {
|
|
|
56
61
|
}
|
|
57
62
|
return null;
|
|
58
63
|
};
|
|
64
|
+
|
|
65
|
+
export const isTabEmpty = (content) => {
|
|
66
|
+
const blocks_field = getBlocksFieldname(content);
|
|
67
|
+
const blocks_layout_field = getBlocksLayoutFieldname(content);
|
|
68
|
+
const blocks = content[blocks_field] || {};
|
|
69
|
+
const blocksNo = content[blocks_layout_field]?.items?.length || 0;
|
|
70
|
+
|
|
71
|
+
if (blocksNo === 1) {
|
|
72
|
+
const blockId = content[blocks_layout_field].items[0];
|
|
73
|
+
const block = blocks[blockId];
|
|
74
|
+
if (block['@type'] === 'slate' && !block['plaintext']) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (blocksNo === 0) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
};
|
package/src/helpers.test.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
emptyTab,
|
|
4
4
|
scrollToTarget,
|
|
5
5
|
getParentTabFromHash,
|
|
6
|
+
isTabEmpty,
|
|
6
7
|
} from './helpers';
|
|
7
8
|
// import { emptyBlocksForm } from '@plone/volto/helpers';
|
|
8
9
|
import { visitBlocks, toSlug } from '@eeacms/volto-anchors/helpers';
|
|
@@ -42,6 +43,19 @@ describe('emptyTab function', () => {
|
|
|
42
43
|
});
|
|
43
44
|
});
|
|
44
45
|
|
|
46
|
+
describe('isTabEmpty function', () => {
|
|
47
|
+
it('returns if a tab is empty', () => {
|
|
48
|
+
// emptyBlocksForm.mockReturnValue({});
|
|
49
|
+
const result = isTabEmpty({
|
|
50
|
+
blocks: {},
|
|
51
|
+
blocks_layout: {
|
|
52
|
+
items: [],
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
expect(result).toEqual(true);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
45
59
|
describe('scrollToTarget', () => {
|
|
46
60
|
it('should call window.scrollTo with the correct arguments', () => {
|
|
47
61
|
window.scrollTo = jest.fn();
|