mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
fix(editor): Ensure Datatable
component renders All
option (#10525)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
This commit is contained in:
parent
f71281221e
commit
bc27beb662
|
@ -7,6 +7,8 @@ import type { DatatableColumn, DatatableRow, DatatableRowDataType } from '../../
|
|||
import { useI18n } from '../../composables/useI18n';
|
||||
import { getValueByPath } from '../../utils';
|
||||
|
||||
const ALL_ROWS = -1;
|
||||
|
||||
interface DatatableProps {
|
||||
columns: DatatableColumn[];
|
||||
rows: DatatableRow[];
|
||||
|
@ -41,6 +43,8 @@ const totalRows = computed(() => {
|
|||
});
|
||||
|
||||
const visibleRows = computed(() => {
|
||||
if (props.rowsPerPage === ALL_ROWS) return props.rows;
|
||||
|
||||
const start = (props.currentPage - 1) * props.rowsPerPage;
|
||||
const end = start + props.rowsPerPage;
|
||||
|
||||
|
@ -59,6 +63,11 @@ function onUpdateCurrentPage(value: number) {
|
|||
function onRowsPerPageChange(value: number) {
|
||||
emit('update:rowsPerPage', value);
|
||||
|
||||
if (value === ALL_ROWS) {
|
||||
onUpdateCurrentPage(1);
|
||||
return;
|
||||
}
|
||||
|
||||
const maxPage = Math.ceil(totalRows.value / value);
|
||||
if (maxPage < props.currentPage) {
|
||||
onUpdateCurrentPage(maxPage);
|
||||
|
@ -131,7 +140,7 @@ function getThStyle(column: DatatableColumn) {
|
|||
:label="`${size}`"
|
||||
:value="size"
|
||||
/>
|
||||
<N8nOption :label="`All`" value="*"> </N8nOption>
|
||||
<N8nOption :label="`All`" :value="ALL_ROWS"> </N8nOption>
|
||||
</N8nSelect>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -75,5 +75,26 @@ describe('components', () => {
|
|||
);
|
||||
expect(wrapper.container.querySelector('tbody td')?.textContent).toEqual('Row slot');
|
||||
});
|
||||
|
||||
it('should render all rows when rowsPerPage is set to -1', () => {
|
||||
const wrapper = render(N8nDatatable, {
|
||||
props: { columns, rows, rowsPerPage: -1 },
|
||||
global: { stubs },
|
||||
});
|
||||
|
||||
const pagination = wrapper.container.querySelector('.pagination');
|
||||
expect(pagination?.querySelector('.el-pager')).toBeNull();
|
||||
|
||||
const pageSizeSelector = wrapper.container.querySelector('.pageSizeSelector');
|
||||
expect(pageSizeSelector?.textContent).toContain('Page size');
|
||||
|
||||
const allOption = wrapper.getByText('All');
|
||||
expect(allOption).not.toBeNull();
|
||||
|
||||
expect(wrapper.container.querySelectorAll('tbody tr').length).toEqual(rows.length);
|
||||
expect(wrapper.container.querySelectorAll('tbody tr td').length).toEqual(
|
||||
columns.length * rows.length,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue