Skip to content

Commit

Permalink
fix(editor): Ensure Datatable component renders All option
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Aug 23, 2024
1 parent 8403f4a commit 7d47e07
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/design-system/src/components/N8nDatatable/Datatable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
:label="`${size}`"
:value="size"
/>
<N8nOption :label="`All`" value="*"> </N8nOption>
<N8nOption :label="`All`" :value="ALL_ROWS"> </N8nOption>
</N8nSelect>
</div>
</div>
Expand All @@ -69,6 +69,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[];
Expand Down Expand Up @@ -103,6 +105,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;
Expand All @@ -121,6 +125,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
});
});
});

0 comments on commit 7d47e07

Please sign in to comment.