-
Notifications
You must be signed in to change notification settings - Fork 16
feat(table): introduce recent active markers #3516
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
@use '../../../style/mixins'; | ||
@use '../../../style/functions'; | ||
|
||
@use '../../../style/theme-color-variables'; | ||
@use '../../../style/color-palette-extended'; | ||
|
||
@mixin table-row-selected-indicator($border-color, $z-index) { | ||
&:before { | ||
$width-of-selected-row-indicator: 0.2rem; | ||
content: ''; | ||
display: inline-block; | ||
box-sizing: border-box; | ||
position: sticky; | ||
z-index: $z-index; | ||
inset: 0 0 auto 0; | ||
border: $width-of-selected-row-indicator solid $border-color; | ||
border-radius: 1rem; | ||
margin-right: -$width-of-selected-row-indicator * 2; | ||
} | ||
} | ||
.interactive-feedback { | ||
// This is a div, injected by us into all rows. | ||
// We use it to visualize interactive feedback. | ||
|
@@ -45,19 +61,10 @@ | |
box-shadow: var(--button-shadow-inset-pressed); | ||
} | ||
|
||
&:before { | ||
$width-of-selected-row-indicator: 0.2rem; | ||
content: ''; | ||
display: inline-block; | ||
box-sizing: border-box; | ||
position: sticky; | ||
z-index: $table--has-interactive-rows--selectable-row--hover + 1; | ||
inset: 0 0 auto 0; | ||
border: $width-of-selected-row-indicator solid | ||
var(--mdc-theme-primary); | ||
border-radius: 1rem; | ||
margin-right: -$width-of-selected-row-indicator * 2; | ||
} | ||
@include table-row-selected-indicator( | ||
var(--mdc-theme-primary), | ||
$table--has-interactive-rows--selectable-row--hover + 1 | ||
); | ||
} | ||
} | ||
} | ||
|
@@ -89,6 +96,12 @@ | |
} | ||
} | ||
} | ||
.recent-active { | ||
@include table-row-selected-indicator( | ||
rgb(var(--contrast-700)), | ||
$table--has-interactive-rows--selectable-row--hover + 1 | ||
); | ||
} | ||
Comment on lines
+99
to
+104
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. 🛠️ Refactor suggestion Scope and z-index of
Example diff: @@ :host(.has-interactive-rows) {
- .recent-active {
+ .tabulator-row.selectable.recent-active {
@include table-row-selected-indicator(
rgb(var(--contrast-700)),
- $table--has-interactive-rows--selectable-row--hover + 1
+ $table--has-interactive-rows--selectable-row--hover
);
} 🤖 Prompt for AI Agents (early access)
|
||
} | ||
|
||
:host(.has-low-density) { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -41,11 +41,7 @@ | |||||||||||||||||||||||||||
* @exampleComponent limel-example-table-layout-low-density | ||||||||||||||||||||||||||||
* @exampleComponent limel-example-table-interactive-rows | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
@Component({ | ||||||||||||||||||||||||||||
tag: 'limel-table', | ||||||||||||||||||||||||||||
styleUrl: 'table.scss', | ||||||||||||||||||||||||||||
shadow: true, | ||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||
@Component({ tag: 'limel-table', styleUrl: 'table.scss', shadow: true }) | ||||||||||||||||||||||||||||
Kiarokh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
export class Table { | ||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Data to be displayed in the table | ||||||||||||||||||||||||||||
|
@@ -103,6 +99,16 @@ | |||||||||||||||||||||||||||
@Prop({ mutable: true }) | ||||||||||||||||||||||||||||
public activeRow: RowData; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Array of rows that have been active | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
private activeRowHistory: Tabulator.RowComponent[] = []; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Maximum number of rows to keep in the active row history | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
private static readonly MAX_ACTIVE_ROW_HISTORY = 2; | ||||||||||||||||||||||||||||
Comment on lines
+103
to
+110
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. 💡 Verification agent 🧩 Analysis chainGood implementation of active row tracking history. The active row history tracking implementation is clean and concise. The static constant for the max history size helps maintain code clarity. Consider using a named constant instead of the magic number 2 to help with code clarity and maintenance: - private static readonly MAX_ACTIVE_ROW_HISTORY = 2;
+ /**
+ * Maximum number of rows to keep in the active row history
+ * Used to track the current and previous active rows
+ */
+ private static readonly MAX_ACTIVE_ROW_HISTORY = 2; Let's verify that this constant is the only place where this limit is referenced: 🏁 Script executed: #!/bin/bash
# Check if the value 2 is hardcoded elsewhere in relation to the active row history
rg -A 1 -B 1 "activeRowHistory" src/components/table/ | grep -E "2|two" Length of output: 165 Enhance constant documentation for clarity We’ve confirmed that • File: src/components/table/table.tsx /**
* Maximum number of rows to keep in the active row history
+ * Used to track both the current active row and its immediate predecessor
*/
- private static readonly MAX_ACTIVE_ROW_HISTORY = 2;
+ private static readonly MAX_ACTIVE_ROW_HISTORY = 2; 📝 Committable suggestion
Suggested change
🧰 Tools🪛 ESLint[error] 110-110: No magic number: 2. (no-magic-numbers) 🤖 Prompt for AI Agents (early access)
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Set to `true` to enable reordering of the columns by dragging them | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
|
@@ -638,10 +644,7 @@ | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const columnSorters = sorters.map(createColumnSorter(this.columns)); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const load = { | ||||||||||||||||||||||||||||
page: currentPage, | ||||||||||||||||||||||||||||
sorters: columnSorters, | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
const load = { page: currentPage, sorters: columnSorters }; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// In order to make limel-table behave more like a controlled component, | ||||||||||||||||||||||||||||
// we always return the existing data from this function, therefore | ||||||||||||||||||||||||||||
|
@@ -705,7 +708,16 @@ | |||||||||||||||||||||||||||
this.activeRow = row.getData(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const clickedRow = this.tabulator.getRow(row.getData().id); | ||||||||||||||||||||||||||||
this.activeRowHistory.push(clickedRow); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// Keep the history array limited to the last two rows | ||||||||||||||||||||||||||||
if (this.activeRowHistory.length > Table.MAX_ACTIVE_ROW_HISTORY) { | ||||||||||||||||||||||||||||
this.activeRowHistory.shift(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
this.activate.emit(this.activeRow); | ||||||||||||||||||||||||||||
this.formatRows(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private getActiveRows: () => Tabulator.RowComponent[] = () => { | ||||||||||||||||||||||||||||
|
@@ -746,6 +758,15 @@ | |||||||||||||||||||||||||||
row.getElement().classList.remove('active'); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const previousActiveRow = | ||||||||||||||||||||||||||||
this.activeRowHistory.length > 1 ? this.activeRowHistory[0] : null; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if (previousActiveRow === row) { | ||||||||||||||||||||||||||||
row.getElement().classList.add('recent-active'); | ||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||
row.getElement().classList.remove('recent-active'); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const interactiveFeedbackElement = row | ||||||||||||||||||||||||||||
.getElement() | ||||||||||||||||||||||||||||
.getElementsByClassName('interactive-feedback'); | ||||||||||||||||||||||||||||
|
@@ -788,10 +809,7 @@ | |||||||||||||||||||||||||||
return {}; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||
movableColumns: true, | ||||||||||||||||||||||||||||
columnMoved: this.handleMoveColumn, | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
return { movableColumns: true, columnMoved: this.handleMoveColumn }; | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private handleMoveColumn = (_, components: Tabulator.ColumnComponent[]) => { | ||||||||||||||||||||||||||||
|
@@ -810,11 +828,7 @@ | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
render() { | ||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||
<Host | ||||||||||||||||||||||||||||
class={{ | ||||||||||||||||||||||||||||
'has-low-density': this.layout === 'lowDensity', | ||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||
<Host class={{ 'has-low-density': this.layout === 'lowDensity' }}> | ||||||||||||||||||||||||||||
Kiarokh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
<div | ||||||||||||||||||||||||||||
id="tabulator-container" | ||||||||||||||||||||||||||||
class={{ | ||||||||||||||||||||||||||||
|
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.
🧹 Nitpick (assertive)
DRY refactor: extract row indicator pseudo-element into a mixin
Great consolidation of the repeated
:before
pseudo-element styling into@mixin table-row-selected-indicator
. As an optional improvement, you could expose the$width-of-selected-row-indicator
as a mixin parameter to make this more flexible for different indicator sizes.🤖 Prompt for AI Agents (early access)