Skip to content

Commit

Permalink
DEV inventoryCardContext, helpers, table expandContent adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Aug 23, 2023
1 parent 635e91a commit a1f86e8
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/components/inventoryCard/_inventoryCardContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const useGetInstancesInventory = ({
const session = useAliasSession();
const query = useAliasProductInventoryQuery();
const dispatch = useAliasDispatch();
const { filters, columnCountAndWidths } = useAliasParseInstancesFiltersSettings();
const { columnCountAndWidths, filters, settings } = useAliasParseInstancesFiltersSettings();
const { cancelled, pending, data, ...response } = useAliasSelectorsResponse(
({ inventory }) => inventory?.instancesInventory?.[productId]
);
Expand All @@ -95,11 +95,11 @@ const useGetInstancesInventory = ({
const parsedData = useMemo(() => {
if (response?.fulfilled) {
const updatedData = (data?.length === 1 && data[0]) || data || {};
return inventoryCardHelpers.parseInventoryResponse({ data: updatedData, filters, query, session });
return inventoryCardHelpers.parseInventoryResponse({ data: updatedData, filters, query, session, settings });
}

return undefined;
}, [data, filters, query, response?.fulfilled, session]);
}, [data, filters, query, response?.fulfilled, session, settings]);

return {
...response,
Expand Down
18 changes: 16 additions & 2 deletions src/components/inventoryCard/_inventoryCardHelpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import { translate } from '../i18n/i18n';
import { RHSM_API_QUERY_SET_TYPES, RHSM_API_RESPONSE_META_TYPES } from '../../services/rhsm/rhsmConstants';
import { InventoryGuests } from '../inventoryGuests/inventoryGuests';
import { tableHelpers } from '../table/_table';

/**
Expand Down Expand Up @@ -74,9 +76,10 @@ const normalizeInventorySettings = ({ filters = [], settings = {}, productId } =
* @param {Array} params.filters
* @param {object} params.query
* @param {object} params.session
* @param {object} params.settings
* @returns {{dataSetColumnHeaders: [], resultsPerPage: number, resultsOffset: number, dataSetRows: [], resultsCount: number}}
*/
const parseInventoryResponse = ({ data = {}, filters = [], query = {}, session = {} } = {}) => {
const parseInventoryResponse = ({ data = {}, filters = [], query = {}, session = {}, settings = {} } = {}) => {
const { data: listData = [], meta = {} } = data;
const resultsCount = meta[RHSM_API_RESPONSE_META_TYPES.COUNT];
const {
Expand All @@ -92,6 +95,8 @@ const parseInventoryResponse = ({ data = {}, filters = [], query = {}, session =

listData.forEach(rowData => {
const dataSetRow = [];
let expandedContent;

filters.forEach(({ metric, label, cell, ...rest }) => {
const updatedCell = cell({ ...rowData }, { ...session }, { ...meta });
dataSetRow.push({ metric, ...rest, dataLabel: label, content: updatedCell });
Expand All @@ -100,7 +105,16 @@ const parseInventoryResponse = ({ data = {}, filters = [], query = {}, session =
columnData[metric].push(updatedCell);
});

dataSetRows.push({ cells: dataSetRow });
if (typeof settings?.guestContent === 'function') {
const guestContentResults = settings.guestContent({ ...rowData }, { ...session }, { ...meta });
const { id: guestId, numberOfGuests } = guestContentResults || {};

if (guestId && numberOfGuests) {
expandedContent = <InventoryGuests key={`guests-${guestId}`} id={guestId} numberOfGuests={numberOfGuests} />;
}
}

dataSetRows.push({ cells: dataSetRow, expandedContent });
});

filters.forEach(({ metric, header, ...rest }) => {
Expand Down
31 changes: 16 additions & 15 deletions src/components/table/_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,14 @@ const Table = ({
return (
<CellWrapper key={`${rowKey}-parent-row`} {...cellWrapperProps}>
<Tr className={componentClassNames.tr} key={`${rowKey}-row`}>
{expand && (
{(expand && (
<Td
className={`${componentClassNames.td} ${componentClassNames.tdExpand}`}
key={`${rowKey}-expand-col`}
expand={expand}
/>
)}
)) ||
(updatedIsExpandableRow && <Td className={componentClassNames.td} key="expand-td-cell" />)}
{select && (
<Td
className={`${componentClassNames.td} ${componentClassNames.tdSelect}`}
Expand Down Expand Up @@ -472,19 +473,19 @@ Table.defaultProps = {
className: '',
columnHeaders: [],
componentClassNames: {
table: 'quipucords-table',
td: 'quipucords-table__td',
tdAction: 'quipucords-table__td-action',
tdSelect: 'quipucords-table__td-select',
th: 'quipucords-table__th',
tr: 'quipucords-table__tr',
trExpand: 'quipucords-table__tr-expand',
trExpanded: 'quipucords-table__tr-expand-expanded',
trExpandedContent: 'quipucords-table__tr-expand-content',
tdExpand: 'quipucords-table__td-expand',
tdExpanded: 'quipucords-table__td-expand-expanded',
tdExpandedWrapper: 'quipucords-table__td-expand-wrapper',
tdExpandedContent: 'quipucords-table__td-expand-content'
table: 'curiosity-table',
td: 'curiosity-table__td',
tdAction: 'curiosity-table__td-action',
tdSelect: 'curiosity-table__td-select',
th: 'curiosity-table__th',
tr: 'curiosity-table__tr',
trExpand: 'curiosity-table__tr-expand',
trExpanded: 'curiosity-table__tr-expand-expanded',
trExpandedContent: 'curiosity-table__tr-expand-content',
tdExpand: 'curiosity-table__td-expand',
tdExpanded: 'curiosity-table__td-expand-expanded',
tdExpandedWrapper: 'curiosity-table__td-expand-wrapper',
tdExpandedContent: 'curiosity-table__td-expand-content'
},
isBorders: true,
isHeader: false,
Expand Down
2 changes: 1 addition & 1 deletion src/config/product.openshiftContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const config = {
guestContent: ({
[INVENTORY_TYPES.NUMBER_OF_GUESTS]: numberOfGuests = {},
[INVENTORY_TYPES.INSTANCE_ID]: id
} = {}) => (numberOfGuests > 0 && id) || undefined
} = {}) => (numberOfGuests > 0 && id && { id, numberOfGuests }) || undefined
},
initialSubscriptionsInventoryFilters: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/config/product.openshiftDedicated.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const config = {
guestContent: ({
[INVENTORY_TYPES.NUMBER_OF_GUESTS]: numberOfGuests = {},
[INVENTORY_TYPES.INSTANCE_ID]: id
} = {}) => (numberOfGuests > 0 && id) || undefined
} = {}) => (numberOfGuests > 0 && id && { id, numberOfGuests }) || undefined
},
initialToolbarFilters: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/config/product.openshiftMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const config = {
guestContent: ({
[INVENTORY_TYPES.NUMBER_OF_GUESTS]: numberOfGuests = {},
[INVENTORY_TYPES.INSTANCE_ID]: id
} = {}) => (numberOfGuests > 0 && id) || undefined
} = {}) => (numberOfGuests > 0 && id && { id, numberOfGuests }) || undefined
},
initialToolbarFilters: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/config/product.rhacs.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const config = {
guestContent: ({
[INVENTORY_TYPES.NUMBER_OF_GUESTS]: numberOfGuests = {},
[INVENTORY_TYPES.INSTANCE_ID]: id
} = {}) => (numberOfGuests > 0 && id) || undefined
} = {}) => (numberOfGuests > 0 && id && { id, numberOfGuests }) || undefined
},
initialSubscriptionsInventoryFilters: [
{
Expand Down
5 changes: 1 addition & 4 deletions src/config/product.rhel.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ const config = {
const { inventory: authorized } = session?.authorized || {};

if (!instanceId) {
console.log('>>>> DISPLAY NAME CELL', displayName);
return displayName;
}

Expand All @@ -211,8 +210,6 @@ const config = {
);
}

console.log('>>>> DISPLAY NAME CELL', updatedDisplayName);

return updatedDisplayName;
},
isSort: true
Expand Down Expand Up @@ -266,7 +263,7 @@ const config = {
guestContent: ({
[INVENTORY_TYPES.NUMBER_OF_GUESTS]: numberOfGuests = {},
[INVENTORY_TYPES.INSTANCE_ID]: id
} = {}) => (numberOfGuests > 0 && id) || undefined
} = {}) => (numberOfGuests > 0 && id && { id, numberOfGuests }) || undefined
},
initialSubscriptionsInventoryFilters: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/config/product.rhods.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const config = {
guestContent: ({
[INVENTORY_TYPES.NUMBER_OF_GUESTS]: numberOfGuests = {},
[INVENTORY_TYPES.INSTANCE_ID]: id
} = {}) => (numberOfGuests > 0 && id) || undefined
} = {}) => (numberOfGuests > 0 && id && { id, numberOfGuests }) || undefined
},
initialSubscriptionsInventoryFilters: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/config/product.rosa.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const config = {
guestContent: ({
[INVENTORY_TYPES.NUMBER_OF_GUESTS]: numberOfGuests = {},
[INVENTORY_TYPES.INSTANCE_ID]: id
} = {}) => (numberOfGuests > 0 && id) || undefined
} = {}) => (numberOfGuests > 0 && id && { id, numberOfGuests }) || undefined
},
initialSubscriptionsInventoryFilters: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/config/product.satellite.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const config = {
guestContent: ({
[INVENTORY_TYPES.NUMBER_OF_GUESTS]: numberOfGuests = {},
[INVENTORY_TYPES.INSTANCE_ID]: id
} = {}) => (numberOfGuests > 0 && id) || undefined
} = {}) => (numberOfGuests > 0 && id && { id, numberOfGuests }) || undefined
},
initialToolbarFilters: [
{
Expand Down

0 comments on commit a1f86e8

Please sign in to comment.