Skip to content

Commit

Permalink
Merge pull request #19 from eea/develop
Browse files Browse the repository at this point in the history
Citations in metadata
  • Loading branch information
avoinea committed Sep 10, 2021
2 parents 7c4c99f + 7010a35 commit 3b25f6c
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 20 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +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).

#### [3.1.1](https://github.com/eea/volto-slate-footnote/compare/3.1.0...3.1.1)

- Citations in metadata [`#18`](https://github.com/eea/volto-slate-footnote/pull/18)
- Remove console.log [`b5d83e7`](https://github.com/eea/volto-slate-footnote/commit/b5d83e7c13240151f602d122ecf09ba9b8e335f3)
- Fix slate json field default value in DX layout [`f2805bb`](https://github.com/eea/volto-slate-footnote/commit/f2805bbc15c51ebd914ee5f4eb9dd34ef32e095b)
- Fix cypress api_url [`6a4966a`](https://github.com/eea/volto-slate-footnote/commit/6a4966a2f92e932e1d0df35351989cda535f15c8)
- Add Sonarqube tag using ims-frontend addons list [`aed3984`](https://github.com/eea/volto-slate-footnote/commit/aed39840ecd467689eaf0adb352bd00ce95bdbbe)

#### [3.1.0](https://github.com/eea/volto-slate-footnote/compare/3.0.0...3.1.0)

> 9 September 2021
- Release [`#17`](https://github.com/eea/volto-slate-footnote/pull/17)
- render elements with multiple citations [`#15`](https://github.com/eea/volto-slate-footnote/pull/15)
- make accordion reference toggle when clicking citations refs #137423 [`#16`](https://github.com/eea/volto-slate-footnote/pull/16)
- Release 3.1.0 [`d87a1b0`](https://github.com/eea/volto-slate-footnote/commit/d87a1b0b893bb8fc090dcde193d3ac628471c352)
Expand Down
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-slate-footnote"
NAMESPACE = "@eeacms"
SONARQUBE_TAGS = "volto.eea.europa.eu,biodiversity.europa.eu"
SONARQUBE_TAGS = "volto.eea.europa.eu,biodiversity.europa.eu,www.eea.europa.eu-ims"
DEPENDENCIES = ""
}

Expand Down
20 changes: 8 additions & 12 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,15 @@ Cypress.Commands.add(
// --- Add DX Content-Type ----------------------------------------------------------
Cypress.Commands.add('addContentType', (name) => {
let api_url, auth;
api_url =
Cypress.env('API_PATH') ||
'http://localhost:8080/Plone/@controlpanels/dexterity-types';
api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
auth = {
user: 'admin',
pass: 'admin',
};
return cy
.request({
method: 'POST',
url: `${api_url}/${name}`,
url: `${api_url}/@controlpanels/dexterity-types/${name}`,
headers: {
Accept: 'application/json',
},
Expand All @@ -153,17 +151,15 @@ Cypress.Commands.add('addContentType', (name) => {
// --- Remove DX behavior ----------------------------------------------------------
Cypress.Commands.add('removeContentType', (name) => {
let api_url, auth;
api_url =
Cypress.env('API_PATH') ||
'http://localhost:8080/Plone/@controlpanels/dexterity-types';
api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
auth = {
user: 'admin',
pass: 'admin',
};
return cy
.request({
method: 'DELETE',
url: `${api_url}/${name}`,
url: `${api_url}/@controlpanels/dexterity-types/${name}`,
headers: {
Accept: 'application/json',
},
Expand All @@ -176,15 +172,15 @@ Cypress.Commands.add('removeContentType', (name) => {
// --- Add DX field ----------------------------------------------------------
Cypress.Commands.add('addSlateJSONField', (type, name) => {
let api_url, auth;
api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone/@types';
api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
auth = {
user: 'admin',
pass: 'admin',
};
return cy
.request({
method: 'POST',
url: `${api_url}/${type}`,
url: `${api_url}/@types/${type}`,
headers: {
Accept: 'application/json',
},
Expand All @@ -203,15 +199,15 @@ Cypress.Commands.add('addSlateJSONField', (type, name) => {
// --- Remove DX field ----------------------------------------------------------
Cypress.Commands.add('removeSlateJSONField', (type, name) => {
let api_url, auth;
api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone/@types';
api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
auth = {
user: 'admin',
pass: 'admin',
};
return cy
.request({
method: 'DELETE',
url: `${api_url}/${type}/${name}`,
url: `${api_url}/@types/${type}/${name}`,
headers: {
Accept: 'application/json',
},
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-slate-footnote",
"version": "3.1.0",
"version": "3.1.1",
"description": "volto-slate-footnote: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
5 changes: 3 additions & 2 deletions src/Blocks/Footnote/FootnotesBlockView.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useState } from 'react';
import { getAllBlocks } from 'volto-slate/utils';
import { getAllBlocksAndSlateFields } from '@eeacms/volto-slate-footnote/editor/utils';

import './less/public.less';
import {
makeFootnoteListOfUniqueItems,
Expand All @@ -25,7 +26,7 @@ const FootnotesBlockView = (props) => {
useEffect(() => {
if (properties) {
const globalMetadata = global ? metadata : properties;
const blocks = getAllBlocks(globalMetadata, []);
const blocks = getAllBlocksAndSlateFields(globalMetadata);
const notesObjResult = makeFootnoteListOfUniqueItems(blocks);

setNodesObjs(notesObjResult);
Expand Down
4 changes: 2 additions & 2 deletions src/editor/FootnoteEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import briefcaseSVG from '@plone/volto/icons/briefcase.svg';
import checkSVG from '@plone/volto/icons/check.svg';
import clearSVG from '@plone/volto/icons/clear.svg';
import { Node } from 'slate';
import { getAllBlocks } from 'volto-slate/utils';
import { getAllBlocksAndSlateFields } from '@eeacms/volto-slate-footnote/editor/utils';

const FootnoteEditor = (props) => {
const {
Expand Down Expand Up @@ -37,7 +37,7 @@ const FootnoteEditor = (props) => {

const blockProps = editor?.getBlockProps ? editor.getBlockProps() : {};
const metadata = blockProps.metadata || blockProps.properties || {};
const blocks = getAllBlocks(metadata, []);
const blocks = getAllBlocksAndSlateFields(metadata);
const filteredBlocks = [];

// make a list of filtered footnotes that have unique title
Expand Down
4 changes: 2 additions & 2 deletions src/editor/render.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { Popup, List } from 'semantic-ui-react';
import { useEditorContext } from 'volto-slate/hooks';
import { getAllBlocks } from 'volto-slate/utils';
import { getAllBlocksAndSlateFields } from '@eeacms/volto-slate-footnote/editor/utils';
import { makeFootnoteListOfUniqueItems } from './utils';

const makeFootnote = (footnote) => {
Expand Down Expand Up @@ -37,7 +37,7 @@ export const FootnoteElement = (props) => {
const metadata = blockProps
? blockProps.metadata || blockProps.properties
: extras?.metadata || {};
const blocks = getAllBlocks(metadata, []);
const blocks = getAllBlocksAndSlateFields(metadata);
const notesObjResult = makeFootnoteListOfUniqueItems(blocks);

const indice = zoteroId
Expand Down
41 changes: 41 additions & 0 deletions src/editor/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config from '@plone/volto/registry';
import { Node } from 'slate';
import { getAllBlocks } from 'volto-slate/utils';

/**
* remove <?xml version="1.0"?> from the string
Expand Down Expand Up @@ -42,6 +43,46 @@ const iterateZoteroObj = (notesObjResultTemp, zoteroObj, parentUid) => {
}
};

/**
* Extends volto-slate getAllBlocks functionality also to SlateJSONFields
* inserted within blocks via Metadata / Metadata section block
* @param {Object} properties metadata properties received by the View component
* @returns {Array} Returns a flat array of blocks and slate fields
*/
export const getAllBlocksAndSlateFields = (properties) => {
const blocks = getAllBlocks(properties, []);
const flat_blocks = [];
for (const b_idx in blocks) {
const block = blocks[b_idx];
if (block['@type'] === 'metadataSection') {
const fields = block.fields;
for (const f_idx in fields) {
const field = fields[f_idx];
if (field?.field?.widget === 'slate') {
const field_id = field.field.id;
flat_blocks.push({
'@type': 'slate',
id: field_id,
value: properties[field_id]?.length ? properties[field_id] : null,
});
}
}
} else if (block['@type'] === 'metadata') {
if (block?.data?.widget === 'slate') {
const f_id = block.data.id;
flat_blocks.push({
'@type': 'slate',
id: f_id,
value: properties[f_id]?.length ? properties[f_id] : null,
});
}
} else {
flat_blocks.push(block);
}
}
return flat_blocks;
};

/**
* Will make an object with keys for every zoteroId and some uid that are unique
* or referenced multiple times
Expand Down

0 comments on commit 3b25f6c

Please sign in to comment.