Skip to content

Commit

Permalink
feat(inventoryList): issues/493 product disable guests setting (#510)
Browse files Browse the repository at this point in the history
* inventoryList, hasGuests callback setting
* openshiftView, rhelView, apply basic inventoryList settings
  • Loading branch information
cdcabrera committed Nov 19, 2020
1 parent 7281f0c commit 7c0b23a
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,39 @@ exports[`InventoryList Component should handle expandable guests data: number of
/>
`;

exports[`InventoryList Component should handle expandable guests data: number of guests, id, and NO expandable guests display 1`] = `
<Table
ariaLabel={null}
borders={true}
className="curiosity-inventory-list"
columnHeaders={
Array [
"t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
"t(curiosity-inventory.header, {\\"context\\":\\"dolor\\"})",
"t(curiosity-inventory.header, {\\"context\\":\\"numberOfGuests\\"})",
"t(curiosity-inventory.header, {\\"context\\":\\"subscriptionManagerId\\"})",
]
}
isHeader={true}
rows={
Array [
Object {
"cells": Array [
"sit",
"amet",
2,
"loremipsum",
],
"expandedContent": undefined,
},
]
}
summary={null}
t={[Function]}
variant="compact"
/>
`;

exports[`InventoryList Component should handle updating sorting through redux state: dispatch filter 1`] = `
Array [
Array [
Expand Down Expand Up @@ -183,15 +216,15 @@ exports[`InventoryList Component should handle variations in data: filtered data
"title": "ipsum",
},
],
"expandedContent": false,
"expandedContent": undefined,
},
Object {
"cells": Array [
Object {
"title": "sit",
},
],
"expandedContent": false,
"expandedContent": undefined,
},
]
}
Expand Down Expand Up @@ -287,14 +320,14 @@ exports[`InventoryList Component should handle variations in data: variable data
"ipsum",
"sit",
],
"expandedContent": false,
"expandedContent": undefined,
},
Object {
"cells": Array [
"sit",
"amet",
],
"expandedContent": false,
"expandedContent": undefined,
},
]
}
Expand Down
13 changes: 13 additions & 0 deletions src/components/inventoryList/__tests__/inventoryList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ describe('InventoryList Component', () => {
});

expect(component.find(Table)).toMatchSnapshot('number of guests, and id');

component.setProps({
...props,
listData: [{ lorem: 'sit', dolor: 'amet', numberOfGuests: 2, subscriptionManagerId: 'loremipsum' }],
settings: {
hasGuests: data => {
const { numberOfGuests = 0, subscriptionManagerId = null } = data;
return numberOfGuests > 2 && subscriptionManagerId;
}
}
});

expect(component.find(Table)).toMatchSnapshot('number of guests, id, and NO expandable guests display');
});

it('should handle updating sorting through redux state', () => {
Expand Down
44 changes: 28 additions & 16 deletions src/components/inventoryList/inventoryList.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class InventoryList extends React.Component {
* @returns {Node}
*/
renderTable() {
const { filterGuestsData, filterInventoryData, listData, query, session } = this.props;
const { filterGuestsData, filterInventoryData, listData, query, session, settings } = this.props;
let updatedColumnHeaders = [];

const updatedRows = listData.map(({ ...cellData }) => {
Expand All @@ -113,21 +113,29 @@ class InventoryList extends React.Component {
session
});

const hasGuests = cellData?.numberOfGuests > 0;
const guestsId = cellData?.subscriptionManagerId;
updatedColumnHeaders = columnHeaders;

const guestsId = cellData?.subscriptionManagerId;
let hasGuests = cellData?.numberOfGuests > 0 && guestsId;

// Apply hasGuests callback, return boolean
if (typeof settings?.hasGuests === 'function') {
hasGuests = settings.hasGuests({ ...cellData }, { ...session });
}

return {
cells,
expandedContent: hasGuests && guestsId && (
<GuestsList
key={guestsId}
filterGuestsData={filterGuestsData}
numberOfGuests={cellData?.numberOfGuests}
id={guestsId}
query={query}
/>
)
expandedContent:
(hasGuests && (
<GuestsList
key={guestsId}
filterGuestsData={filterGuestsData}
numberOfGuests={cellData?.numberOfGuests}
id={guestsId}
query={query}
/>
)) ||
undefined
};
});

Expand Down Expand Up @@ -240,7 +248,7 @@ class InventoryList extends React.Component {
/**
* Prop types.
*
* @type {{productId: string, listData: Array, session: object, pending: boolean, query: object,
* @type {{settings: object, productId: string, listData: Array, session: object, pending: boolean, query: object,
* fulfilled: boolean, getHostsInventory: Function, error: boolean, cardTitle: string, itemCount: number,
* viewId: string, filterInventoryData: Array, filterGuestsData: Array, perPageDefault: number,
* isDisabled: boolean}}
Expand Down Expand Up @@ -278,15 +286,18 @@ InventoryList.propTypes = {
perPageDefault: PropTypes.number,
query: PropTypes.object.isRequired,
session: PropTypes.object,
settings: PropTypes.shape({
hasGuests: PropTypes.func
}),
viewId: PropTypes.string
};

/**
* Default props.
*
* @type {{listData: Array, session: object, pending: boolean, fulfilled: boolean, getHostsInventory: Function,
* error: boolean, cardTitle: null, itemCount: number, viewId: string, filterInventoryData: Array,
* filterGuestsData: Array, perPageDefault: number, isDisabled: boolean}}
* @type {{settings: object, listData: Array, session: object, pending: boolean, fulfilled: boolean,
* getHostsInventory: Function, error: boolean, cardTitle: null, itemCount: number, viewId: string,
* filterInventoryData: Array, filterGuestsData: Array, perPageDefault: number, isDisabled: boolean}}
*/
InventoryList.defaultProps = {
cardTitle: null,
Expand All @@ -301,6 +312,7 @@ InventoryList.defaultProps = {
pending: false,
perPageDefault: 10,
session: {},
settings: {},
viewId: 'inventoryList'
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ exports[`OpenshiftView Component should display an alternate graph on query-stri
"uom": "cores",
}
}
settings={Object {}}
viewId="viewOpenShift"
/>
</PageSection>
Expand Down Expand Up @@ -322,6 +323,7 @@ exports[`OpenshiftView Component should have a fallback title: title 1`] = `
"uom": "cores",
}
}
settings={Object {}}
viewId="viewOpenShift"
/>
</PageSection>
Expand Down Expand Up @@ -905,6 +907,7 @@ exports[`OpenshiftView Component should render a non-connected component: non-co
"uom": "cores",
}
}
settings={Object {}}
viewId="viewOpenShift"
/>
</PageSection>
Expand Down
10 changes: 8 additions & 2 deletions src/components/openshiftView/openshiftView.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class OpenshiftView extends React.Component {
const {
initialGuestsFilters,
initialToolbarFilters,
initialInventorySettings,
location,
productLabel,
query,
Expand Down Expand Up @@ -180,6 +181,7 @@ class OpenshiftView extends React.Component {
key={routeDetail.pathParameter}
filterGuestsData={initialGuestsFilters}
filterInventoryData={inventoryFilters}
settings={initialInventorySettings}
query={initialInventoryQuery}
productId={routeDetail.pathParameter}
viewId={viewId}
Expand All @@ -196,7 +198,7 @@ class OpenshiftView extends React.Component {
*
* @type {{productLabel: string, initialOption: string, initialToolbarFilters: Array, viewId: string,
* t: Function, query: object, initialGraphFilters: Array, routeDetail: object, location: object,
* initialGuestsFilters: Array, initialInventoryFilters: Array}}
* initialGuestsFilters: Array, initialInventorySettings: object, initialInventoryFilters: Array}}
*/
OpenshiftView.propTypes = {
query: PropTypes.shape({
Expand All @@ -206,6 +208,9 @@ OpenshiftView.propTypes = {
initialGraphFilters: PropTypes.array,
initialGuestsFilters: PropTypes.array,
initialInventoryFilters: PropTypes.array,
initialInventorySettings: PropTypes.shape({
hasGuests: PropTypes.func
}),
initialToolbarFilters: PropTypes.array,
location: PropTypes.shape({
parsedSearch: PropTypes.objectOf(PropTypes.string)
Expand All @@ -227,7 +232,7 @@ OpenshiftView.propTypes = {
*
* @type {{productLabel: string, initialOption: string, initialToolbarFilters: Array, viewId: string,
* t: translate, query: object, initialGraphFilters: Array, initialGuestsFilters: Array,
* initialInventoryFilters: Array}}
* initialInventorySettings: object, initialInventoryFilters: Array}}
*/
OpenshiftView.defaultProps = {
query: {
Expand Down Expand Up @@ -377,6 +382,7 @@ OpenshiftView.defaultProps = {
cellWidth: 15
}
],
initialInventorySettings: {},
initialToolbarFilters: [
{
id: RHSM_API_QUERY_TYPES.SLA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ exports[`RhelView Component should display an alternate graph on query-string up
"sort": "last_seen",
}
}
settings={Object {}}
viewId="viewRHEL"
/>
</PageSection>
Expand Down Expand Up @@ -292,6 +293,7 @@ exports[`RhelView Component should have a fallback title: title 1`] = `
"sort": "last_seen",
}
}
settings={Object {}}
viewId="viewRHEL"
/>
</PageSection>
Expand Down Expand Up @@ -832,6 +834,7 @@ exports[`RhelView Component should render a non-connected component: non-connect
"sort": "last_seen",
}
}
settings={Object {}}
viewId="viewRHEL"
/>
</PageSection>
Expand Down
11 changes: 9 additions & 2 deletions src/components/rhelView/rhelView.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class RhelView extends React.Component {
initialGraphFilters,
initialGuestsFilters,
initialInventoryFilters,
initialInventorySettings,
initialToolbarFilters,
location,
productLabel,
Expand Down Expand Up @@ -103,6 +104,7 @@ class RhelView extends React.Component {
key={routeDetail.pathParameter}
filterGuestsData={initialGuestsFilters}
filterInventoryData={initialInventoryFilters}
settings={initialInventorySettings}
query={initialInventoryQuery}
productId={routeDetail.pathParameter}
viewId={viewId}
Expand All @@ -119,7 +121,7 @@ class RhelView extends React.Component {
*
* @type {{productLabel: string, initialToolbarFilters: Array, viewId: string, t: Function, query: object,
* initialGraphFilters: Array, routeDetail: object, location: object, initialGuestsFilters: Array,
* initialInventoryFilters: Array}}
* initialInventorySettings: object, initialInventoryFilters: Array}}
*/
RhelView.propTypes = {
query: PropTypes.shape({
Expand All @@ -128,6 +130,9 @@ RhelView.propTypes = {
initialGraphFilters: PropTypes.array,
initialGuestsFilters: PropTypes.array,
initialInventoryFilters: PropTypes.array,
initialInventorySettings: PropTypes.shape({
hasGuests: PropTypes.func
}),
initialToolbarFilters: PropTypes.array,
location: PropTypes.shape({
parsedSearch: PropTypes.objectOf(PropTypes.string)
Expand All @@ -148,7 +153,8 @@ RhelView.propTypes = {
* Default props.
*
* @type {{productLabel: string, initialToolbarFilters: Array, viewId: string, t: translate, query: object,
* initialGraphFilters: Array, initialGuestsFilters: Array, initialInventoryFilters: Array}}
* initialGraphFilters: Array, initialGuestsFilters: Array, initialInventorySettings: object,
* initialInventoryFilters: Array}}
*/
RhelView.defaultProps = {
query: {
Expand Down Expand Up @@ -291,6 +297,7 @@ RhelView.defaultProps = {
cellWidth: 15
}
],
initialInventorySettings: {},
initialToolbarFilters: [
{
id: RHSM_API_QUERY_TYPES.SLA
Expand Down

0 comments on commit 7c0b23a

Please sign in to comment.