diff --git a/src/Pages/Shared/ConfigMapSecret/ConfigMapSecretData.tsx b/src/Pages/Shared/ConfigMapSecret/ConfigMapSecretData.tsx index 2757070cad..3703a4e216 100644 --- a/src/Pages/Shared/ConfigMapSecret/ConfigMapSecretData.tsx +++ b/src/Pages/Shared/ConfigMapSecret/ConfigMapSecretData.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ChangeEvent, useEffect, useState } from 'react' +import { useEffect, useState } from 'react' import { Button, @@ -25,6 +25,8 @@ import { CodeEditor, ComponentSizeType, configMapSecretMountDataMap, + CONFIGURATION_TYPE_OPTIONS, + ConfigurationType, convertKeyValuePairToYAML, convertYAMLToKeyValuePair, KeyValueTable, @@ -32,8 +34,8 @@ import { MODES, noop, OverrideMergeStrategyType, + SegmentedControl, SelectPickerOptionType, - StyledRadioGroup, ToastManager, ToastVariantType, YAMLStringify, @@ -44,9 +46,9 @@ import { ReactComponent as HideIcon } from '@Icons/ic-visibility-off.svg' import { importComponentFromFELibrary } from '@Components/common' import { - CODE_EDITOR_RADIO_STATE_VALUE, CONFIG_MAP_SECRET_REQUIRED_FIELD_ERROR, DATA_HEADER_MAP, + EXTERNAL_CODE_EDITOR_RADIO_STATE, sampleJSONs, VIEW_MODE, } from './constants' @@ -162,14 +164,9 @@ export const ConfigMapSecretData = ({ setValue('yamlMode', mode === VIEW_MODE.YAML) } - const handleGuiYamlSwitch = (e: ChangeEvent) => { - const { value } = e.target - toggleYamlMode(value as (typeof VIEW_MODE)[keyof typeof VIEW_MODE]) + const handleExternalCodeEditorRadioChange = (selectedSegment: SelectPickerOptionType) => { + setCodeEditorRadio(selectedSegment.value as CODE_EDITOR_RADIO_STATE) } - - const handleCodeEditorRadioChange = (e: ChangeEvent) => - setCodeEditorRadio(e.target.value as CODE_EDITOR_RADIO_STATE) - /** * Determines the key to be used for the code editor form based on the current configuration. * @returns The key in the `data` object corresponding to the selected mode (ESO, HashiCorp/AWS, or YAML). @@ -211,6 +208,14 @@ export const ConfigMapSecretData = ({ ) } + const handleToggleEditMode = (selectedSegment: SelectPickerOptionType) => { + if (selectedSegment.value === ConfigurationType.YAML) { + toggleYamlMode(VIEW_MODE.YAML) + } else { + toggleYamlMode(VIEW_MODE.GUI) + } + } + // USE-EFFECTS useEffect(() => { // Switch to YAML mode if the user is in the express edit comparison view. @@ -246,22 +251,12 @@ export const ConfigMapSecretData = ({ {/* eslint-disable-next-line jsx-a11y/label-has-associated-control */} {!isESO && !isHashiOrAWS && ( - - {Object.keys(VIEW_MODE).map((key) => - VIEW_MODE[key] !== VIEW_MODE.MANIFEST ? ( - - {VIEW_MODE[key].toUpperCase()} - - ) : null, - )} - + )} ) @@ -345,18 +340,12 @@ export const ConfigMapSecretData = ({
{!isHashiOrAWS && data.external ? ( - - {Object.keys(CODE_EDITOR_RADIO_STATE).map((key) => ( - - {CODE_EDITOR_RADIO_STATE_VALUE[key]} - - ))} - + segments={EXTERNAL_CODE_EDITOR_RADIO_STATE} + value={codeEditorRadio} + onChange={handleExternalCodeEditorRadioChange} + /> ) : null}
{renderSecretShowHide()} diff --git a/src/Pages/Shared/ConfigMapSecret/constants.ts b/src/Pages/Shared/ConfigMapSecret/constants.ts index 30bac068c0..ac1694cf1b 100644 --- a/src/Pages/Shared/ConfigMapSecret/constants.ts +++ b/src/Pages/Shared/ConfigMapSecret/constants.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { CMSecretComponentType, ConfigMapSecretUseFormProps } from '@devtron-labs/devtron-fe-common-lib' +import { + CMSecretComponentType, + CODE_EDITOR_RADIO_STATE, + ConfigMapSecretUseFormProps, +} from '@devtron-labs/devtron-fe-common-lib' import { ConfigMapSecretNullStateProps } from './types' @@ -73,8 +77,6 @@ export const getCMSecretNullStateText = ( }, }) -export const CODE_EDITOR_RADIO_STATE_VALUE = { DATA: 'Data', SAMPLE: 'Sample' } - export const DATA_HEADER_MAP = { DEFAULT: 'default' } export const VIEW_MODE = { @@ -223,3 +225,8 @@ export const CONFIG_MAP_SECRET_DATA_KEYS: (keyof ConfigMapSecretUseFormProps)[] 'esoSecretYaml', 'secretDataYaml', ] + +export const EXTERNAL_CODE_EDITOR_RADIO_STATE = Object.values(CODE_EDITOR_RADIO_STATE).map((value) => ({ + label: value, + value, +})) diff --git a/src/components/CIPipelineN/CreatePluginModal/CreatePluginFormContent.tsx b/src/components/CIPipelineN/CreatePluginModal/CreatePluginFormContent.tsx index c8edda17e2..66fb049264 100644 --- a/src/components/CIPipelineN/CreatePluginModal/CreatePluginFormContent.tsx +++ b/src/components/CIPipelineN/CreatePluginModal/CreatePluginFormContent.tsx @@ -23,12 +23,13 @@ import { getIsRequestAborted, logExceptionToSentry, OptionType, + SegmentedControl, + SegmentedControlProps, SelectPicker, SelectPickerOptionType, SelectPickerProps, SEMANTIC_VERSION_DOCUMENTATION_LINK, stopPropagation, - StyledRadioGroup, TippyCustomized, TippyTheme, } from '@devtron-labs/devtron-fe-common-lib' @@ -66,16 +67,6 @@ const CreatePluginFormContent = ({ const { currentTab, name, pluginIdentifier, docLink, pluginVersion, description, tags, inputVariables, icon } = pluginForm - const handleTabChange = (e: React.ChangeEvent) => { - const targetMode = e.target.value as CreatePluginFormViewType - - if (targetMode === currentTab) { - return - } - - handleChange({ action: CreatePluginActionType.UPDATE_CURRENT_TAB, payload: targetMode }) - } - const handlePluginSelection: SelectPickerProps['onChange'] = (newValue: SelectPickerOptionType) => { handleChange({ action: CreatePluginActionType.UPDATE_PARENT_PLUGIN, @@ -209,20 +200,31 @@ const CreatePluginFormContent = ({ const showPluginDetailFields = currentTab !== CreatePluginFormViewType.EXISTING_PLUGIN || !!name + const CREATE_PLUGIN_FORM_VIEW_TYPE_SEGMENTS = Object.values(CreatePluginFormViewType).map((tab) => ({ + label: tab, + value: tab, + })) + + const handleSegmentedControlChange: SegmentedControlProps['onChange'] = (selectedSegment) => { + const targetMode = selectedSegment.value as CreatePluginFormViewType + + if (targetMode === currentTab) { + return + } + + handleChange({ action: CreatePluginActionType.UPDATE_CURRENT_TAB, payload: targetMode }) + } + return (
- - {Object.values(CreatePluginFormViewType).map((tab) => ( - - {tab} - - ))} - +
+ +
{currentTab === CreatePluginFormViewType.NEW_PLUGIN && (