Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upkeep: Add TS support for IsAdmin component #299

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions components/is-admin/index.js → components/is-admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { useSelect } from '@wordpress/data';

interface IsAdminProps {
fallback: React.ReactNode | null;
children: React.ReactNode;
}

/**
* IsAdmin
*
Expand All @@ -8,12 +13,15 @@ import { useSelect } from '@wordpress/data';
* fallback component via the fallback prop.
*
* @param {object} props react props
* @param {*} props.fallback fallback component
* @param {*} props.children child components
* @returns {*}
* @param {React.ReactNode|null} props.fallback fallback component
* @param {React.ReactNode} props.children child components
* @returns {null|React.ReactNode}
Copy link
Member

Choose a reason for hiding this comment

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

When we are adding types I think we can safely remove the JSDoc comments.

If we want to add additional context to the type we can add a comment above the type value like so:

interface IsAdminProps {
    /**
     * fallback component
     */
 	fallback: React.ReactNode | null;

    /**
     * child component
     */
 	children: React.ReactNode;
 }

*/
export const IsAdmin = ({ fallback = null, children }) => {
const hasAdminPermissions = useSelect(
export const IsAdmin: React.FC<IsAdminProps> = ({
fallback = null,
children,
}): null | React.ReactNode => {
Copy link
Member

Choose a reason for hiding this comment

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

I still think we can leave the return type off here

const hasAdminPermissions: boolean = useSelect(
(select) => select('core').canUser('read', 'users?roles=1'),
[],
);
Expand Down
Loading