UNPKG

@wordpress/editor

Version:
66 lines (65 loc) 1.86 kB
// packages/editor/src/components/post-taxonomies/most-used-terms.js import { BaseControl, Button } from "@wordpress/components"; import { useSelect } from "@wordpress/data"; import { store as coreStore } from "@wordpress/core-data"; import { unescapeTerms } from "../../utils/terms.mjs"; import { jsx, jsxs } from "react/jsx-runtime"; var MIN_MOST_USED_TERMS = 3; var DEFAULT_QUERY = { per_page: 10, orderby: "count", order: "desc", hide_empty: true, _fields: "id,name,count", context: "view" }; function MostUsedTerms({ onSelect, taxonomy }) { const { _terms, showTerms } = useSelect( (select) => { const mostUsedTerms = select(coreStore).getEntityRecords( "taxonomy", taxonomy.slug, DEFAULT_QUERY ); return { _terms: mostUsedTerms, showTerms: mostUsedTerms?.length >= MIN_MOST_USED_TERMS }; }, [taxonomy.slug] ); if (!showTerms) { return null; } const terms = unescapeTerms(_terms); return /* @__PURE__ */ jsxs("div", { className: "editor-post-taxonomies__flat-term-most-used", children: [ /* @__PURE__ */ jsx( BaseControl.VisualLabel, { as: "h3", className: "editor-post-taxonomies__flat-term-most-used-label", children: taxonomy.labels.most_used } ), /* @__PURE__ */ jsx( "ul", { role: "list", className: "editor-post-taxonomies__flat-term-most-used-list", children: terms.map((term) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx( Button, { __next40pxDefaultSize: true, variant: "link", onClick: () => onSelect(term), children: term.name } ) }, term.id)) } ) ] }); } export { MostUsedTerms as default }; //# sourceMappingURL=most-used-terms.mjs.map