Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions src/components/table/partial-styles/tabulator-custom-styles.scss
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;
}
}
Comment on lines +6 to +19
Copy link

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)
In src/components/table/partial-styles/tabulator-custom-styles.scss between
lines 6 and 19, the mixin table-row-selected-indicator currently uses a fixed
width for the selected row indicator. To improve flexibility, add a new
parameter to the mixin for the width of the selected row indicator, replacing
the hardcoded value. Update all references inside the mixin to use this
parameter instead of the fixed 0.2rem value.

.interactive-feedback {
// This is a div, injected by us into all rows.
// We use it to visualize interactive feedback.
Expand Down Expand Up @@ -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
);
}
}
}
Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Scope and z-index of .recent-active should differ from the active indicator
The new .recent-active class currently sits at the same specificity and z-index as .active. To avoid stacking conflicts and unintended styling on non-row elements, consider:

  1. Nesting the selector under .tabulator-row.selectable (e.g. .tabulator-row.selectable.recent-active)
  2. Using a slightly lower z-index (for example, $table--has-interactive-rows--selectable-row--hover) so the recent marker appears behind the current one

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)
In src/components/table/partial-styles/tabulator-custom-styles.scss around lines
99 to 104, the .recent-active class has the same scope and z-index as the
.active indicator, causing stacking conflicts. To fix this, nest the
.recent-active selector under .tabulator-row.selectable (e.g.,
.tabulator-row.selectable.recent-active) to increase specificity, and adjust its
z-index to be slightly lower, such as using
$table--has-interactive-rows--selectable-row--hover, so the recent-active marker
appears behind the active indicator.

}

:host(.has-low-density) {
Expand Down
50 changes: 32 additions & 18 deletions src/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
export class Table {
/**
* Data to be displayed in the table
Expand Down Expand Up @@ -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;

Check failure on line 110 in src/components/table/table.tsx

View workflow job for this annotation

GitHub Actions / Lint

No magic number: 2
Comment on lines +103 to +110
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Good 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 MAX_ACTIVE_ROW_HISTORY is the sole reference controlling the “last two” rows, and no other hard-coded 2 appears in the active‐row logic. To improve maintainability, let’s expand its JSDoc to explain why two rows are tracked:

• File: src/components/table/table.tsx
• Location: around line 110

     /**
      * 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* 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;
/**
* 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;
🧰 Tools
🪛 ESLint

[error] 110-110: No magic number: 2.

(no-magic-numbers)

🤖 Prompt for AI Agents (early access)
In src/components/table/table.tsx around lines 103 to 110, enhance the JSDoc
comment for the MAX_ACTIVE_ROW_HISTORY constant by adding an explanation of why
the value 2 is used, clarifying that it represents tracking the last two active
rows for specific functional reasons. This improves code clarity and
maintainability by documenting the rationale behind the chosen limit.


/**
* Set to `true` to enable reordering of the columns by dragging them
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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[] = () => {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -788,10 +809,7 @@
return {};
}

return {
movableColumns: true,
columnMoved: this.handleMoveColumn,
};
return { movableColumns: true, columnMoved: this.handleMoveColumn };
};

private handleMoveColumn = (_, components: Tabulator.ColumnComponent[]) => {
Expand All @@ -810,11 +828,7 @@

render() {
return (
<Host
class={{
'has-low-density': this.layout === 'lowDensity',
}}
>
<Host class={{ 'has-low-density': this.layout === 'lowDensity' }}>
<div
id="tabulator-container"
class={{
Expand Down
Loading