Skip to content

Commit

Permalink
Merge pull request #51 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea authored Sep 19, 2023
2 parents 807b639 + dc701d8 commit fbc69ba
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ -n "$CI" ] && exit 0
yarn lint-staged
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ 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).

### [6.1.5](https://github.com/eea/volto-slate-footnote/compare/6.1.4...6.1.5) - 19 September 2023

#### :bug: Bug Fixes

- fix: index not showing on diff - refs #257191 [dobri1408 - [`bd6eb19`](https://github.com/eea/volto-slate-footnote/commit/bd6eb197213e23420fdd2f185447cb92a8156fc9)]

#### :house: Internal changes

- style: lint-staged reorder in package.json [Alin Voinea - [`c618c3c`](https://github.com/eea/volto-slate-footnote/commit/c618c3c12a878cc87fb9c3fd658eeb5d1241e871)]

#### :hammer_and_wrench: Others

- test: EN locales, pre-commit fix, feature PRs checks Refs #257193 [valentinab25 - [`6886cf7`](https://github.com/eea/volto-slate-footnote/commit/6886cf796c58d38fcce7c515bda1d3586420a58a)]
### [6.1.4](https://github.com/eea/volto-slate-footnote/compare/6.1.3...6.1.4) - 1 September 2023

#### :bug: Bug Fixes
Expand Down
66 changes: 45 additions & 21 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ pipeline {

stage('Tests') {
when {
allOf {
environment name: 'CHANGE_ID', value: ''
anyOf {
not { changelog '.*^Automated release [0-9\\.]+$' }
branch 'master'
anyOf {
allOf {
not { environment name: 'CHANGE_ID', value: '' }
environment name: 'CHANGE_TARGET', value: 'develop'
}
allOf {
environment name: 'CHANGE_ID', value: ''
anyOf {
not { changelog '.*^Automated release [0-9\\.]+$' }
branch 'master'
}
}
}
}
Expand Down Expand Up @@ -110,11 +116,17 @@ pipeline {

stage('Integration tests') {
when {
allOf {
environment name: 'CHANGE_ID', value: ''
anyOf {
not { changelog '.*^Automated release [0-9\\.]+$' }
branch 'master'
anyOf {
allOf {
not { environment name: 'CHANGE_ID', value: '' }
environment name: 'CHANGE_TARGET', value: 'develop'
}
allOf {
environment name: 'CHANGE_ID', value: ''
anyOf {
not { changelog '.*^Automated release [0-9\\.]+$' }
branch 'master'
}
}
}
}
Expand Down Expand Up @@ -167,13 +179,19 @@ pipeline {

stage('Report to SonarQube') {
when {
allOf {
environment name: 'CHANGE_ID', value: ''
anyOf {
branch 'master'
allOf {
branch 'develop'
not { changelog '.*^Automated release [0-9\\.]+$' }
anyOf {
allOf {
not { environment name: 'CHANGE_ID', value: '' }
environment name: 'CHANGE_TARGET', value: 'develop'
}
allOf {
environment name: 'CHANGE_ID', value: ''
anyOf {
allOf {
branch 'develop'
not { changelog '.*^Automated release [0-9\\.]+$' }
}
branch 'master'
}
}
}
Expand All @@ -199,10 +217,16 @@ pipeline {

stage('SonarQube compare to master') {
when {
allOf {
environment name: 'CHANGE_ID', value: ''
branch 'develop'
not { changelog '.*^Automated release [0-9\\.]+$' }
anyOf {
allOf {
not { environment name: 'CHANGE_ID', value: '' }
environment name: 'CHANGE_TARGET', value: 'develop'
}
allOf {
environment name: 'CHANGE_ID', value: ''
branch 'develop'
not { changelog '.*^Automated release [0-9\\.]+$' }
}
}
}
steps {
Expand Down
4 changes: 2 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const { defineConfig } = require('cypress');

module.exports = defineConfig({
viewportWidth: 1280,
defaultCommandTimeout: 8888,
defaultCommandTimeout: 5000,
chromeWebSecurity: false,
reporter: 'junit',
video: true,
retries: {
runMode: 8,
runMode: 1,
openMode: 0,
},
reporterOptions: {
Expand Down
28 changes: 26 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-slate-footnote",
"version": "6.1.4",
"version": "6.1.5",
"description": "volto-slate-footnote: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand All @@ -23,8 +23,31 @@
"@cypress/code-coverage": "^3.10.0",
"@plone/scripts": "*",
"babel-plugin-transform-class-properties": "^6.24.1",
"husky": "*",
"lint-staged": "*",
"md5": "^2.3.0"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json}": [
"make lint-fix",
"make prettier-fix"
],
"src/**/*.{jsx}": [
"make i18n"
],
"theme/**/*.{css,less}": [
"make stylelint-fix"
],
"src/**/*.{css,less}": [
"make stylelint-fix"
],
"theme/**/*.overrides": [
"make stylelint-fix"
],
"src/**/*.overrides": [
"make stylelint-fix"
]
},
"scripts": {
"release": "release-it",
"release-major-beta": "release-it major --preRelease=beta",
Expand All @@ -42,6 +65,7 @@
"lint:fix": "make lint-fix",
"i18n": "make i18n",
"cypress:run": "make cypress-run",
"cypress:open": "make cypress-open"
"cypress:open": "make cypress-open",
"prepare": "husky install"
}
}
10 changes: 10 additions & 0 deletions src/editor/SearchWidget.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import renderer from 'react-test-renderer';
import SearchWidget from './SearchWidget';
describe('Test SearchWidget', () => {
it('check html content', () => {
const component = renderer.create(<SearchWidget />);
const json = component.toJSON();
expect(json).toMatchSnapshot();
});
});
72 changes: 72 additions & 0 deletions src/editor/__snapshots__/SearchWidget.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test SearchWidget check html content 1`] = `
<div
id="blockform-fieldset-default"
>
<div
className="ui segment attached"
fluid={true}
>
<div
className="ui fluid card"
onClick={[Function]}
>
<div
className="content"
fluid={true}
>
<div
className="header"
>
Citation
</div>
<div
className="description"
fluid={true}
>
<div
className="ui fluid search"
onBlur={[Function]}
onFocus={[Function]}
onMouseDown={[Function]}
>
<div
className="ui fluid right icon input"
>
<input
autoComplete="off"
className="prompt"
id="field-footnote"
onChange={[Function]}
onClick={[Function]}
tabIndex="0"
type="text"
value=""
/>
<i
aria-hidden="true"
className="search icon"
onClick={[Function]}
/>
</div>
<div
className="results transition"
>
<div
className="message empty"
>
<div
className="header"
>
No results found.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
`;
112 changes: 51 additions & 61 deletions src/editor/render.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React from 'react';
import { Popup, List } from 'semantic-ui-react';
import { useEditorContext } from '@plone/volto-slate/hooks';
import { getAllBlocksAndSlateFields } from '@eeacms/volto-slate-footnote/editor/utils';
Expand All @@ -24,71 +24,61 @@ export const FootnoteElement = (props) => {
const { data = {} } = element;
const { uid, zoteroId } = data;
const editor = useEditorContext();
const [citationIndice, setCitationIndice] = useState(null); // list of indices to reference
const [citationRefId, setCitationRefId] = useState(null); // indice of element to be referenced
const initialFormData = useSelector((state) => state?.content?.data || {});

useEffect(() => {
const blockProps = editor?.getBlockProps ? editor.getBlockProps() : null;
const metadata = blockProps
? blockProps.metadata || blockProps.properties
: extras?.metadata || {};
const blocks = getAllBlocksAndSlateFields(metadata);
const storeBlocks = getAllBlocksAndSlateFields(initialFormData);

const notesObjResult = isEmpty(metadata)
? makeFootnoteListOfUniqueItems(storeBlocks)
: makeFootnoteListOfUniqueItems(blocks);
const initialFormData = useSelector((state) => state?.content?.data || {});
const blockProps = editor?.getBlockProps ? editor.getBlockProps() : null;
const metadata = blockProps
? blockProps.metadata || blockProps.properties
: extras?.metadata || {};
const blocks = getAllBlocksAndSlateFields(metadata);
const storeBlocks = getAllBlocksAndSlateFields(initialFormData);

// will cosider zotero citations and footnote
// notesObjResult contains all zotero/footnote as unique, and contain refs for other zotero/footnote
const indiceIfZoteroId = data.extra
? [
`[${Object.keys(notesObjResult).indexOf(zoteroId) + 1}]`, // parent footnote
...data.extra.map(
// citations from extra
(zoteroObj, _index) =>
// all zotero citation are indexed by zoteroId in notesObjResult
`[${
Object.keys(notesObjResult).indexOf(zoteroObj.zoteroId) + 1
}]`,
),
].join('')
: // no extra citations (no multiples)
`[${Object.keys(notesObjResult).indexOf(zoteroId) + 1}]`;
const notesObjResult = isEmpty(metadata)
? makeFootnoteListOfUniqueItems(storeBlocks)
: makeFootnoteListOfUniqueItems(blocks);

const indice = zoteroId // ZOTERO
? indiceIfZoteroId
: // FOOTNOTES
// parent footnote
[data, ...(data.extra || [])]
.map((footnoteObj, _index) => {
return `[${
Object.keys(notesObjResult).indexOf(
Object.keys(notesObjResult).find(
(key) =>
notesObjResult[key].footnote === footnoteObj.footnote,
),
) + 1
}]`;
})
.join('');
// will cosider zotero citations and footnote
// notesObjResult contains all zotero/footnote as unique, and contain refs for other zotero/footnote
const indiceIfZoteroId = data.extra
? [
`[${Object.keys(notesObjResult).indexOf(zoteroId) + 1}]`, // parent footnote
...data.extra.map(
// citations from extra
(zoteroObj, _index) =>
// all zotero citation are indexed by zoteroId in notesObjResult
`[${Object.keys(notesObjResult).indexOf(zoteroObj.zoteroId) + 1}]`,
),
].join('')
: // no extra citations (no multiples)
`[${Object.keys(notesObjResult).indexOf(zoteroId) + 1}]`;

const findReferenceId =
// search within parent citations first, otherwise the uid might be inside a refs obj that comes before
Object.keys(notesObjResult).find(
(noteKey) => notesObjResult[noteKey].uid === uid,
) ||
// if not found in parent, search in refs, it might be a footnote references multiple times
Object.keys(notesObjResult).find(
(noteKey) =>
notesObjResult[noteKey].uid === uid ||
(notesObjResult[noteKey].refs && notesObjResult[noteKey].refs[uid]),
);
const citationIndice = zoteroId // ZOTERO
? indiceIfZoteroId
: // FOOTNOTES
// parent footnote
[data, ...(data.extra || [])]
.map((footnoteObj, _index) => {
return `[${
Object.keys(notesObjResult).indexOf(
Object.keys(notesObjResult).find(
(key) => notesObjResult[key].footnote === footnoteObj.footnote,
),
) + 1
}]`;
})
.join('');

setCitationIndice(indice);
setCitationRefId(findReferenceId);
}, [editor, element, children]); // eslint-disable-line
const citationRefId =
// search within parent citations first, otherwise the uid might be inside a refs obj that comes before
Object.keys(notesObjResult).find(
(noteKey) => notesObjResult[noteKey].uid === uid,
) ||
// if not found in parent, search in refs, it might be a footnote references multiple times
Object.keys(notesObjResult).find(
(noteKey) =>
notesObjResult[noteKey].uid === uid ||
(notesObjResult[noteKey].refs && notesObjResult[noteKey].refs[uid]),
);

return (
<>
Expand Down

0 comments on commit fbc69ba

Please sign in to comment.