Skip to content
Open
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
107 changes: 81 additions & 26 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 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'>
<DropdownMenuItem onSelect={noop}>
<Icon name='copy' />
Copy feature name
</DropdownMenuItem>
<DropdownMenuItem onSelect={noop}>
<Icon name='list' />
Show audit logs
</DropdownMenuItem>
<DropdownMenuItem
disabled
disabledReason='History needs feature versioning'
onSelect={noop}
>
<Icon name='clock' />
Show history
</DropdownMenuItem>
<DropdownMenuItem destructive onSelect={noop}>
<Icon name='trash-2' />
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')
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
31 changes: 22 additions & 9 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 @@ -612,7 +612,7 @@ export class E2EHelpers {
const dropdownSelector = byId(`select-segment-option-${selectionIndex}`);
const isDropdownVisible = await this.page.locator(dropdownSelector).isVisible().catch(() => false);
if (!isDropdownVisible) {
await this.click(byId('segment_overrides'));
await this.openFeatureTab('Segment Overrides');
}
await this.click(dropdownSelector);
await this.waitForElementVisible(this.segmentOverrideValueField(index));
Expand All @@ -638,7 +638,7 @@ export class E2EHelpers {
// Add a remote config override for a segment picked by name, so other
// segments in a shared project can't shift the selection
async addSegmentOverrideConfigForSegment(segmentName: string, value: string) {
await this.click(byId('segment_overrides'));
await this.openFeatureTab('Segment Overrides');
// E2E builds render the select's options as plain links
await this.page
.locator('[data-test^="select-segment-option-"]')
Expand All @@ -659,7 +659,7 @@ export class E2EHelpers {

// Set segment override index (for reordering)
async setSegmentOverrideIndex(index: number, newIndex: number) {
await this.click(byId('segment_overrides'));
await this.openFeatureTab('Segment Overrides');
await this.setText(byId(`sort-${index}`), `${newIndex}`);
}

Expand Down Expand Up @@ -809,15 +809,28 @@ export class E2EHelpers {
throw new Error(`Try-it failed after ${maxRetries} attempts: ${key}.${field} never became ${expected}`);
}

// Open a feature drawer tab, from "More tabs" when it has overflowed
async openFeatureTab(name: string) {
const tab = this.page
.getByRole('button', { name: new RegExp(`^${name}`) })
.filter({ visible: true });
if (!(await tab.count())) {
await this.page.getByRole('button', { exact: true, name: 'More tabs' }).click();
}
await tab.first().click();
}

// 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
5 changes: 3 additions & 2 deletions frontend/e2e/tests/environment-permission-test.pw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test.describe('Environment Permission Tests', () => {
gotoTraits,
login,
logout,
openFeatureTab,
setUserPermission,
toggleFeature,
waitForElementClickable,
Expand Down Expand Up @@ -100,7 +101,7 @@ test.describe('Environment Permission Tests', () => {
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await gotoProject(PROJECT_NAME)
await gotoFeature('my_feature')
await click(byId('segment_overrides'))
await openFeatureTab('Segment Overrides')
await waitForElementNotClickable('#update-feature-segments-btn')
await closeModal()
await logout()
Expand All @@ -112,7 +113,7 @@ test.describe('Environment Permission Tests', () => {
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await gotoProject(PROJECT_NAME)
await gotoFeature('my_feature')
await click(byId('segment_overrides'))
await openFeatureTab('Segment Overrides')
await waitForElementClickable('#update-feature-segments-btn')
await closeModal()
await logout()
Expand Down
15 changes: 11 additions & 4 deletions frontend/e2e/tests/experimentation-test.pw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ test.describe('Experimentation Tests', () => {
page,
}, testInfo) => {
await skipOnSaas()
const { click, closeModal, featureValueField, gotoFeature, gotoFeatures } =
await setup(page)
const {
click,
closeModal,
featureValueField,
gotoFeature,
gotoFeatures,
openFeatureTab,
} = await setup(page)

log('Create an experiment')
await createExperiment(page, FIRST_EXPERIMENT)
Expand All @@ -127,7 +133,7 @@ test.describe('Experimentation Tests', () => {
`This flag is part of the experiment ${FIRST_EXPERIMENT}`,
)
await expect(featureValueField()).not.toBeEditable()
await click(byId('segment_overrides'))
await openFeatureTab('Segment Overrides')
await expect(rolloutOverride(page)).toHaveCount(1)
await closeModal()
})
Expand All @@ -142,6 +148,7 @@ test.describe('Experimentation Tests', () => {
closeModal,
gotoFeature,
gotoFeatures,
openFeatureTab,
waitForToast,
} = await setup(page)

Expand Down Expand Up @@ -172,7 +179,7 @@ test.describe('Experimentation Tests', () => {
'100',
)
await expect(page.locator(byId('featureVariationWeighta'))).toHaveValue('0')
await click(byId('segment_overrides'))
await openFeatureTab('Segment Overrides')
await expectNoRolloutOverride(page)
await closeModal()
})
Expand Down
55 changes: 36 additions & 19 deletions frontend/web/components/IntegrationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ 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 { configuredActionsLabel } from './integrations/configuredActionsLabel'
import Icon from './icons/Icon'
import { IonIcon } from '@ionic/react'
import { close as closeIcon } from 'ionicons/icons'
Expand Down Expand Up @@ -270,7 +271,22 @@ const Integration: FC<IntegrationProps> = (props) => {
}
return button
}
return <DropdownMenu items={actions} />
return (
<DropdownMenu
aria-label={`Actions for ${props.integration.title ?? 'integration'}`}
>
{actions.map((action) => (
<DropdownMenuItem
key={action.label}
disabled={action.disabled}
disabledReason={action.tooltip}
onSelect={action.onClick}
>
{action.label}
</DropdownMenuItem>
))}
</DropdownMenu>
)
}

return (
Expand Down Expand Up @@ -325,7 +341,7 @@ const Integration: FC<IntegrationProps> = (props) => {
)}

{activeIntegrations &&
activeIntegrations.map((integration) => (
activeIntegrations.map((integration, index) => (
<div
key={integration.id}
className='list-integrations clickable p-3 mt-3'
Expand All @@ -341,22 +357,23 @@ const Integration: FC<IntegrationProps> = (props) => {
integration={props.integration}
/>
</Flex>
<div onClick={(e) => e.stopPropagation()}>
<DropdownMenu
items={[
{
dataTest: 'edit-integration',
label: 'Edit',
onClick: () => edit(integration),
},
{
dataTest: 'delete-integration',
label: 'Delete',
onClick: () => remove(integration),
},
]}
/>
</div>
<DropdownMenu
aria-label={configuredActionsLabel(
props.integration.title,
index,
activeIntegrations.length,
)}
>
<DropdownMenuItem onSelect={() => edit(integration)}>
Edit
</DropdownMenuItem>
<DropdownMenuItem
destructive
onSelect={() => remove(integration)}
>
Delete
</DropdownMenuItem>
</DropdownMenu>
</Row>
</div>
))}
Expand Down
Loading
Loading