Skip to content

Commit 55629dd

Browse files
whDongRuisunnywx
authored andcommitted
fix: Deploy app click submit button throw error when config file is empty (#324)
1 parent d9f3ec1 commit 55629dd

File tree

2 files changed

+29
-48
lines changed

2 files changed

+29
-48
lines changed

src/pages/Admin/Apps/Deploy/index.jsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default class AppDeploy extends Component {
9898
changeVersion,
9999
changeSubnet
100100
} = appDeployStore;
101+
const btnDisabled = isLoading || !configBasics.length || !runtimes.length;
101102

102103
return (
103104
<form
@@ -207,7 +208,7 @@ export default class AppDeploy extends Component {
207208
))}
208209

209210
<div className={styles.submitBtnGroup}>
210-
<Button type={`primary`} className={`primary`} htmlType="submit" disabled={isLoading}>
211+
<Button type={`primary`} className={`primary`} htmlType="submit" disabled={btnDisabled}>
211212
{t('Confirm')}
212213
</Button>
213214
<Button
@@ -237,6 +238,7 @@ export default class AppDeploy extends Component {
237238
changeRuntime,
238239
changeVersion
239240
} = appDeployStore;
241+
const btnDisabled = isLoading || !yamlConfig.length || !runtimes.length;
240242

241243
return (
242244
<form
@@ -249,7 +251,7 @@ export default class AppDeploy extends Component {
249251
<label className={styles.name}>Name</label>
250252
<Input
251253
className={styles.input}
252-
name="Name"
254+
name="name"
253255
type="text"
254256
maxLength="50"
255257
onChange={changeName}
@@ -279,20 +281,19 @@ export default class AppDeploy extends Component {
279281
</div>
280282

281283
<div className={styles.moduleTitle}>2. {t('Deploy Settings')}</div>
282-
{yamlConfig &&
283-
yamlConfig.map((conf, index) => (
284-
<YamlCell
285-
key={conf.name}
286-
name={conf.name}
287-
value={conf.value}
288-
index={index}
289-
className={styles.cellModule}
290-
changeCell={changeYmalCell}
291-
/>
292-
))}
284+
{yamlConfig.map((conf, index) => (
285+
<YamlCell
286+
key={conf.name}
287+
name={conf.name}
288+
value={conf.value}
289+
index={index}
290+
className={styles.cellModule}
291+
changeCell={changeYmalCell}
292+
/>
293+
))}
293294

294295
<div className={styles.submitBtnGroup}>
295-
<Button type={`primary`} className={`primary`} htmlType="submit" disabled={isLoading}>
296+
<Button type={`primary`} className={`primary`} htmlType="submit" disabled={btnDisabled}>
296297
{t('Confirm')}
297298
</Button>
298299
<Button

src/stores/app/deploy.js

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class AppDeployStore extends Store {
1616
cluster: {},
1717
env: {}
1818
};
19-
@observable Name = '';
19+
@observable name = '';
2020
@observable isKubernetes = false;
2121
@observable paramsData = '';
2222
@observable configBasics = [];
@@ -58,7 +58,7 @@ export default class AppDeployStore extends Store {
5858

5959
@action
6060
changeName = event => {
61-
this.Name = event.target.value;
61+
this.name = event.target.value;
6262
};
6363

6464
@action
@@ -87,14 +87,8 @@ export default class AppDeployStore extends Store {
8787
let conf = null;
8888

8989
if (this.isKubernetes) {
90-
//this.checkResult = 'ok';
91-
let yamlObj = unflattenObject(this.yamlObj);
92-
/*this.yamlConfig.map(config => {
93-
if (typeof config.value === 'string' && !config.value) {
94-
this.checkResult = config.name;
95-
}
96-
});*/
97-
yamlObj.Name = this.Name;
90+
const yamlObj = unflattenObject(this.yamlObj);
91+
yamlObj.name = this.name;
9892
conf = yaml.safeDump(yamlObj);
9993
} else {
10094
this.getConfigData();
@@ -165,35 +159,26 @@ export default class AppDeployStore extends Store {
165159
this.configData = { cluster, env };
166160
};
167161

168-
changeConfigData = (item, root, parent) => {
169-
let location = '{{.';
170-
if (parent) {
171-
location += root + '.' + parent + '.' + item.key + '}}';
172-
} else {
173-
location += root + '.' + item.key + '}}';
174-
}
175-
if (item.type === 'integer') item.default = parseInt(item.default);
176-
this.paramsData = this.paramsData.replace(location, item.default);
177-
};
178-
179162
@action
180-
async fetchVersions(params = {}, flag) {
181-
//this.isLoading = true;
163+
fetchVersions = async (params = {}, flag) => {
182164
const result = await this.request.get('app_versions', params);
183165
this.versions = get(result, 'app_version_set', []);
184166
this.versionId = get(this.versions[0], 'version_id');
185-
//if (!flag) this.isLoading = false;
186-
if (flag) await this.fetchFiles(get(this.versions[0], 'version_id'));
187-
}
167+
if (flag) {
168+
await this.fetchFiles(get(this.versions[0], 'version_id'));
169+
}
170+
};
188171

189172
@action
190173
fetchRuntimes = async (params = {}) => {
191174
this.isLoading = true;
192175
const result = await this.request.get('runtimes', params);
193176
this.runtimes = get(result, 'runtime_set', []);
194-
if (this.runtimes.length && this.runtimes[0]) {
177+
if (this.runtimes.length > 0) {
195178
this.runtimeId = this.runtimes[0].runtime_id;
196-
if (!this.isKubernetes) await this.fetchSubnets(this.runtimes[0].runtime_id);
179+
if (!this.isKubernetes) {
180+
await this.fetchSubnets(this.runtimeId);
181+
}
197182
} else {
198183
this.info('Not find Runtime data!');
199184
}
@@ -204,12 +189,7 @@ export default class AppDeployStore extends Store {
204189
async fetchSubnets(runtimeId) {
205190
const result = await this.request.get(`clusters/subnets`, { runtime_id: runtimeId });
206191
this.subnets = get(result, 'subnet_set', []);
207-
let arrSubnets = this.subnets.toJSON();
208-
if (arrSubnets[0]) {
209-
this.subnetId = arrSubnets[0].subnet_id;
210-
} else {
211-
this.subnetId = '';
212-
}
192+
this.subnetId = this.subnets[0] ? this.subnets[0].subnet_id : '';
213193
}
214194

215195
@action

0 commit comments

Comments
 (0)