From cff309828f20f05aa75e3fcee98aeb6ca379643c Mon Sep 17 00:00:00 2001 From: Ron Lavi <1ronlavi@gmail.com> Date: Mon, 1 Jan 2024 10:44:17 +0000 Subject: [PATCH] Fixes #36469 - fix React tests --- .../components/AnsibleVariableOverrides/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/index.js b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/index.js index 20527acf..d386e2f7 100644 --- a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/index.js +++ b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/index.js @@ -17,6 +17,9 @@ const AnsibleVariableOverrides = ({ hostId, hostAttrs, history }) => { const hostGlobalId = encodeId('Host', hostId); const pagination = useCurrentPagination(history); const [totalItems, setTotalItems] = useState(0); + const setTotalCount = totalCount => { + if (totalCount === 0) setTotalItems(totalCount); + } const useFetchFn = () => useQuery(variableOverrides, { @@ -31,7 +34,8 @@ const AnsibleVariableOverrides = ({ hostId, hostAttrs, history }) => { const renameData = data => { const { totalCount } = data.host.ansibleVariablesWithOverrides; - if (totalItems === 0) setTotalItems(totalCount); + // Moved into a seperate function after React complained on setstate-in-render issue. + setTotalCount(totalCount) return { variables: data.host.ansibleVariablesWithOverrides.nodes, totalCount,