From 638e8c7add2597a30993aee6e11289434c94ce4b Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Mon, 3 Feb 2020 09:43:06 -0800 Subject: [PATCH] delete dead code/comments & add useRequest docstring --- awx/ui_next/src/screens/Inventory/Inventory.jsx | 2 -- .../Inventory/InventoryDetail/InventoryDetail.jsx | 4 ++-- awx/ui_next/src/util/useRequest.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/awx/ui_next/src/screens/Inventory/Inventory.jsx b/awx/ui_next/src/screens/Inventory/Inventory.jsx index 5a3d26179f..6e8f55c60b 100644 --- a/awx/ui_next/src/screens/Inventory/Inventory.jsx +++ b/awx/ui_next/src/screens/Inventory/Inventory.jsx @@ -37,8 +37,6 @@ function Inventory({ i18n, setBreadcrumb }) { useEffect(() => { async function fetchData() { try { - // TODO: delete next line - // setHasContentLoading(true); const { data } = await InventoriesAPI.readDetail(match.params.id); setBreadcrumb(data); setInventory(data); diff --git a/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx b/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx index 8d3f2eb8fb..628d5d71e7 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx @@ -31,8 +31,8 @@ function InventoryDetail({ inventory, i18n }) { ); useEffect(() => { - fetchInstanceGroups(inventory.id); - }, [fetchInstanceGroups, inventory.id]); + fetchInstanceGroups(); + }, [fetchInstanceGroups]); const deleteInventory = async () => { await InventoriesAPI.destroy(inventory.id); diff --git a/awx/ui_next/src/util/useRequest.js b/awx/ui_next/src/util/useRequest.js index 909dfda683..f6e9426dc8 100644 --- a/awx/ui_next/src/util/useRequest.js +++ b/awx/ui_next/src/util/useRequest.js @@ -1,5 +1,16 @@ import { useEffect, useState, useRef, useCallback } from 'react'; +/* + * The useRequest hook accepts a request function and returns an object with + * four values: + * request: a function to call to invoke the request + * result: the value returned from the request function (once invoked) + * isLoading: boolean state indicating whether the request is in active/in flight + * error: any caught error resulting from the request + * + * The hook also accepts an optional second parameter which is a default + * value to set as result before the first time the request is made. + */ export default function useRequest(makeRequest, initialValue) { const [result, setResult] = useState(initialValue); const [error, setError] = useState(null);