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

Change the style of the comparison drag and drop feedback #2077

Merged
merged 11 commits into from
Jul 22, 2022
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;
}
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