@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
47 lines (46 loc) • 1.54 kB
JavaScript
// packages/core-data/src/components/entities-saved-states/entity-record-item.js
import { CheckboxControl, PanelRow } from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import { useSelect } from "@wordpress/data";
import { decodeEntities } from "@wordpress/html-entities";
import { STORE_NAME } from "../../name.mjs";
import { getTemplateInfo } from "../../utils/get-template-info.mjs";
import { Fragment, jsx } from "react/jsx-runtime";
function EntityRecordItem({ record, checked, onChange }) {
const { name, kind, title, key } = record;
const { entityRecordTitle } = useSelect(
(select) => {
if ("postType" !== kind || "wp_template" !== name) {
return {
entityRecordTitle: title
};
}
const template = select(STORE_NAME).getEditedEntityRecord(
kind,
name,
key
);
const { default_template_types: templateTypes = [] } = select(STORE_NAME).getCurrentTheme() ?? {};
return {
entityRecordTitle: getTemplateInfo({
template,
templateTypes
}).title
};
},
[name, kind, title, key]
);
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(PanelRow, { children: /* @__PURE__ */ jsx(
CheckboxControl,
{
label: decodeEntities(entityRecordTitle) || __("Untitled"),
checked,
onChange,
className: "entities-saved-states__change-control"
}
) }) });
}
export {
EntityRecordItem as default
};
//# sourceMappingURL=entity-record-item.mjs.map