Skip to content

Commit

Permalink
Mapping categories to tax categories.
Browse files Browse the repository at this point in the history
ronaldhuereca committed Apr 9, 2024
1 parent 3e2e8b5 commit 9e1a72c
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 4 additions & 2 deletions php/Admin.php
Original file line number Diff line number Diff line change
@@ -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 );
}

/**
11 changes: 5 additions & 6 deletions src/js/react/views/main/main.js
Original file line number Diff line number Diff line change
@@ -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 (
<li key={ category.slug }>
<Category category={ category } control={ control } getValues={ getValues } setValue={ setValue } />
<Category category={ category } control={ control } getValues={ getValues } setValue={ setValue } taxCategories={ data.categories } />
</li>
);
} ) }

0 comments on commit 9e1a72c

Please sign in to comment.