Skip to content

Commit

Permalink
Merge pull request #30 from eea/develop
Browse files Browse the repository at this point in the history
fix(toc): make it work, refs #265201
  • Loading branch information
claudiaifrim committed Feb 19, 2024
2 parents ec8cfe2 + e9e2bbf commit 2111100
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Jest configuration variables
# - possible values: ON, OFF
JEST_USE_SETUP=ON
65 changes: 65 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const fs = require('fs');
const path = require('path');
const projectRootPath = fs.realpathSync(__dirname + '/../../../');

let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto');
let configFile;
if (fs.existsSync(`${projectRootPath}/tsconfig.json`))
configFile = `${projectRootPath}/tsconfig.json`;
else if (fs.existsSync(`${projectRootPath}/jsconfig.json`))
configFile = `${projectRootPath}/jsconfig.json`;

if (configFile) {
const jsConfig = require(configFile).compilerOptions;
const pathsConfig = jsConfig.paths;
if (pathsConfig['@plone/volto'])
voltoPath = `./${jsConfig.baseUrl}/${pathsConfig['@plone/volto'][0]}`;
}

const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`);
const reg = new AddonConfigurationRegistry(projectRootPath);

// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons
const addonAliases = Object.keys(reg.packages).map((o) => [
o,
reg.packages[o].modulePath,
]);

const addonExtenders = reg.getEslintExtenders().map((m) => require(m));

const defaultConfig = {
extends: `${voltoPath}/.eslintrc`,
settings: {
'import/resolver': {
alias: {
map: [
['@plone/volto', '@plone/volto/src'],
['@plone/volto-slate', '@plone/volto/packages/volto-slate/src'],
...addonAliases,
['@package', `${__dirname}/src`],
['@root', `${__dirname}/src`],
['~', `${__dirname}/src`],
],
extensions: ['.js', '.jsx', '.json'],
},
'babel-plugin-root-import': {
rootPathSuffix: 'src',
},
},
},
rules: {
'react/jsx-no-target-blank': [
'error',
{
allowReferrer: true,
},
],
}
};

const config = addonExtenders.reduce(
(acc, extender) => extender.modify(acc),
defaultConfig,
);

module.exports = config;
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.vscode/
.history
.eslintrc.js
.nyc_output
project
coverage
Expand Down
48 changes: 0 additions & 48 deletions .project.eslintrc.js

This file was deleted.

20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ 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).

### [0.6.0](https://github.com/eea/volto-anchors/compare/0.5.0...0.6.0) - 16 February 2024

#### :bug: Bug Fixes

- fix(toc): make it work, refs #265201 [Razvan - [`d9316ae`](https://github.com/eea/volto-anchors/commit/d9316ae298746df976d9053f6a9ea708ac870483)]

#### :house: Internal changes

- chore: package.json [Alin Voinea - [`1bed96f`](https://github.com/eea/volto-anchors/commit/1bed96f3fb4a4a2ad7dd5621822ce9729b4e7683)]

#### :hammer_and_wrench: Others

- bump version [Razvan - [`db8e899`](https://github.com/eea/volto-anchors/commit/db8e899b29c5ffbe5169d867a3a64af5ee663a22)]
- Remove unused target and title attributes from renderLinkElement function [David Ichim - [`5a9d684`](https://github.com/eea/volto-anchors/commit/5a9d684bd468cb44a580758b390007ea2414af52)]
- set JEST_USE_SETUP=ON [Miu Razvan - [`97929a3`](https://github.com/eea/volto-anchors/commit/97929a3a3aae2646edabc5b2d973ff869ccc6413)]
- test: Update jest,Jenkinsfile,lint to volto-addons-template PR30 [valentinab25 - [`ea1f44c`](https://github.com/eea/volto-anchors/commit/ea1f44c9ea68ba37877d9213550ba5c4e4cd841e)]
- test: Update jest,Jenkinsfile,lint to volto-addons-template PR30 [valentinab25 - [`9fc3606`](https://github.com/eea/volto-anchors/commit/9fc360620c0ce329d48815980439dccaa363d31c)]
- test: Update jest,Jenkinsfile,lint to volto-addons-template PR30 [valentinab25 - [`f5d57b6`](https://github.com/eea/volto-anchors/commit/f5d57b697830abba5ed739822dc4379f2a581163)]
- fix helpers [nileshgulia1 - [`80e5633`](https://github.com/eea/volto-anchors/commit/80e5633bff8265d8d6b5eec78831fdb7955dadd0)]
### [0.5.0](https://github.com/eea/volto-anchors/compare/0.4.2...0.5.0) - 17 January 2024

#### :house: Internal changes
Expand All @@ -13,7 +32,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### :hammer_and_wrench: Others

- Release 0.5.0 [Alin Voinea - [`7ce0db5`](https://github.com/eea/volto-anchors/commit/7ce0db50c0a6a75486560f66b15ee5ef70e545e3)]
- fix tests [Miu Razvan - [`1777cba`](https://github.com/eea/volto-anchors/commit/1777cba0d12a7828c90a447f6076f5feed8db6b0)]
- fix jest [Miu Razvan - [`56d727a`](https://github.com/eea/volto-anchors/commit/56d727a2d276daa49df0733e66ab0f8b5b163620)]
- fix jest [Miu Razvan - [`8f2fd76`](https://github.com/eea/volto-anchors/commit/8f2fd76d21e59dab6136e59ae054f6ecaa8eb8c8)]
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pipeline {
environment {
GIT_NAME = "volto-anchors"
NAMESPACE = "@eeacms"
SONARQUBE_TAGS = "volto.eea.europa.eu,demo-www.eea.europa.eu,biodiversity.europa.eu,www.eea.europa.eu-ims,clmsdemo.devel6cph.eea.europa.eu,climate-advisory-board.europa.eu,forest.eea.europa.eu,climate-adapt.eea.europa.eu,www.eea.europa.eu-en,water.europa.eu-marine,industry.eea.europa.eu,climate-energy.eea.europa.eu,water.europa.eu-freshwater,land.copernicus.eu"
SONARQUBE_TAGS = "volto.eea.europa.eu,demo-www.eea.europa.eu,biodiversity.europa.eu,www.eea.europa.eu-ims,clmsdemo.devel6cph.eea.europa.eu,climate-advisory-board.europa.eu,forest.eea.europa.eu,climate-adapt.eea.europa.eu,www.eea.europa.eu-en,water.europa.eu-marine,industry.eea.europa.eu,climate-energy.eea.europa.eu,water.europa.eu-freshwater,land.copernicus.eu,insitu-frontend.eionet.europa.eu"
DEPENDENCIES = ""
BACKEND_PROFILES = "eea.kitkat:testing"
BACKEND_ADDONS = ""
Expand Down
12 changes: 8 additions & 4 deletions jest-addon.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('dotenv').config({ path: __dirname + '/.env' })

module.exports = {
testMatch: ['**/src/addons/**/?(*.)+(spec|test).[jt]s?(x)'],
collectCoverageFrom: [
Expand Down Expand Up @@ -38,7 +40,9 @@ module.exports = {
statements: 5,
},
},
setupFilesAfterEnv: [
'<rootDir>/node_modules/@eeacms/volto-anchors/jest.setup.js',
],
};
...(process.env.JEST_USE_SETUP === 'ON' && {
setupFilesAfterEnv: [
'<rootDir>/node_modules/@eeacms/volto-anchors/jest.setup.js',
],
}),
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-anchors",
"version": "0.5.0",
"version": "0.6.0",
"description": "@eeacms/volto-anchors: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand All @@ -24,6 +24,7 @@
"@plone/scripts": "*",
"babel-plugin-transform-class-properties": "^6.24.1",
"cypress-fail-fast": "^5.0.1",
"dotenv": "^16.3.2",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"md5": "^2.3.0"
Expand Down Expand Up @@ -69,4 +70,4 @@
"cypress:open": "make cypress-open",
"prepare": "husky install"
}
}
}
2 changes: 0 additions & 2 deletions src/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ exports[`renderLinkElement renders a UniversalLink when mode is set to view 1`]
href="/#test"
onClick={[Function]}
tabIndex={-1}
target={null}
title={null}
>
<svg
dangerouslySetInnerHTML={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const TextBlockView = (props) => {
const res = { ...styling };
if (node.type && isEqual(path, [0])) {
if (topLevelTargetElements.includes(node.type) || override_toc) {
const text = serializeNodesToText(node?.children || []);
const text = serializeNodesToText([node] || []);
const slug = Slugger.slug(text);
res.id = slug || id;
res['data-block'] = id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import DefaultTocRenderer from './DefaultTocRenderer';
import HorizontalMenu from './HorizontalMenu';

const ToCVariations = [
{
id: 'default',
title: 'Listing (default)',
view: DefaultTocRenderer,
isDefault: true,
},
{
id: 'horizontalMenu',
title: 'Horizontal Menu',
view: HorizontalMenu,
},
];

export default ToCVariations;
8 changes: 4 additions & 4 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isArray } from 'lodash';
import Slugger from 'github-slugger';
import config from '@plone/volto/registry';
import { serializeNodes } from '@plone/volto-slate/editor/render';
import { UniversalLink } from '@plone/volto/components';
import { Link } from 'react-router-dom';
import { getBlocks } from '@plone/volto/helpers/Blocks/Blocks';
import linkSVG from '@plone/volto/icons/link.svg';

Expand Down Expand Up @@ -97,19 +97,19 @@ export const renderLinkElement = (tagName) => {
) : (
<Tag className={className} {...attributes}>
{mode === 'view' && slug && (
<UniversalLink
<Link
className="anchor"
aria-hidden="true"
tabIndex={-1}
href={`#${slug}`}
to={`#${slug}`}
>
<svg
{...linkSVG.attributes}
dangerouslySetInnerHTML={{ __html: linkSVG.content }}
width="2em"
height={null}
></svg>
</UniversalLink>
</Link>
)}
{children}
</Tag>
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ScrollToAnchor from './components/ScrollToAnchor';
import { renderLinkElement } from './helpers';
import tocVariations from './customizations/volto/components/manage/Blocks/ToC/variations';

const applyConfig = (config) => {
config.settings.slate.useLinkedHeadings = true;
Expand All @@ -20,6 +21,11 @@ const applyConfig = (config) => {
},
];
}

config.blocks.blocksConfig.toc = {
...config.blocks.blocksConfig.toc,
variations: tocVariations,
};
return config;
};

Expand Down

0 comments on commit 2111100

Please sign in to comment.