Skip to content
This repository has been archived by the owner on Nov 23, 2022. It is now read-only.

Lighthouse draftjs #613

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/config/RichTextEditor/ToolbarButtons/Lighthouse.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { injectLazyLibs } from '@plone/volto/helpers/Loadable/Loadable';
import Icon from '@plone/volto/components/theme/Icon/Icon';
import showSVG from '@plone/volto/icons/show.svg';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questa icona dell'occhio non mi convince perchè viene utilizzata in generale per mostrare e nascondere un contenuto, non vorrei che venisse fraintesa, suggerisco di utilizzare una di queste due icone

  • un target, più generico

Screenshot 2022-11-22 alle 12 19 53

  • l'icona delle news che potrebbe vagamente assomigliare al faro di lighthouse però ditemi voi

Screenshot 2022-11-22 alle 12 19 33


import DraftJsDropdownButton from './DraftJsDropdownButton';

const AlignButtonComponent = (props) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'è un refuso, dai un nome specifico a questo componente

const createBlockStyleButton = props.draftJsCreateBlockStyleButton.default;
const options = [
{
block_type: 'lighthouse_appointment-booking',
value: createBlockStyleButton({
blockType: 'lighthouse_appointment-booking',
children: 'appointment-booking',
}),
contentWhenSelected: <Icon name={showSVG} size="24px" />,
},
{
block_type: 'lighthouse_faq',
value: createBlockStyleButton({
blockType: 'lighthouse_faq',
children: 'faq',
}),
contentWhenSelected: <Icon name={showSVG} size="24px" />,
},
{
block_type: 'lighthouse_report-inefficency',
value: createBlockStyleButton({
blockType: 'lighthouse_report-inefficency',
children: 'report-inefficency',
}),
contentWhenSelected: <Icon name={showSVG} size="24px" />,
},
{
block_type: 'lighthouse_accessibility-link',
value: createBlockStyleButton({
blockType: 'lighthouse_accessibility-link',
children: 'accessibility-link',
}),
contentWhenSelected: <Icon name={showSVG} size="24px" />,
},
{
block_type: 'lighthouse_privacy-policy-link',
value: createBlockStyleButton({
blockType: 'lighthouse_privacy-policy-link',
children: 'privacy-policy-link',
}),
contentWhenSelected: <Icon name={showSVG} size="24px" />,
},
];

return (
<DraftJsDropdownButton
{...props}
optionsList={options}
content={<Icon name={showSVG} size="24px" />}
/>
);
};

export const AlignButton = injectLazyLibs(['draftJsCreateBlockStyleButton'])(
AlignButtonComponent,
);

export default React.memo(AlignButton);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem qua come sopra, occhio quando copi e incolli!

47 changes: 47 additions & 0 deletions src/config/RichTextEditor/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Blocks from '@plone/volto/config/RichTextEditor/Blocks';
import UnderlineButton from '@italia/config/RichTextEditor/ToolbarButtons/UnderlineButton';
import HeadingsButton from '@italia/config/RichTextEditor/ToolbarButtons/HeadingsButton';
import AlignButton from '@italia/config/RichTextEditor/ToolbarButtons/AlignButton';
import Lighthouse from '@italia/config/RichTextEditor/ToolbarButtons/Lighthouse';
import CalloutsButton from '@italia/config/RichTextEditor/ToolbarButtons/CalloutsButton';
import ButtonsButton from '@italia/config/RichTextEditor/ToolbarButtons/ButtonsButton';
import TextSizeButton from '@italia/config/RichTextEditor/ToolbarButtons/TextSizeButton';
Expand Down Expand Up @@ -48,6 +49,8 @@ const ItaliaRichTextEditorInlineToolbarButtons = (props, plugins) => {
OrderedListButton,
BlockquoteButton,
CalloutsButton(props),
Separator,
Lighthouse,
];
};

Expand All @@ -72,6 +75,15 @@ const renderHTMLBlock = (child) => {
}
});
};
const renderDataElement = (element) => {
if (typeof document !== 'undefined') {
document.querySelector(`.lighthouse_${element} a`) &&
document
.querySelector(`.lighthouse_${element} a`)
.setAttribute('data-element', element);
}
};
Copy link
Contributor

@SaraBianchi SaraBianchi Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questo seleziona un elemento con una classe specifica ma se creo due link con lo stesso data element il secondo è vuoto, qui ho inserito nel secondo e nel terzo link lo stesso data element, il secondo non popola neanche la classe
Screenshot 2022-11-22 alle 12 52 52

Chiedo, non è possibile invece di utilizzare un selettore, applicare direttamente il data element ad un tag <a> invece che a un <p>?


const ItaliaBlocksHtmlRenderers = {
blockquote: (children, { keys }) =>
children.map((child, i) => (
Expand All @@ -83,6 +95,41 @@ const ItaliaBlocksHtmlRenderers = {
{renderHTMLBlock(child)}
</p>
)),
'lighthouse_appointment-booking': (children, { keys }) =>
children.map((child, i) => (
<p id={keys[i]} key={keys[i]} className="lighthouse_appointment-booking">
{renderHTMLBlock(child)}
{renderDataElement('appointment-booking')}
</p>
)),
lighthouse_faq: (children, { keys }) =>
children.map((child, i) => (
<p id={keys[i]} key={keys[i]} className="lighthouse_faq">
{renderHTMLBlock(child)}
{renderDataElement('faq')}
</p>
)),
'lighthouse_report-inefficency': (children, { keys }) =>
children.map((child, i) => (
<p id={keys[i]} key={keys[i]} className="lighthouse_report-inefficency">
{renderHTMLBlock(child)}
{renderDataElement('report-inefficency')}
</p>
)),
'lighthouse_accessibility-link': (children, { keys }) =>
children.map((child, i) => (
<p id={keys[i]} key={keys[i]} className="lighthouse_accessibility-link">
{renderHTMLBlock(child)}
{renderDataElement('accessibility-link')}
</p>
)),
'lighthouse_privacy-policy-link': (children, { keys }) =>
children.map((child, i) => (
<p id={keys[i]} key={keys[i]} className="lighthouse_privacy-policy-link">
{renderHTMLBlock(child)}
{renderDataElement('privacy-policy-link')}
</p>
)),
'align-right': (children, { keys }) =>
children.map((child, i) => (
<p id={keys[i]} key={keys[i]} className="text-right">
Expand Down