Skip to content

Commit

Permalink
Merge branch 'develop' into upkeep/hook-use-taxonomy
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 authored Mar 11, 2024
2 parents bdd79a6 + 376e81f commit 2c1020e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { SVGProps } from 'react';

/**
* Renders an SVG drag handle.
*
* @param {object} props The prop object.
* @returns {*} React JSX
*/
export const DragHandle = (props) => (

export const DragHandle: React.FC<SVGProps<SVGSVGElement>> = (props) => (
<svg
style={{ marginRight: '10px', cursor: 'grab', flexShrink: 0 }}
width="18"
Expand Down
24 changes: 17 additions & 7 deletions components/is-admin/index.js → components/is-admin/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { useSelect } from '@wordpress/data';

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

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

/**
* IsAdmin
*
* A wrapper component that checks wether the current user has admin capabilities
* and only returns the child components if the user is an admin. You can pass a
* fallback component via the fallback prop.
*
* @param {object} props react props
* @param {*} props.fallback fallback component
* @param {*} props.children child components
* @returns {*}
*/
export const IsAdmin = ({ fallback = null, children }) => {
const hasAdminPermissions = useSelect(
export const IsAdmin: React.FC<IsAdminProps> = ({
fallback = null,
children,
}) => {
const hasAdminPermissions: boolean = useSelect(
(select) => select('core').canUser('read', 'users?roles=1'),
[],
);
Expand Down
20 changes: 0 additions & 20 deletions hooks/use-is-plugin-active/index.js

This file was deleted.

29 changes: 29 additions & 0 deletions hooks/use-is-plugin-active/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import type { Plugin } from '@wordpress/core-data';

const ACTIVE_STATUSES = ['active', 'network-active'] as const;

/**
* Custom hook to check if a plugin is active and whether its resolution has finished.
*
* @param pluginName The name of the plugin to check.
* @returns A tuple containing two boolean values: the first indicating whether the plugin is active,
* and the second indicating whether the resolution for the plugin has finished.
*/
export const useIsPluginActive = (pluginName: string) => {
return useSelect(
(select) => {
const storeSelectors = select(coreStore);
const plugin: Plugin = (storeSelectors as any).getPlugin(pluginName);
const hasResolvedPlugins: boolean = (storeSelectors as any).hasFinishedResolution('getPlugin', [
pluginName,
]);

const isPluginActive: boolean = ACTIVE_STATUSES.includes(plugin?.status);

return [isPluginActive, hasResolvedPlugins];
},
[pluginName],
) as [boolean, boolean];
};
2 changes: 1 addition & 1 deletion hooks/use-media/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function BlockEdit(props) {
}

return (
<img src={ media.source_url } alt={image.alt} />
<img src={ media.source_url } alt={ media.alt_text } />
);
}
```
Expand Down

0 comments on commit 2c1020e

Please sign in to comment.