From 587c48e3fce1d0fcbf9dd8a7d0a43a560f4859d0 Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Wed, 1 Mar 2023 13:17:31 +0100 Subject: [PATCH] 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 --- .../StrategySwitch/StrategySwitch.tsx | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/frontend/src/component/strategies/StrategiesList/StrategySwitch/StrategySwitch.tsx b/frontend/src/component/strategies/StrategiesList/StrategySwitch/StrategySwitch.tsx index 58c9c394f4..2f76af138e 100644 --- a/frontend/src/component/strategies/StrategiesList/StrategySwitch/StrategySwitch.tsx +++ b/frontend/src/component/strategies/StrategiesList/StrategySwitch/StrategySwitch.tsx @@ -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 = ({ onToggle(deprecated); }; const id = useId(); + const access = useHasRootAccess(UPDATE_STRATEGY); - const title = deprecated - ? 'Excluded from strategy list' - : 'Included in strategy list'; + 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 ( - +