Skip to content

Commit

Permalink
fix(inventoryCard): sw-703 reset columns, rows
Browse files Browse the repository at this point in the history
* inventoryCard, allow empty cols, rows
* inventoryCardContext, SubsContext, consistent response
  • Loading branch information
cdcabrera committed Nov 28, 2022
1 parent 973b4bd commit 89b0f4d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,29 @@ exports[`InventoryCardContext should handle a store response with useGetHostsInv
],
"error": false,
"fulfilled": true,
"message": null,
"pending": false,
"responses": {
"id": {},
"list": [
{
"data": [
{
"data": [
{
"lorem": "ipsum",
},
{
"dolor": "sit",
},
],
"meta": {},
},
],
"fulfilled": true,
},
],
},
}
`;

Expand All @@ -53,7 +75,29 @@ exports[`InventoryCardContext should handle a store response with useGetInstance
],
"error": false,
"fulfilled": true,
"message": null,
"pending": false,
"responses": {
"id": {},
"list": [
{
"data": [
{
"data": [
{
"lorem": "ipsum",
},
{
"dolor": "sit",
},
],
"meta": {},
},
],
"fulfilled": true,
},
],
},
}
`;

Expand Down Expand Up @@ -145,17 +189,13 @@ exports[`InventoryCardContext should handle an onPage event: onPage event, dispa
exports[`InventoryCardContext should handle variations in hosts inventory API responses: inventory, cancelled 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": undefined,
"pending": true,
}
`;

exports[`InventoryCardContext should handle variations in hosts inventory API responses: inventory, disabled 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": undefined,
"pending": false,
}
`;
Expand All @@ -164,15 +204,13 @@ exports[`InventoryCardContext should handle variations in hosts inventory API re
{
"data": {},
"error": true,
"fulfilled": undefined,
"pending": false,
}
`;

exports[`InventoryCardContext should handle variations in hosts inventory API responses: inventory, fulfilled 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": true,
"pending": false,
}
Expand All @@ -181,26 +219,20 @@ exports[`InventoryCardContext should handle variations in hosts inventory API re
exports[`InventoryCardContext should handle variations in hosts inventory API responses: inventory, pending 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": undefined,
"pending": true,
}
`;

exports[`InventoryCardContext should handle variations in instances inventory API responses: inventory, cancelled 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": undefined,
"pending": true,
}
`;

exports[`InventoryCardContext should handle variations in instances inventory API responses: inventory, disabled 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": undefined,
"pending": false,
}
`;
Expand All @@ -209,15 +241,13 @@ exports[`InventoryCardContext should handle variations in instances inventory AP
{
"data": {},
"error": true,
"fulfilled": undefined,
"pending": false,
}
`;

exports[`InventoryCardContext should handle variations in instances inventory API responses: inventory, fulfilled 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": true,
"pending": false,
}
Expand All @@ -226,8 +256,6 @@ exports[`InventoryCardContext should handle variations in instances inventory AP
exports[`InventoryCardContext should handle variations in instances inventory API responses: inventory, pending 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": undefined,
"pending": true,
}
`;
Expand Down
16 changes: 9 additions & 7 deletions src/components/inventoryCard/inventoryCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ const InventoryCard = ({
const { data: listData = [], meta = {} } = data;

useDeepCompareEffect(() => {
let updatedColumnHeaders = [];
let updatedRows = [];

if (fulfilled && listData.length) {
let updatedColumnHeaders = [];
const updatedRows = listData.map(({ ...cellData }) => {
updatedRows = listData.map(({ ...cellData }) => {
const { columnHeaders, cells } = inventoryCardHelpers.parseRowCellsListData({
filters: inventoryCardHelpers.parseInventoryFilters({
filters: filterInventoryData,
Expand Down Expand Up @@ -112,12 +114,12 @@ const InventoryCard = ({
undefined
};
});

setUpdatedColumnsRows(() => ({
columnHeaders: updatedColumnHeaders,
rows: updatedRows
}));
}

setUpdatedColumnsRows(() => ({
columnHeaders: updatedColumnHeaders,
rows: updatedRows
}));
}, [filterInventoryData, fulfilled, listData]);

if (isDisabled) {
Expand Down
10 changes: 4 additions & 6 deletions src/components/inventoryCard/inventoryCardContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const useGetHostsInventory = ({
const { productId } = useAliasProduct();
const query = useAliasProductInventoryQuery();
const dispatch = useAliasDispatch();
const { error, cancelled, fulfilled, pending, data } = useAliasSelectorsResponse(
const { cancelled, pending, data, ...response } = useAliasSelectorsResponse(
({ inventory }) => inventory?.hostsInventory?.[productId]
);

Expand All @@ -45,8 +45,7 @@ const useGetHostsInventory = ({
}, [dispatch, isDisabled, productId, query]);

return {
error,
fulfilled,
...response,
pending: pending || cancelled || false,
data: (data?.length === 1 && data[0]) || data || {}
};
Expand Down Expand Up @@ -75,7 +74,7 @@ const useGetInstancesInventory = ({
const { productId } = useAliasProduct();
const query = useAliasProductInventoryQuery();
const dispatch = useAliasDispatch();
const { error, cancelled, fulfilled, pending, data } = useAliasSelectorsResponse(
const { cancelled, pending, data, ...response } = useAliasSelectorsResponse(
({ inventory }) => inventory?.instancesInventory?.[productId]
);

Expand All @@ -86,8 +85,7 @@ const useGetInstancesInventory = ({
}, [dispatch, isDisabled, productId, query]);

return {
error,
fulfilled,
...response,
pending: pending || cancelled || false,
data: (data?.length === 1 && data[0]) || data || {}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,29 @@ exports[`InventoryCardSubscriptionsContext should handle a store response with u
],
"error": false,
"fulfilled": true,
"message": null,
"pending": false,
"responses": {
"id": {},
"list": [
{
"data": [
{
"data": [
{
"lorem": "ipsum",
},
{
"dolor": "sit",
},
],
"meta": {},
},
],
"fulfilled": true,
},
],
},
}
`;

Expand Down Expand Up @@ -89,17 +111,13 @@ exports[`InventoryCardSubscriptionsContext should handle an onPage event: onPage
exports[`InventoryCardSubscriptionsContext should handle variations in instances inventory API responses: inventory, cancelled 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": undefined,
"pending": true,
}
`;

exports[`InventoryCardSubscriptionsContext should handle variations in instances inventory API responses: inventory, disabled 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": undefined,
"pending": false,
}
`;
Expand All @@ -108,15 +126,13 @@ exports[`InventoryCardSubscriptionsContext should handle variations in instances
{
"data": {},
"error": true,
"fulfilled": undefined,
"pending": false,
}
`;

exports[`InventoryCardSubscriptionsContext should handle variations in instances inventory API responses: inventory, fulfilled 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": true,
"pending": false,
}
Expand All @@ -125,8 +141,6 @@ exports[`InventoryCardSubscriptionsContext should handle variations in instances
exports[`InventoryCardSubscriptionsContext should handle variations in instances inventory API responses: inventory, pending 1`] = `
{
"data": {},
"error": undefined,
"fulfilled": undefined,
"pending": true,
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const useGetSubscriptionsInventory = ({
const { productId } = useAliasProduct();
const query = useAliasProductInventoryQuery();
const dispatch = useAliasDispatch();
const { error, cancelled, fulfilled, pending, data } = useAliasSelectorsResponse(
const { cancelled, pending, data, ...response } = useAliasSelectorsResponse(
({ inventory }) => inventory?.subscriptionsInventory?.[productId]
);

Expand All @@ -44,8 +44,7 @@ const useGetSubscriptionsInventory = ({
}, [dispatch, isDisabled, productId, query]);

return {
error,
fulfilled,
...response,
pending: pending || cancelled || false,
data: (data?.length === 1 && data[0]) || data || {}
};
Expand Down
6 changes: 3 additions & 3 deletions tests/__snapshots__/code.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

exports[`General code checks should only have specific console.[warn|log|info|error] methods: console methods 1`] = `
[
"components/inventoryCard/inventoryCardContext.js:169: console.warn(\`Sorting can only be performed on select fields, confirm field \${id} is allowed.\`);",
"components/inventoryCard/inventoryCardContext.js:231: console.warn(\`Sorting can only be performed on select fields, confirm field \${id} is allowed.\`);",
"components/inventoryCard/inventoryCardContext.js:167: console.warn(\`Sorting can only be performed on select fields, confirm field \${id} is allowed.\`);",
"components/inventoryCard/inventoryCardContext.js:229: console.warn(\`Sorting can only be performed on select fields, confirm field \${id} is allowed.\`);",
"components/inventoryCard/inventoryCardHelpers.js:87: console.warn(\`Warning: Filter "\${id}" not found in "table row" response data.\`, cellData);",
"components/inventoryCard/inventoryList.deprecated.js:62: console.warn(\`Sorting can only be performed on select fields, confirm field \${id} is allowed.\`);",
"components/inventoryCardSubscriptions/inventoryCardSubscriptionsContext.js:127: console.warn(\`Sorting can only be performed on select fields, confirm field \${id} is allowed.\`);",
"components/inventoryCardSubscriptions/inventoryCardSubscriptionsContext.js:126: console.warn(\`Sorting can only be performed on select fields, confirm field \${id} is allowed.\`);",
"index.js:12: console.log(\`Emulated appNavClick: \${JSON.stringify({ id, ...rest })}\`);",
"redux/common/reduxHelpers.js:282: console.error(\`Error: Property \${prop} does not exist within the passed state.\`, state);",
"redux/common/reduxHelpers.js:286: console.warn(\`Warning: Property \${prop} does not exist within the passed initialState.\`, initialState);",
Expand Down

0 comments on commit 89b0f4d

Please sign in to comment.