Skip to content
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

Cleanup of comparison table stories #1771

Merged
merged 1 commit into from
May 25, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,6 @@ describe('ComparisonTable', () => {
expect(headers).toStrictEqual([...namedRevisions, newRevName])
})

it('should pin the current pinned column on first render', () => {
const pinnedRevision = 'main'

renderTable({ ...basicProps, currentPinnedColumn: pinnedRevision })

const [pinnedColumn] = getHeaders()

expect(pinnedColumn.textContent).toBe(pinnedRevision)
})

it('should display a refresh button for each revision that has a missing image', () => {
const revisionWithNoData = 'missing-data'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ import plotsStyles from '../styles.module.scss'
import { withScale } from '../../../util/styles'
import { sendMessage } from '../../../shared/vscode'

export interface ComparisonTableProps
extends Omit<PlotsComparisonData, 'sectionName' | 'size'> {
currentPinnedColumn?: string
}
export type ComparisonTableProps = Omit<
PlotsComparisonData,
'sectionName' | 'size'
>

export const ComparisonTable: React.FC<ComparisonTableProps> = ({
plots,
revisions,
currentPinnedColumn
revisions
}) => {
const pinnedColumn = useRef(currentPinnedColumn || '')
const pinnedColumn = useRef('')
const [columns, setColumns] = useState<ComparisonTableColumn[]>([])
const [comparisonPlots, setComparisonPlots] = useState<ComparisonPlots>([])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export const ComparisonTableHeader: React.FC<ComparisonTableHeaderProps> = ({
})

return (
<div className={styles.header}>
<div
className={styles.header}
data-testid={`${children?.toString().split(',')[0]}-header`}
>
{!isPinned && <GripIcon className={styles.gripIcon} />}
<button className={pinClasses} onClick={onClicked}>
<Pin />
Expand Down
36 changes: 20 additions & 16 deletions webview/src/stories/ComparisonTable.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meta, Story } from '@storybook/react/types-6-0'
import { fireEvent, within } from '@testing-library/react'
import React from 'react'
import { ComparisonRevisionData } from 'dvc/src/plots/webview/contract'
import comparisonTableFixture from 'dvc/src/test/fixtures/plotsDiff/comparison'
Expand All @@ -7,33 +8,36 @@ import {
ComparisonTableProps
} from '../plots/components/comparisonTable/ComparisonTable'
import { Theme } from '../shared/components/theme/Theme'
import { DragDropProvider } from '../shared/components/dragDrop/DragDropContext'

export default {
args: comparisonTableFixture,
component: ComparisonTable,
title: 'Comparison Table'
} as Meta

const Template: Story<ComparisonTableProps> = ({
plots,
revisions,
currentPinnedColumn
}) => (
<Theme>
<ComparisonTable
plots={plots}
revisions={revisions}
currentPinnedColumn={currentPinnedColumn}
/>
</Theme>
)
const Template: Story<ComparisonTableProps> = ({ plots, revisions }) => {
return (
<Theme>
<DragDropProvider>
<ComparisonTable plots={plots} revisions={revisions} />
</DragDropProvider>
</Theme>
)
}

export const Basic = Template.bind({})

export const WithPinnedColumn = Template.bind({})
WithPinnedColumn.args = {
...comparisonTableFixture,
currentPinnedColumn: 'main'
WithPinnedColumn.parameters = {
chromatic: { delay: 300 }
}
WithPinnedColumn.play = async ({ canvasElement }) => {
const canvas = within(canvasElement)
const mainHeader = await canvas.findByTestId('main-header')
const pin = within(mainHeader).getByRole('button')

fireEvent.click(pin)
}

const removeSingleImage = (
Expand Down