Skip to content
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
@@ -1,10 +1,12 @@
import React from 'react'
import { Revision } from 'dvc/src/plots/webview/contract'
import cx from 'classnames'
import { useSelector } from 'react-redux'
import styles from './styles.module.scss'
import { DropTarget } from './DropTarget'
import { ComparisonTableHeader } from './ComparisonTableHeader'
import { DragDropContainer } from '../../../shared/components/dragDrop/DragDropContainer'
import { RootState } from '../../store'

export type ComparisonTableColumn = Revision

Expand All @@ -21,14 +23,19 @@ export const ComparisonTableHead: React.FC<ComparisonTableHeadProps> = ({
setColumnsOrder,
setPinnedColumn
}) => {
const draggedId = useSelector(
(state: RootState) => state.dragAndDrop.draggedRef?.itemId
)

const items = columns.map(({ revision, displayColor, group }) => {
const isPinned = revision === pinnedColumn
return (
<th
key={revision}
id={revision}
className={cx(styles.comparisonTableHeader, {
[styles.pinnedColumnHeader]: isPinned
[styles.pinnedColumnHeader]: isPinned,
[styles.draggedColumn]: draggedId === revision
})}
>
<ComparisonTableHeader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
/**
* @jest-environment jsdom
*/
import { configureStore } from '@reduxjs/toolkit'
import { join } from 'dvc/src/test/util/path'
import React from 'react'
import { render, cleanup, screen, fireEvent } from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
import comparisonPlotsFixture from 'dvc/src/test/fixtures/plotsDiff/comparison'
import { Provider } from 'react-redux'
import {
ComparisonTableRow,
ComparisonTableRowProps
} from './ComparisonTableRow'
import styles from '../styles.module.scss'
import { storeReducers } from '../../store'

jest.mock('../../../shared/api')

Expand All @@ -32,9 +35,15 @@ describe('ComparisonTableRow', () => {

const renderRow = (props = basicProps) =>
render(
<table>
<ComparisonTableRow {...props} />
</table>
<Provider
store={configureStore({
reducer: storeReducers
})}
>
<table>
<ComparisonTableRow {...props} />
</table>
</Provider>
)

it('should render a row toggler', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { ComparisonPlot } from 'dvc/src/plots/webview/contract'
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
import React, { useState } from 'react'
import cx from 'classnames'
import { useSelector } from 'react-redux'
import styles from './styles.module.scss'
import { Icon } from '../../../shared/components/Icon'
import { RefreshButton } from '../../../shared/components/button/RefreshButton'
import { sendMessage } from '../../../shared/vscode'
import { ChevronDown, ChevronRight } from '../../../shared/components/icons'
import { RootState } from '../../store'

export interface ComparisonTableRowProps {
path: string
Expand All @@ -21,6 +23,9 @@ export const ComparisonTableRow: React.FC<ComparisonTableRowProps> = ({
nbColumns,
pinnedColumn
}) => {
const draggedId = useSelector(
(state: RootState) => state.dragAndDrop.draggedRef?.itemId
)
const [isShown, setIsShown] = useState(true)

const toggleIsShownState = () => setIsShown(!isShown)
Expand All @@ -46,7 +51,8 @@ export const ComparisonTableRow: React.FC<ComparisonTableRowProps> = ({
key={path + plot.revision}
className={cx({
[styles.pinnedColumnCell]: isPinned,
[styles.missing]: isShown && missing
[styles.missing]: isShown && missing,
[styles.draggedColumn]: draggedId === plot.revision
})}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,7 @@ $gap: 4px;
height: 100%;
border-right: 2px dashed $accent-color;
}

.draggedColumn {
opacity: 0.4;
}
8 changes: 7 additions & 1 deletion webview/src/shared/components/dragDrop/DragDropContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const DragDropContainer: React.FC<DragDropContainerProps> = ({
setDraggedId('')
}, 0)
if (e.dataTransfer.getData('itemId') === draggedOverId) {
dispatch(changeRef(undefined))
return
}
const newOrder = [...order]
Expand Down Expand Up @@ -203,12 +204,17 @@ export const DragDropContainer: React.FC<DragDropContainerProps> = ({
}
}

const handleDragEnd = () => {
dispatch(changeRef(undefined))
cleanup()
}

const buildItem = (id: string, draggable: JSX.Element) => (
<draggable.type
key={draggable.key}
{...draggable.props}
onDragStart={handleDragStart}
onDragEnd={cleanup}
onDragEnd={handleDragEnd}
onDragOver={handleDragOver}
onDragEnter={handleDragEnter}
onDrop={handleOnDrop}
Expand Down