Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): use buttons for version filters (#40357)

yyhf5e1f1590f3e
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index b5ef78304f6..36e09b0c5a2 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -5083,14 +5083,6 @@
"count": 4
}
},
- "web/app/components/workflow/panel/version-history-panel/filter/filter-item.tsx": {
- "jsx_a11y/click-events-have-key-events": {
- "count": 1
- },
- "jsx_a11y/no-static-element-interactions": {
- "count": 1
- }
- },
"web/app/components/workflow/panel/version-history-panel/index.tsx": {
"jsx_a11y/click-events-have-key-events": {
"count": 2
diff --git a/web/app/components/workflow/panel/version-history-panel/filter/__tests__/filter-item.spec.tsx b/web/app/components/workflow/panel/version-history-panel/filter/__tests__/filter-item.spec.tsx
index b2d7eccc48d..82ba355941d 100644
--- a/web/app/components/workflow/panel/version-history-panel/filter/__tests__/filter-item.spec.tsx
+++ b/web/app/components/workflow/panel/version-history-panel/filter/__tests__/filter-item.spec.tsx
@@ -7,7 +7,7 @@ describe('FilterItem', () => {
it('renders the label, fires selection, and shows the check mark when selected', async () => {
const user = userEvent.setup()
const onClick = vi.fn()
- const { container } = render(
+ render(
<FilterItem
item={{
key: WorkflowVersionFilterOptions.onlyYours,
@@ -18,9 +18,12 @@ describe('FilterItem', () => {
/>,
)
- await user.click(screen.getByText('Only yours'))
+ const option = screen.getByRole('button', { name: 'Only yours' })
+ expect(option).toHaveAttribute('aria-pressed', 'true')
+
+ option.focus()
+ await user.keyboard(' ')
expect(onClick).toHaveBeenCalledWith(WorkflowVersionFilterOptions.onlyYours)
- expect(container.querySelector('svg')).not.toBeNull()
})
})
diff --git a/web/app/components/workflow/panel/version-history-panel/filter/__tests__/index.spec.tsx b/web/app/components/workflow/panel/version-history-panel/filter/__tests__/index.spec.tsx
index 08e5371664d..50c5698bf01 100644
--- a/web/app/components/workflow/panel/version-history-panel/filter/__tests__/index.spec.tsx
+++ b/web/app/components/workflow/panel/version-history-panel/filter/__tests__/index.spec.tsx
@@ -1,7 +1,6 @@
import { fireEvent, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { WorkflowVersionFilterOptions } from '../../../../types'
-import FilterItem from '../filter-item'
import FilterSwitch from '../filter-switch'
import Filter from '../index'
@@ -29,32 +28,6 @@ describe('VersionHistory Filter Components', () => {
})
})
- // Filter items should show the current selection and forward the option key.
- describe('FilterItem', () => {
- it('should call onClick with the selected filter key', async () => {
- const user = userEvent.setup()
- const onClick = vi.fn()
-
- const { container } = render(
- <FilterItem
- item={{
- key: WorkflowVersionFilterOptions.onlyYours,
- name: 'Only Yours',
- }}
- isSelected
- onClick={onClick}
- />,
- )
-
- expect(screen.getByText('Only Yours')).toBeInTheDocument()
- expect(container.querySelector('svg')).toBeInTheDocument()
-
- await user.click(screen.getByText('Only Yours'))
-
- expect(onClick).toHaveBeenCalledWith(WorkflowVersionFilterOptions.onlyYours)
- })
- })
-
// The composed filter popover should open, list options, and delegate actions.
describe('Filter', () => {
it('should open the menu and forward option and switch actions', async () => {
@@ -79,7 +52,9 @@ describe('VersionHistory Filter Components', () => {
expect(screen.getByText('workflow.versionHistory.filter.all')).toBeInTheDocument()
expect(screen.getByText('workflow.versionHistory.filter.onlyYours')).toBeInTheDocument()
- await user.click(screen.getByText('workflow.versionHistory.filter.onlyYours'))
+ await user.click(
+ screen.getByRole('button', { name: 'workflow.versionHistory.filter.onlyYours' }),
+ )
expect(onClickFilterItem).toHaveBeenCalledWith(WorkflowVersionFilterOptions.onlyYours)
fireEvent.click(screen.getByRole('switch'))
diff --git a/web/app/components/workflow/panel/version-history-panel/filter/filter-item.tsx b/web/app/components/workflow/panel/version-history-panel/filter/filter-item.tsx
index 78b42402c27..42a6fbc83f0 100644
--- a/web/app/components/workflow/panel/version-history-panel/filter/filter-item.tsx
+++ b/web/app/components/workflow/panel/version-history-panel/filter/filter-item.tsx
@@ -14,15 +14,17 @@ type FilterItemProps = {
const FilterItem: FC<FilterItemProps> = ({ item, isSelected = false, onClick }) => {
return (
- <div
- className="flex cursor-pointer items-center justify-between gap-x-1 rounded-lg px-2 py-1.5 hover:bg-state-base-hover"
+ <button
+ type="button"
+ aria-pressed={isSelected}
+ className="flex w-full cursor-pointer appearance-none items-center justify-between gap-x-1 rounded-lg px-2 py-1.5 text-start outline-hidden hover:bg-state-base-hover focus-visible:ring-2 focus-visible:ring-state-accent-solid"
onClick={() => {
onClick(item.key)
}}
>
- <div className="flex-1 system-md-regular text-text-primary">{item.name}</div>
- {isSelected && <RiCheckLine className="size-4 shrink-0 text-text-accent" />}
- </div>
+ <span className="flex-1 system-md-regular text-text-primary">{item.name}</span>
+ {isSelected && <RiCheckLine aria-hidden className="size-4 shrink-0 text-text-accent" />}
+ </button>
)
}