Skip to content

Guidelines: Refactor components and improve TypeScript typing#76394

Merged
im3dabasia merged 4 commits intoWordPress:trunkfrom
im3dabasia:fix/feedbacks-76387
Mar 23, 2026
Merged

Guidelines: Refactor components and improve TypeScript typing#76394
im3dabasia merged 4 commits intoWordPress:trunkfrom
im3dabasia:fix/feedbacks-76387

Conversation

@im3dabasia
Copy link
Copy Markdown
Contributor

What?

Closes #76387

Refactors parts of the Content Guidelines implementation to improve component structure and TypeScript typing.

Why?

During the review of #76155 a few code quality improvements were identified, mainly around component readability and stronger typing.

How?

  • Decompose actions-section into smaller components for better readability.
  • Refactor guideline TypeScript types and use the exported store object instead of STORE_NAME to avoid as unknown casts and improve type inference.

Testing Instructions

  1. Open the Content Guidelines screen.
  2. Verify that all actions and guideline content behave as expected.
  3. Confirm there are no regressions in functionality.

@im3dabasia im3dabasia added [Type] Experimental Experimental feature or API. [Feature] Guidelines An experimental feature for adding site-wide editorial rules. labels Mar 11, 2026
@im3dabasia
Copy link
Copy Markdown
Contributor Author

Fix error typing
Error type is unknown in catch blocks even though we control the throwing functions. Give errors a proper type.

Ref: #76155 (comment)

I’m not sure what the best way to handle this is. try/catch returns a variable typed as unknown, which cannot be typecast. I think the current approach is fine, but I’m open to making changes if there’s a better solution.

Reference

@im3dabasia im3dabasia marked this pull request as ready for review March 11, 2026 12:13
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 11, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: aswasif007 <aswasif007@git.wordpress.org>
Co-authored-by: aagam-shah <aagam94@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@im3dabasia im3dabasia requested a review from andrewserong March 11, 2026 13:47
@im3dabasia
Copy link
Copy Markdown
Contributor Author

@andrewserong, @aagam-shah would appreciate your review on this PR when you get a chance

@aagam-shah
Copy link
Copy Markdown
Contributor

@im3dabasia Thanks for the refactoring — the typed store object change is a solid improvement.

A few things:

  1. Keep ACTIONS.map() pattern — I agree with @aswasif007's suggestion. Combine it with your new ActionItem component. Define the array inside the component so handlers are in scope, and spread props: <ActionItem key={ action.slug } { ...action } />. This also eliminates the old buttonProps lookup.

  2. Leftover @ts-ignore comments — a few remain that are likely unnecessary now (e.g., api.ts:51 has @ts-ignore on dispatch(coreContentGuidelinesStore) but the identical call in fetchContentGuidelines works without it; same for guideline-accordion-form.tsx:33,41). Worth testing removal.

  3. Fix lint failures.

@im3dabasia
Copy link
Copy Markdown
Contributor Author

@aagam-shah, I’m done addressing the feedback. I’d appreciate your review once you’re back.

Copy link
Copy Markdown
Contributor

@aagam-shah aagam-shah left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Code changes look good to me 🚢

Copy link
Copy Markdown
Contributor

@aswasif007 aswasif007 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

@im3dabasia im3dabasia force-pushed the fix/feedbacks-76387 branch from 23f4857 to 70237ce Compare March 23, 2026 04:24
@im3dabasia
Copy link
Copy Markdown
Contributor Author

I’ll go ahead with the merge. I rebased the PR to check if the failing tests would pass, though they seem unrelated.

@im3dabasia im3dabasia merged commit 73361f6 into WordPress:trunk Mar 23, 2026
39 checks passed
@github-actions github-actions bot added this to the Gutenberg 22.9 milestone Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Guidelines An experimental feature for adding site-wide editorial rules. [Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Content Guidelines: Refactor components and TypeScript types

3 participants