This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 73
Issue 315: Clearable columns #497
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
50daad3
Initial working implementation of clearable
933506c
refactor map
7713b22
clean up types + lint
86cf59b
sanity test for clear and delete columns
f94dfca
- fix behavior for merged / not merged headers
0b9cb9c
- update clear/delete tests
4fabe49
revert appmode default state changes
18ab550
Merge branch 'master' into 315-clearable-columns
Marc-Andre-Rivet 93d22d6
Merge master into 315-clearable-columns
efc45e8
fix merge issues
207c5b2
add header actions visual tests with variants
d50f7a1
action icons through ::before pseudo
39aa505
less rows in header action visual tests
ab899e0
revert '×' -> 'x' change
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 hidden or 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
Submodule dash-main
deleted from
9819e5
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -2,8 +2,8 @@ import * as R from 'ramda'; | |
|
||
import { memoizeOneFactory } from 'core/memoizer'; | ||
|
||
import { VisibleColumns, IVisibleColumn } from 'dash-table/components/Table/props'; | ||
import { SingleColumnSyntaxTree, MultiColumnsSyntaxTree, getSingleColumnMap } from 'dash-table/syntax-tree'; | ||
import { VisibleColumns, IVisibleColumn, SetFilter } from 'dash-table/components/Table/props'; | ||
import { SingleColumnSyntaxTree, MultiColumnsSyntaxTree, getMultiColumnQueryString, getSingleColumnMap } from 'dash-table/syntax-tree'; | ||
|
||
const cloneIf = ( | ||
current: Map<string, SingleColumnSyntaxTree>, | ||
|
@@ -61,20 +61,49 @@ export default memoizeOneFactory(( | |
return newMap; | ||
}); | ||
|
||
export const updateMap = ( | ||
map: Map<string, SingleColumnSyntaxTree>, | ||
column: IVisibleColumn, | ||
value: any | ||
): Map<string, SingleColumnSyntaxTree> => { | ||
const safeColumnId = column.id.toString(); | ||
|
||
function updateMap(map: Map<string, SingleColumnSyntaxTree>, column: IVisibleColumn, value: any) { | ||
const id = column.id.toString(); | ||
const newMap = new Map<string, SingleColumnSyntaxTree>(map); | ||
|
||
if (value && value.length) { | ||
newMap.set(safeColumnId, new SingleColumnSyntaxTree(value, column)); | ||
newMap.set(id, new SingleColumnSyntaxTree(value, column)); | ||
} else { | ||
newMap.delete(safeColumnId); | ||
newMap.delete(id); | ||
} | ||
|
||
return newMap; | ||
} | ||
|
||
function updateState(map: Map<string, SingleColumnSyntaxTree>, setFilter: SetFilter) { | ||
const asts = Array.from(map.values()); | ||
const globalFilter = getMultiColumnQueryString(asts); | ||
|
||
const rawGlobalFilter = R.map( | ||
ast => ast.query || '', | ||
R.filter<SingleColumnSyntaxTree>(ast => Boolean(ast), asts) | ||
).join(' && '); | ||
|
||
setFilter(globalFilter, rawGlobalFilter, map); | ||
} | ||
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. Same idea here, isolating the state update logic for both scenarios. |
||
|
||
export const updateColumnFilter = ( | ||
map: Map<string, SingleColumnSyntaxTree>, | ||
column: IVisibleColumn, | ||
value: any, | ||
setFilter: SetFilter | ||
) => { | ||
map = updateMap(map, column, value); | ||
updateState(map, setFilter); | ||
}; | ||
|
||
export const clearColumnsFilter = ( | ||
map: Map<string, SingleColumnSyntaxTree>, | ||
columns: VisibleColumns, | ||
setFilter: SetFilter | ||
) => { | ||
R.forEach(column => { | ||
map = updateMap(map, column, ''); | ||
}, columns); | ||
|
||
updateState(map, setFilter); | ||
}; |
Oops, something went wrong.
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.
Isolating the map update logic - can be called for a single column update (user edits filter) or through header
clear
anddelete
column actions (which may impact multiple columns at the same time)