Skip to content

Commit

Permalink
Fix [Batch Run] UI should not try to fetch hub functions without navi…
Browse files Browse the repository at this point in the history
…gating to "Hub" tab (#2040)
  • Loading branch information
ilan7empest authored Oct 23, 2023
1 parent e1290ed commit ed75e9c
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 105 deletions.
70 changes: 43 additions & 27 deletions src/actions/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
FETCH_HUB_FUNCTION_TEMPLATE_BEGIN,
FETCH_HUB_FUNCTION_TEMPLATE_FAILURE,
FETCH_HUB_FUNCTION_TEMPLATE_SUCCESS,
FETCH_HUB_FUNCTIONS_BEGIN,
REMOVE_FUNCTION_TEMPLATE,
SET_FUNCTIONS_TEMPLATES,
SET_LOADING,
Expand Down Expand Up @@ -75,6 +76,7 @@ import {
GET_FUNCTION_FAILURE,
GET_FUNCTION_BEGIN,
REMOVE_FUNCTION,
REMOVE_HUB_FUNCTIONS,
SET_NEW_FUNCTION_FORCE_BUILD,
SET_NEW_FUNCTION_PREEMTION_MODE,
SET_NEW_FUNCTION_PRIORITY_CLASS_NAME,
Expand Down Expand Up @@ -207,20 +209,22 @@ const functionsActions = {
type: FETCH_FUNCTION_TEMPLATE_FAILURE,
payload: err
}),
fetchFunctions: (project, filters, withoutLoader = false) => dispatch => {
dispatch(functionsActions.fetchFunctionsBegin(withoutLoader))
fetchFunctions:
(project, filters, withoutLoader = false) =>
dispatch => {
dispatch(functionsActions.fetchFunctionsBegin(withoutLoader))

return functionsApi
.getFunctions(project, filters)
.then(({ data }) => {
dispatch(functionsActions.fetchFunctionsSuccess(data.funcs))
return functionsApi
.getFunctions(project, filters)
.then(({ data }) => {
dispatch(functionsActions.fetchFunctionsSuccess(data.funcs))

return data.funcs
})
.catch(err => {
dispatch(functionsActions.fetchFunctionsFailure(err.message))
})
},
return data.funcs
})
.catch(err => {
dispatch(functionsActions.fetchFunctionsFailure(err.message))
})
},
fetchFunctionsBegin: () => ({
type: FETCH_FUNCTIONS_BEGIN
}),
Expand Down Expand Up @@ -284,25 +288,34 @@ const functionsActions = {
payload: err
}),
fetchHubFunctions: () => dispatch => {
return functionsApi.getHubFunctions().then(({ data: functionTemplates }) => {
const templatesData = generateHubCategories(functionTemplates.catalog)
dispatch(functionsActions.fetchHubFunctionsBegin())

dispatch(functionsActions.setHubFunctions(templatesData))
return functionsApi
.getHubFunctions()
.then(({ data: functionTemplates }) => {
const templatesData = generateHubCategories(functionTemplates.catalog)

return templatesData
}).catch((error) => {
const errorMsg = get(error, 'response.data.detail', 'Functions failed to load')
dispatch(functionsActions.setHubFunctions(templatesData))

dispatch(
setNotification({
status: error.response?.status || 400,
id: Math.random(),
message: errorMsg,
error
})
)
})
return templatesData
})
.catch(error => {
const errorMsg = get(error, 'response.data.detail', 'Functions failed to load')

dispatch(
setNotification({
status: error.response?.status || 400,
id: Math.random(),
message: errorMsg,
error
})
)
})
},

fetchHubFunctionsBegin: () => ({
type: FETCH_HUB_FUNCTIONS_BEGIN
}),
fetchHubFunctionsFailure: err => ({
type: FETCH_HUB_FUNCTIONS_FAILURE,
payload: err
Expand Down Expand Up @@ -336,6 +349,9 @@ const functionsActions = {
removeFunction: () => ({
type: REMOVE_FUNCTION
}),
removeHubFunctions: () => ({
type: REMOVE_HUB_FUNCTIONS
}),
removeFunctionTemplate: () => ({
type: REMOVE_FUNCTION_TEMPLATE
}),
Expand Down
11 changes: 6 additions & 5 deletions src/components/JobWizard/JobWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const JobWizard = ({
onWizardClose,
params,
removeJobFunction,
removeHubFunctions,
runNewJob,
wizardTitle
}) => {
Expand All @@ -92,7 +93,6 @@ const JobWizard = ({
const [filteredFunctions, setFilteredFunctions] = useState([])
const [filteredTemplates, setFilteredTemplates] = useState([])
const [functions, setFunctions] = useState([])
const [isLoading, setIsLoading] = useState(false)
const [templatesCategories, setTemplatesCategories] = useState([])
const [templates, setTemplates] = useState([])
const [jobAdditionalData, setJobAdditionalData] = useState({})
Expand Down Expand Up @@ -179,8 +179,12 @@ const JobWizard = ({
useEffect(() => {
return () => {
setFunctions([])
setTemplatesCategories([])
setTemplates([])

removeHubFunctions()
}
}, [setFunctions])
}, [removeHubFunctions, setFunctions])

useEffect(() => {
if (isBatchInference) {
Expand Down Expand Up @@ -298,7 +302,6 @@ const JobWizard = ({
{formState => {
return (
<>
{isLoading && <Loader />}
<Wizard
className="form"
formState={formState}
Expand Down Expand Up @@ -331,15 +334,13 @@ const JobWizard = ({
frontendSpec={frontendSpec}
functions={functions}
isEditMode={isEditMode}
isLoading={isLoading}
params={params}
selectedFunctionData={selectedFunctionData}
selectedFunctionTab={selectedFunctionTab}
setActiveTab={setActiveTab}
setFilteredFunctions={setFilteredFunctions}
setFilteredTemplates={setFilteredTemplates}
setFunctions={setFunctions}
setIsLoading={setIsLoading}
setJobAdditionalData={setJobAdditionalData}
setSelectedFunctionData={setSelectedFunctionData}
setSelectedFunctionTab={setSelectedFunctionTab}
Expand Down
Loading

0 comments on commit ed75e9c

Please sign in to comment.