Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 82 additions & 27 deletions frontend/documentation/components/DropdownMenu.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,100 @@
import React from 'react'
import React, { useState } from 'react'
import type { Meta, StoryObj } from 'storybook'
import { screen, userEvent, within } from 'storybook/test'

import DropdownMenu from 'components/base/DropdownMenu'
import DropdownMenu, { DropdownMenuItem } from 'components/base/DropdownMenu'
import IconButton from 'components/base/IconButton'
import Button from 'components/base/forms/Button'
import Icon from 'components/icons/Icon'

const meta: Meta = {
const meta: Meta<typeof DropdownMenu> = {
component: DropdownMenu,
parameters: {
docs: { story: { height: '260px' } },
docs: { story: { height: '320px' } },
layout: 'centered',
},
title: 'Components/Data Display/DropdownMenu',
}
export default meta

type Story = StoryObj
type Story = StoryObj<typeof DropdownMenu>

const DEMO_ITEMS = [
{ label: 'Edit', onClick: () => {} },
{ label: 'Duplicate', onClick: () => {} },
{ label: 'Archive', onClick: () => {} },
{ label: 'Delete', onClick: () => {} },
]
const noop = () => undefined

export const Default: Story = {
render: () => <DropdownMenu items={DEMO_ITEMS} />,
const ActionsMenu = () => (
<DropdownMenu
aria-label='Feature actions'
trigger={
<IconButton variant='ghost' size='small' aria-label='Feature actions'>
<Icon name='more-vertical' width={18} />
</IconButton>
}
>
<DropdownMenuItem icon='copy' onSelect={noop}>
Copy feature name
</DropdownMenuItem>
<DropdownMenuItem icon='list' onSelect={noop}>
Show audit logs
</DropdownMenuItem>
<DropdownMenuItem icon='clock' disabled onSelect={noop}>
Show history
</DropdownMenuItem>
<DropdownMenuItem icon='trash-2' destructive onSelect={noop}>
Remove feature
</DropdownMenuItem>
</DropdownMenu>
)

const SECTIONS = ['Value', 'Segment overrides', 'History', 'Settings']

const SectionsMenu = () => {
const [current, setCurrent] = useState(2)
return (
<DropdownMenu
aria-label='Sections'
trigger={<Button theme='secondary'>{SECTIONS[current]}</Button>}
>
{SECTIONS.map((section, i) => (
<DropdownMenuItem
key={section}
current={current === i}
onSelect={() => setCurrent(i)}
>
{section}
</DropdownMenuItem>
))}
</DropdownMenu>
)
}

export const Open: Story = {
const openMenu = async (canvasElement: HTMLElement, name: string) => {
const canvas = within(canvasElement)
await userEvent.click(canvas.getByRole('button', { name }))
await screen.findByRole('dialog')
}

export const Actions: Story = {
parameters: { chromatic: { delay: 300 } },
play: ({ canvasElement }: { canvasElement: HTMLElement }) =>
openMenu(canvasElement, 'Feature actions'),
render: () => <ActionsMenu />,
}

export const CurrentItem: Story = {
parameters: { chromatic: { delay: 300 } },
play: ({ canvasElement }: { canvasElement: HTMLElement }) =>
openMenu(canvasElement, 'History'),
render: () => <SectionsMenu />,
}

// On phones the menu opens as a bottom sheet
export const MobileSheet: Story = {
globals: { viewport: { isRotated: false, value: 'mobile1' } },
parameters: {
chromatic: { delay: 300 },
docs: {
description: {
story:
'Menu in its open state. Storybook clicks the trigger in `play`; the menu portals into `document.body`, so it is queried via `screen` rather than the local canvas.',
},
},
},
play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
const canvas = within(canvasElement)
await userEvent.click(canvas.getByRole('button'))
await screen.findByText('Edit')
chromatic: { delay: 300, viewports: [375] },
docs: { story: { height: '420px', inline: false } },
},
render: () => <DropdownMenu items={DEMO_ITEMS} />,
play: ({ canvasElement }: { canvasElement: HTMLElement }) =>
openMenu(canvasElement, 'Feature actions'),
render: () => <ActionsMenu />,
}
3 changes: 3 additions & 0 deletions frontend/documentation/components/OverflowNav.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const NAV_ITEMS = (
export const ProjectNavbar: Story = {
render: () => (
<OverflowNav
label='More pages'
gap={3}
containerClassName='px-2 pb-1 bg-faint'
className='py-0 d-flex'
Expand All @@ -68,6 +69,7 @@ export const WithOverflow: Story = {
},
render: () => (
<OverflowNav
label='More pages'
force
gap={3}
containerClassName='px-2 pb-1 bg-faint'
Expand Down Expand Up @@ -97,6 +99,7 @@ export const OverflowOpen: Story = {
},
render: () => (
<OverflowNav
label='More pages'
force
gap={3}
containerClassName='px-2 pb-1 bg-faint'
Expand Down
14 changes: 8 additions & 6 deletions frontend/e2e/helpers/e2e-helpers.playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class E2EHelpers {
await element.waitFor({ state: 'visible', timeout: SHORT_TIMEOUT });
return;
} catch {
const overflowButton = this.page.locator(byId('overflow-nav-button')).first();
const overflowButton = this.page.getByRole('button', { name: /^More (project|organisation|environment) pages$/ }).filter({ visible: true }).first();
if (await overflowButton.isVisible()) {
await overflowButton.click();
}
Expand Down Expand Up @@ -812,12 +812,14 @@ export class E2EHelpers {
// Go to feature versions
async goToFeatureVersions(featureName: string) {
await this.gotoFeature(featureName);
if (await this.isElementExists('change-history')) {
await this.click(byId('change-history'));
} else {
await this.click(byId('tabs-overflow-button'));
await this.click(byId('change-history'));
// History is a tab, or an item in the "More tabs" menu when the tabs overflow
const history = this.page
.getByRole('button', { exact: true, name: 'History' })
.filter({ visible: true });
if (!(await history.count())) {
await this.page.getByRole('button', { exact: true, name: 'More tabs' }).click();
}
await history.first().click();
}

// Compare version
Expand Down
72 changes: 57 additions & 15 deletions frontend/web/components/IntegrationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import {
} from 'common/types/responses'
import map from 'lodash/map'
import Button from './base/forms/Button'
import DropdownMenu from './base/DropdownMenu'
import DropdownMenu, { DropdownMenuItem } from './base/DropdownMenu'
import IconButton from './base/IconButton'
import Icon from './icons/Icon'
import Tooltip from './Tooltip'
import { IonIcon } from '@ionic/react'
import { close as closeIcon } from 'ionicons/icons'
import Utils from 'common/utils/utils'
Expand Down Expand Up @@ -270,7 +272,39 @@ const Integration: FC<IntegrationProps> = (props) => {
}
return button
}
return <DropdownMenu items={actions} />
return (
<DropdownMenu
aria-label={`${props.integration.title ?? 'Integration'} actions`}
trigger={
<IconButton
variant='ghost'
size='small'
aria-label={`${props.integration.title ?? 'Integration'} actions`}
>
<Icon name='more-vertical' width={18} />
</IconButton>
}
>
{actions.map((action) => {
const item = (
<DropdownMenuItem
key={action.label}
disabled={action.disabled}
onSelect={action.onClick}
>
{action.label}
</DropdownMenuItem>
)
return action.tooltip ? (
<Tooltip key={action.label} title={item} place='right'>
{action.tooltip}
</Tooltip>
) : (
item
)
})}
</DropdownMenu>
)
}

return (
Expand Down Expand Up @@ -343,19 +377,27 @@ const Integration: FC<IntegrationProps> = (props) => {
</Flex>
<div onClick={(e) => e.stopPropagation()}>
<DropdownMenu
items={[
{
dataTest: 'edit-integration',
label: 'Edit',
onClick: () => edit(integration),
},
{
dataTest: 'delete-integration',
label: 'Delete',
onClick: () => remove(integration),
},
]}
/>
aria-label='Integration actions'
trigger={
<IconButton
variant='ghost'
size='small'
aria-label='Integration actions'
>
<Icon name='more-vertical' width={18} />
</IconButton>
}
>
<DropdownMenuItem onSelect={() => edit(integration)}>
Edit
</DropdownMenuItem>
<DropdownMenuItem
destructive
onSelect={() => remove(integration)}
>
Delete
</DropdownMenuItem>
</DropdownMenu>
</div>
</Row>
</div>
Expand Down
117 changes: 0 additions & 117 deletions frontend/web/components/base/DropdownMenu.tsx

This file was deleted.

Loading
Loading