Skip to content

Commit 9cde739

Browse files
Merge pull request #1283 from devtron-labs/fix/variables-update
Fix: variables update
2 parents c70c086 + 464d6a5 commit 9cde739

File tree

8 files changed

+57
-107
lines changed

8 files changed

+57
-107
lines changed

src/components/scopedVariables/Descriptor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default function Descriptor({ children, showUploadButton, readFile, onSea
5454
</div>
5555

5656
<div className="flex dc__gap-12">
57-
{onSearch && <SearchBar onSearch={onSearch} placeholder="Search Variables" Icon={ICSearch} />}
57+
{onSearch && <SearchBar onSearch={onSearch} placeholder="Search variables" Icon={ICSearch} />}
5858

5959
{showUploadButton && (
6060
<button

src/components/scopedVariables/SavedVariables.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PopupMenu } from '@devtron-labs/devtron-fe-common-lib'
44
import ScopedVariablesLoader from './ScopedVariablesLoader'
55
import ScopedVariablesEditor from './ScopedVariablesEditor'
66
import VariablesList from './VariablesList'
7-
import { useFileReader } from '../common'
7+
import { importComponentFromFELibrary, useFileReader } from '../common'
88
import CodeEditor from '../CodeEditor/CodeEditor'
99
import Descriptor from './Descriptor'
1010
import { downloadData, parseIntoYAMLString } from './utils'
@@ -33,6 +33,11 @@ export default function SavedVariablesView({
3333
const scopedVariablesYAML = parseIntoYAMLString(scopedVariablesData)
3434

3535
const { status, progress, fileData, abortRead, readFile } = useFileReader()
36+
const SCOPED_VARIABLES_TEMPLATE = importComponentFromFELibrary(
37+
'SCOPED_VARIABLES_TEMPLATE_DATA',
38+
SCOPED_VARIABLES_TEMPLATE_DATA,
39+
'function',
40+
)
3641

3742
useEffect(() => {
3843
if (status?.status == null && scopedVariablesData?.spec?.length) {
@@ -74,7 +79,7 @@ export default function SavedVariablesView({
7479
downloadData(scopedVariablesYAML, DOWNLOAD_FILE_NAME, DOWNLOAD_FILES_AS)
7580
break
7681
case DROPDOWN_ITEMS[1]:
77-
downloadData(SCOPED_VARIABLES_TEMPLATE_DATA, DOWNLOAD_TEMPLATE_NAME, DOWNLOAD_FILES_AS)
82+
downloadData(SCOPED_VARIABLES_TEMPLATE, DOWNLOAD_TEMPLATE_NAME, DOWNLOAD_FILES_AS)
7883
break
7984
}
8085
}

src/components/scopedVariables/ScopedVariablesEditor.tsx

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function ScopedVariablesEditor({
2828
const [showSaveView, setShowSaveView] = useState<boolean>(false)
2929
const [loadingSavedScopedVariables, setLoadingSavedScopedVariables] = useState<boolean>(false)
3030
const [isSaving, setIsSaving] = useState<boolean>(false)
31-
const [footerError, setFooterError] = useState<string>('')
31+
const [infoError, setInfoError] = useState<string>('')
3232

3333
const handleParsing = (data: string): ScopedVariablesDataType => {
3434
let variablesObj: ScopedVariablesDataType
@@ -60,7 +60,7 @@ export default function ScopedVariablesEditor({
6060
}
6161
} catch (e) {
6262
if (e instanceof ServerErrors && Array.isArray(e.errors) && e.code === 406) {
63-
setFooterError(e.errors[0]?.userMessage || UPLOAD_FAILED_STANDARD_MESSAGE)
63+
setInfoError(e.errors[0]?.userMessage || UPLOAD_FAILED_STANDARD_MESSAGE)
6464
}
6565
toast.error(UPLOAD_FAILED_STANDARD_MESSAGE)
6666
setIsSaving(false)
@@ -108,22 +108,6 @@ export default function ScopedVariablesEditor({
108108
abortRead()
109109
}
110110

111-
const handleClearError = () => {
112-
setFooterError('')
113-
}
114-
115-
function renderInfoBarCloseButton(): JSX.Element {
116-
return (
117-
<button
118-
type="button"
119-
className="p-0 h-20 dc__no-border dc__outline-none-imp bcr-1"
120-
onClick={handleClearError}
121-
>
122-
<ICClose className="icon-dim-20 mt-2" />
123-
</button>
124-
)
125-
}
126-
127111
return (
128112
<div className="flex column dc__content-space h-100 bcn-0 saved-variables-editor">
129113
<Descriptor />
@@ -154,6 +138,15 @@ export default function ScopedVariablesEditor({
154138
</Tippy>
155139
</div>
156140

141+
{infoError && (
142+
<InfoColourBar
143+
message={infoError}
144+
classname="w-100 bcr-1 mb-16 m-0 dc__border dc__border-bottom-r2 dc__no-border-radius dc__no-top-border dc__no-left-border dc__no-right-border"
145+
Icon={ICError}
146+
iconClass="icon-dim-20"
147+
/>
148+
)}
149+
157150
{showSaveView && (
158151
<div className="bcn-1 flexbox dc__content-space w-100 h-32 dc__align-items-center">
159152
<div
@@ -182,16 +175,6 @@ export default function ScopedVariablesEditor({
182175
validatorSchema={jsonSchema}
183176
/>
184177

185-
{footerError && (
186-
<InfoColourBar
187-
message={footerError}
188-
classname="w-100 bcr-1 mb-16 m-0"
189-
Icon={ICError}
190-
iconClass="icon-dim-20"
191-
renderActionButton={renderInfoBarCloseButton}
192-
/>
193-
)}
194-
195178
<div className="flexbox pt-13 pb-13 pl-12 pr-12 bcn-0 dc__border-top dc__content-end dc__align-items-center dc__align-self-stretch dc__gap-12">
196179
<button
197180
type="button"

src/components/scopedVariables/UploadScopedVariables.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { useFileReader, HiddenInput } from '../common'
2+
import { useFileReader, HiddenInput, importComponentFromFELibrary } from '../common'
33
import ScopedVariablesEditor from './ScopedVariablesEditor'
44
import ScopedVariablesLoader from './ScopedVariablesLoader'
55
import { validator, downloadData } from './utils'
@@ -24,13 +24,19 @@ export default function UploadScopedVariables({
2424
}: UploadScopedVariablesProps) {
2525
const { fileData, progress, status, readFile, abortRead } = useFileReader()
2626

27+
const SCOPED_VARIABLES_TEMPLATE = importComponentFromFELibrary(
28+
'SCOPED_VARIABLES_TEMPLATE_DATA',
29+
SCOPED_VARIABLES_TEMPLATE_DATA,
30+
'function',
31+
)
32+
2733
const handleFileUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
2834
e.preventDefault()
2935
readFile(e.target.files![0], validator, ReadFileAs.TEXT)
3036
}
3137

3238
const handleDownloadTemplate = () => {
33-
downloadData(SCOPED_VARIABLES_TEMPLATE_DATA, DOWNLOAD_TEMPLATE_NAME, DOWNLOAD_FILES_AS)
39+
downloadData(SCOPED_VARIABLES_TEMPLATE, DOWNLOAD_TEMPLATE_NAME, DOWNLOAD_FILES_AS)
3440
}
3541

3642
return status?.status === FileReaderStatus.SUCCESS ? (

src/components/scopedVariables/__tests__/UploadScopedVariables.test.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fireEvent, render } from '@testing-library/react'
33
import UploadScopedVariables from '../UploadScopedVariables'
44
import { downloadData } from '../utils'
55
import { SCOPED_VARIABLES_TEMPLATE_DATA, DOWNLOAD_TEMPLATE_NAME, DOWNLOAD_FILES_AS } from '../constants'
6+
import { importComponentFromFELibrary } from '../../common'
67

78
jest.mock('../utils', () => ({
89
validator: jest.fn(),
@@ -12,6 +13,11 @@ jest.mock('../utils', () => ({
1213
describe('UploadScopedVariables', () => {
1314
describe('UploadScopedVariables', () => {
1415
it('should download template when download template button is clicked', () => {
16+
const downloadTemplateData = importComponentFromFELibrary(
17+
'SCOPED_VARIABLES_TEMPLATE_DATA',
18+
SCOPED_VARIABLES_TEMPLATE_DATA,
19+
'function',
20+
)
1521
const { container } = render(
1622
<UploadScopedVariables
1723
reloadScopedVariables={() => {}}
@@ -20,11 +26,7 @@ describe('UploadScopedVariables', () => {
2026
/>,
2127
)
2228
fireEvent.click(container.querySelector('button')!)
23-
expect(downloadData).toHaveBeenCalledWith(
24-
SCOPED_VARIABLES_TEMPLATE_DATA,
25-
DOWNLOAD_TEMPLATE_NAME,
26-
DOWNLOAD_FILES_AS,
27-
)
29+
expect(downloadData).toHaveBeenCalledWith(downloadTemplateData, DOWNLOAD_TEMPLATE_NAME, DOWNLOAD_FILES_AS)
2830
})
2931

3032
it('should read file when file is uploaded', () => {

src/components/scopedVariables/constants.tsx

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const DOWNLOAD_FILE_NAME = 'variables.yaml'
1010
export const DOWNLOAD_TEMPLATE_NAME = 'variables-template.yaml'
1111
export const DOWNLOAD_FILES_AS = 'application/x-yaml'
1212
export const DROPDOWN_ITEMS = ['Download saved file', 'Download template']
13-
export const TABLE_LIST_HEADINGS = ['VARIABLE NAMES', 'DESCRIPTION', 'VALUE IS']
13+
export const TABLE_LIST_HEADINGS = ['VARIABLE NAME', 'DESCRIPTION', 'VALUE IS']
1414

1515
// File Reader error messages
1616
export const PARSE_ERROR_STATUS = {
@@ -55,67 +55,19 @@ export const UPLOAD_FAILED_STANDARD_MESSAGE = 'Invalid file content'
5555
export const SCOPED_VARIABLES_TEMPLATE_DATA = `apiVersion: devtron.ai/v1beta1
5656
kind: Variable
5757
spec:
58-
- description: Sample Variable 1
59-
name: variableNew1
60-
values:
61-
- category: ApplicationEnv
62-
value: test-app-env
63-
selectors:
64-
attributeSelectors:
65-
ApplicationName: dev-test
66-
EnvName: dev
67-
- category: Env
68-
value: 'null'
69-
selectors:
70-
attributeSelectors:
71-
EnvName: dev
72-
- category: Env
73-
value: 'null'
74-
selectors:
75-
attributeSelectors:
76-
EnvName: virtual-env-1
77-
- category: Cluster
78-
value: test-cluster
79-
selectors:
80-
attributeSelectors:
81-
ClusterName: default_cluster
82-
- category: Global
83-
value: test-global
84-
selectors: null
85-
- description: 'Sample Variable 2'
86-
name: variableNew2
87-
values:
88-
- category: ApplicationEnv
89-
value: test-app-env
90-
selectors:
91-
attributeSelectors:
92-
ApplicationName: dev-test
93-
EnvName: dev
94-
- category: ApplicationEnv
95-
value: test-app-env
96-
selectors:
97-
attributeSelectors:
98-
ApplicationName: dev-test
99-
EnvName: virtual-env-1
100-
- category: Application
101-
value: test-app
102-
selectors:
103-
attributeSelectors:
104-
ApplicationName: dev-test
105-
- category: Env
106-
value: test-env
107-
selectors:
108-
attributeSelectors:
109-
EnvName: dev
110-
- category: Cluster
111-
value: test-cluster
112-
selectors:
113-
attributeSelectors:
114-
ClusterName: default_cluster
115-
- category: Global
116-
value: test-global
117-
selectors: null
118-
`
58+
# Name of the variable, must be unique
59+
- name: KAFKA
60+
#Provide a short description for this variable in max 120 characters. This description will be shown in UI while using the variable.
61+
shortDescription: Enter a short description here
62+
# Mention notes that tell more about this variable. This will not be shown in UI while using the variable. No char limit.
63+
notes: Enter any notes for additional details
64+
# Optional property. Accepts Boolean Value, default value false. Values for sensitive variables are not shown in UI while using the variable
65+
isSensitive: false
66+
# List of values for this variable
67+
values:
68+
#Global category can be used to define variables which are common across all applications
69+
- category: Global
70+
value: Global`
11971

12072
// TOAST Messages while saving file
12173
export const SAVE_SUCCESS_TOAST_MESSAGE = 'File saved successfully'
@@ -129,5 +81,5 @@ export const NO_VARIABLES_MESSAGE = {
12981
}
13082

13183
export const NO_DESCRIPTION_MESSAGE = 'No description'
132-
export const SENSITIVE_VARIABLE_DESCRIPTION = 'Value is sensitive & hidden while using this variable'
133-
export const IN_SENSITIVE_VARIABLE_DESCRIPTION = 'Value is not sensitive & visible while using this variable'
84+
export const SENSITIVE_VARIABLE_DESCRIPTION = 'Value is sensitive & will be hidden while using this variable'
85+
export const IN_SENSITIVE_VARIABLE_DESCRIPTION = 'Value is not sensitive & will be visible while using this variable'

src/components/scopedVariables/mocks.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ export const validScopedVariablesData = {
2727
},
2828
],
2929
},
30-
jsonSchema:
31-
'{\n "$schema": "https://json-schema.org/draft/2020-12/schema",\n "$id": "https://github.com/devtron-labs/devtron/pkg/variables/models/scoped-variable-manifest",\n "$ref": "#/$defs/ScopedVariableManifest",\n "$defs": {\n "ScopedVariableManifest": {\n "properties": {\n "apiVersion": {\n "type": "string"\n },\n "kind": {\n "type": "string"\n },\n "spec": {\n "items": {\n "$ref": "#/$defs/VariableSpec"\n },\n "type": "array"\n }\n },\n "additionalProperties": false,\n "type": "object",\n "required": [\n "apiVersion",\n "kind",\n "spec"\n ]\n },\n "Selector": {\n "properties": {\n "attributeSelectors": {\n "patternProperties": {\n ".*": {\n "type": "string"\n }\n },\n "type": "object"\n }\n },\n "additionalProperties": false,\n "type": "object",\n "required": [\n "attributeSelectors"\n ]\n },\n "VariableSpec": {\n "properties": {\n "notes": {\n "type": "string"\n },\n "shortDescription": {\n "type": "string"\n },\n "isSensitive": {\n "type": "boolean"\n },\n "name": {\n "type": "string"\n },\n "values": {\n "items": {\n "$ref": "#/$defs/VariableValueSpec"\n },\n "type": "array"\n }\n },\n "additionalProperties": false,\n "type": "object",\n "required": [\n "notes",\n "shortDescription",\n "isSensitive",\n "name",\n "values"\n ]\n },\n "VariableValueSpec": {\n "properties": {\n "category": {\n "type": "string"\n },\n "value": true,\n "selectors": {\n "$ref": "#/$defs/Selector"\n }\n },\n "additionalProperties": false,\n "type": "object",\n "required": [\n "category",\n "value"\n ]\n }\n }\n}',
30+
jsonSchema: `{}`
3231
},
3332
}
3433

3534
export const noScopedVariablesData = {
3635
result: {
3736
manifest: null,
38-
jsonSchema:
39-
'{\n "$schema": "https://json-schema.org/draft/2020-12/schema",\n "$id": "https://github.com/devtron-labs/devtron/pkg/variables/repository/payload",\n "$ref": "#/$defs/Payload",\n "$defs": {\n "AttributeValue": {\n "properties": {\n "variableValue": {\n "$ref": "#/$defs/VariableValue"\n },\n "attributeType": {\n "type": "string"\n },\n "attributeParams": {\n "patternProperties": {\n ".*": {\n "type": "string"\n }\n },\n "type": "object"\n }\n },\n "additionalProperties": false,\n "type": "object",\n "required": [\n "variableValue",\n "attributeType",\n "attributeParams"\n ]\n },\n "Definition": {\n "properties": {\n "varName": {\n "type": "string"\n },\n "dataType": {\n "type": "string"\n },\n "varType": {\n "type": "string"\n },\n "description": {\n "type": "string"\n }\n },\n "additionalProperties": false,\n "type": "object",\n "required": [\n "varName",\n "dataType",\n "varType",\n "description"\n ]\n },\n "Payload": {\n "properties": {\n "variables": {\n "items": {\n "$ref": "#/$defs/Variables"\n },\n "type": "array"\n }\n },\n "additionalProperties": false,\n "type": "object",\n "required": [\n "variables"\n ]\n },\n "VariableValue": {\n "properties": {\n "value": {\n "type": "string"\n }\n },\n "additionalProperties": false,\n "type": "object",\n "required": [\n "value"\n ]\n },\n "Variables": {\n "properties": {\n "definition": {\n "$ref": "#/$defs/Definition"\n },\n "attributeValue": {\n "items": {\n "$ref": "#/$defs/AttributeValue"\n },\n "type": "array"\n }\n },\n "additionalProperties": false,\n "type": "object",\n "required": [\n "definition",\n "attributeValue"\n ]\n }\n }\n}',
37+
jsonSchema: '{}'
4038
},
4139
code: 200,
4240
}

src/css/base.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,11 @@ button.anchor {
19671967

19681968
.dc__border-bottom-v2 {
19691969
border-bottom: solid 1px var(--V200);
1970-
}
1970+
}
1971+
1972+
.dc__border-bottom-r2 {
1973+
border-bottom: 1px solid var(--R200);
1974+
}
19711975

19721976
.dc__border-bottom-imp {
19731977
border-bottom: solid 1px var(--N200) !important;

0 commit comments

Comments
 (0)