-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add columns indicator (select columns) to table indicators #4293
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1584,136 +1584,178 @@ describe('App', () => { | |
expect(sortIndicator).toHaveTextContent('2') | ||
jest.useRealTimers() | ||
}) | ||
}) | ||
|
||
it('should show an indicator with the amount of applied filters', () => { | ||
renderTable({ | ||
...tableDataFixture, | ||
filters: [] | ||
}) | ||
jest.useFakeTimers() | ||
const filterIndicator = screen.getByLabelText('filters') | ||
expect(filterIndicator).toHaveTextContent('') | ||
it('should show an indicator with the amount of applied filters', () => { | ||
renderTable({ | ||
...tableDataFixture, | ||
filters: [] | ||
}) | ||
jest.useFakeTimers() | ||
const filterIndicator = screen.getByLabelText('filters') | ||
expect(filterIndicator).toHaveTextContent('') | ||
|
||
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument() | ||
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument() | ||
|
||
fireEvent.mouseEnter(filterIndicator) | ||
advanceTimersByTime(1000) | ||
fireEvent.mouseEnter(filterIndicator) | ||
advanceTimersByTime(1000) | ||
|
||
const tooltip = screen.getByRole('tooltip') | ||
const tooltip = screen.getByRole('tooltip') | ||
|
||
expect(tooltip).toHaveTextContent('Show Filters') | ||
expect(tooltip).toHaveTextContent('Show Filters') | ||
|
||
const { columns } = tableDataFixture | ||
const firstFilterPath = columns[columns.length - 1].path | ||
const secondFilterPath = columns[columns.length - 2].path | ||
setTableData({ | ||
...tableDataFixture, | ||
filters: [firstFilterPath] | ||
}) | ||
expect(filterIndicator).toHaveTextContent('1') | ||
const { columns } = tableDataFixture | ||
const firstFilterPath = columns[columns.length - 1].path | ||
const secondFilterPath = columns[columns.length - 2].path | ||
setTableData({ | ||
...tableDataFixture, | ||
filters: [firstFilterPath] | ||
}) | ||
expect(filterIndicator).toHaveTextContent('1') | ||
|
||
setTableData({ | ||
...tableDataFixture, | ||
filters: [firstFilterPath, secondFilterPath] | ||
}) | ||
expect(filterIndicator).toHaveTextContent('2') | ||
setTableData({ | ||
...tableDataFixture, | ||
filters: [firstFilterPath, secondFilterPath] | ||
}) | ||
expect(filterIndicator).toHaveTextContent('2') | ||
|
||
setTableData({ | ||
...tableDataFixture, | ||
filters: [firstFilterPath, secondFilterPath] | ||
}) | ||
expect(filterIndicator).toHaveTextContent('2') | ||
setTableData({ | ||
...tableDataFixture, | ||
filters: [firstFilterPath, secondFilterPath] | ||
}) | ||
expect(filterIndicator).toHaveTextContent('2') | ||
|
||
setTableData({ | ||
...tableDataFixture, | ||
filters: [] | ||
setTableData({ | ||
...tableDataFixture, | ||
filters: [] | ||
}) | ||
expect(filterIndicator).toHaveTextContent('') | ||
expect(tooltip).not.toHaveTextContent('Experiment') | ||
jest.useRealTimers() | ||
}) | ||
expect(filterIndicator).toHaveTextContent('') | ||
expect(tooltip).not.toHaveTextContent('Experiment') | ||
jest.useRealTimers() | ||
}) | ||
|
||
it('should show a tooltip for the branches indicator', () => { | ||
renderTable({ | ||
...tableDataFixture | ||
}) | ||
jest.useFakeTimers() | ||
const branchesIndicator = screen.getByLabelText('branches') | ||
expect(branchesIndicator).toHaveTextContent('') | ||
it('should show a tooltip for the branches indicator', () => { | ||
renderTable({ | ||
...tableDataFixture | ||
}) | ||
jest.useFakeTimers() | ||
const branchesIndicator = screen.getByLabelText('branches') | ||
expect(branchesIndicator).toHaveTextContent('') | ||
|
||
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument() | ||
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument() | ||
|
||
fireEvent.mouseEnter(branchesIndicator) | ||
advanceTimersByTime(1000) | ||
fireEvent.mouseEnter(branchesIndicator) | ||
advanceTimersByTime(1000) | ||
|
||
const tooltip = screen.getByRole('tooltip') | ||
const tooltip = screen.getByRole('tooltip') | ||
|
||
expect(tooltip).toHaveTextContent('Select Branches') | ||
jest.useRealTimers() | ||
}) | ||
expect(tooltip).toHaveTextContent('Select Branches') | ||
jest.useRealTimers() | ||
}) | ||
|
||
it('should show an indicator for the number of branches selected', () => { | ||
const branches = ['main', 'other', 'third'] | ||
it('should show an indicator for the number of branches selected', () => { | ||
const branches = ['main', 'other', 'third'] | ||
|
||
let workspace | ||
const rowsWithoutWorkspace = [] | ||
for (const row of tableDataFixture.rows) { | ||
if (row.id !== EXPERIMENT_WORKSPACE_ID) { | ||
rowsWithoutWorkspace.push(row) | ||
continue | ||
let workspace | ||
const rowsWithoutWorkspace = [] | ||
for (const row of tableDataFixture.rows) { | ||
if (row.id !== EXPERIMENT_WORKSPACE_ID) { | ||
rowsWithoutWorkspace.push(row) | ||
continue | ||
} | ||
workspace = row | ||
} | ||
workspace = row | ||
} | ||
|
||
const multipleBranches = { | ||
...tableDataFixture, | ||
branches, | ||
hasData: true, | ||
rows: [ | ||
workspace as Commit, | ||
...rowsWithoutWorkspace.map(row => ({ | ||
...row, | ||
branch: branches[0], | ||
subRows: undefined | ||
})), | ||
...rowsWithoutWorkspace.map(row => ({ | ||
...row, | ||
branch: branches[1], | ||
subRows: undefined | ||
})), | ||
...rowsWithoutWorkspace.map(row => ({ | ||
...row, | ||
branch: branches[2], | ||
subRows: undefined | ||
})) | ||
] | ||
} | ||
const multipleBranches = { | ||
...tableDataFixture, | ||
branches, | ||
hasData: true, | ||
rows: [ | ||
workspace as Commit, | ||
...rowsWithoutWorkspace.map(row => ({ | ||
...row, | ||
branch: branches[0], | ||
subRows: undefined | ||
})), | ||
...rowsWithoutWorkspace.map(row => ({ | ||
...row, | ||
branch: branches[1], | ||
subRows: undefined | ||
})), | ||
...rowsWithoutWorkspace.map(row => ({ | ||
...row, | ||
branch: branches[2], | ||
subRows: undefined | ||
})) | ||
] | ||
} | ||
|
||
renderTable(multipleBranches) | ||
renderTable(multipleBranches) | ||
|
||
const [indicator] = screen.getAllByLabelText('branches') | ||
const [indicator] = screen.getAllByLabelText('branches') | ||
|
||
expect(indicator).toHaveTextContent(`${branches.length - 1}`) | ||
}) | ||
expect(indicator).toHaveTextContent(`${branches.length - 1}`) | ||
}) | ||
|
||
it('should send a message to focus the relevant tree when clicked', () => { | ||
renderTable() | ||
mockPostMessage.mockClear() | ||
fireEvent.click(screen.getByLabelText('sorts')) | ||
expect(mockPostMessage).toHaveBeenCalledWith({ | ||
type: MessageFromWebviewType.FOCUS_SORTS_TREE | ||
it('should send a message to focus the relevant tree when clicked', () => { | ||
renderTable() | ||
mockPostMessage.mockClear() | ||
fireEvent.click(screen.getByLabelText('sorts')) | ||
expect(mockPostMessage).toHaveBeenCalledWith({ | ||
type: MessageFromWebviewType.FOCUS_SORTS_TREE | ||
}) | ||
mockPostMessage.mockClear() | ||
fireEvent.click(screen.getByLabelText('filters')) | ||
expect(mockPostMessage).toHaveBeenCalledWith({ | ||
type: MessageFromWebviewType.FOCUS_FILTERS_TREE | ||
}) | ||
|
||
mockPostMessage.mockClear() | ||
fireEvent.click(screen.getByLabelText('selected for plots')) | ||
expect(mockPostMessage).toHaveBeenCalledWith({ | ||
type: MessageFromWebviewType.OPEN_PLOTS_WEBVIEW | ||
}) | ||
}) | ||
mockPostMessage.mockClear() | ||
fireEvent.click(screen.getByLabelText('filters')) | ||
expect(mockPostMessage).toHaveBeenCalledWith({ | ||
type: MessageFromWebviewType.FOCUS_FILTERS_TREE | ||
|
||
it('should show an indicator with the amount of displayed columns', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] last two tests are new |
||
renderTable({ | ||
...tableDataFixture | ||
}) | ||
jest.useFakeTimers() | ||
const columnsIndicator = screen.getByLabelText('columns') | ||
expect(columnsIndicator).toHaveTextContent('22') | ||
|
||
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument() | ||
|
||
fireEvent.mouseEnter(columnsIndicator) | ||
advanceTimersByTime(1000) | ||
const tooltip = screen.getByRole('tooltip') | ||
|
||
expect(tooltip).toHaveTextContent('Select Columns') | ||
|
||
setTableData({ | ||
...tableDataFixture, | ||
columns: tableDataFixture.columns.slice(1) | ||
}) | ||
|
||
expect(columnsIndicator).toHaveTextContent('21') | ||
|
||
setTableData({ | ||
...tableDataFixture, | ||
columns: [] | ||
}) | ||
|
||
expect(columnsIndicator).toHaveTextContent('') | ||
|
||
jest.useRealTimers() | ||
}) | ||
|
||
mockPostMessage.mockClear() | ||
fireEvent.click(screen.getByLabelText('selected for plots')) | ||
expect(mockPostMessage).toHaveBeenCalledWith({ | ||
type: MessageFromWebviewType.OPEN_PLOTS_WEBVIEW | ||
it('should send a message to select columns when the select columns icon is clicked', () => { | ||
renderTable() | ||
mockPostMessage.mockClear() | ||
fireEvent.click(screen.getByLabelText('columns')) | ||
expect(mockPostMessage).toHaveBeenCalledWith({ | ||
type: MessageFromWebviewType.SELECT_COLUMNS | ||
}) | ||
}) | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ import { | |
focusFiltersTree, | ||
focusSortsTree, | ||
openPlotsWebview, | ||
selectBranches | ||
selectBranches, | ||
selectColumns | ||
} from '../../util/messages' | ||
import { Icon } from '../../../shared/components/Icon' | ||
import { | ||
Filter, | ||
GitMerge, | ||
GraphScatter, | ||
ListFilter, | ||
SortPrecedence | ||
} from '../../../shared/components/icons' | ||
import { ExperimentsState } from '../../store' | ||
|
@@ -72,21 +74,30 @@ export const Indicators = () => { | |
const filters = useSelector( | ||
(state: ExperimentsState) => state.tableData.filters | ||
) | ||
const filtersCount = filters?.length | ||
|
||
const sorts = useSelector((state: ExperimentsState) => state.tableData.sorts) | ||
const sortsCount = sorts?.length | ||
|
||
const selectedForPlotsCount = useSelector( | ||
(state: ExperimentsState) => state.tableData.selectedForPlotsCount | ||
) | ||
|
||
const branchesSelected = useSelector( | ||
(state: ExperimentsState) => | ||
Math.max(state.tableData.branches.filter(Boolean).length - 1, 0) // We always have one branch by default (the current one which is not selected) and undefined for the workspace | ||
) | ||
|
||
const { hasBranchesToSelect } = useSelector( | ||
(state: ExperimentsState) => state.tableData | ||
) | ||
|
||
const sortsCount = sorts?.length | ||
const filtersCount = filters?.length | ||
const columnsSelected = useSelector( | ||
(state: ExperimentsState) => | ||
state.tableData.columns.filter(({ hasChildren }) => !hasChildren).length | ||
) | ||
const hasColumns = useSelector( | ||
(state: ExperimentsState) => state.tableData.hasColumns | ||
) | ||
|
||
return ( | ||
<div className={styles.tableIndicators}> | ||
|
@@ -123,6 +134,15 @@ export const Indicators = () => { | |
> | ||
<Icon width={16} height={16} icon={GitMerge} /> | ||
</Indicator> | ||
<Indicator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] Considered making this the first indicator. Decided against it. Happy to update if you have a different opinion. |
||
count={columnsSelected} | ||
aria-label="columns" | ||
onClick={selectColumns} | ||
tooltipContent="Select Columns" | ||
disabled={!hasColumns} | ||
> | ||
<Icon width={16} height={16} icon={ListFilter} /> | ||
</Indicator> | ||
</div> | ||
) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[F] The describe block shouldn't have ended here. I'll mark the new test(s).