From 7561aa5a3525ff7684407205dfcb3f92b81aed84 Mon Sep 17 00:00:00 2001 From: Andrii Mavdryk Date: Thu, 16 Nov 2023 13:33:18 +0200 Subject: [PATCH] Fix [New function] No default for handler --- src/components/JobWizard/JobWizard.util.js | 5 +++-- src/constants.js | 1 + src/elements/FunctionsPanelCode/FunctionsPanelCode.js | 10 ++-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/components/JobWizard/JobWizard.util.js b/src/components/JobWizard/JobWizard.util.js index d9f671e7f..11d742a3a 100644 --- a/src/components/JobWizard/JobWizard.util.js +++ b/src/components/JobWizard/JobWizard.util.js @@ -38,6 +38,7 @@ import { ENV_VARIABLE_TYPE_SECRET, ENV_VARIABLE_TYPE_VALUE, EXISTING_IMAGE_SOURCE, + FUNCTION_DEFAULT_HANDLER, HYPERPARAMETER_STRATEGY_STEP, JOB_DEFAULT_OUTPUT_PATH, LIST_TUNING_STRATEGY, @@ -385,9 +386,9 @@ const getDefaultMethod = (methodOptions, selectedFunctions) => { if (methodOptions.length) { method = methodOptions[0]?.id } else if (latestFunction) { - method = latestFunction.spec.default_handler || 'handler' + method = latestFunction.spec.default_handler || FUNCTION_DEFAULT_HANDLER } else { - method = selectedFunctions[0]?.spec.default_handler || 'handler' + method = selectedFunctions[0]?.spec.default_handler || FUNCTION_DEFAULT_HANDLER } return method diff --git a/src/constants.js b/src/constants.js index 387f949c4..28cd9bf87 100644 --- a/src/constants.js +++ b/src/constants.js @@ -283,6 +283,7 @@ export const FUNCTION_INITIALIZED_STATE = 'initialized' export const FUNCTION_READY_STATE = 'ready' export const FUNCTION_PENDINDG_STATE = 'pending' export const FUNCTION_RUNNING_STATE = 'running' +export const FUNCTION_DEFAULT_HANDLER = 'handler' /*=========== ARTIFACTS =============*/ diff --git a/src/elements/FunctionsPanelCode/FunctionsPanelCode.js b/src/elements/FunctionsPanelCode/FunctionsPanelCode.js index efce681b6..9097a0329 100644 --- a/src/elements/FunctionsPanelCode/FunctionsPanelCode.js +++ b/src/elements/FunctionsPanelCode/FunctionsPanelCode.js @@ -32,7 +32,7 @@ import { NEW_IMAGE, sourceCodeInBase64 } from './functionsPanelCode.util' -import { PANEL_CREATE_MODE, TAG_LATEST } from '../../constants' +import { FUNCTION_DEFAULT_HANDLER, PANEL_CREATE_MODE, TAG_LATEST } from '../../constants' import { splitTrim, trimSplit } from '../../utils' import { useParams } from 'react-router-dom' @@ -59,7 +59,7 @@ const FunctionsPanelCode = ({ const [data, setData] = useState({ default_class: defaultData.default_class ?? '', entry: DEFAULT_ENTRY, - handler: defaultData.default_handler ?? '', + handler: defaultData.default_handler ?? FUNCTION_DEFAULT_HANDLER, image: defaultData.image ?? '', base_image: defaultData.build?.base_image ?? '', requirements: (defaultData.build?.requirements || []).join(', ') ?? '', @@ -83,12 +83,6 @@ const FunctionsPanelCode = ({ setNewFunctionSourceCode ]) - useEffect(() => { - if (!functionsStore.newFunction.spec.default_handler) { - setNewFunctionHandler('handler') - } - }, [functionsStore.newFunction.spec.default_handler, setNewFunctionHandler]) - useEffect(() => { if (mode === PANEL_CREATE_MODE && imageType.length === 0) { if (appStore.frontendSpec.default_function_image_by_kind?.[functionsStore.newFunction.kind]) {