From cb72079c9865e2427dde6ec800bc5c7ec51e3ba3 Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Wed, 14 May 2025 19:08:27 +0200 Subject: [PATCH 1/2] Mocks togglable --- .../vml/es/aem/acm/core/gui/SpaSettings.java | 12 +++++++++++ .../es/aem/acm/core/mock/MockHttpFilter.java | 2 +- .../example/ACME-300_extension.groovy | 5 ----- ui.frontend/src/App.tsx | 1 + ui.frontend/src/pages/ScriptsPage.tsx | 20 ++++++++++++------- ui.frontend/src/utils/api.types.ts | 1 + 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/com/vml/es/aem/acm/core/gui/SpaSettings.java b/core/src/main/java/com/vml/es/aem/acm/core/gui/SpaSettings.java index 015b9023..5c52ee8a 100644 --- a/core/src/main/java/com/vml/es/aem/acm/core/gui/SpaSettings.java +++ b/core/src/main/java/com/vml/es/aem/acm/core/gui/SpaSettings.java @@ -18,12 +18,15 @@ public class SpaSettings implements Serializable { private long scriptStatsLimit; + private boolean mocksVisible; + @Activate @Modified protected void activate(Config config) { this.appStateInterval = config.appStateInterval(); this.executionPollInterval = config.executionPollInterval(); this.scriptStatsLimit = config.scriptStatsLimit(); + this.mocksVisible = config.mocksVisible(); } public long getAppStateInterval() { @@ -38,6 +41,10 @@ public long getScriptStatsLimit() { return scriptStatsLimit; } + public boolean isMocksVisible() { + return mocksVisible; + } + @ObjectClassDefinition(name = "AEM Content Manager - SPA Settings") public @interface Config { @@ -56,5 +63,10 @@ public long getScriptStatsLimit() { description = "Limit for the number of historical executions to be considered to calculate the average duration.") long scriptStatsLimit() default 30; + + @AttributeDefinition( + name = "Mocks Visible", + description = "Controls visibility of mocks under scripts section.") + boolean mocksVisible() default false; } } diff --git a/core/src/main/java/com/vml/es/aem/acm/core/mock/MockHttpFilter.java b/core/src/main/java/com/vml/es/aem/acm/core/mock/MockHttpFilter.java index 8d816bd0..bc2c8748 100644 --- a/core/src/main/java/com/vml/es/aem/acm/core/mock/MockHttpFilter.java +++ b/core/src/main/java/com/vml/es/aem/acm/core/mock/MockHttpFilter.java @@ -141,7 +141,7 @@ public void destroy() { public @interface Config { @AttributeDefinition(name = "Enabled") - boolean enabled() default true; + boolean enabled() default false; @AttributeDefinition( name = "Whiteboard Filter Regex", diff --git a/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy b/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy index 9f5bad53..ee6f057e 100644 --- a/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy +++ b/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy @@ -1,6 +1,5 @@ import com.vml.es.aem.acm.core.code.ExecutionContext import com.vml.es.aem.acm.core.code.Execution -import com.vml.es.aem.acm.core.mock.MockContext void prepareRun(ExecutionContext context) { context.variable("acme", new AcmeFacade()) @@ -13,10 +12,6 @@ void completeRun(Execution execution) { } } -void prepareMock(MockContext context) { - context.variable("acme", new AcmeFacade()) -} - class AcmeFacade { def now() { return new Date() diff --git a/ui.frontend/src/App.tsx b/ui.frontend/src/App.tsx index 4d2b6065..38c11bcb 100644 --- a/ui.frontend/src/App.tsx +++ b/ui.frontend/src/App.tsx @@ -17,6 +17,7 @@ function App() { appStateInterval: 3000, executionPollInterval: 1000, scriptStatsLimit: 30, + mocksVisible: false, }, healthStatus: { healthy: true, diff --git a/ui.frontend/src/pages/ScriptsPage.tsx b/ui.frontend/src/pages/ScriptsPage.tsx index 99e58917..2bc90f39 100644 --- a/ui.frontend/src/pages/ScriptsPage.tsx +++ b/ui.frontend/src/pages/ScriptsPage.tsx @@ -9,8 +9,10 @@ import ScriptListSimple from '../components/ScriptListSimple.tsx'; import { useNavigationTab } from '../hooks/navigation'; import { ScriptType } from '../utils/api.types'; import styles from './ScriptsPage.module.css'; +import {useAppState} from "../hooks/app.ts"; const ScriptsPage = () => { + const appState = useAppState(); const [selectedTab, handleTabChange] = useNavigationTab('manual'); return ( @@ -29,10 +31,12 @@ const ScriptsPage = () => { Disabled - - - Mock - + {appState.spaSettings.mocksVisible ? ( + + + Mock + + ) : null} Extension @@ -48,9 +52,11 @@ const ScriptsPage = () => { - - - + {appState.spaSettings.mocksVisible ? ( + + + + ) : null} diff --git a/ui.frontend/src/utils/api.types.ts b/ui.frontend/src/utils/api.types.ts index abb6484f..752dca03 100644 --- a/ui.frontend/src/utils/api.types.ts +++ b/ui.frontend/src/utils/api.types.ts @@ -228,6 +228,7 @@ export type SpaSettings = { appStateInterval: number; executionPollInterval: number; scriptStatsLimit: number; + mocksVisible: boolean; }; export type InstanceSettings = { From ac9ea49488de50403b9dc7eacb48fdda10044a7b Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Wed, 14 May 2025 19:22:36 +0200 Subject: [PATCH 2/2] Single feature toggle for mocks --- .../com/vml/es/aem/acm/core/gui/SpaSettings.java | 12 ------------ .../vml/es/aem/acm/core/mock/MockHttpFilter.java | 5 ++++- ui.frontend/src/App.tsx | 1 - ui.frontend/src/pages/ScriptsPage.tsx | 14 +++++++------- ui.frontend/src/utils/api.types.ts | 1 - 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/com/vml/es/aem/acm/core/gui/SpaSettings.java b/core/src/main/java/com/vml/es/aem/acm/core/gui/SpaSettings.java index 5c52ee8a..015b9023 100644 --- a/core/src/main/java/com/vml/es/aem/acm/core/gui/SpaSettings.java +++ b/core/src/main/java/com/vml/es/aem/acm/core/gui/SpaSettings.java @@ -18,15 +18,12 @@ public class SpaSettings implements Serializable { private long scriptStatsLimit; - private boolean mocksVisible; - @Activate @Modified protected void activate(Config config) { this.appStateInterval = config.appStateInterval(); this.executionPollInterval = config.executionPollInterval(); this.scriptStatsLimit = config.scriptStatsLimit(); - this.mocksVisible = config.mocksVisible(); } public long getAppStateInterval() { @@ -41,10 +38,6 @@ public long getScriptStatsLimit() { return scriptStatsLimit; } - public boolean isMocksVisible() { - return mocksVisible; - } - @ObjectClassDefinition(name = "AEM Content Manager - SPA Settings") public @interface Config { @@ -63,10 +56,5 @@ public boolean isMocksVisible() { description = "Limit for the number of historical executions to be considered to calculate the average duration.") long scriptStatsLimit() default 30; - - @AttributeDefinition( - name = "Mocks Visible", - description = "Controls visibility of mocks under scripts section.") - boolean mocksVisible() default false; } } diff --git a/core/src/main/java/com/vml/es/aem/acm/core/mock/MockHttpFilter.java b/core/src/main/java/com/vml/es/aem/acm/core/mock/MockHttpFilter.java index bc2c8748..328abaae 100644 --- a/core/src/main/java/com/vml/es/aem/acm/core/mock/MockHttpFilter.java +++ b/core/src/main/java/com/vml/es/aem/acm/core/mock/MockHttpFilter.java @@ -140,7 +140,10 @@ public void destroy() { "Dedicated for dynamic response generation for mocking purposes, ideal for simulating 3rd-party system responses when their base URL is redirected to this service.") public @interface Config { - @AttributeDefinition(name = "Enabled") + @AttributeDefinition( + name = "Enabled", + description = + "When disabled, the filter will not process any requests. Also GUI no longer will display the mock scripts.") boolean enabled() default false; @AttributeDefinition( diff --git a/ui.frontend/src/App.tsx b/ui.frontend/src/App.tsx index 38c11bcb..4d2b6065 100644 --- a/ui.frontend/src/App.tsx +++ b/ui.frontend/src/App.tsx @@ -17,7 +17,6 @@ function App() { appStateInterval: 3000, executionPollInterval: 1000, scriptStatsLimit: 30, - mocksVisible: false, }, healthStatus: { healthy: true, diff --git a/ui.frontend/src/pages/ScriptsPage.tsx b/ui.frontend/src/pages/ScriptsPage.tsx index 2bc90f39..16e84bb8 100644 --- a/ui.frontend/src/pages/ScriptsPage.tsx +++ b/ui.frontend/src/pages/ScriptsPage.tsx @@ -6,10 +6,10 @@ import FlashOn from '@spectrum-icons/workflow/FlashOn'; import Hand from '@spectrum-icons/workflow/Hand'; import ScriptListRich from '../components/ScriptListRich.tsx'; import ScriptListSimple from '../components/ScriptListSimple.tsx'; +import { useAppState } from '../hooks/app.ts'; import { useNavigationTab } from '../hooks/navigation'; import { ScriptType } from '../utils/api.types'; import styles from './ScriptsPage.module.css'; -import {useAppState} from "../hooks/app.ts"; const ScriptsPage = () => { const appState = useAppState(); @@ -31,11 +31,11 @@ const ScriptsPage = () => { Disabled - {appState.spaSettings.mocksVisible ? ( - - - Mock - + {appState.mockStatus.enabled ? ( + + + Mock + ) : null} @@ -52,7 +52,7 @@ const ScriptsPage = () => { - {appState.spaSettings.mocksVisible ? ( + {appState.mockStatus.enabled ? ( diff --git a/ui.frontend/src/utils/api.types.ts b/ui.frontend/src/utils/api.types.ts index 752dca03..abb6484f 100644 --- a/ui.frontend/src/utils/api.types.ts +++ b/ui.frontend/src/utils/api.types.ts @@ -228,7 +228,6 @@ export type SpaSettings = { appStateInterval: number; executionPollInterval: number; scriptStatsLimit: number; - mocksVisible: boolean; }; export type InstanceSettings = {