React 18 and Vite (#4510)

This commit is contained in:
Matthew Penner 2022-11-25 13:25:03 -07:00 committed by GitHub
parent 1bb1b13f6d
commit 21613fa602
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
244 changed files with 4547 additions and 8933 deletions

View file

@ -2,7 +2,7 @@ import { ServerContext } from '@/state/server';
import { useDeepCompareMemo } from '@/plugins/useDeepCompareMemo';
export const usePermissions = (action: string | string[]): boolean[] => {
const userPermissions = ServerContext.useStoreState((state) => state.server.permissions);
const userPermissions = ServerContext.useStoreState(state => state.server.permissions);
return useDeepCompareMemo(() => {
if (userPermissions[0] === '*') {
@ -10,13 +10,13 @@ export const usePermissions = (action: string | string[]): boolean[] => {
}
return (Array.isArray(action) ? action : [action]).map(
(permission) =>
permission =>
// Allows checking for any permission matching a name, for example files.*
// will return if the user has any permission under the file.XYZ namespace.
(permission.endsWith('.*') &&
userPermissions.filter((p) => p.startsWith(permission.split('.')[0])).length > 0) ||
userPermissions.filter(p => p.startsWith(permission.split('.')?.[0] ?? '')).length > 0) ||
// Otherwise just check if the entire permission exists in the array or not.
userPermissions.indexOf(permission) >= 0
userPermissions.indexOf(permission) >= 0,
);
}, [action, userPermissions]);
};