From 9e1a72c53892e60e887c88394c4870c067392f52 Mon Sep 17 00:00:00 2001 From: Ronald Huereca Date: Tue, 9 Apr 2024 06:29:02 -0500 Subject: [PATCH] Mapping categories to tax categories. --- php/Admin.php | 6 ++++-- src/js/react/views/main/main.js | 11 +++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/php/Admin.php b/php/Admin.php index f7c2333..c1ec6e1 100644 --- a/php/Admin.php +++ b/php/Admin.php @@ -206,9 +206,11 @@ public function ajax_get_options() { } $options = Options::get_options(); - $categories = Functions::get_pattern_categories(); + $categories = Functions::get_pattern_categories(); + $options['registered'] = $categories['registered']; + $options['categories'] = $categories['categories']; - wp_send_json_success( $categories ); + wp_send_json_success( $options ); } /** diff --git a/src/js/react/views/main/main.js b/src/js/react/views/main/main.js index c883053..65c1f67 100644 --- a/src/js/react/views/main/main.js +++ b/src/js/react/views/main/main.js @@ -66,13 +66,13 @@ const usePatternCategories = ( props ) => { const Category = ( props ) => { const [ showLabelPopover, setShowLabelPopover ] = useState( false ); const [ labelEditButton, setLabelEditButton ] = useState( false ); - const { category, control, getValues, setValue } = props; + const { category, control, getValues, setValue, taxCategories } = props; const { enabledCategories } = usePatternCategories( { getValues } ); const getCategories = () => { - const localCategories = enabledCategories.map( ( cat ) => { + const localCategories = taxCategories.map( ( cat ) => { return { - label: cat.label + ' (' + cat.slug + ')', + label: cat.name + ' (' + cat.slug + ')', value: cat.slug, }; } ); @@ -224,12 +224,11 @@ const Interface = ( props ) => { hideThemePatterns: data.hideThemePatterns, hidePluginPatterns: data.hidePluginPatterns, showMenusUI: data.showMenusUI, - categories: data.categories.registered ?? [], + categories: data.registered ?? [], saveNonce: dlxPatternWranglerAdmin.saveNonce, resetNonce: dlxPatternWranglerAdmin.resetNonce, }, } ); - console.log( data.categories ); const formValues = useWatch( { control } ); const { errors, isDirty, dirtyFields } = useFormState( { control, @@ -243,7 +242,7 @@ const Interface = ( props ) => { { Object.values( categories ).map( ( category ) => { return (
  • - +
  • ); } ) }