This repository has been 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 256, 257, 608 - Add conditional styling capabilities #729
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
edc3bf1
Support arrays for conditional styling `if`: row_index, header_index,…
a02c8d3
- Add support for `is_active` and `is_selected` conditional styling
09d7f53
remove useless check (cell & filter don't support active conditions)
6ce6ef6
Update CHANGELOG.md
Marc-Andre-Rivet 4fa6feb
update unit tests
fe025ef
Merge branch 'style-active-focused-cell' of github.com:plotly/dash-ta…
c843e7e
consider offset when calculating edges
6e007b3
selectedCells || [activeCell]
e8257d4
clean up
de55351
clean up tests
ee5b9ff
base style for active vs. selected
6f93020
only apply styles for active/selected cells when updating active/sele…
6a0bc64
inactive -> baseline -> active style
2af76ce
Change deprecated R.contains to R.includes
b6d6300
Merge branch 'dev' into style-active-focused-cell
Marc-Andre-Rivet 43c00fb
refactor `is_selected` and `is_active` into `state: 'active'|'selected'`
56b29fb
Merge branch 'style-active-focused-cell' of github.com:plotly/dash-ta…
1db84eb
Update src/dash-table/conditional/index.ts
Marc-Andre-Rivet df99bf6
update unit tests
622325b
Merge branch 'style-active-focused-cell' of github.com:plotly/dash-ta…
ce95cfc
fix conditional styles regression
65df9b2
Merge branch 'dev' into style-active-focused-cell
Marc-Andre-Rivet 254fb2c
Replace use of var(--accent) and var(--selected-background) for backg…
b8d482c
Merge branch 'style-active-focused-cell' of github.com:plotly/dash-ta…
7252b03
fix bug with row_index and header_index handling + new test
53753e1
clean up visual tests
7e9601b
update edges unit cases
345918a
Use hard-coded values for IE11 / browsers that don't support variable…
bb1f6e5
missing `;`
8085950
active partially overrides selected
e6d05fb
Merge branch 'dev' into style-active-focused-cell
Marc-Andre-Rivet d387aae
Merge branch 'dev' into style-active-focused-cell
Marc-Andre-Rivet e3d6fca
Remove invalid check - object.length === 0 -> always `le` to offset
8350c64
Improving typing on `data` prop and related manipulations
b5065ef
Merge branch 'style-active-focused-cell' of github.com:plotly/dash-ta…
22fc0ad
Merge branch 'dev' into style-active-focused-cell
Marc-Andre-Rivet 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
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
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
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
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
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
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 |
---|---|---|
|
@@ -13,11 +13,15 @@ export interface IIndexedHeaderElement { | |
} | ||
|
||
export interface IIndexedRowElement { | ||
row_index?: number | 'odd' | 'even'; | ||
row_index?: number[] | number | 'odd' | 'even'; | ||
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. Support array of values |
||
} | ||
|
||
export interface INamedElement { | ||
column_id?: ColumnId; | ||
column_id?: ColumnId[] | ColumnId; | ||
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. Support array of values |
||
} | ||
|
||
export interface IStateElement { | ||
state?: 'active' | 'selected'; | ||
} | ||
|
||
export interface ITypedElement { | ||
|
@@ -29,17 +33,29 @@ export interface IEditableElement { | |
} | ||
|
||
export type ConditionalBasicFilter = INamedElement & ITypedElement; | ||
export type ConditionalDataCell = IConditionalElement & IIndexedRowElement & INamedElement & ITypedElement & IEditableElement; | ||
export type ConditionalDataCell = IConditionalElement & IIndexedRowElement & INamedElement & IStateElement & ITypedElement & IEditableElement; | ||
export type ConditionalCell = INamedElement & ITypedElement; | ||
export type ConditionalHeader = IIndexedHeaderElement & INamedElement & ITypedElement; | ||
|
||
function ifAstFilter(ast: QuerySyntaxTree, datum: Datum) { | ||
return ast.isValid && ast.evaluate(datum); | ||
} | ||
|
||
export function ifColumnStateActive(condition: IStateElement | undefined, active: boolean) { | ||
return condition?.state !== 'active' || active; | ||
} | ||
|
||
export function ifColumnStateSelected(condition: IStateElement | undefined, selected: boolean) { | ||
return condition?.state !== 'selected' || selected; | ||
} | ||
|
||
export function ifColumnId(condition: INamedElement | undefined, columnId: ColumnId) { | ||
return !condition || | ||
condition.column_id === undefined || | ||
if (!condition || condition.column_id === undefined) { | ||
return true; | ||
} | ||
|
||
return Array.isArray(condition.column_id) ? | ||
R.includes(columnId, condition.column_id) : | ||
condition.column_id === columnId; | ||
} | ||
|
||
|
@@ -50,27 +66,29 @@ export function ifColumnType(condition: ITypedElement | undefined, columnType?: | |
} | ||
|
||
export function ifRowIndex(condition: IIndexedRowElement | undefined, rowIndex: number) { | ||
if (!condition || | ||
condition.row_index === undefined) { | ||
if (!condition || condition.row_index === undefined) { | ||
return true; | ||
} | ||
|
||
const rowCondition = condition.row_index; | ||
return typeof rowCondition === 'number' ? | ||
rowIndex === rowCondition : | ||
rowCondition === 'odd' ? rowIndex % 2 === 1 : rowIndex % 2 === 0; | ||
return typeof rowCondition === 'string' ? | ||
rowIndex % 2 === (rowCondition === 'odd' ? 1 : 0) : | ||
Array.isArray(rowCondition) ? | ||
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. Check for array |
||
R.includes(rowIndex, rowCondition) : | ||
rowIndex === rowCondition; | ||
} | ||
|
||
export function ifHeaderIndex(condition: IIndexedHeaderElement | undefined, headerIndex: number) { | ||
if (!condition || | ||
condition.header_index === undefined) { | ||
if (!condition || condition.header_index === undefined) { | ||
return true; | ||
} | ||
|
||
const headerCondition = condition.header_index; | ||
return typeof headerCondition === 'number' ? | ||
headerIndex === headerCondition : | ||
headerCondition === 'odd' ? headerIndex % 2 === 1 : headerIndex % 2 === 0; | ||
return typeof headerCondition === 'string' ? | ||
headerIndex % 2 === (headerCondition === 'odd' ? 1 : 0) : | ||
Array.isArray(headerCondition) ? | ||
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. Check for array |
||
R.includes(headerIndex, headerCondition) : | ||
headerIndex === headerCondition; | ||
} | ||
|
||
export function ifFilter(condition: IConditionalElement | undefined, datum: Datum) { | ||
|
@@ -89,32 +107,52 @@ export function ifEditable(condition: IEditableElement | undefined, isEditable: | |
|
||
export type Filter<T> = (s: T[]) => T[]; | ||
|
||
export const matchesDataCell = (datum: Datum, i: number, column: IColumn): Filter<IConvertedStyle> => R.filter<IConvertedStyle>((style => | ||
style.matchesRow(i) && | ||
export const matchesDataCell = ( | ||
datum: Datum, | ||
i: number, column: IColumn, | ||
active: boolean, | ||
selected: boolean | ||
): Filter<IConvertedStyle> => R.filter<IConvertedStyle>((style => | ||
!style.checksHeaderRow() && | ||
style.matchesActive(active) && | ||
style.matchesSelected(selected) && | ||
style.matchesDataRow(i) && | ||
style.matchesColumn(column) && | ||
style.matchesFilter(datum) | ||
)); | ||
|
||
export const matchesFilterCell = (column: IColumn): Filter<IConvertedStyle> => R.filter<IConvertedStyle>((style => | ||
!style.checksState() && | ||
!style.checksDataRow() && | ||
!style.checksHeaderRow() && | ||
style.matchesColumn(column) | ||
)); | ||
|
||
export const matchesHeaderCell = (i: number, column: IColumn): Filter<IConvertedStyle> => R.filter<IConvertedStyle>((style => | ||
style.matchesRow(i) && | ||
!style.checksState() && | ||
!style.checksDataRow() && | ||
style.matchesHeaderRow(i) && | ||
style.matchesColumn(column) | ||
)); | ||
|
||
export const matchesDataOpCell = (datum: Datum, i: number): Filter<IConvertedStyle> => R.filter<IConvertedStyle>((style => | ||
!style.checksState() && | ||
!style.checksColumn() && | ||
style.matchesRow(i) && | ||
!style.checksHeaderRow() && | ||
style.matchesDataRow(i) && | ||
style.matchesFilter(datum) | ||
)); | ||
|
||
export const getFilterOpStyles: Filter<IConvertedStyle> = R.filter<IConvertedStyle>((style => | ||
!style.checksState() && | ||
!style.checksDataRow() && | ||
!style.checksHeaderRow() && | ||
!style.checksColumn() | ||
)); | ||
|
||
export const getHeaderOpStyles = (i: number): Filter<IConvertedStyle> => R.filter<IConvertedStyle>((style => | ||
style.matchesRow(i) && | ||
!style.checksColumn() | ||
)); | ||
!style.checksDataRow() && | ||
!style.checksState() && | ||
!style.checksColumn() && | ||
style.matchesHeaderRow(i) | ||
)); |
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.
Whoa, the optional chaining operator
?.
was new to me as well 🤯 🤩https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
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.
Yup. Using all the new things! 😀