Skip to content
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

[ENH] Implemented styling for table rows of annot-single-tool component #655

Merged
merged 3 commits into from
Dec 15, 2023
Merged
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
44 changes: 41 additions & 3 deletions components/annot-single-tool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<div>
<b-table
striped
:data-cy="('tool-annotation-for-' + name)"
:fields="toolFields"
:items="uniqueColumnValues">
:items="uniqueColumnValues"
:tbody-tr-class="styleTableRow">
<template #cell(missing_value)="row">
<b-button
:data-cy="'missingValueButton_' + row.index"
Expand Down Expand Up @@ -52,8 +52,46 @@
methods: {
emitMissingValue(column, value) {
this.$emit("declareMissing", {column, value});
},
styleTableRow(row) {
const styleClass = [];
const columns = this.uniqueColumnValues.map(item => item.column);
const uniqueColumns = [...new Set(columns)];
const colIndex = uniqueColumns.indexOf(row.column);
// Apply special styling if we are in a row that belongs to an even column
if (colIndex % 2 === 0) {
// Apply "stripe" styling if we are in an even row
if (this.uniqueColumnValues.indexOf(row) % 2 === 0) {
styleClass.push('column1-color1');
}
else {
styleClass.push('column1-color2');
}
} else {
if (this.uniqueColumnValues.indexOf(row) % 2 === 0) {
styleClass.push('column2-color1');
}
else {
styleClass.push('column2-color2');
}
}
return styleClass;
}
}
};

</script>
</script>
<style>
.column1-color1 {
background-color: #f9f9f9;
}
.column1-color2 {
background-color: #e9ecef;
}
.column2-color1 {
background-color: #abdde5;
}
.column2-color2 {
background-color: #aed2d7;
}
</style>
23 changes: 23 additions & 0 deletions cypress/component/annot-tool-single.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,28 @@ describe("Annotation tool component", () => {
});

});
it("Displays rows in the table with the correct background color", () => {
cy.mount(annotSingleTool, {
propsData: props
});
cy.get('table')
.find('tr')
.eq(1)
.then(row => {
cy.wrap(row).should('have.class', 'column1-color1');
});
cy.get('table')
.find('tr')
.eq(2)
.then(row => {
cy.wrap(row).should('have.class', 'column2-color2');
});
cy.get('table')
.find('tr')
.eq(3)
.then(row => {
cy.wrap(row).should('have.class', 'column2-color1');
});
});

});
Loading