From 9753ea948906f1ebf064c8c2f57a38faa7e7e257 Mon Sep 17 00:00:00 2001 From: Katia Aresti Date: Tue, 2 Jul 2024 12:08:58 +0200 Subject: [PATCH] ISPN-16256 Don't validate config on every step --- cypress/e2e/3_proto-schema.cy.js | 3 +- src/app/Caches/Create/CreateCacheWizard.tsx | 1 - src/app/Caches/Create/FeaturesSelector.tsx | 1 - .../Caches/Create/LanguageToggleRadios.tsx | 4 -- src/app/Caches/Create/ReviewCacheConfig.tsx | 47 +++++++++++-------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cypress/e2e/3_proto-schema.cy.js b/cypress/e2e/3_proto-schema.cy.js index d927cbac..782494b2 100644 --- a/cypress/e2e/3_proto-schema.cy.js +++ b/cypress/e2e/3_proto-schema.cy.js @@ -58,7 +58,6 @@ describe('Proto Schema CRUD', () => { cy.get('.pf-v5-c-alert__action > .pf-v5-c-button').click(); //Closing alert popup. cy.contains(schemaName + '.proto'); cy.contains('Schema ' + schemaName + '.proto has errors'); - cy.wait(50000) // Update cy.get('[data-cy="actions-' + schemaName + '.proto"]>button').click(); @@ -74,7 +73,7 @@ describe('Proto Schema CRUD', () => { cy.contains('Schema ' + schemaName +'.proto updated.'); cy.get('.pf-v5-c-alert__action > .pf-v5-c-button').click(); //Closing alert popup. cy.get('[data-cy="' + schemaName + '.protoConfig"]').click(); - cy.wait(10000) + cy.contains('schemaValue').should('not.exist'); cy.contains('ExampleProto'); cy.contains('Schema ' + schemaName + '.proto has errors').should('not.exist'); diff --git a/src/app/Caches/Create/CreateCacheWizard.tsx b/src/app/Caches/Create/CreateCacheWizard.tsx index 85a38276..68967255 100644 --- a/src/app/Caches/Create/CreateCacheWizard.tsx +++ b/src/app/Caches/Create/CreateCacheWizard.tsx @@ -258,7 +258,6 @@ const CreateCacheWizard = (props: { cacheManager: CacheManager; create: boolean diff --git a/src/app/Caches/Create/FeaturesSelector.tsx b/src/app/Caches/Create/FeaturesSelector.tsx index 54570a2c..894075c3 100644 --- a/src/app/Caches/Create/FeaturesSelector.tsx +++ b/src/app/Caches/Create/FeaturesSelector.tsx @@ -30,7 +30,6 @@ const FeaturesSelector = () => { const [isBackups, setIsBackups] = useState(false); useEffect(() => { - console.log(cm); if (!loading) { setIsBackups(cm.backups_enabled); } diff --git a/src/app/Caches/Create/LanguageToggleRadios.tsx b/src/app/Caches/Create/LanguageToggleRadios.tsx index 9acd7b0a..204b3005 100644 --- a/src/app/Caches/Create/LanguageToggleRadios.tsx +++ b/src/app/Caches/Create/LanguageToggleRadios.tsx @@ -6,7 +6,6 @@ import { useTranslation } from 'react-i18next'; const LanguageToggleRadios = (props: { language: ConfigDownloadType; setLanguage: (ConfigDownloadType) => void; - setContentType: (string) => void; }) => { const { t } = useTranslation(); @@ -17,7 +16,6 @@ const LanguageToggleRadios = (props: { id="JSON" onChange={() => { props.setLanguage(ConfigDownloadType.JSON); - props.setContentType(ConfigDownloadType.JSON.toLowerCase()); }} isChecked={(props.language as ConfigDownloadType) == ConfigDownloadType.JSON} label={t('caches.create.review.json')} @@ -27,7 +25,6 @@ const LanguageToggleRadios = (props: { id="XML" onChange={() => { props.setLanguage(ConfigDownloadType.XML); - props.setContentType(ConfigDownloadType.XML.toLowerCase()); }} isChecked={(props.language as ConfigDownloadType) == ConfigDownloadType.XML} label={t('caches.create.review.xml')} @@ -37,7 +34,6 @@ const LanguageToggleRadios = (props: { id="YAML" onChange={() => { props.setLanguage(ConfigDownloadType.YAML); - props.setContentType(ConfigDownloadType.YAML.toLowerCase()); }} isChecked={(props.language as ConfigDownloadType) == ConfigDownloadType.YAML} label={t('caches.create.review.yaml')} diff --git a/src/app/Caches/Create/ReviewCacheConfig.tsx b/src/app/Caches/Create/ReviewCacheConfig.tsx index ee3827d5..ec13337e 100644 --- a/src/app/Caches/Create/ReviewCacheConfig.tsx +++ b/src/app/Caches/Create/ReviewCacheConfig.tsx @@ -13,11 +13,9 @@ import { toCodeEditorLanguage } from '@utils/getLanguage'; const ReviewCacheConfig = (props: { setReviewConfig: (string) => void; setContentType: (string) => void; - contentType: 'json' | 'yaml' | 'xml'; }) => { const { configuration } = useCreateCache(); const { t } = useTranslation(); - const [config, setConfig] = useState(CacheConfigUtils.createCacheConfigFromData(configuration)); const { theme } = useContext(ThemeContext); const [language, setLanguage] = useState(ConfigDownloadType.JSON); @@ -25,44 +23,53 @@ const ReviewCacheConfig = (props: { const [yamlConfig, setYamlConfig] = useState(''); const [xmlConfig, setXmlConfig] = useState(''); const [error, setError] = useState(''); + const [validate, setValidate] = useState(true); useEffect(() => { - props.setContentType('json'); - }, []); - useEffect(() => { - props.setReviewConfig(config); - - if (configuration && config && language.toLowerCase() === props.contentType) { + if (validate) { // Convert the config to all formats // Also to check if the config is valid ConsoleServices.caches() - .convertToAllFormat(configuration.start.cacheName, config, props.contentType) + .convertToAllFormat(configuration.start.cacheName, jsonConfig, 'json') .then((r) => { if (r.isRight()) { setYamlConfig(r.value.yaml); setJsonConfig(r.value.json); setXmlConfig(r.value.xml); setError(''); + props.setReviewConfig(r.value.json); } else { setError(r.value.message); } - }); + }).then(() => setValidate(false)); } - }, [config, configuration]); + }, [validate]); useEffect(() => { - language === ConfigDownloadType.JSON - ? setConfig(jsonConfig) - : language === ConfigDownloadType.YAML - ? setConfig(yamlConfig) - : setConfig(xmlConfig); - }, [jsonConfig, yamlConfig, xmlConfig, language]); + props.setContentType(language.toLowerCase()); + }, [language]); const onChangeConfig = (editedConfig) => { props.setReviewConfig(editedConfig); - setConfig(editedConfig); + if (language == ConfigDownloadType.JSON) { + setJsonConfig(editedConfig); + } else if (language == ConfigDownloadType.YAML) { + setYamlConfig(editedConfig); + } else { + setXmlConfig(editedConfig); + } }; + const config = () => { + if (language == ConfigDownloadType.JSON) { + return jsonConfig; + } + if (language == ConfigDownloadType.YAML) { + return yamlConfig; + } + return xmlConfig; + } + const displayCacheConfigEditor = () => { return ( @@ -76,7 +83,7 @@ const ReviewCacheConfig = (props: { language={toCodeEditorLanguage(language)} isLineNumbersVisible isLanguageLabelVisible - code={config} + code={config()} height={'400px'} isCopyEnabled isDarkTheme={theme === 'dark'} @@ -103,7 +110,7 @@ const ReviewCacheConfig = (props: { {configuration.start.cacheName} - + {displayCacheConfigEditor()} );