FEATURE Desactivating pannel for other publication thatn dynamiques papers
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Antoine M 2026-05-28 10:38:14 +02:00
parent 1dcbcfa9b8
commit 6f098e4881
4 changed files with 151 additions and 144 deletions

View File

@ -1 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-components', 'wp-data', 'wp-date', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '2926f9bf61acc4d0cf7e'); <?php return array('dependencies' => array('react-jsx-runtime', 'wp-components', 'wp-data', 'wp-date', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '3c86a0bf59d03b58250c');

View File

@ -19,13 +19,10 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__); /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); /* harmony import */ var _wordpress_date__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/date */ "@wordpress/date");
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_5__); /* harmony import */ var _wordpress_date__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_date__WEBPACK_IMPORTED_MODULE_5__);
/* harmony import */ var _wordpress_date__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/date */ "@wordpress/date"); /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime");
/* harmony import */ var _wordpress_date__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_date__WEBPACK_IMPORTED_MODULE_6__); /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime");
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__);
@ -35,19 +32,26 @@ __webpack_require__.r(__webpack_exports__);
const ModificationDatePanel = () => { const ModificationDatePanel = () => {
const { const {
modificationDate modificationDate,
postType
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => { } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => {
const meta = select("core/editor").getEditedPostAttribute("meta"); const meta = select("core/editor").getEditedPostAttribute("meta");
const postType = select("core/editor").getCurrentPostType();
return { return {
modificationDate: meta?.article_modification_date || "" modificationDate: meta?.article_modification_date || "",
postType: postType
}; };
}); });
const allowedPostTypes = ["article", "revue"]; // adapte avec tes vrais slugs
if (!allowedPostTypes.includes(postType)) {
return null;
}
const { const {
editPost editPost
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useDispatch)("core/editor"); } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useDispatch)("core/editor");
const settings = (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_6__.getSettings)(); const settings = (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_5__.getSettings)();
const updateModificationDate = newDate => { const updateModificationDate = newDate => {
const formattedDate = (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_6__.format)("Y-m-d H:i:s", newDate); const formattedDate = (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_5__.format)("Y-m-d H:i:s", newDate);
editPost({ editPost({
meta: { meta: {
article_modification_date: formattedDate article_modification_date: formattedDate
@ -63,22 +67,22 @@ const ModificationDatePanel = () => {
}; };
// Formater la date pour l'affichage // Formater la date pour l'affichage
const displayDate = modificationDate ? (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_6__.dateI18n)(settings.formats.datetime, modificationDate) : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Non définie", "dynamiques-modification-date"); const displayDate = modificationDate ? (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_5__.dateI18n)(settings.formats.datetime, modificationDate) : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Non définie", "dynamiques-modification-date");
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsxs)(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__.PluginDocumentSettingPanel, { return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__.PluginDocumentSettingPanel, {
name: "modification-date-panel", name: "modification-date-panel",
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Dernière mise à jour du papier", "dynamiques-modification-date"), title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Dernière mise à jour du papier", "dynamiques-modification-date"),
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)("div", { children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)("div", {
style: { style: {
marginBottom: "12px", marginBottom: "12px",
fontSize: "12px", fontSize: "12px",
color: "#757575" color: "#757575"
}, },
children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Choisissez ici la dernière date de révision de cet article", "dynamiques-modification-date") children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Choisissez ici la dernière date de révision de cet article", "dynamiques-modification-date")
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)("div", { }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)("div", {
style: { style: {
marginBottom: "16px" marginBottom: "16px"
}, },
children: modificationDate ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Dropdown, { children: modificationDate ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Dropdown, {
popoverProps: { popoverProps: {
placement: "bottom-start" placement: "bottom-start"
}, },
@ -86,7 +90,7 @@ const ModificationDatePanel = () => {
renderToggle: ({ renderToggle: ({
isOpen, isOpen,
onToggle onToggle
}) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, { }) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, {
variant: "secondary", variant: "secondary",
onClick: onToggle, onClick: onToggle,
"aria-expanded": isOpen, "aria-expanded": isOpen,
@ -100,24 +104,24 @@ const ModificationDatePanel = () => {
}), }),
renderContent: ({ renderContent: ({
onClose onClose
}) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsxs)("div", { }) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)("div", {
style: { style: {
padding: "16px" padding: "16px"
}, },
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.DateTimePicker, { children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.DateTimePicker, {
currentDate: modificationDate, currentDate: modificationDate,
onChange: newDate => { onChange: newDate => {
updateModificationDate(newDate); updateModificationDate(newDate);
onClose(); onClose();
}, },
is12Hour: settings.formats.time.includes("a") is12Hour: settings.formats.time.includes("a")
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)("div", { }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)("div", {
style: { style: {
marginTop: "16px", marginTop: "16px",
display: "flex", display: "flex",
gap: "8px" gap: "8px"
}, },
children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, { children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, {
variant: "secondary", variant: "secondary",
onClick: () => { onClick: () => {
clearModificationDate(); clearModificationDate();
@ -127,7 +131,7 @@ const ModificationDatePanel = () => {
}) })
})] })]
}) })
}) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, { }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, {
variant: "secondary", variant: "secondary",
onClick: () => updateModificationDate(new Date()), onClick: () => updateModificationDate(new Date()),
style: { style: {
@ -187,16 +191,6 @@ module.exports = window["wp"]["editor"];
/***/ }), /***/ }),
/***/ "@wordpress/element":
/*!*********************************!*\
!*** external ["wp","element"] ***!
\*********************************/
/***/ ((module) => {
module.exports = window["wp"]["element"];
/***/ }),
/***/ "@wordpress/i18n": /***/ "@wordpress/i18n":
/*!******************************!*\ /*!******************************!*\
!*** external ["wp","i18n"] ***! !*** external ["wp","i18n"] ***!

File diff suppressed because one or more lines are too long

View File

@ -3,126 +3,139 @@ import { Button, DateTimePicker, Dropdown } from "@wordpress/components";
import { PluginDocumentSettingPanel } from "@wordpress/editor"; import { PluginDocumentSettingPanel } from "@wordpress/editor";
import { useSelect, useDispatch } from "@wordpress/data"; import { useSelect, useDispatch } from "@wordpress/data";
import { __ } from "@wordpress/i18n"; import { __ } from "@wordpress/i18n";
import { useState } from "@wordpress/element";
import { dateI18n, format, getSettings } from "@wordpress/date"; import { dateI18n, format, getSettings } from "@wordpress/date";
const ModificationDatePanel = () => { const ModificationDatePanel = () => {
const { modificationDate } = useSelect((select) => { const { modificationDate, postType } = useSelect((select) => {
const meta = select("core/editor").getEditedPostAttribute("meta"); const meta = select("core/editor").getEditedPostAttribute("meta");
return { const postType = select("core/editor").getCurrentPostType();
modificationDate: meta?.article_modification_date || "",
};
});
const { editPost } = useDispatch("core/editor"); return {
const settings = getSettings(); modificationDate: meta?.article_modification_date || "",
postType: postType,
};
});
const updateModificationDate = (newDate) => { const allowedPostTypes = ["article", "revue"]; // adapte avec tes vrais slugs
const formattedDate = format("Y-m-d H:i:s", newDate); if (!allowedPostTypes.includes(postType)) {
editPost({ return null;
meta: { }
article_modification_date: formattedDate,
},
});
};
const clearModificationDate = () => { const { editPost } = useDispatch("core/editor");
editPost({ const settings = getSettings();
meta: {
article_modification_date: "",
},
});
};
// Formater la date pour l'affichage const updateModificationDate = (newDate) => {
const displayDate = modificationDate const formattedDate = format("Y-m-d H:i:s", newDate);
? dateI18n(settings.formats.datetime, modificationDate) editPost({
: __("Non définie", "dynamiques-modification-date"); meta: {
article_modification_date: formattedDate,
},
});
};
return ( const clearModificationDate = () => {
<PluginDocumentSettingPanel editPost({
name='modification-date-panel' meta: {
title={__("Dernière mise à jour du papier", "dynamiques-modification-date")}> article_modification_date: "",
<div },
style={{ });
marginBottom: "12px", };
fontSize: "12px",
color: "#757575",
}}>
{__(
"Choisissez ici la dernière date de révision de cet article",
"dynamiques-modification-date"
)}
</div>
<div style={{ marginBottom: "16px" }}> // Formater la date pour l'affichage
{modificationDate ? ( const displayDate = modificationDate
<Dropdown ? dateI18n(settings.formats.datetime, modificationDate)
popoverProps={{ placement: "bottom-start" }} : __("Non définie", "dynamiques-modification-date");
contentClassName='edit-post-post-schedule__dialog'
renderToggle={({ isOpen, onToggle }) => ( return (
<Button <PluginDocumentSettingPanel
variant='secondary' name="modification-date-panel"
onClick={onToggle} title={__(
aria-expanded={isOpen} "Dernière mise à jour du papier",
style={{ "dynamiques-modification-date",
textAlign: "left", )}
width: "100%", >
justifyContent: "flex-start", <div
color: "#1e1e1e", style={{
}}> marginBottom: "12px",
{displayDate} fontSize: "12px",
</Button> color: "#757575",
)} }}
renderContent={({ onClose }) => ( >
<div style={{ padding: "16px" }}> {__(
<DateTimePicker "Choisissez ici la dernière date de révision de cet article",
currentDate={modificationDate} "dynamiques-modification-date",
onChange={(newDate) => { )}
updateModificationDate(newDate); </div>
onClose();
}} <div style={{ marginBottom: "16px" }}>
is12Hour={settings.formats.time.includes("a")} {modificationDate ? (
/> <Dropdown
<div popoverProps={{ placement: "bottom-start" }}
style={{ contentClassName="edit-post-post-schedule__dialog"
marginTop: "16px", renderToggle={({ isOpen, onToggle }) => (
display: "flex", <Button
gap: "8px", variant="secondary"
}}> onClick={onToggle}
<Button aria-expanded={isOpen}
variant='secondary' style={{
onClick={() => { textAlign: "left",
clearModificationDate(); width: "100%",
onClose(); justifyContent: "flex-start",
}}> color: "#1e1e1e",
{__( }}
"Effacer", >
"dynamiques-modification-date" {displayDate}
)} </Button>
</Button> )}
</div> renderContent={({ onClose }) => (
</div> <div style={{ padding: "16px" }}>
)} <DateTimePicker
/> currentDate={modificationDate}
) : ( onChange={(newDate) => {
<Button updateModificationDate(newDate);
variant='secondary' onClose();
onClick={() => updateModificationDate(new Date())} }}
style={{ is12Hour={settings.formats.time.includes("a")}
textAlign: "left", />
width: "100%", <div
justifyContent: "flex-start", style={{
color: "#757575", marginTop: "16px",
}}> display: "flex",
{displayDate} gap: "8px",
</Button> }}
)} >
</div> <Button
</PluginDocumentSettingPanel> variant="secondary"
); onClick={() => {
clearModificationDate();
onClose();
}}
>
{__("Effacer", "dynamiques-modification-date")}
</Button>
</div>
</div>
)}
/>
) : (
<Button
variant="secondary"
onClick={() => updateModificationDate(new Date())}
style={{
textAlign: "left",
width: "100%",
justifyContent: "flex-start",
color: "#757575",
}}
>
{displayDate}
</Button>
)}
</div>
</PluginDocumentSettingPanel>
);
}; };
registerPlugin("modification-date-panel", { registerPlugin("modification-date-panel", {
render: ModificationDatePanel, render: ModificationDatePanel,
}); });