diff --git a/.gitignore b/.gitignore
index 6a2215e3b..233c5e67d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-
# Binaries for programs and plugins
*.exe
*.exe~
@@ -39,3 +38,4 @@ dashboard/node_modules/
dashboard/package-lock.json
dashboard/src/.umi/
package-lock.json
+
diff --git a/dashboard/src/components/GlobalHeader/workSpaceDropDown.jsx b/dashboard/src/components/GlobalHeader/workSpaceDropDown.jsx
index 6bf3f2409..7f1e364ec 100644
--- a/dashboard/src/components/GlobalHeader/workSpaceDropDown.jsx
+++ b/dashboard/src/components/GlobalHeader/workSpaceDropDown.jsx
@@ -1,4 +1,4 @@
-import { Menu, Dropdown, Button } from 'antd';
+import { Menu, Dropdown, Button, message } from 'antd';
import { DownOutlined } from '@ant-design/icons';
import React from 'react';
import { connect } from 'dva';
@@ -15,29 +15,42 @@ export default class WorkSpaceDropDown extends React.Component {
async componentDidMount() {
const envs = await this.props.dispatch({
- type: 'applist/getEnvs', // applist对应models层的命名空间namespace
- });
- const { name = 'test' } = envs.find((a) => {
- return a.current === '*';
- });
- this.setState({
- envs,
- workSpaceName: name,
- });
- this.props.dispatch({
- type: 'globalData/currentEnv',
- payload: {
- currentEnv: name,
- },
+ type: 'envs/getEnvs', // applist对应models层的命名空间namespace
});
+ if (envs) {
+ const { name = 'test' } = envs.find((a) => {
+ return a.current === '*';
+ });
+ this.setState({
+ envs,
+ workSpaceName: name,
+ });
+ this.props.dispatch({
+ type: 'globalData/currentEnv',
+ payload: {
+ currentEnv: name,
+ },
+ });
+ }
}
- handleMenuClick = (e) => {
+ handleMenuClick = async (e) => {
+ // 发送切换envs的接口
+ const switchResult = await this.props.dispatch({
+ type: 'envs/switchEnv',
+ payload: {
+ currentEnv: e.key,
+ },
+ });
+ if (switchResult) {
+ message.success(switchResult);
+ }
this.setState(
{
workSpaceName: e.key,
},
() => {
+ // 值切换存储
this.props.dispatch({
type: 'globalData/currentEnv',
payload: {
diff --git a/dashboard/src/locales/en-US/menu.js b/dashboard/src/locales/en-US/menu.js
index 9b4362e4e..728f5cfae 100644
--- a/dashboard/src/locales/en-US/menu.js
+++ b/dashboard/src/locales/en-US/menu.js
@@ -13,7 +13,7 @@ export default {
'menu.Capability.Detail': 'Detail',
'menu.Workload': 'Workloads',
'menu.Workload.Deployment': 'Deployment',
- 'menu.Workload.Task': 'Task',
+ 'menu.Workload.Containerized': 'Containerized',
'menu.Workload.Detail': 'Detail',
'menu.Release': 'Release',
'menu.admin': 'Admin',
diff --git a/dashboard/src/models/getAppList.js b/dashboard/src/models/application.js
similarity index 87%
rename from dashboard/src/models/getAppList.js
rename to dashboard/src/models/application.js
index 47f6865ed..6bf29a7ba 100644
--- a/dashboard/src/models/getAppList.js
+++ b/dashboard/src/models/application.js
@@ -1,4 +1,4 @@
-import { getapplist, createApp, getEnvs } from '@/services/getAppList';
+import { getapplist, createApp } from '@/services/application';
const TestModel = {
namespace: 'applist',
@@ -22,10 +22,6 @@ const TestModel = {
const res = yield call(createApp, payload);
return res;
},
- *getEnvs({ payload }, { call }) {
- const res = yield call(getEnvs, payload);
- return res;
- },
},
reducers: {
addList(state, { payload: { returnObj } }) {
diff --git a/dashboard/src/models/env.js b/dashboard/src/models/env.js
new file mode 100644
index 000000000..938b8fd5f
--- /dev/null
+++ b/dashboard/src/models/env.js
@@ -0,0 +1,20 @@
+import { getEnvs, switchEnv } from '@/services/env';
+
+const TestModel = {
+ namespace: 'envs',
+ state: {
+ // initailState: '8880'
+ },
+ effects: {
+ *getEnvs({ payload }, { call }) {
+ const res = yield call(getEnvs, payload);
+ return res;
+ },
+ *switchEnv({ payload }, { call }) {
+ const res = yield call(switchEnv, payload);
+ return res;
+ },
+ },
+ reducers: {},
+};
+export default TestModel;
diff --git a/dashboard/src/models/global.js b/dashboard/src/models/global.js
index ff10d9e8c..74cf45565 100644
--- a/dashboard/src/models/global.js
+++ b/dashboard/src/models/global.js
@@ -1,7 +1,7 @@
const globalModel = {
namespace: 'globalData',
state: {
- currentEnv: 'test',
+ currentEnv: '',
},
effects: {
*currentEnv({ payload }, { put }) {
diff --git a/dashboard/src/models/trait.js b/dashboard/src/models/trait.js
new file mode 100644
index 000000000..9a6e25d83
--- /dev/null
+++ b/dashboard/src/models/trait.js
@@ -0,0 +1,20 @@
+import { getTraitByName, getTraits } from '@/services/trait.js';
+
+const TestModel = {
+ namespace: 'trait',
+ state: {
+ // initailState: '8880'
+ },
+ effects: {
+ *getTraitByName({ payload }, { call }) {
+ const res = yield call(getTraitByName, payload);
+ return res;
+ },
+ *getTraits({ payload }, { call }) {
+ const res = yield call(getTraits, payload);
+ return res;
+ },
+ },
+ reducers: {},
+};
+export default TestModel;
diff --git a/dashboard/src/models/workload.js b/dashboard/src/models/workload.js
new file mode 100644
index 000000000..22390aa6a
--- /dev/null
+++ b/dashboard/src/models/workload.js
@@ -0,0 +1,24 @@
+import { createWorkload, getWorkload, getWorkloadByName } from '@/services/workload.js';
+
+const TestModel = {
+ namespace: 'workload',
+ state: {
+ // initailState: '8880'
+ },
+ effects: {
+ *createWorkload({ payload }, { call }) {
+ const res = yield call(createWorkload, payload);
+ return res;
+ },
+ *getWorkload({ payload }, { call }) {
+ const res = yield call(getWorkload, payload);
+ return res;
+ },
+ *getWorkloadByName({ payload }, { call }) {
+ const res = yield call(getWorkloadByName, payload);
+ return res;
+ },
+ },
+ reducers: {},
+};
+export default TestModel;
diff --git a/dashboard/src/pages/Addon/index.jsx b/dashboard/src/pages/Addon/index.jsx
deleted file mode 100644
index 8a646e83c..000000000
--- a/dashboard/src/pages/Addon/index.jsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import React from "react";
-import { PageContainer } from "@ant-design/pro-layout";
-
-class TableList extends React.Component {
- render() {
- return (
-
-
- Addon
-
-
- );
- }
-}
-
-export default TableList;
\ No newline at end of file
diff --git a/dashboard/src/pages/ApplicationList/CreateApplication/index.jsx b/dashboard/src/pages/ApplicationList/CreateApplication/index.jsx
index cb8a2d1d0..5ff489cb2 100644
--- a/dashboard/src/pages/ApplicationList/CreateApplication/index.jsx
+++ b/dashboard/src/pages/ApplicationList/CreateApplication/index.jsx
@@ -1,9 +1,11 @@
-import React from 'react';
+import React, { Fragment } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import './index.less';
-import { Button, Row, Col, Form, Input, Select, Steps } from 'antd';
+import { Button, Row, Col, Form, Input, Select, Steps, message } from 'antd';
import { connect } from 'dva';
import { Link } from 'umi';
+import _ from 'lodash';
+import CreateTraitItem from '../createTrait/index.jsx';
const { Option } = Select;
const { Step } = Steps;
@@ -17,42 +19,93 @@ const layout = {
},
};
-@connect(() => ({}))
+@connect(({ loading, globalData }) => ({
+ loadingAll: loading.models.workload,
+ currentEnv: globalData.currentEnv,
+}))
class TableList extends React.Component {
formRefStep1 = React.createRef();
- formRefStep2 = React.createRef();
+ formRefStep2All = React.createRef();
constructor(props) {
super(props);
this.state = {
current: 0,
isShowMore: false,
- traitNum: [1],
+ traitNum: [
+ {
+ refname: null,
+ initialData: {},
+ },
+ ],
+ traitList: [],
+ availableTraitList: [],
+ workloadList: [],
+ workloadSettings: [],
step1InitialValues: {
- WorkloadType: 'Deployment',
- },
- step2InitialValues: {
- TraitType0: 'Autoscaling',
+ workload_type: '',
},
+ step1Settings: [],
};
}
UNSAFE_componentWillMount() {
- if (this.props.location.state) {
- const WorkloadType = this.props.location.state.WorkloadType || 'Deployment';
- const TraitType = this.props.location.state.TraitType || 'Autoscaling';
- const activeStep = this.props.location.state.activeStep || 0;
- const tempState1 = { ...this.state.step1InitialValues, WorkloadType };
- const tempState2 = { ...this.state.step2InitialValues, TraitType0: TraitType };
- this.setState(() => ({
- current: activeStep,
- step1InitialValues: tempState1,
- step2InitialValues: tempState2,
- }));
- }
+ const activeStep = _.get(this.props, 'location.state.activeStep', 0);
+ this.setState(() => ({
+ current: activeStep,
+ }));
}
+ componentDidMount() {
+ this.getInitalData();
+ }
+
+ getInitalData = async () => {
+ const res = await this.props.dispatch({
+ type: 'workload/getWorkload',
+ });
+ const traits = await this.props.dispatch({
+ type: 'trait/getTraits',
+ });
+ this.setState({
+ traitList: traits,
+ });
+ // 如果直接跳转到第二步,需要设置值
+ const traitType = _.get(this.props, 'location.state.TraitType', '');
+ if (traitType) {
+ // let availableTraitList = traits.filter((item)=>{
+ // return item.name === traitType
+ // })
+ this.setState({
+ availableTraitList: traits,
+ traitNum: [
+ {
+ refname: null,
+ initialData: { name: traitType },
+ },
+ ],
+ });
+ }
+
+ if (Array.isArray(res) && res.length) {
+ this.setState(
+ () => ({
+ workloadList: res,
+ }),
+ () => {
+ if (this.state.current === 0) {
+ const WorkloadType = _.get(this.props, 'location.state.WorkloadType', '');
+ this.formRefStep1.current.setFieldsValue({
+ workload_type: WorkloadType || this.state.workloadList[0].name,
+ });
+ this.workloadTypeChange(this.state.workloadList[0].name);
+ }
+ },
+ );
+ }
+ };
+
onFinishStep1 = (values) => {
this.setState({
current: 1,
@@ -61,11 +114,17 @@ class TableList extends React.Component {
});
};
- onFinishStep2 = (values) => {
- this.setState({
- current: 2,
- step2InitialValues: values,
+ onFinishStep2 = () => {
+ const newTraitNum = this.state.traitNum.map((item) => {
+ // eslint-disable-next-line no-param-reassign
+ item.initialData = item.refname.getSelectValue();
+ return item;
});
+ // 进行trait数据整理,便于第三步展示
+ this.setState(() => ({
+ traitNum: newTraitNum,
+ current: 2,
+ }));
};
gotoStep2 = () => {
@@ -90,22 +149,103 @@ class TableList extends React.Component {
addMore = (e) => {
e.preventDefault();
this.setState((prev) => ({
- traitNum: prev.traitNum.concat([1]),
+ traitNum: prev.traitNum.concat([
+ {
+ refname: null,
+ initialData: {},
+ },
+ ]),
}));
};
- createApp = async () => {
- await this.props.dispatch({
- type: 'applist/createApp', // applist对应models层的命名空间namespace
+ createApp = () => {};
+
+ createWorkload = async () => {
+ await this.formRefStep1.current.validateFields();
+ const currentData = this.formRefStep1.current.getFieldsValue();
+ const submitObj = {
+ env_name: this.props.currentEnv,
+ workload_type: currentData.workload_type,
+ workload_name: currentData.workload_name,
+ flags: [],
+ };
+ Object.keys(currentData).forEach((key) => {
+ if (key !== 'workload_name' && key !== 'workload_type' && currentData[key]) {
+ submitObj.flags.push({
+ name: key,
+ value: currentData[key].toString(),
+ });
+ }
+ });
+ const res = await this.props.dispatch({
+ type: 'workload/createWorkload',
payload: {
- a: 1,
- b: 3,
+ params: submitObj,
},
});
+ if (res) {
+ message.success(res);
+ }
+ this.setState({
+ current: 1,
+ step1InitialValues: currentData,
+ step1Settings: submitObj.flags,
+ });
+ this.getAcceptTrait(currentData.workload_type);
+ };
+
+ workloadTypeChange = (value) => {
+ const content = this.formRefStep1.current.getFieldsValue();
+ this.formRefStep1.current.resetFields();
+ const initialObj = {
+ workload_type: content.workload_type,
+ workload_name: content.workload_name,
+ };
+ this.formRefStep1.current.setFieldsValue(initialObj);
+ const currentWorkloadSetting = this.state.workloadList.filter((item) => {
+ return item.name === value;
+ });
+ if (currentWorkloadSetting.length) {
+ this.setState(
+ {
+ workloadSettings: currentWorkloadSetting[0].parameters,
+ },
+ () => {
+ this.state.workloadSettings.forEach((item) => {
+ if (item.default) {
+ initialObj[item.name] = item.default;
+ }
+ });
+ this.formRefStep1.current.setFieldsValue(initialObj);
+ },
+ );
+ }
+ this.setState({
+ traitNum: [
+ {
+ refname: null,
+ initialData: {},
+ },
+ ],
+ });
+ };
+
+ getAcceptTrait = (workloadType) => {
+ const res = this.state.traitList.filter((item) => {
+ if (item.appliesTo.indexOf(workloadType) !== -1) {
+ return true;
+ }
+ return false;
+ });
+ this.setState(() => ({
+ availableTraitList: res,
+ }));
};
render() {
- const { current, step1InitialValues, step2InitialValues, traitNum } = this.state;
+ const { current, step1InitialValues, traitNum, workloadSettings } = this.state;
+ let { workloadList } = this.state;
+ workloadList = Array.isArray(workloadList) ? workloadList : [];
let currentDetail;
if (current === 0) {
currentDetail = (
@@ -122,7 +262,7 @@ class TableList extends React.Component {
>
-
-