1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00
Tymoteusz Czech 2023-03-01 13:17:31 +01:00 committed by GitHub
parent 3832148c0c
commit 587c48e3fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,9 @@
import { VFC } from 'react'; import { useMemo, VFC } from 'react';
import PermissionSwitch from 'component/common/PermissionSwitch/PermissionSwitch'; import PermissionSwitch from 'component/common/PermissionSwitch/PermissionSwitch';
import { UPDATE_STRATEGY } from 'component/providers/AccessProvider/permissions'; import { UPDATE_STRATEGY } from 'component/providers/AccessProvider/permissions';
import { Tooltip } from '@mui/material'; import { Tooltip } from '@mui/material';
import { useId } from 'hooks/useId'; import { useId } from 'hooks/useId';
import { useHasRootAccess } from 'hooks/useHasAccess';
interface IStrategySwitchProps { interface IStrategySwitchProps {
deprecated: boolean; deprecated: boolean;
@ -19,17 +20,24 @@ export const StrategySwitch: VFC<IStrategySwitchProps> = ({
onToggle(deprecated); onToggle(deprecated);
}; };
const id = useId(); const id = useId();
const access = useHasRootAccess(UPDATE_STRATEGY);
const title = deprecated const title = useMemo(() => {
? 'Excluded from strategy list' if (!access) {
: 'Included in strategy list'; return '';
}
if (disabled) {
return 'You cannot disable default strategy';
}
return deprecated
? 'Excluded from strategy list'
: 'Included in strategy list';
}, [deprecated, disabled, access]);
return ( return (
<Tooltip <Tooltip title={title} describeChild arrow>
title={disabled ? 'You cannot disable default strategy' : title}
describeChild
arrow
>
<div id={id}> <div id={id}>
<PermissionSwitch <PermissionSwitch
checked={!deprecated} checked={!deprecated}