-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Extract Chrome app header infra fixes #271670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Dosant
merged 4 commits into
elastic:main
from
Dosant:chrome-next-main/extract-various-fixes
May 28, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
182 changes: 182 additions & 0 deletions
182
src/core/packages/chrome/app-header/src/app_header/app_badge.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import React, { useState } from 'react'; | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
| import { action } from '@storybook/addon-actions'; | ||
| import { | ||
| EuiBadge, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiHeader, | ||
| EuiHeaderSection, | ||
| EuiPageTemplate, | ||
| EuiPopover, | ||
| EuiTitle, | ||
| } from '@elastic/eui'; | ||
| import type { AppHeaderBadge } from '../types'; | ||
| import { AppBadge } from './app_badge'; | ||
|
|
||
| const MAX_VISIBLE_BADGES = 2; | ||
| const OVERFLOW_THRESHOLD = 3; | ||
|
|
||
| interface AppBadgeStoryProps { | ||
| title: string; | ||
| badges: AppHeaderBadge[]; | ||
| } | ||
|
|
||
| const HeaderWithBadges = ({ title, badges }: AppBadgeStoryProps) => { | ||
| const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
| const shouldOverflow = badges.length > OVERFLOW_THRESHOLD; | ||
| const visibleBadges = shouldOverflow ? badges.slice(0, MAX_VISIBLE_BADGES) : badges; | ||
| const overflowBadges = shouldOverflow ? badges.slice(MAX_VISIBLE_BADGES) : []; | ||
|
|
||
| return ( | ||
| <EuiHeader> | ||
| <EuiHeaderSection> | ||
| <EuiFlexGroup alignItems="center" gutterSize="s" responsive={false} wrap={false}> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiTitle size="xs"> | ||
| <h1>{title}</h1> | ||
| </EuiTitle> | ||
| </EuiFlexItem> | ||
| {visibleBadges.map((badge) => ( | ||
| <EuiFlexItem grow={false} key={badge.label}> | ||
| <AppBadge badge={badge} /> | ||
| </EuiFlexItem> | ||
| ))} | ||
| {overflowBadges.length > 0 && ( | ||
| <EuiFlexItem grow={false}> | ||
| <EuiPopover | ||
| aria-label="More badges" | ||
| button={ | ||
| <EuiBadge | ||
| color="hollow" | ||
| onClick={() => setIsPopoverOpen((open) => !open)} | ||
| onClickAriaLabel={`Show ${overflowBadges.length} more badges`} | ||
| > | ||
| +{overflowBadges.length} | ||
| </EuiBadge> | ||
| } | ||
| isOpen={isPopoverOpen} | ||
| closePopover={() => setIsPopoverOpen(false)} | ||
| panelPaddingSize="s" | ||
| > | ||
| <EuiFlexGroup direction="column" gutterSize="xs" alignItems="center"> | ||
| {overflowBadges.map((badge) => ( | ||
| <EuiFlexItem grow={false} key={badge.label}> | ||
| <AppBadge badge={badge} /> | ||
| </EuiFlexItem> | ||
| ))} | ||
| </EuiFlexGroup> | ||
| </EuiPopover> | ||
| </EuiFlexItem> | ||
| )} | ||
| </EuiFlexGroup> | ||
| </EuiHeaderSection> | ||
| </EuiHeader> | ||
| ); | ||
| }; | ||
|
|
||
| const meta: Meta<AppBadgeStoryProps> = { | ||
| title: 'Chrome/App Badge', | ||
| component: HeaderWithBadges, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <EuiPageTemplate> | ||
| <Story /> | ||
| </EuiPageTemplate> | ||
| ), | ||
| ], | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: | ||
| 'Badges displayed inline next to the page title in the Chrome header. ' + | ||
| 'Each badge can be a simple label, have a click handler, or open a context menu.', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<AppBadgeStoryProps>; | ||
|
|
||
| export const Badges: Story = { | ||
| args: { | ||
| title: '[Logs] Web Traffic', | ||
| badges: [ | ||
| { label: 'Beta' }, | ||
| { | ||
| label: 'Tech Preview', | ||
| color: 'warning', | ||
| tooltip: 'This feature is in tech preview and may change.', | ||
| onClick: action('tech-preview-clicked'), | ||
| onClickAriaLabel: 'Click to learn more about tech preview', | ||
| }, | ||
| { | ||
| label: 'Managed', | ||
| color: 'primary', | ||
| popoverWidth: 180, | ||
| items: [ | ||
| { | ||
| name: 'View details', | ||
| icon: 'inspect', | ||
| onClick: action('view-details-clicked'), | ||
| }, | ||
| { | ||
| name: 'Export', | ||
| icon: 'exportAction', | ||
| popoverWidth: 180, | ||
| items: [ | ||
| { | ||
| name: 'Export as CSV', | ||
| icon: 'document', | ||
| onClick: action('export-csv-clicked'), | ||
| }, | ||
| { | ||
| name: 'Export as JSON', | ||
| icon: 'document', | ||
| onClick: action('export-json-clicked'), | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'Unlink', | ||
| icon: 'unlink', | ||
| onClick: action('unlink-clicked'), | ||
| }, | ||
| ], | ||
| }, | ||
| { label: 'New', color: 'primary' }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| export const ThreeBadges: Story = { | ||
| name: 'Three badges', | ||
| args: { | ||
| title: '[Logs] Web Traffic', | ||
| badges: [ | ||
| { label: 'Beta' }, | ||
| { | ||
| label: 'Tech Preview', | ||
| color: 'warning', | ||
| tooltip: 'This feature is in tech preview and may change.', | ||
| }, | ||
| { | ||
| label: 'Managed', | ||
| color: 'primary', | ||
| onClick: action('managed-clicked'), | ||
| onClickAriaLabel: 'Click to view managed details', | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,4 +37,5 @@ export { | |
| getPopoverPanels, | ||
| getPopoverActionItems, | ||
| getIsSelectedColor, | ||
| hasNonGlobalStaticItems, | ||
| } from './src'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/core/packages/chrome/browser-hooks/use_is_next_chrome.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { useChromeService } from '@kbn/core-chrome-browser-context'; | ||
|
|
||
| /** | ||
| * Returns `true` when Chrome Next is enabled. | ||
| * Note: this only checks the feature flag, it does not check whether current chrome is classic vs project. | ||
| * Combine with `useChromeStyle` to check if the current chrome is classic vs project. | ||
| */ | ||
| export function useIsNextChrome(): boolean { | ||
|
angeles-mb marked this conversation as resolved.
|
||
| const chrome = useChromeService(); | ||
| return chrome.next.isEnabled; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beta and New badges are clickable even if they don't have an
onClick