Skip to content

Commit 568fef9

Browse files
committed
feat: integrate bulk edit dryrun & post apis
1 parent 5d8bc3a commit 568fef9

File tree

3 files changed

+38
-68
lines changed

3 files changed

+38
-68
lines changed

src/components/bulkEdits/BulkEdits.tsx

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
MODES,
3535
Icon,
3636
GenericSectionErrorState,
37+
ResponseType,
38+
BulkEditConfigV2Type,
3739
} from '@devtron-labs/devtron-fe-common-lib'
3840
import { SERVER_MODE, ViewType } from '../../config'
3941
import { BulkEditsProps, BulkEditsState, BulkEditVersion } from './bulkEdits.type'
@@ -53,10 +55,6 @@ import { importComponentFromFELibrary } from '@Components/common'
5355
const getBulkEditConfig = importComponentFromFELibrary('getBulkEditConfig', null, 'function')
5456

5557
const ReadmeVersionOptions = [
56-
{
57-
label: 'v1beta1/application',
58-
value: BulkEditVersion.v1,
59-
},
6058
...(getBulkEditConfig
6159
? [
6260
{
@@ -65,6 +63,10 @@ const ReadmeVersionOptions = [
6563
},
6664
]
6765
: []),
66+
{
67+
label: 'v1beta1/application',
68+
value: BulkEditVersion.v1,
69+
},
6870
]
6971

7072
export default class BulkEdits extends Component<BulkEditsProps, BulkEditsState> {
@@ -77,7 +79,6 @@ export default class BulkEdits extends Component<BulkEditsProps, BulkEditsState>
7779
outputResult: undefined,
7880
impactedObjects: undefined,
7981
isReadmeLoading: true,
80-
bulkConfig: [],
8182
readmeVersionOptions: ReadmeVersionOptions,
8283
selectedReadmeVersionOption: ReadmeVersionOptions[0],
8384
readmeResult: {
@@ -87,6 +88,7 @@ export default class BulkEdits extends Component<BulkEditsProps, BulkEditsState>
8788
showExamples: true,
8889
activeOutputTab: 'output',
8990
codeEditorPayload: undefined,
91+
schema: null,
9092
}
9193
}
9294

@@ -101,26 +103,26 @@ export default class BulkEdits extends Component<BulkEditsProps, BulkEditsState>
101103

102104
getInitialized() {
103105
Promise.allSettled([
104-
getBulkEditConfig?.().then(({ result: { readme } }) => {
105-
return readme
106-
}),
106+
(getBulkEditConfig?.() as Promise<ResponseType<BulkEditConfigV2Type>>).then(
107+
({ result: { readme, schema } }) => {
108+
this.setState({ schema })
109+
110+
return readme
111+
},
112+
),
107113
getSeeExample().then(({ result }) => {
108114
return result[0].readme
109115
}),
110-
])
111-
.then(([v2ReadmeResult, v1ReadmeResult]) => {
112-
const v2Readme = v2ReadmeResult.status === 'fulfilled' ? v2ReadmeResult.value : null
113-
const v1Readme = v1ReadmeResult.status === 'fulfilled' ? v1ReadmeResult.value : null
116+
]).then(([v2ReadmeResult, v1ReadmeResult]) => {
117+
const v2Readme = v2ReadmeResult.status === 'fulfilled' ? v2ReadmeResult.value : null
118+
const v1Readme = v1ReadmeResult.status === 'fulfilled' ? v1ReadmeResult.value : null
114119

115-
this.setState({
116-
isReadmeLoading: false,
117-
readmeResult: { [BulkEditVersion.v1]: v1Readme, [BulkEditVersion.v2]: v2Readme },
118-
})
119-
})
120-
.catch((error) => {
121-
showError(error)
122-
this.setState({ isReadmeLoading: false, statusCode: error.code })
120+
this.setState({
121+
isReadmeLoading: false,
122+
view: ViewType.FORM,
123+
readmeResult: { [BulkEditVersion.v1]: v1Readme, [BulkEditVersion.v2]: v2Readme },
123124
})
125+
})
124126
}
125127

126128
handleRunButton = () => {
@@ -248,12 +250,13 @@ export default class BulkEdits extends Component<BulkEditsProps, BulkEditsState>
248250

249251
return (
250252
<div className="dc__grid-rows-2 flex-grow-1 dc__overflow-hidden">
251-
<div className="dc__overflow-auto">
253+
<div className="dc__overflow-hidden">
252254
<CodeEditor
253255
mode={MODES.YAML}
254-
height="auto"
256+
height="100%"
255257
value={this.state.codeEditorPayload}
256258
onChange={this.handleConfigChange}
259+
validatorSchema={this.state.schema}
257260
/>
258261
</div>
259262
<div className="bulk-output-drawer bg__primary flexbox-col dc__overflow-auto">
@@ -449,7 +452,7 @@ export default class BulkEdits extends Component<BulkEditsProps, BulkEditsState>
449452
}
450453

451454
if (!readmeJson) {
452-
return <GenericSectionErrorState rootClassName='flex-grow-1' />
455+
return <GenericSectionErrorState rootClassName="flex-grow-1" />
453456
}
454457

455458
return (

src/components/bulkEdits/bulkEdits.type.tsx

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,6 @@ import { OptionType } from '@devtron-labs/devtron-fe-common-lib'
2020

2121
import { SERVER_MODE_TYPE } from '../../config'
2222

23-
export interface CodeEditorScript {
24-
apiVersion: string
25-
kind: string
26-
spec: {
27-
include: {
28-
names: string[]
29-
}
30-
exclude: {
31-
names: string[]
32-
}
33-
envId: number[]
34-
global: boolean
35-
deploymentTemplate: {
36-
spec: {
37-
patchJson: any
38-
}
39-
}
40-
configMap: {
41-
spec: {
42-
names: string[]
43-
patchJson: any
44-
}
45-
}
46-
secret: {
47-
spec: {
48-
names: string[]
49-
patchJson: any
50-
}
51-
}
52-
}
53-
}
54-
55-
export interface BulkConfiguration {
56-
operation: string
57-
script: CodeEditorScript
58-
readme: string
59-
}
60-
6123
export interface DTImpactedObjects {
6224
appId: number
6325
appName: string
@@ -122,9 +84,9 @@ export interface BulkEditsState {
12284
outputResult: BulkOutput
12385
showExamples: boolean
12486
activeOutputTab: 'output' | 'impacted'
125-
bulkConfig: BulkConfiguration[]
12687
codeEditorPayload: string
12788
selectedReadmeVersionOption: OptionType<BulkEditVersion>
89+
schema: Record<string, any> | null
12890
}
12991

13092
export interface OutputTabType {
@@ -140,6 +102,6 @@ export interface BulkEditsProps extends RouteComponentProps<{}> {
140102
}
141103

142104
export enum BulkEditVersion {
143-
v1 = 'v1beta1',
144-
v2 = 'v1beta2',
105+
v1 = 'batch/v1beta1',
106+
v2 = 'batch/v1beta2',
145107
}

src/components/bulkEdits/bulkedits.service.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616

1717
import { get, post } from '@devtron-labs/devtron-fe-common-lib'
1818

19+
import { importComponentFromFELibrary } from '@Components/common'
20+
1921
import { Routes } from '../../config'
2022
import { BulkEditVersion } from './bulkEdits.type'
2123

24+
const postBulkEditScript = importComponentFromFELibrary('postBulkEditScript', null, 'function')
25+
const dryRunBulkEditScript = importComponentFromFELibrary('dryRunBulkEditScript', null, 'function')
26+
2227
export function updateBulkList(request): Promise<any> {
2328
const { apiVersion } = request ?? {}
2429

25-
if (apiVersion === BulkEditVersion.v2) {
26-
// TODO
30+
if (apiVersion === BulkEditVersion.v2 && postBulkEditScript) {
31+
return postBulkEditScript(request)
2732
}
2833

2934
return post(Routes.BULK_EDIT_V1_BASEPATH, request)
@@ -32,8 +37,8 @@ export function updateBulkList(request): Promise<any> {
3237
export function updateImpactedObjectsList(request): Promise<any> {
3338
const { apiVersion } = request
3439

35-
if (apiVersion === BulkEditVersion.v2) {
36-
// TODO
40+
if (apiVersion === BulkEditVersion.v2 && dryRunBulkEditScript) {
41+
return dryRunBulkEditScript(request)
3742
}
3843

3944
return post(`${Routes.BULK_EDIT_V1_BASEPATH}/dryrun`, request)

0 commit comments

Comments
 (0)