1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-10 01:19:53 +01:00
unleash.unleash/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvSwitches/FeatureOverviewEnvSwitches.tsx
olav d8143c6ff4 chore: update react-router to v6 (#946)
* refactor: fix child selector warnings

* refactor: update react-router-dom

* refactor: use BrowserRouter as in react-router docs

* refactor: replace Redirect with Navigate

* refactor: replace Switch with Routes

* refactor: replace useHistory with useNavigate

* refactor: replace useParams types with useRequiredPathParam

* refactor: replace NavLink activeStyle with callback

* refactor: fix matchPath arg order

* refactor: Remove unused link state

* refactor: delete broken snapshot test

* refactor: render 404 page without redirect

* refactor: normalize path parameter names

* refactor: fix Route component usage
2022-05-05 13:42:18 +02:00

62 lines
2.2 KiB
TypeScript

import { Tooltip } from '@mui/material';
import { useState } from 'react';
import useFeatureApi from 'hooks/api/actions/useFeatureApi/useFeatureApi';
import { useFeature } from 'hooks/api/getters/useFeature/useFeature';
import EnvironmentStrategyDialog from 'component/common/EnvironmentStrategiesDialog/EnvironmentStrategyDialog';
import FeatureOverviewEnvSwitch from './FeatureOverviewEnvSwitch/FeatureOverviewEnvSwitch';
import { useStyles } from './FeatureOverviewEnvSwitches.styles';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
const FeatureOverviewEnvSwitches = () => {
const { classes: styles } = useStyles();
const projectId = useRequiredPathParam('projectId');
const featureId = useRequiredPathParam('featureId');
const { feature } = useFeature(projectId, featureId);
useFeatureApi();
const [showInfoBox, setShowInfoBox] = useState(false);
const [environmentName, setEnvironmentName] = useState('');
const closeInfoBox = () => {
setShowInfoBox(false);
};
const renderEnvironmentSwitches = () => {
return feature?.environments.map(env => {
return (
<FeatureOverviewEnvSwitch
key={env.name}
env={env}
showInfoBox={() => {
setEnvironmentName(env.name);
setShowInfoBox(true);
}}
/>
);
});
};
return (
<div className={styles.container}>
<Tooltip
arrow
title="Environments can be switched off for a single toggle. Resulting in all calls towards the toggle to return false."
>
<h3 className={styles.header} data-loading>
Feature toggle status
</h3>
</Tooltip>
{renderEnvironmentSwitches()}
<EnvironmentStrategyDialog
open={showInfoBox}
onClose={closeInfoBox}
projectId={projectId}
featureId={featureId}
environmentName={environmentName}
/>
</div>
);
};
export default FeatureOverviewEnvSwitches;