Skip to content

Commit

Permalink
Merge pull request #19 from fhlavac/tree
Browse files Browse the repository at this point in the history
Support Tree Table in DataView
  • Loading branch information
fhlavac authored Sep 11, 2024
2 parents d8900b3 + a7db24b commit 8c14e4c
Show file tree
Hide file tree
Showing 32 changed files with 3,258 additions and 195 deletions.
22 changes: 11 additions & 11 deletions cypress/component/DataView.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const PAGINATION = {
}

const repositories: Repository[] = [
{ name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
{ name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
{ name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
{ name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
{ name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
{ name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
];
const rows = repositories.map(item => Object.values(item));

Expand Down Expand Up @@ -69,11 +69,11 @@ describe('DataView', () => {
cy.get('[data-ouia-component-id="data-th-3"]').contains('Workspaces');
cy.get('[data-ouia-component-id="data-th-4"]').contains('Last commit');

cy.get('[data-ouia-component-id="data-td-0-0"]').contains('one');
cy.get('[data-ouia-component-id="data-td-2-1"]').contains('two - 3');
cy.get('[data-ouia-component-id="data-td-3-2"]').contains('null');
cy.get('[data-ouia-component-id="data-td-4-3"]').contains('four - 5');
cy.get('[data-ouia-component-id="data-td-5-4"]').contains('five - 6');
cy.get('[data-ouia-component-id="data-td-0-0"]').contains('Repository one');
cy.get('[data-ouia-component-id="data-td-2-1"]').contains('Branch three');
cy.get('[data-ouia-component-id="data-td-3-2"]').contains('Pull request four');
cy.get('[data-ouia-component-id="data-td-4-3"]').contains('Workspace five');
cy.get('[data-ouia-component-id="data-td-5-4"]').contains('Timestamp six');

cy.get('[data-ouia-component-id="DataViewFooter-pagination"]').should('exist');
});
Expand Down
103 changes: 90 additions & 13 deletions cypress/component/DataViewTable.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,67 @@
import React from 'react';
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
import { DataViewTable, DataViewTrTree } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';

interface Repository {
name: string;
branches: string | null;
prs: string | null;
workspaces: string;
lastCommit: string;
children?: Repository[];
}

const repositories: Repository[] = [
{ name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
{ name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
{ name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
{ name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
{ name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
{ name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
];
const rows = repositories.map(item => Object.values(item));

const repositoriesTree: Repository[] = [
{
name: 'Repository one',
branches: 'Branch one',
prs: 'Pull request one',
workspaces: 'Workspace one',
lastCommit: 'Timestamp one',
children: [
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
]
},
{
name: 'Repository four',
branches: 'Branch four',
prs: 'Pull request four',
workspaces: 'Workspace four',
lastCommit: 'Timestamp four',
children: [ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' } ]
},
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
];



const buildRows = (repositories: Repository[]): DataViewTrTree[] => repositories.map((repo) => ({
row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
id: repo.name, // unique ID for each row
...(repo.children
? {
children: buildRows(repo.children) // build rows for children
}
: {})
}));

const treeRows = buildRows(repositoriesTree);

const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];

describe('DataViewTable', () => {

it('renders the data view table', () => {
it('renders a basic data view table', () => {
const ouiaId = 'data';

cy.mount(
Expand All @@ -36,10 +74,49 @@ describe('DataViewTable', () => {
cy.get('[data-ouia-component-id="data-th-3"]').contains('Workspaces');
cy.get('[data-ouia-component-id="data-th-4"]').contains('Last commit');

cy.get('[data-ouia-component-id="data-td-0-0"]').contains('one');
cy.get('[data-ouia-component-id="data-td-2-1"]').contains('two - 3');
cy.get('[data-ouia-component-id="data-td-3-2"]').contains('null');
cy.get('[data-ouia-component-id="data-td-4-3"]').contains('four - 5');
cy.get('[data-ouia-component-id="data-td-5-4"]').contains('five - 6');
cy.get('[data-ouia-component-id="data-td-0-0"]').contains('Repository one');
cy.get('[data-ouia-component-id="data-td-2-1"]').contains('Branch three');
cy.get('[data-ouia-component-id="data-td-3-2"]').contains('Pull request four');
cy.get('[data-ouia-component-id="data-td-4-3"]').contains('Workspace five');
cy.get('[data-ouia-component-id="data-td-5-4"]').contains('Timestamp six');
});

it('renders a tree data view table', () => {
const ouiaId = 'tree';

cy.mount(
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={treeRows} />
);

cy.get('[data-ouia-component-id="tree-td-0-0"]')
.should('exist')
.find('button')
.should('have.length', 2);

cy.get('[data-ouia-component-id="tree-td-3-0"]')
.should('exist')
.find('button')
.should('have.length', 2);

cy.get('[data-ouia-component-id="tree-td-5-0"]')
.should('exist')
.find('button')
.should('have.length', 1);

cy.get('[data-ouia-component-id="tree-th-0"]').contains('Repositories');
cy.get('[data-ouia-component-id="tree-th-1"]').contains('Branches');
cy.get('[data-ouia-component-id="tree-th-2"]').contains('Pull requests');
cy.get('[data-ouia-component-id="tree-th-3"]').contains('Workspaces');
cy.get('[data-ouia-component-id="tree-th-4"]').contains('Last commit');

cy.get('[data-ouia-component-id="tree-td-0-0"]').contains('Repository one');
cy.get('[data-ouia-component-id="tree-td-0-0"]').should('be.visible');
cy.get('[data-ouia-component-id="tree-td-2-1"]').contains('Branch three');
cy.get('[data-ouia-component-id="tree-td-2-1"]').should('not.be.visible');
cy.get('[data-ouia-component-id="tree-td-3-2"]').contains('Pull request four');
cy.get('[data-ouia-component-id="tree-td-4-3"]').contains('Workspace five');
cy.get('[data-ouia-component-id="tree-td-4-3"]').should('not.be.visible');
cy.get('[data-ouia-component-id="tree-td-5-4"]').contains('Timestamp six');
cy.get('[data-ouia-component-id="tree-td-5-4"]').should('not.be.visible');
});
});
46 changes: 46 additions & 0 deletions cypress/component/DataViewTableBasic.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import DataViewTableBasic from '@patternfly/react-data-view/dist/esm/DataViewTableBasic';

interface Repository {
name: string;
branches: string | null;
prs: string | null;
workspaces: string;
lastCommit: string;
children?: Repository[];
}

const repositories: Repository[] = [
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
];
const rows = repositories.map(item => Object.values(item));

const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];

describe('DataViewTableBasic', () => {

it('renders a basic data view table', () => {
const ouiaId = 'data';

cy.mount(
<DataViewTableBasic aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
);

cy.get('[data-ouia-component-id="data-th-0"]').contains('Repositories');
cy.get('[data-ouia-component-id="data-th-1"]').contains('Branches');
cy.get('[data-ouia-component-id="data-th-2"]').contains('Pull requests');
cy.get('[data-ouia-component-id="data-th-3"]').contains('Workspaces');
cy.get('[data-ouia-component-id="data-th-4"]').contains('Last commit');

cy.get('[data-ouia-component-id="data-td-0-0"]').contains('Repository one');
cy.get('[data-ouia-component-id="data-td-2-1"]').contains('Branch three');
cy.get('[data-ouia-component-id="data-td-3-2"]').contains('Pull request four');
cy.get('[data-ouia-component-id="data-td-4-3"]').contains('Workspace five');
cy.get('[data-ouia-component-id="data-td-5-4"]').contains('Timestamp six');
});
});
21 changes: 21 additions & 0 deletions cypress/component/DataViewTableHeader.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { DataViewTableHeader } from '@patternfly/react-data-view/dist/dynamic/DataViewTableHeader';

const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];

describe('DataViewTableHeader', () => {

it('renders a data view table header', () => {
const ouiaId = 'data';

cy.mount(
<DataViewTableHeader ouiaId={ouiaId} columns={columns} />
);

cy.get('[data-ouia-component-id="data-th-0"]').contains('Repositories');
cy.get('[data-ouia-component-id="data-th-1"]').contains('Branches');
cy.get('[data-ouia-component-id="data-th-2"]').contains('Pull requests');
cy.get('[data-ouia-component-id="data-th-3"]').contains('Workspaces');
cy.get('[data-ouia-component-id="data-th-4"]').contains('Last commit');
});
});
128 changes: 128 additions & 0 deletions cypress/component/DataViewTableTree.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React from 'react';
import { DataViewTable, DataViewTrTree } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';

interface Repository {
name: string;
branches: string | null;
prs: string | null;
workspaces: string;
lastCommit: string;
children?: Repository[];
}

const repositoriesTree: Repository[] = [
{
name: 'Repository one',
branches: 'Branch one',
prs: 'Pull request one',
workspaces: 'Workspace one',
lastCommit: 'Timestamp one',
children: [
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
]
},
{
name: 'Repository four',
branches: 'Branch four',
prs: 'Pull request four',
workspaces: 'Workspace four',
lastCommit: 'Timestamp four',
children: [ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' } ]
},
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
];

const buildRows = (repositories: Repository[]): DataViewTrTree[] => repositories.map((repo) => ({
row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
id: repo.name, // unique ID for each row
...(repo.children
? {
children: buildRows(repo.children) // build rows for children
}
: {})
}));

const treeRows = buildRows(repositoriesTree);

const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];

describe('DataViewTableTree', () => {

it('renders a tree data view table', () => {
const ouiaId = 'tree';

cy.mount(
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={treeRows} />
);

cy.get('[data-ouia-component-id="tree-td-0-0"]')
.should('exist')
.find('button')
.should('have.length', 2);

cy.get('[data-ouia-component-id="tree-td-3-0"]')
.should('exist')
.find('button')
.should('have.length', 2);

cy.get('[data-ouia-component-id="tree-td-5-0"]')
.should('exist')
.find('button')
.should('have.length', 1);

cy.get('[data-ouia-component-id="tree-th-0"]').contains('Repositories');
cy.get('[data-ouia-component-id="tree-th-1"]').contains('Branches');
cy.get('[data-ouia-component-id="tree-th-2"]').contains('Pull requests');
cy.get('[data-ouia-component-id="tree-th-3"]').contains('Workspaces');
cy.get('[data-ouia-component-id="tree-th-4"]').contains('Last commit');

cy.get('[data-ouia-component-id="tree-td-0-0"]').contains('Repository one');
cy.get('[data-ouia-component-id="tree-td-0-0"]').should('be.visible');
cy.get('[data-ouia-component-id="tree-td-1-0"]').contains('Repository two');
cy.get('[data-ouia-component-id="tree-td-1-0"]').should('not.be.visible');
cy.get('[data-ouia-component-id="tree-td-2-0"]').contains('Repository three');
cy.get('[data-ouia-component-id="tree-td-2-0"]').should('not.be.visible');
cy.get('[data-ouia-component-id="tree-td-3-0"]').contains('Repository four');
cy.get('[data-ouia-component-id="tree-td-3-0"]').should('be.visible');
cy.get('[data-ouia-component-id="tree-td-4-0"]').contains('Repository five');
cy.get('[data-ouia-component-id="tree-td-4-0"]').should('not.be.visible');
cy.get('[data-ouia-component-id="tree-td-5-0"]').contains('Repository six');
cy.get('[data-ouia-component-id="tree-td-5-0"]').should('be.visible');

// try open and close tree nodes
cy.get('[data-ouia-component-id="tree-td-0-0"]')
.should('exist')
.find('button')
.first()
.click()

cy.get('[data-ouia-component-id="tree-td-1-0"]').should('be.visible');
cy.get('[data-ouia-component-id="tree-td-2-0"]').should('be.visible');

cy.get('[data-ouia-component-id="tree-td-0-0"]')
.should('exist')
.find('button')
.first()
.click()

cy.get('[data-ouia-component-id="tree-td-1-0"]').should('not.be.visible');
cy.get('[data-ouia-component-id="tree-td-2-0"]').should('not.be.visible');

cy.get('[data-ouia-component-id="tree-td-3-0"]')
.should('exist')
.find('button')
.first()
.click()

cy.get('[data-ouia-component-id="tree-td-4-0"]').should('be.visible');

cy.get('[data-ouia-component-id="tree-td-3-0"]')
.should('exist')
.find('button')
.first()
.click()

cy.get('[data-ouia-component-id="tree-td-4-0"]').should('not.be.visible');
});
});
Loading

0 comments on commit 8c14e4c

Please sign in to comment.