mirror of https://github.com/grafana/grafana
Alerting: Adds visual component for feature toggles (#63621)
parent
91d2df59fc
commit
09fdbb69ec
@ -1,18 +1,40 @@ |
|||||||
import React from 'react'; |
import Mousetrap from 'mousetrap'; |
||||||
|
import React, { useEffect, useState } from 'react'; |
||||||
|
import { Features, ToggleFeatures } from 'react-enable'; |
||||||
|
|
||||||
import { NavModelItem } from '@grafana/data'; |
import { NavModelItem } from '@grafana/data'; |
||||||
import { Page } from 'app/core/components/Page/Page'; |
import { Page } from 'app/core/components/Page/Page'; |
||||||
|
|
||||||
|
import FEATURES from '../features'; |
||||||
|
|
||||||
interface Props { |
interface Props { |
||||||
pageId: string; |
pageId: string; |
||||||
isLoading?: boolean; |
isLoading?: boolean; |
||||||
pageNav?: NavModelItem; |
pageNav?: NavModelItem; |
||||||
} |
} |
||||||
|
|
||||||
|
const SHOW_TOGGLES_KEY_COMBO = 'ctrl+1'; |
||||||
|
const combokeys = new Mousetrap(document.body); |
||||||
|
|
||||||
export const AlertingPageWrapper = ({ children, pageId, pageNav, isLoading }: React.PropsWithChildren<Props>) => { |
export const AlertingPageWrapper = ({ children, pageId, pageNav, isLoading }: React.PropsWithChildren<Props>) => { |
||||||
|
const [showFeatureToggle, setShowFeatureToggles] = useState(false); |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
combokeys.bind(SHOW_TOGGLES_KEY_COMBO, () => { |
||||||
|
setShowFeatureToggles((show) => !show); |
||||||
|
}); |
||||||
|
|
||||||
|
return () => { |
||||||
|
combokeys.unbind(SHOW_TOGGLES_KEY_COMBO); |
||||||
|
}; |
||||||
|
}, []); |
||||||
|
|
||||||
return ( |
return ( |
||||||
|
<Features features={FEATURES}> |
||||||
<Page pageNav={pageNav} navId={pageId}> |
<Page pageNav={pageNav} navId={pageId}> |
||||||
<Page.Contents isLoading={isLoading}>{children}</Page.Contents> |
<Page.Contents isLoading={isLoading}>{children}</Page.Contents> |
||||||
</Page> |
</Page> |
||||||
|
{showFeatureToggle ? <ToggleFeatures defaultOpen={true} /> : null} |
||||||
|
</Features> |
||||||
); |
); |
||||||
}; |
}; |
||||||
|
|||||||
@ -0,0 +1,10 @@ |
|||||||
|
import { FeatureDescription } from 'react-enable/dist/FeatureState'; |
||||||
|
|
||||||
|
const FEATURES: FeatureDescription[] = [ |
||||||
|
{ |
||||||
|
name: 'notification-policies.v2.matching-instances', |
||||||
|
defaultValue: false, |
||||||
|
}, |
||||||
|
]; |
||||||
|
|
||||||
|
export default FEATURES; |
||||||
Loading…
Reference in new issue