Skip to content

Commit

Permalink
Cleanup in comparison table stories (#1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
sroy3 authored May 25, 2022
1 parent b9f016d commit 68e9cac
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
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
13 changes: 6 additions & 7 deletions webview/src/plots/components/comparisonTable/ComparisonTable.tsx
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

0 comments on commit 68e9cac

Please sign in to comment.