handling empty block notifications
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e6c233376e
commit
29bfa6e9f0
|
|
@ -1 +1 @@
|
|||
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '510e7794936cc8444189');
|
||||
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-notices'), 'version' => 'bda8b3f54e1d213d5635');
|
||||
|
|
|
|||
|
|
@ -11,4 +11,9 @@
|
|||
filter: saturate(90%);
|
||||
}
|
||||
|
||||
.wp-block-homegrade-content-blocks-questions-container:has(.components-notice) {
|
||||
opacity: 100%;
|
||||
filter: saturate(100%);
|
||||
}
|
||||
|
||||
/*# sourceMappingURL=index.css.map*/
|
||||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.css","mappings":";;;AAAA;;;;EAAA;AAMA;EACC;EACA;AAAD,C","sources":["webpack://multiblocks/./src/editor.scss"],"sourcesContent":["/**\n * The following styles get applied inside the editor only.\n *\n * Replace them with your own styles or remove the file completely.\n */\n\n.wp-block-homegrade-content-blocks-questions-container {\n\topacity: 50%;\n\tfilter: saturate(90%);\n}\n"],"names":[],"sourceRoot":""}
|
||||
{"version":3,"file":"index.css","mappings":";;;AAAA;;;;EAAA;AAMA;EACC;EACA;AAAD;;AAGA;EACC;EACA;AAAD,C","sources":["webpack://multiblocks/./src/editor.scss"],"sourcesContent":["/**\n * The following styles get applied inside the editor only.\n *\n * Replace them with your own styles or remove the file completely.\n */\n\n.wp-block-homegrade-content-blocks-questions-container {\n\topacity: 50%;\n\tfilter: saturate(90%);\n}\n\n.wp-block-homegrade-content-blocks-questions-container:has(.components-notice) {\n\topacity: 100%;\n\tfilter: saturate(100%);\n}\n"],"names":[],"sourceRoot":""}
|
||||
|
|
@ -147,12 +147,19 @@ __webpack_require__.r(__webpack_exports__);
|
|||
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor");
|
||||
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
|
||||
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./editor.scss */ "./src/editor.scss");
|
||||
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/html-entities */ "@wordpress/html-entities");
|
||||
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_5__);
|
||||
/* harmony import */ var _OptionsSelectControl__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./OptionsSelectControl */ "./src/OptionsSelectControl.js");
|
||||
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
|
||||
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _wordpress_notices__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/notices */ "@wordpress/notices");
|
||||
/* harmony import */ var _wordpress_notices__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_notices__WEBPACK_IMPORTED_MODULE_4__);
|
||||
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
|
||||
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_5__);
|
||||
/* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./editor.scss */ "./src/editor.scss");
|
||||
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/html-entities */ "@wordpress/html-entities");
|
||||
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_7__);
|
||||
/* harmony import */ var _OptionsSelectControl__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./OptionsSelectControl */ "./src/OptionsSelectControl.js");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -162,6 +169,7 @@ __webpack_require__.r(__webpack_exports__);
|
|||
|
||||
|
||||
|
||||
|
||||
function parseBlockContentForTooltips(editorContent) {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(editorContent, "text/html");
|
||||
|
|
@ -191,7 +199,10 @@ function Edit({
|
|||
const {
|
||||
relatedPostId
|
||||
} = attributes;
|
||||
let currentRelatedPost = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => select("core").getEntityRecord("postType", "questions", relatedPostId));
|
||||
const {
|
||||
createErrorNotice
|
||||
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_5__.useDispatch)(_wordpress_notices__WEBPACK_IMPORTED_MODULE_4__.store);
|
||||
let currentRelatedPost = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_5__.useSelect)(select => select("core").getEntityRecord("postType", "questions", relatedPostId));
|
||||
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
||||
if (currentRelatedPost) {
|
||||
const currentBlockTooltips = parseBlockContentForTooltips(currentRelatedPost.content.rendered);
|
||||
|
|
@ -199,15 +210,23 @@ function Edit({
|
|||
tooltipsWordsUsed: currentBlockTooltips
|
||||
});
|
||||
}
|
||||
if (!relatedPostId) {
|
||||
createErrorNotice((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Un bloc question est vide ou n'est relié à aucune question"), {
|
||||
explicitDismiss: true
|
||||
});
|
||||
}
|
||||
}, [currentRelatedPost]);
|
||||
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_OptionsSelectControl__WEBPACK_IMPORTED_MODULE_6__["default"], {
|
||||
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_OptionsSelectControl__WEBPACK_IMPORTED_MODULE_8__["default"], {
|
||||
relatedPostId: relatedPostId,
|
||||
setAttributes: setAttributes
|
||||
}), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("section", {
|
||||
...(0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.useBlockProps)({
|
||||
className: `questions-container`
|
||||
})
|
||||
}, !relatedPostId && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Ce bloc n'est relié à aucune question. Rattachez-le à une fiche question dans la barre latérale.", "homegrade-blocks__texte-backoffice"))), currentRelatedPost && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("h3", null, (0,_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_5__.decodeEntities)(currentRelatedPost.title.rendered)), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.RawHTML, null, currentRelatedPost.content.rendered))));
|
||||
}, !relatedPostId && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Notice, {
|
||||
status: "error",
|
||||
isDismissible: false
|
||||
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Ce bloc n'est relié à aucune question. Rattachez-le à une fiche question dans la barre latérale.", "homegrade-blocks__texte-backoffice")))), currentRelatedPost && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("h3", null, (0,_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_7__.decodeEntities)(currentRelatedPost.title.rendered)), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.RawHTML, null, currentRelatedPost.content.rendered))));
|
||||
}
|
||||
|
||||
/***/ }),
|
||||
|
|
@ -328,6 +347,16 @@ module.exports = window["wp"]["i18n"];
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ "@wordpress/notices":
|
||||
/*!*********************************!*\
|
||||
!*** external ["wp","notices"] ***!
|
||||
\*********************************/
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = window["wp"]["notices"];
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./src/block.json":
|
||||
/*!************************!*\
|
||||
!*** ./src/block.json ***!
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
$relatedPostId = $attributes['relatedPostId'] ?? null;
|
||||
if (!$relatedPostId) return;
|
||||
|
||||
$relatedPost = get_post($relatedPostId);
|
||||
|
||||
?>
|
||||
|
||||
<section id="questions-container-<?php echo $relatedPostId ?>" class="questions-container-block">
|
||||
<h2 class="questions-container-block__title"><?php echo $relatedPost->post_title ?></h2>
|
||||
<?php echo do_blocks($relatedPost->post_content) ?>
|
||||
</section>
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
/*!***************************************************************************************************************************************************************************************************************************************************!*\
|
||||
!*** css ../../node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[4].use[1]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[4].use[2]!../../node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[4].use[3]!./src/style.scss ***!
|
||||
\***************************************************************************************************************************************************************************************************************************************************/
|
||||
/**
|
||||
* The following styles get applied both on the front of your site
|
||||
* and in the editor.
|
||||
*
|
||||
* Replace them with your own styles or remove the file completely.
|
||||
*/
|
||||
.wp-block-homegrade-content-blocks-questions-container h2 {
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
/*# sourceMappingURL=style-index.css.map*/
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"./style-index.css","mappings":";;;AAAA;;;;;EAAA;AAQC;EACC;AADF,C","sources":["webpack://multiblocks/./src/style.scss"],"sourcesContent":["/**\n * The following styles get applied both on the front of your site\n * and in the editor.\n *\n * Replace them with your own styles or remove the file completely.\n */\n\n.wp-block-homegrade-content-blocks-questions-container {\n\th2 {\n\t\tfont-weight: 800;\n\t}\n}\n"],"names":[],"sourceRoot":""}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
import { __ } from "@wordpress/i18n";
|
||||
import { useBlockProps } from "@wordpress/block-editor";
|
||||
import { Notice } from "@wordpress/components";
|
||||
import { store as noticesStore } from "@wordpress/notices";
|
||||
import { useDispatch } from "@wordpress/data";
|
||||
|
||||
import { useSelect } from "@wordpress/data"; // pour les querry
|
||||
import "./editor.scss";
|
||||
|
|
@ -7,6 +10,7 @@ import { RawHTML } from "@wordpress/element";
|
|||
import { useEffect } from "@wordpress/element";
|
||||
import { decodeEntities } from "@wordpress/html-entities";
|
||||
import OptionsSelectControl from "./OptionsSelectControl";
|
||||
import { Button } from "@wordpress/components";
|
||||
|
||||
function parseBlockContentForTooltips(editorContent) {
|
||||
const parser = new DOMParser();
|
||||
|
|
@ -20,11 +24,11 @@ function parseBlockContentForTooltips(editorContent) {
|
|||
const tooltipID = tooltipWord.getAttribute("data-definition-id");
|
||||
const tooltipText = tooltipWord.getAttribute("data-tooltip-word");
|
||||
const tooltipDefinition = tooltipWord.getAttribute(
|
||||
"data-tooltip-definition",
|
||||
"data-tooltip-definition"
|
||||
);
|
||||
|
||||
const existingTooltip = filteredTooltipWords.find(
|
||||
(item) => item.tooltipID === tooltipID,
|
||||
(item) => item.tooltipID === tooltipID
|
||||
);
|
||||
|
||||
if (!existingTooltip) {
|
||||
|
|
@ -40,18 +44,28 @@ function parseBlockContentForTooltips(editorContent) {
|
|||
|
||||
export default function Edit({ attributes, setAttributes }) {
|
||||
const { relatedPostId } = attributes;
|
||||
const { createErrorNotice } = useDispatch(noticesStore);
|
||||
|
||||
let currentRelatedPost = useSelect((select) =>
|
||||
select("core").getEntityRecord("postType", "questions", relatedPostId),
|
||||
select("core").getEntityRecord("postType", "questions", relatedPostId)
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (currentRelatedPost) {
|
||||
const currentBlockTooltips = parseBlockContentForTooltips(
|
||||
currentRelatedPost.content.rendered,
|
||||
currentRelatedPost.content.rendered
|
||||
);
|
||||
setAttributes({ tooltipsWordsUsed: currentBlockTooltips });
|
||||
}
|
||||
|
||||
if (!relatedPostId) {
|
||||
createErrorNotice(
|
||||
__("Un bloc question est vide ou n'est relié à aucune question"),
|
||||
{
|
||||
explicitDismiss: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
}, [currentRelatedPost]);
|
||||
|
||||
return (
|
||||
|
|
@ -68,12 +82,14 @@ export default function Edit({ attributes, setAttributes }) {
|
|||
>
|
||||
{!relatedPostId && (
|
||||
<>
|
||||
<p>
|
||||
{__(
|
||||
"Ce bloc n'est relié à aucune question. Rattachez-le à une fiche question dans la barre latérale.",
|
||||
"homegrade-blocks__texte-backoffice",
|
||||
)}
|
||||
</p>
|
||||
<Notice status="error" isDismissible={false}>
|
||||
<p>
|
||||
{__(
|
||||
"Ce bloc n'est relié à aucune question. Rattachez-le à une fiche question dans la barre latérale.",
|
||||
"homegrade-blocks__texte-backoffice"
|
||||
)}
|
||||
</p>
|
||||
</Notice>
|
||||
</>
|
||||
)}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,3 +8,8 @@
|
|||
opacity: 50%;
|
||||
filter: saturate(90%);
|
||||
}
|
||||
|
||||
.wp-block-homegrade-content-blocks-questions-container:has(.components-notice) {
|
||||
opacity: 100%;
|
||||
filter: saturate(100%);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user