import React from 'react'; import { observer } from 'mobx-react-lite'; import { useStore } from 'App/mstore'; import { Toggler, Loader, Button, NoContent, ItemMenu } from 'UI'; import Breadcrumb from 'Shared/Breadcrumb'; import { useHistory } from 'react-router'; import { withSiteId, fflag, fflags } from 'App/routes'; import Multivariant from "Components/FFlags/NewFFlag/Multivariant"; import { toast } from 'react-toastify'; import RolloutCondition from "Shared/ConditionSet"; function FlagView({ siteId, fflagId }: { siteId: string; fflagId: string }) { const { featureFlagsStore } = useStore(); const history = useHistory(); React.useEffect(() => { if (fflagId) { void featureFlagsStore.fetchFlag(parseInt(fflagId, 10)); } }, [fflagId]); const current = featureFlagsStore.currentFflag; if (featureFlagsStore.isLoading) return ; if (!current) return ; const deleteHandler = () => { featureFlagsStore.deleteFlag(current.featureFlagId).then(() => { toast.success('Feature flag deleted.'); history.push(withSiteId(fflags(), siteId)); }); }; const menuItems = [{ icon: 'trash', text: 'Delete', onClick: deleteHandler }]; const toggleActivity = () => { const newValue = !current.isActive; current.setIsEnabled(newValue); featureFlagsStore .updateFlagStatus(current.featureFlagId, newValue) .then(() => { toast.success('Feature flag status has been updated.'); }) .catch(() => { current.setIsEnabled(!newValue); toast.error('Something went wrong, please try again.'); }); }; return (
{current.flagKey}
{current.description || 'There is no description for this feature flag.'}
{current.isPersist ? 'This flag maintains its state through successive authentication events.' : 'This flag is not persistent across authentication events.'}
{!current.isSingleOption ? ( ) : null} {current.conditions.length > 0 ? (
{current.conditions.map((condition, index) => (
))}
) : null}
); } export default observer(FlagView);