mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
fix: strategy access tooltip (#3228)
Fixing this issue: ![image (9)](https://user-images.githubusercontent.com/2625371/222119224-f3482e5d-96b2-4ea3-a676-b77f349a1326.png) https://linear.app/unleash/issue/1-699/ui-bug-duplicate-strategy-tooltip
This commit is contained in:
parent
3832148c0c
commit
587c48e3fc
@ -1,8 +1,9 @@
|
||||
import { VFC } from 'react';
|
||||
import { useMemo, VFC } from 'react';
|
||||
import PermissionSwitch from 'component/common/PermissionSwitch/PermissionSwitch';
|
||||
import { UPDATE_STRATEGY } from 'component/providers/AccessProvider/permissions';
|
||||
import { Tooltip } from '@mui/material';
|
||||
import { useId } from 'hooks/useId';
|
||||
import { useHasRootAccess } from 'hooks/useHasAccess';
|
||||
|
||||
interface IStrategySwitchProps {
|
||||
deprecated: boolean;
|
||||
@ -19,17 +20,24 @@ export const StrategySwitch: VFC<IStrategySwitchProps> = ({
|
||||
onToggle(deprecated);
|
||||
};
|
||||
const id = useId();
|
||||
const access = useHasRootAccess(UPDATE_STRATEGY);
|
||||
|
||||
const title = deprecated
|
||||
const title = useMemo(() => {
|
||||
if (!access) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (disabled) {
|
||||
return 'You cannot disable default strategy';
|
||||
}
|
||||
|
||||
return deprecated
|
||||
? 'Excluded from strategy list'
|
||||
: 'Included in strategy list';
|
||||
}, [deprecated, disabled, access]);
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
title={disabled ? 'You cannot disable default strategy' : title}
|
||||
describeChild
|
||||
arrow
|
||||
>
|
||||
<Tooltip title={title} describeChild arrow>
|
||||
<div id={id}>
|
||||
<PermissionSwitch
|
||||
checked={!deprecated}
|
||||
|
Loading…
Reference in New Issue
Block a user