diff --git a/packages/create-plugin/templates/app/src/components/AppConfig/AppConfig.tsx b/packages/create-plugin/templates/app/src/components/AppConfig/AppConfig.tsx index f6333cd84..19fba6438 100644 --- a/packages/create-plugin/templates/app/src/components/AppConfig/AppConfig.tsx +++ b/packages/create-plugin/templates/app/src/components/AppConfig/AppConfig.tsx @@ -30,6 +30,8 @@ export const AppConfig = ({ plugin }: AppConfigProps) => { isApiKeySet: Boolean(secureJsonFields?.apiKey), }); + const isSubmitDisabled = Boolean(!state.apiUrl || (!state.isApiKeySet && !state.apiKey)); + const onResetApiKey = () => setState({ ...state, @@ -44,8 +46,29 @@ export const AppConfig = ({ plugin }: AppConfigProps) => { }); }; + const onSubmit = () => { + if (isSubmitDisabled) { + return; + } + + updatePluginAndReload(plugin.meta.id, { + enabled, + pinned, + jsonData: { + apiUrl: state.apiUrl, + }, + // This cannot be queried later by the frontend. + // We don't want to override it in case it was set previously and left untouched now. + secureJsonData: state.isApiKeySet + ? undefined + : { + apiKey: state.apiKey, + }, + }); + }; + return ( -
+
{
- + ); }; diff --git a/packages/create-plugin/templates/app/src/components/testIds.ts b/packages/create-plugin/templates/app/src/components/testIds.ts index c17eb2248..a5728c160 100644 --- a/packages/create-plugin/templates/app/src/components/testIds.ts +++ b/packages/create-plugin/templates/app/src/components/testIds.ts @@ -1,6 +1,5 @@ export const testIds = { appConfig: { - container: 'data-testid ac-container', apiKey: 'data-testid ac-api-key', apiUrl: 'data-testid ac-api-url', submit: 'data-testid ac-submit-form', diff --git a/packages/create-plugin/templates/scenes-app/src/components/AppConfig/AppConfig.tsx b/packages/create-plugin/templates/scenes-app/src/components/AppConfig/AppConfig.tsx index 8ad9e8e0d..5d324ffd9 100644 --- a/packages/create-plugin/templates/scenes-app/src/components/AppConfig/AppConfig.tsx +++ b/packages/create-plugin/templates/scenes-app/src/components/AppConfig/AppConfig.tsx @@ -33,6 +33,8 @@ export const AppConfig = ({ plugin }: Props) => { isApiKeySet: Boolean(jsonData?.isApiKeySet), }); + const isSubmitDisabled = Boolean(!state.apiUrl || (!state.isApiKeySet && !state.apiKey)); + const onResetApiKey = () => setState({ ...state, @@ -54,51 +56,26 @@ export const AppConfig = ({ plugin }: Props) => { }); }; - return ( -
- {/* ENABLE / DISABLE PLUGIN */} -
- {!enabled && ( - <> -
The plugin is currently not enabled.
- - - )} - - {/* Disable the plugin */} - {enabled && ( - <> -
The plugin is currently enabled.
- - - )} -
+ const onSubmit = () => { + updatePluginAndReload(plugin.meta.id, { + enabled, + pinned, + jsonData: { + apiUrl: state.apiUrl, + isApiKeySet: true, + }, + // This cannot be queried later by the frontend. + // We don't want to override it in case it was set previously and left untouched now. + secureJsonData: state.isApiKeySet + ? undefined + : { + apiKey: state.apiKey, + }, + }); + }; - {/* CUSTOM SETTINGS */} + return ( +
{/* API Key */} @@ -128,33 +105,12 @@ export const AppConfig = ({ plugin }: Props) => {
-
-
+ ); };