diff --git a/public_html/wp-content/plugins/pattern-creator/pattern-creator.php b/public_html/wp-content/plugins/pattern-creator/pattern-creator.php
index 7fbcc07e6..9d59b9c07 100644
--- a/public_html/wp-content/plugins/pattern-creator/pattern-creator.php
+++ b/public_html/wp-content/plugins/pattern-creator/pattern-creator.php
@@ -16,6 +16,7 @@
use WP_Block_Editor_Context;
use function WordPressdotorg\MU_Plugins\Global_Header_Footer\{ is_rosetta_site, get_rosetta_name };
+use function WordPressdotorg\Pattern_Directory\Pattern_Post_Type\get_selectable_category_slugs;
use const WordPressdotorg\Pattern_Directory\Pattern_Post_Type\POST_TYPE;
const AUTOSAVE_INTERVAL = 30;
@@ -126,7 +127,8 @@ function pattern_creator_init() {
rawurlencode(
wp_json_encode(
array(
- 'siteUrl' => esc_url( home_url() ),
+ 'siteUrl' => esc_url( home_url() ),
+ 'categorySlugs' => get_selectable_category_slugs(),
)
)
)
diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/pattern-categories-control/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/pattern-categories-control/index.js
index 7104d152a..372b01fd0 100644
--- a/public_html/wp-content/plugins/pattern-creator/src/components/pattern-categories-control/index.js
+++ b/public_html/wp-content/plugins/pattern-creator/src/components/pattern-categories-control/index.js
@@ -7,7 +7,7 @@ import { find, get, unescape as unescapeString } from 'lodash';
* WordPress dependencies
*/
import { __, _n, sprintf } from '@wordpress/i18n';
-import { CheckboxControl, TextControl } from '@wordpress/components';
+import { CheckboxControl, Flex, TextControl } from '@wordpress/components';
import { speak } from '@wordpress/a11y';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';
@@ -19,18 +19,11 @@ import { useSelect } from '@wordpress/data';
* Internal dependencies
*/
import { CATEGORY_SLUG } from '../../store';
+import usePatternCategories from '../../hooks/use-pattern-categories';
/**
* Module Constants
*/
-const DEFAULT_QUERY = {
- per_page: -1,
- orderby: 'name',
- order: 'asc',
- _fields: 'id,name,parent,slug',
- context: 'view',
-};
-
const MIN_TERMS_COUNT_FOR_FILTER = 8;
const EMPTY_ARRAY = [];
@@ -113,20 +106,14 @@ function PatternCategoriesControl( { selectedTerms = EMPTY_ARRAY, setTerms } ) {
const [ filteredTermsTree, setFilteredTermsTree ] = useState( [] );
const debouncedSpeak = useDebounce( speak, 500 );
- const { hasAssignAction, availableTerms } = useSelect( ( select ) => {
+ const availableTerms = usePatternCategories();
+ const hasAssignAction = useSelect( ( select ) => {
const { getCurrentPost } = select( editorStore );
- const { getTaxonomy, getEntityRecords } = select( coreStore );
- const _taxonomy = getTaxonomy( CATEGORY_SLUG );
-
- const terms = getEntityRecords( 'taxonomy', CATEGORY_SLUG, DEFAULT_QUERY ) || EMPTY_ARRAY;
+ const _taxonomy = select( coreStore ).getTaxonomy( CATEGORY_SLUG );
- return {
- hasAssignAction: _taxonomy
- ? get( getCurrentPost(), [ '_links', 'wp:action-assign-' + _taxonomy.rest_base ], false )
- : false,
- // Filter out the "Featured" category.
- availableTerms: terms.filter( ( { slug } ) => 'featured' !== slug ),
- };
+ return _taxonomy
+ ? get( getCurrentPost(), [ '_links', 'wp:action-assign-' + _taxonomy.rest_base ], false )
+ : false;
}, [] );
const availableTermsTree = useMemo(
@@ -182,7 +169,7 @@ function PatternCategoriesControl( { selectedTerms = EMPTY_ARRAY, setTerms } ) {
const showFilter = availableTerms.length >= MIN_TERMS_COUNT_FOR_FILTER;
return (
- <>
+
{ showFilter && (
- >
+
);
}
diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/index.js
index ba9d70c4a..0ae88c18d 100644
--- a/public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/index.js
+++ b/public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/index.js
@@ -1,16 +1,24 @@
/* global wporgBlockPattern, wporgLocale */
+/**
+ * External dependencies
+ */
+import { unescape as unescapeString } from 'lodash';
+
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
-import { addQueryArgs } from '@wordpress/url';
-import apiFetch from '@wordpress/api-fetch';
import { Button, CheckboxControl, Modal, TextControl, TextareaControl } from '@wordpress/components';
import { createInterpolateElement, useEffect, useRef, useState } from '@wordpress/element';
import { store as editorStore } from '@wordpress/editor';
import { store as noticesStore } from '@wordpress/notices';
import { useDispatch, useSelect } from '@wordpress/data';
+/**
+ * Internal dependencies
+ */
+import usePatternCategories from '../../hooks/use-pattern-categories';
+
const ForwardButton = ( { children, disabled, onClick } ) => (