Skip to content

Commit

Permalink
feat(inventoryList,guestsList): issues/494 fixed column widths
Browse files Browse the repository at this point in the history
* inventoryList, guestsList, proptype expanded, loader colWidth
* inventoryListHelpers, apply filter column widths
* loader, pass colWidth
* openshiftView, rhelView, inventory fixed column widths
* table, check for valid cell contents, proptypes
* tableSkeleton, allow fixed column widths
* styling, fix guestsList padding
  • Loading branch information
cdcabrera committed Nov 5, 2020
1 parent c670525 commit 184f298
Show file tree
Hide file tree
Showing 16 changed files with 531 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`GuestsList Component should handle multiple display states: fulfilled 1
<Table
ariaLabel={null}
borders={false}
className="curiosity-inventory-list"
className="curiosity-guests-list"
columnHeaders={
Array [
"t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
Expand Down Expand Up @@ -60,6 +60,7 @@ exports[`GuestsList Component should handle multiple display states: initial pen
Object {
"borders": false,
"colCount": 1,
"colWidth": Array [],
"rowCount": 1,
"variant": "compact",
}
Expand Down Expand Up @@ -154,23 +155,30 @@ exports[`GuestsList Component should handle variations in data: filtered data 1`
<Table
ariaLabel={null}
borders={false}
className="curiosity-inventory-list"
className="curiosity-guests-list"
columnHeaders={
Array [
"t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
Object {
"title": "t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
"transforms": Array [],
},
]
}
isHeader={true}
rows={
Array [
Object {
"cells": Array [
"ipsum",
Object {
"title": "ipsum",
},
],
},
Object {
"cells": Array [
"amet",
Object {
"title": "amet",
},
],
},
]
Expand Down Expand Up @@ -203,7 +211,7 @@ exports[`GuestsList Component should handle variations in data: variable data 1`
<Table
ariaLabel={null}
borders={false}
className="curiosity-inventory-list"
className="curiosity-guests-list"
columnHeaders={
Array [
"t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
Expand Down
11 changes: 6 additions & 5 deletions src/components/guestsList/guestsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class GuestsList extends React.Component {
<Table
borders={false}
variant={TableVariant.compact}
className="curiosity-inventory-list"
className="curiosity-guests-list"
columnHeaders={updatedColumnHeaders}
rows={updatedRows}
/>
Expand Down Expand Up @@ -176,6 +176,7 @@ class GuestsList extends React.Component {
tableProps={{
borders: false,
colCount: filterGuestsData?.length || (listData?.[0] && Object.keys(listData[0]).length) || 1,
colWidth: (filterGuestsData?.length && filterGuestsData.map(({ cellWidth }) => cellWidth)) || [],
rowCount: numberOfGuests < perPageDefault ? numberOfGuests : perPageDefault,
variant: TableVariant.compact
}}
Expand All @@ -201,17 +202,17 @@ GuestsList.propTypes = {
id: PropTypes.string,
header: PropTypes.oneOfType([
PropTypes.shape({
title: PropTypes.string
title: PropTypes.node.isRequired
}),
PropTypes.func,
PropTypes.string
PropTypes.node
]),
cell: PropTypes.oneOfType([
PropTypes.shape({
title: PropTypes.string
title: PropTypes.node.isRequired
}),
PropTypes.func,
PropTypes.string
PropTypes.node
])
}).isRequired
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,28 @@ exports[`InventoryList Component should handle variations in data: filtered data
className="curiosity-inventory-list"
columnHeaders={
Array [
"t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
Object {
"title": "t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
"transforms": Array [],
},
]
}
isHeader={true}
rows={
Array [
Object {
"cells": Array [
"ipsum",
Object {
"title": "ipsum",
},
],
"expandedContent": false,
},
Object {
"cells": Array [
"sit",
Object {
"title": "sit",
},
],
"expandedContent": false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ Object {
exports[`InventoryListHelpers parseRowCellsListData should parse and return formatted/filtered table cells.: custom callback data 1`] = `
Object {
"cells": Array [
"ipsum/sit",
Object {
"title": "ipsum/sit",
},
],
"columnHeaders": Array [
"t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})/t(curiosity-inventory.header, {\\"context\\":\\"dolor\\"})",
Object {
"title": "t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})/t(curiosity-inventory.header, {\\"context\\":\\"dolor\\"})",
"transforms": Array [],
},
],
"data": Object {
"dolor": Object {
Expand All @@ -116,7 +121,10 @@ Object {
},
],
"columnHeaders": Array [
"t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
Object {
"title": "t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
"transforms": Array [],
},
],
"data": Object {
"dolor": Object {
Expand All @@ -134,14 +142,17 @@ Object {
exports[`InventoryListHelpers parseRowCellsListData should parse and return formatted/filtered table cells.: custom header data 1`] = `
Object {
"cells": Array [
"ipsum",
Object {
"title": "ipsum",
},
],
"columnHeaders": Array [
Object {
"props": Object {
"textCenter": true,
},
"title": "object, header, lorem",
"transforms": Array [],
},
],
"data": Object {
Expand All @@ -160,10 +171,15 @@ Object {
exports[`InventoryListHelpers parseRowCellsListData should parse and return formatted/filtered table cells.: filtered data 1`] = `
Object {
"cells": Array [
"ipsum",
Object {
"title": "ipsum",
},
],
"columnHeaders": Array [
"t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
Object {
"title": "t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
"transforms": Array [],
},
],
"data": Object {
"dolor": Object {
Expand Down
10 changes: 6 additions & 4 deletions src/components/inventoryList/inventoryList.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ class InventoryList extends React.Component {
tableProps={{
className: 'curiosity-inventory-list',
colCount: filterInventoryData?.length || (listData?.[0] && Object.keys(listData[0]).length) || 1,
colWidth:
(filterInventoryData?.length && filterInventoryData.map(({ cellWidth }) => cellWidth)) || [],
rowCount: listData?.length || updatedPerPage,
variant: TableVariant.compact
}}
Expand Down Expand Up @@ -242,17 +244,17 @@ InventoryList.propTypes = {
id: PropTypes.string,
header: PropTypes.oneOfType([
PropTypes.shape({
title: PropTypes.string
title: PropTypes.node.isRequired
}),
PropTypes.func,
PropTypes.string
PropTypes.node
]),
cell: PropTypes.oneOfType([
PropTypes.shape({
title: PropTypes.string
title: PropTypes.node.isRequired
}),
PropTypes.func,
PropTypes.string
PropTypes.node
])
}).isRequired
),
Expand Down
43 changes: 33 additions & 10 deletions src/components/inventoryList/inventoryListHelpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SortByDirection } from '@patternfly/react-table';
import { cellWidth as PfCellWidth, SortByDirection } from '@patternfly/react-table';
import _camelCase from 'lodash/camelCase';
import { translate } from '../i18n/i18n';
import {
Expand Down Expand Up @@ -70,7 +70,7 @@ const parseInventoryFilters = ({ filters = [], onSort, query = {} }) =>
});

/**
* Parse and return formatted/filtered table cells.
* Parse and return formatted/filtered table cells, and apply table filters.
*
* @param {object} params
* @param {Array} params.filters
Expand All @@ -83,7 +83,7 @@ const parseRowCellsListData = ({ filters = [], cellData = {}, session = {} }) =>
const updatedCells = [];
const allCells = {};

// Apply translation and value, "pre" filters/callbacks
// Apply basic translation and value
Object.entries(cellData).forEach(([key, value]) => {
allCells[key] = {
title: translate('curiosity-inventory.header', { context: key }),
Expand All @@ -94,38 +94,61 @@ const parseRowCellsListData = ({ filters = [], cellData = {}, session = {} }) =>
updatedCells.push(value);
});

// Apply header and cell values, apply filters/callbacks
// Apply filters to header and cell values
if (filters?.length) {
updatedColumnHeaders.length = 0;
updatedCells.length = 0;

filters.forEach(({ id, cell, header, onSort, sortActive, sortDirection }) => {
filters.forEach(({ id, cell, cellWidth, header, onSort, sortActive, sortDirection, transforms }) => {
let headerUpdated;
let cellUpdated;

if (allCells[id]) {
headerUpdated = allCells[id].title;
cellUpdated = allCells[id].value;
headerUpdated = allCells[id]?.title ?? id;
cellUpdated = allCells[id]?.value ?? '';
}

// set table header cell filter params
if (header) {
headerUpdated = (typeof header === 'function' && header({ ...allCells })) || header;
}

if (typeof headerUpdated === 'string') {
headerUpdated = {
title: headerUpdated
};
}

headerUpdated.transforms = [];

if (Array.isArray(transforms)) {
headerUpdated.transforms = headerUpdated.transforms.concat([...transforms]);
}

if (typeof cellWidth === 'number') {
headerUpdated.transforms.push(PfCellWidth(cellWidth));
}

if (typeof onSort === 'function') {
headerUpdated = {
...(typeof headerUpdated !== 'string' && headerUpdated),
...headerUpdated,
onSort: obj => onSort({ ...allCells }, { ...obj, id }),
sortActive,
sortDirection,
title: allCells[id].title
sortDirection
};
}

// set table row cell filter params
if (cell) {
cellUpdated = (typeof cell === 'function' && cell({ ...allCells }, { ...session })) || cell;
}

if (typeof cellUpdated === 'string') {
cellUpdated = {
title: cellUpdated
};
}

updatedColumnHeaders.push(headerUpdated);
updatedCells.push(cellUpdated);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ exports[`Loader Component should handle variant loader components: variant: tabl
borders={true}
className={null}
colCount={1}
colWidth={Array []}
isHeader={true}
rowCount={5}
t={[Function]}
Expand Down
1 change: 1 addition & 0 deletions src/components/loader/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Loader.propTypes = {
borders: PropTypes.bool,
className: PropTypes.string,
colCount: PropTypes.number,
colWidth: PropTypes.array,
rowCount: PropTypes.number,
variant: PropTypes.oneOf([...Object.values(TableVariant)])
}),
Expand Down
Loading

0 comments on commit 184f298

Please sign in to comment.