Skip to content

Commit

Permalink
CreateTemplatePartModal: avoid identity warning in useSelect (#67786)
Browse files Browse the repository at this point in the history
Co-authored-by: jsnajdr <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
4 people authored Dec 10, 2024
1 parent 4e67ab6 commit b62887b
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions packages/fields/src/components/create-template-part-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ type CreateTemplatePartModalContentsProps = {
defaultTitle?: string;
};

type TemplatePartArea = {
area: string;
label: string;
icon: string;
description: string;
};

/**
* A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part.
* This component should not live in this package, it should be moved to a dedicated package responsible for managing template.
Expand Down Expand Up @@ -124,22 +131,14 @@ export function CreateTemplatePartModalContents( {
const [ isSubmitting, setIsSubmitting ] = useState( false );
const instanceId = useInstanceId( CreateTemplatePartModal );

const defaultTemplatePartAreas = useSelect( ( select ) => {
const areas =
const defaultTemplatePartAreas = useSelect(
( select ) =>
// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.
select( coreStore ).getEntityRecord< {
default_template_part_areas: Array< {
area: string;
label: string;
icon: string;
description: string;
} >;
} >( 'root', '__unstableBase' )?.default_template_part_areas || [];

return areas.map( ( item ) => {
return { ...item, icon: getTemplatePartIcon( item.icon ) };
} );
}, [] );
default_template_part_areas: Array< TemplatePartArea >;
} >( 'root', '__unstableBase' )?.default_template_part_areas,
[]
);

async function createTemplatePart() {
if ( ! title || isSubmitting ) {
Expand Down Expand Up @@ -219,32 +218,33 @@ export function CreateTemplatePartModalContents( {
}
checked={ area }
>
{ defaultTemplatePartAreas.map(
( { icon, label, area: value, description } ) => (
{ ( defaultTemplatePartAreas ?? [] ).map( ( item ) => {
const icon = getTemplatePartIcon( item.icon );
return (
<Radio
__next40pxDefaultSize
key={ label }
value={ value }
key={ item.label }
value={ item.area }
className="fields-create-template-part-modal__area-radio"
>
<Flex align="start" justify="start">
<FlexItem>
<Icon icon={ icon } />
</FlexItem>
<FlexBlock className="fields-create-template-part-modal__option-label">
{ label }
<div>{ description }</div>
{ item.label }
<div>{ item.description }</div>
</FlexBlock>

<FlexItem className="fields-create-template-part-modal__checkbox">
{ area === value && (
{ area === item.area && (
<Icon icon={ check } />
) }
</FlexItem>
</Flex>
</Radio>
)
) }
);
} ) }
</RadioGroup>
</BaseControl>
<HStack justify="right">
Expand Down

1 comment on commit b62887b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in b62887b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12255484513
📝 Reported issues:

Please sign in to comment.