Skip to content

Commit

Permalink
Merge pull request #11 from eea/develop
Browse files Browse the repository at this point in the history
Possibility to ignore spaces with maxChars
  • Loading branch information
avoinea authored Oct 11, 2021
2 parents 3de2a39 + 72acbc6 commit efe13ee
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 38 deletions.
24 changes: 7 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ 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).

#### [4.3.1](https://github.com/eea/volto-group-block/compare/4.3.0...4.3.1)

- No space count [`#10`](https://github.com/eea/volto-group-block/pull/10)

#### [4.3.0](https://github.com/eea/volto-group-block/compare/4.2.3...4.3.0)

> 24 June 2021
- Refactor counter to use CSS class instead of inline style [`#9`](https://github.com/eea/volto-group-block/pull/9)
- Show help icon only if block instructions differ from section instructions [`a4ca4e5`](https://github.com/eea/volto-group-block/commit/a4ca4e58968dcfb947072a255c8f797df7977852)
- [JENKINS] - Fix stylelint [`c897993`](https://github.com/eea/volto-group-block/commit/c8979933fda9366c8669aa2c494e7442e2ca4bae)
- Refactor counter to use CSS class instead of inline style [`d676d7d`](https://github.com/eea/volto-group-block/commit/d676d7d2fa50eb4c16ab4d332a728ab9a8062c3a)

#### [4.2.3](https://github.com/eea/volto-group-block/compare/4.2.2...4.2.3)

Expand All @@ -20,7 +25,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 14 May 2021
- [JENKINS] - Auto-release pipeline [`#7`](https://github.com/eea/volto-group-block/pull/7)

#### [4.2.1](https://github.com/eea/volto-group-block/compare/4.2.0...4.2.1)

Expand Down Expand Up @@ -100,7 +104,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Drop volto-blocks-form dependency [`#6`](https://github.com/eea/volto-group-block/pull/6)
- Release 3.0.0 [`a83216e`](https://github.com/eea/volto-group-block/commit/a83216ed496b3a14ea49fd9697cd50ac64866092)
- Cleanup Jenkinsfile DEPENDENCIES [`9d2a5d0`](https://github.com/eea/volto-group-block/commit/9d2a5d04308ecef93ca2682d928d0919b0f861ea)
- Cosmetics [`03d6ed8`](https://github.com/eea/volto-group-block/commit/03d6ed8cbb796bacef3b3b78a1cee4114874033c)
- Fix focus management [`35327d7`](https://github.com/eea/volto-group-block/commit/35327d7b457beeed15b7129541bb1665cab4586b)
- Change imports from volto core [`d1dcc14`](https://github.com/eea/volto-group-block/commit/d1dcc14116fa408731d545d45d01669a06563b46)
Expand Down Expand Up @@ -143,19 +146,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Release 1.0.0 [`b6ef873`](https://github.com/eea/volto-group-block/commit/b6ef873cb6f61e17db66fdd4de1d9d4902a66fc6)
- Update package meta info [`143b7d4`](https://github.com/eea/volto-group-block/commit/143b7d44438d7afa5e346a9d21a85352df4e925f)
- [JENKINS] - Fix SONAR tags [`512b56c`](https://github.com/eea/volto-group-block/commit/512b56ce931aa4c14f353e2a4c5bbbb614fe632f)
- [JENKINS] - Update [`2204acd`](https://github.com/eea/volto-group-block/commit/2204acdefee84114bd403f9772a1e610348dc3dd)
- [JENKINS] - Fix code-analysis [`88a5b3d`](https://github.com/eea/volto-group-block/commit/88a5b3d58b951ecfbc6e813accf065ca5e8be990)
- [JENKINS] - Fix SonarQube report [`7fca879`](https://github.com/eea/volto-group-block/commit/7fca879b526be822cd63312ed51447d6e6a59cf2)
- [JENKINS] - Fix unit tests pipeline [`5b9b28f`](https://github.com/eea/volto-group-block/commit/5b9b28f1de060635f1c665a80939bfa66918a918)
- [JENKINS] - Add jest unit tests [`d8af5b7`](https://github.com/eea/volto-group-block/commit/d8af5b7932988b490a079d86079e359b5584fd7f)
- [JENKINS] - Fix develop badge [`857b4ab`](https://github.com/eea/volto-group-block/commit/857b4ab5bc0aa9947c2ed76f35cec7d409c7fa66)
- [JENKINS] - Add jenkins builds badges [`6cebd3e`](https://github.com/eea/volto-group-block/commit/6cebd3e970a840c4951c614a5d130dab05ae553f)
- [JENKINS] - Cleanup console.log [`df38b6f`](https://github.com/eea/volto-group-block/commit/df38b6f7a630176e911ff89263c21e519ab44efa)
- [JENKINS] - Fix eslint pipeline [`ca7c87a`](https://github.com/eea/volto-group-block/commit/ca7c87a4f74f2b0ea354ea5369f0700b8bee92af)
- [JENKINS] - Fix style [`0e2c5a3`](https://github.com/eea/volto-group-block/commit/0e2c5a39b2f785ae1d942d39e7f8b2789dafc795)
- Add Jenkinkins pipeline [`866a4e1`](https://github.com/eea/volto-group-block/commit/866a4e14ea1eb8f5adb01222e576e5ab6dc73a70)
- yarn prettier [`e3fe0a3`](https://github.com/eea/volto-group-block/commit/e3fe0a36b89878769341b45198d6c9e2f2584d15)

#### [0.1.3](https://github.com/eea/volto-group-block/compare/0.1.2...0.1.3)

Expand Down Expand Up @@ -200,5 +191,4 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Render meta block [`0d44560`](https://github.com/eea/volto-group-block/commit/0d4456011ca56454068a54c610250b02df4ccb3b)
- Implement meta block allowedBlocks settings [`f24feb1`](https://github.com/eea/volto-group-block/commit/f24feb1a1751f04841c21c7cd52a517fb02074ba)
- Edit meta block [`236d291`](https://github.com/eea/volto-group-block/commit/236d29156fa835a7aa54eecdb4f120de0d64b271)
- yarn bootstrap [`e009dfb`](https://github.com/eea/volto-group-block/commit/e009dfb6b9b74d101a6722f0982a5359fc522b6b)
- Initial commit [`6a7b0de`](https://github.com/eea/volto-group-block/commit/6a7b0deb8f873d1462fd6a9c61edfc1562b3aace)
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pipeline {
environment {
GIT_NAME = "volto-group-block"
NAMESPACE = "@eeacms"
SONARQUBE_TAGS = "volto.eea.europa.eu"
SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,biodiversity.europa.eu"
DEPENDENCIES = ""
}

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-group-block",
"version": "4.3.0",
"version": "4.3.1",
"description": "volto-group-block: Volto block to be used to group other blocks",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
62 changes: 43 additions & 19 deletions src/components/manage/Blocks/Group/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ const Edit = (props) => {
} = props;

const metadata = props.metadata || props.properties;
const properties = isEmpty(data?.data?.blocks)
? emptyBlocksForm()
: data.data;
const data_blocks = data?.data?.blocks;
const properties = isEmpty(data_blocks) ? emptyBlocksForm() : data.data;

const [selectedBlock, setSelectedBlock] = useState(
properties.blocks_layout.items[0],
);

React.useEffect(() => {
if (
isEmpty(data?.data?.blocks) &&
isEmpty(data_blocks) &&
properties.blocks_layout.items[0] !== selectedBlock
) {
setSelectedBlock(properties.blocks_layout.items[0]);
Expand All @@ -49,40 +48,65 @@ const Edit = (props) => {
data: properties,
});
}
}, [
onChangeBlock,
properties,
selectedBlock,
block,
data,
data?.data?.blocks,
]);
}, [onChangeBlock, properties, selectedBlock, block, data, data_blocks]);

const blockState = {};
let charCount = 0;

/**
* Count the number of characters that are anything except using Regex
* @param {string} paragraph
* @returns
*/
const countCharsWithoutSpaces = (paragraph) => {
const regex = /[^\s\\]/g;

return (paragraph.match(regex) || []).length;
};

/**
* Count the number of characters
* @param {string} paragraph
* @returns
*/
const countCharsWithSpaces = (paragraph) => {
return paragraph?.length || 0;
};

/**
* Recursively look for any block that contains text or plaintext
* @param {Object} blocksObject
* @returns
*/
const countTextInBlocks = (blocksObject) => {
let groupCharCount = 0;

Object.keys(blocksObject).forEach((blockId) => {
const charCountTemp = blocksObject[blockId]?.plaintext
? blocksObject[blockId]?.plaintext.length
const foundText = blocksObject[blockId]?.plaintext
? blocksObject[blockId]?.plaintext
: blocksObject[blockId]?.text?.blocks[0]?.text
? blocksObject[blockId].text.blocks[0].text.length
? blocksObject[blockId].text.blocks[0].text
: blocksObject[blockId]?.data?.blocks
? countTextInBlocks(blocksObject[blockId]?.data?.blocks)
: blocksObject[blockId]?.blocks
? countTextInBlocks(blocksObject[blockId]?.blocks)
: 0;
groupCharCount = groupCharCount + charCountTemp;
: '';
const resultText =
typeof foundText === 'string' || foundText instanceof String
? foundText
: '';

groupCharCount += props.data.ignoreSpaces
? countCharsWithoutSpaces(resultText)
: countCharsWithSpaces(resultText);
});

return groupCharCount;
};

const showCharCounter = () => {
if (props.data?.data?.blocks) {
charCount = countTextInBlocks(props.data?.data?.blocks);
if (data_blocks) {
charCount = countTextInBlocks(data_blocks);
}
};
showCharCounter();
Expand Down
6 changes: 6 additions & 0 deletions src/components/manage/Blocks/Group/LayoutSchema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Schema = {
'allowedBlocks',
'as',
'maxChars',
'ignoreSpaces',
'readOnlySettings',
'disableInnerButtons',
'required',
Expand Down Expand Up @@ -67,6 +68,11 @@ const Schema = {
type: 'integer',
factory: 'Integer',
},
ignoreSpaces: {
title: 'Ignore spaces',
description: 'Ignore spaces while calculating maximum characters',
type: 'boolean',
},
required: {
title: 'Required',
description: "Don't allow deletion of this block",
Expand Down

0 comments on commit efe13ee

Please sign in to comment.