From f99c722ecf46d51b245214b4b358340eb8fababc Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Tue, 14 May 2024 17:58:47 +0200 Subject: [PATCH] FeatureBadge: Update FeatureBadge to support current release stages (#87555) * FeatureBadge: Update avalaiable FeatureState * Move to separate folder * Add private preview state --- packages/grafana-data/src/types/app.ts | 8 +++ .../components/FeatureBadge/FeatureBadge.mdx | 10 ++++ .../FeatureBadge/FeatureBadge.story.tsx | 30 +++++++++++ .../components/FeatureBadge/FeatureBadge.tsx | 54 +++++++++++++++++++ .../src/components/InfoBox/FeatureInfoBox.tsx | 29 +--------- .../src/components/InfoBox/InfoBox.story.tsx | 4 +- packages/grafana-ui/src/components/index.ts | 3 +- 7 files changed, 107 insertions(+), 31 deletions(-) create mode 100644 packages/grafana-ui/src/components/FeatureBadge/FeatureBadge.mdx create mode 100644 packages/grafana-ui/src/components/FeatureBadge/FeatureBadge.story.tsx create mode 100644 packages/grafana-ui/src/components/FeatureBadge/FeatureBadge.tsx diff --git a/packages/grafana-data/src/types/app.ts b/packages/grafana-data/src/types/app.ts index 626ab368bf2..d2ff50ad7dc 100644 --- a/packages/grafana-data/src/types/app.ts +++ b/packages/grafana-data/src/types/app.ts @@ -126,6 +126,14 @@ export class AppPlugin extends GrafanaPlugin + +## FeatureBadge + +A component for displaying information about different release stages of features, in accordance with the guidelines provided at [Grafana's Release Life Cycle](https://grafana.com/docs/release-life-cycle). + + diff --git a/packages/grafana-ui/src/components/FeatureBadge/FeatureBadge.story.tsx b/packages/grafana-ui/src/components/FeatureBadge/FeatureBadge.story.tsx new file mode 100644 index 00000000000..273ea948dd8 --- /dev/null +++ b/packages/grafana-ui/src/components/FeatureBadge/FeatureBadge.story.tsx @@ -0,0 +1,30 @@ +import { Meta, StoryFn } from '@storybook/react'; +import React from 'react'; + +import { FeatureState } from '@grafana/data'; +import { FeatureBadge } from '@grafana/ui'; + +import mdx from './FeatureBadge.mdx'; + +const meta: Meta = { + title: 'Data Display/FeatureBadge', + component: FeatureBadge, + parameters: { + docs: { page: mdx }, + }, + argTypes: { + featureState: { control: { type: 'select', options: ['experimental', 'private preview', 'preview'] } }, + tooltip: { control: 'text' }, + }, +}; + +const Template: StoryFn = (args) => ; + +export const Basic = Template.bind({}); + +Basic.args = { + featureState: FeatureState.preview, + tooltip: `This feature is in selected mode`, +}; + +export default meta; diff --git a/packages/grafana-ui/src/components/FeatureBadge/FeatureBadge.tsx b/packages/grafana-ui/src/components/FeatureBadge/FeatureBadge.tsx new file mode 100644 index 00000000000..f4e99ee5c94 --- /dev/null +++ b/packages/grafana-ui/src/components/FeatureBadge/FeatureBadge.tsx @@ -0,0 +1,54 @@ +import React from 'react'; + +import { FeatureState } from '@grafana/data'; + +import { Badge, BadgeProps } from '../Badge/Badge'; + +interface FeatureBadgeProps { + featureState: FeatureState; + tooltip?: string; +} + +export const FeatureBadge = ({ featureState, tooltip }: FeatureBadgeProps) => { + const display = getPanelStateBadgeDisplayModel(featureState); + return ; +}; + +function getPanelStateBadgeDisplayModel(featureState: FeatureState): BadgeProps { + switch (featureState) { + case FeatureState.alpha: + return { + text: 'Alpha', + icon: 'exclamation-triangle', + color: 'orange', + }; + + case FeatureState.beta: + return { + text: 'Beta', + icon: 'rocket', + color: 'blue', + }; + + case FeatureState.experimental: + return { + text: 'Experimental', + icon: 'exclamation-triangle', + color: 'orange', + }; + + case FeatureState.preview: + return { + text: 'Preview', + icon: 'rocket', + color: 'blue', + }; + + case FeatureState.privatePreview: + return { + text: 'Private preview', + icon: 'rocket', + color: 'blue', + }; + } +} diff --git a/packages/grafana-ui/src/components/InfoBox/FeatureInfoBox.tsx b/packages/grafana-ui/src/components/InfoBox/FeatureInfoBox.tsx index 97f471e7c33..54394183151 100644 --- a/packages/grafana-ui/src/components/InfoBox/FeatureInfoBox.tsx +++ b/packages/grafana-ui/src/components/InfoBox/FeatureInfoBox.tsx @@ -4,7 +4,7 @@ import React from 'react'; import { FeatureState, GrafanaTheme2 } from '@grafana/data'; import { useStyles2 } from '../../themes'; -import { Badge, BadgeProps } from '../Badge/Badge'; +import { FeatureBadge } from '../FeatureBadge/FeatureBadge'; import { InfoBox, InfoBoxProps } from './InfoBox'; @@ -41,30 +41,3 @@ const getFeatureInfoBoxStyles = (theme: GrafanaTheme2) => { }), }; }; - -interface FeatureBadgeProps { - featureState: FeatureState; - tooltip?: string; -} - -export const FeatureBadge = ({ featureState, tooltip }: FeatureBadgeProps) => { - const display = getPanelStateBadgeDisplayModel(featureState); - return ; -}; - -function getPanelStateBadgeDisplayModel(featureState: FeatureState): BadgeProps { - switch (featureState) { - case FeatureState.alpha: - return { - text: 'Alpha', - icon: 'exclamation-triangle', - color: 'orange', - }; - } - - return { - text: 'Beta', - icon: 'rocket', - color: 'blue', - }; -} diff --git a/packages/grafana-ui/src/components/InfoBox/InfoBox.story.tsx b/packages/grafana-ui/src/components/InfoBox/InfoBox.story.tsx index cd5ab6d93ef..2f767731676 100644 --- a/packages/grafana-ui/src/components/InfoBox/InfoBox.story.tsx +++ b/packages/grafana-ui/src/components/InfoBox/InfoBox.story.tsx @@ -24,7 +24,7 @@ const meta: Meta = { }, argTypes: { featureState: { - control: { type: 'select', options: ['alpha', 'beta', undefined] }, + control: { type: 'select', options: ['experimental', 'preview'] }, }, }, }; @@ -33,7 +33,7 @@ const defaultProps: FeatureInfoBoxProps = { title: 'A title', severity: 'info', url: 'http://www.grafana.com', - featureState: FeatureState.beta, + featureState: FeatureState.preview, children: (

diff --git a/packages/grafana-ui/src/components/index.ts b/packages/grafana-ui/src/components/index.ts index 274cea8e082..08abb985340 100644 --- a/packages/grafana-ui/src/components/index.ts +++ b/packages/grafana-ui/src/components/index.ts @@ -175,7 +175,8 @@ export { } from './DataLinks/DataLinksContextMenu'; export { SeriesIcon } from './VizLegend/SeriesIcon'; export { InfoBox } from './InfoBox/InfoBox'; -export { FeatureBadge, FeatureInfoBox } from './InfoBox/FeatureInfoBox'; +export { FeatureInfoBox } from './InfoBox/FeatureInfoBox'; +export { FeatureBadge } from './FeatureBadge/FeatureBadge'; export { JSONFormatter } from './JSONFormatter/JSONFormatter'; export { JsonExplorer } from './JSONFormatter/json_explorer/json_explorer';