Skip to content

Commit

Permalink
Feat: support list and create project (#254)
Browse files Browse the repository at this point in the history
* Feat: support list and create project

Signed-off-by: barnettZQG <[email protected]>

* Fix: fix change project not query target bug

Signed-off-by: barnettZQG <[email protected]>
  • Loading branch information
barnettZQG authored Dec 8, 2021
1 parent b9e9314 commit e4630e7
Show file tree
Hide file tree
Showing 29 changed files with 293 additions and 231 deletions.
2 changes: 1 addition & 1 deletion src/api/devLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const application_mock = '/mock/application.json';
export const addons_mock = '/mock/addonsList.json';
export const cluster_mock = '/mock/cluster.json';
export const workflows_mock = '/mock/workflows.json';
export const namespace_mock = '/mock/namespacelist.json';
export const project_mock = '/mock/projectlist.json';

export const addonsDetails_mock = '/mock/addonsDetails.json';
export const disabletAddonsCluster_mock = '/mock/disabletAddonsCluster.json';
Expand Down
21 changes: 0 additions & 21 deletions src/api/namespace.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/api/productionLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export const addons = `/api/v1/addons`;
export const addonRegistrys = `/api/v1/addon_registries`;
export const cluster = '/api/v1/clusters';
export const workflows = '/api/v1/applications';
export const namespace = `/api/v1/namespaces`;
export const deliveryTarget = `/api/v1/deliveryTargets`;
export const project = `/api/v1/projects`;
export const target = `/api/v1/targets`;
16 changes: 16 additions & 0 deletions src/api/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { post, get } from './request';
import { project_mock } from './devLink';
import { project } from './productionLink';
import { getDomain } from '../utils/common';

const baseURLOject = getDomain();
const isMock = baseURLOject.MOCK;
const url = isMock ? project_mock : project;

export function getProjectList(params: any) {
return get(url, params).then((res) => res);
}

export function createProject(params: any) {
return post(url, params).then((res) => res);
}
10 changes: 5 additions & 5 deletions src/api/deliveryTarget.ts → src/api/target.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { post, get, rdelete, put } from './request';
import { getDeliveryTarget_mock } from './devLink';
import { deliveryTarget } from './productionLink';
import { target } from './productionLink';
import { getDomain } from '../utils/common';
import type { DeliveryTarget } from '../interface/deliveryTarget';
import type { QueryDeliveryTarget } from '../model/deliveryTarget';
Expand All @@ -9,21 +9,21 @@ const baseURLOject = getDomain();
const isMock = baseURLOject.MOCK;

export function getDeliveryTarget(params: QueryDeliveryTarget) {
const url = isMock ? getDeliveryTarget_mock : deliveryTarget;
const url = isMock ? getDeliveryTarget_mock : target;
return get(url, { params: params }).then((res) => res);
}

export function createDeliveryTarget(params: DeliveryTarget) {
const url = isMock ? getDeliveryTarget_mock : deliveryTarget;
const url = isMock ? getDeliveryTarget_mock : target;
return post(url, params);
}

export function deleteDeliveryTarget(params: { name: string }) {
const url = isMock ? getDeliveryTarget_mock : `${deliveryTarget}/${params.name}`;
const url = isMock ? getDeliveryTarget_mock : `${target}/${params.name}`;
return rdelete(url, params);
}

export function updateDeliveryTarget(params: DeliveryTarget) {
const url = isMock ? getDeliveryTarget_mock : `${deliveryTarget}/${params.name}`;
const url = isMock ? getDeliveryTarget_mock : `${target}/${params.name}`;
return put(url, params);
}
8 changes: 8 additions & 0 deletions src/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,11 @@ a {
.monaco-editor {
min-height: 400px;
}

.next-btn.next-large {
padding: 0 16px !important;
}

.next-btn.next-large.isOnlyIcon {
width: auto !important;
}
2 changes: 2 additions & 0 deletions src/components/EnvPlan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Props = {
t: (key: string) => string;
onUpdateTarget: () => void;
projects: Project[];
syncProjectList: () => void;
clusterList: Cluster[];
};

Expand Down Expand Up @@ -271,6 +272,7 @@ export default class EnvPlan extends React.Component<Props, State> {
this.props.onUpdateTarget();
this.setState({ showAddTarget: false });
}}
syncProjectList={this.props.syncProjectList}
projects={projects || []}
clusterList={clusterList || []}
project={project}
Expand Down
3 changes: 2 additions & 1 deletion src/interface/application.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { DeliveryTarget } from './deliveryTarget';
import type { Project } from './project';

export interface ApplicationDetail {
name: string;
alias?: string;
namespace: string;
project?: Project;
description?: string;
createTime?: string;
updateTime?: string;
Expand Down
4 changes: 3 additions & 1 deletion src/interface/deliveryTarget.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { Project } from './project';

export type DeliveryTarget = {
id?: string;
name: string;
alias?: string;
namespace?: string;
project?: Project;
description?: string;
cluster?: {
clusterName?: string;
Expand Down
4 changes: 3 additions & 1 deletion src/interface/project.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface Project {
name: string;
description: string;
alias?: string;
description?: string;
namespace: string;
createTime?: string;
updateTime?: string;
}
6 changes: 3 additions & 3 deletions src/layout/Application/components/AddEnvBind/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ApplicationDetail } from '../../../../interface/application';
import { createApplicationEnv } from '../../../../api/application';
import Translation from '../../../../components/Translation';
import { checkName } from '../../../../utils/common';
import { getDeliveryTarget } from '../../../../api/deliveryTarget';
import { getDeliveryTarget } from '../../../../api/target';
import type { DeliveryTarget } from '../../../../interface/deliveryTarget';
import locale from '../../../../utils/locale';

Expand Down Expand Up @@ -41,8 +41,8 @@ class EnvBindPlanDialog extends Component<Props, State> {
loadDeliveryTargets = async () => {
const { applicationDetail } = this.props;
if (applicationDetail) {
getDeliveryTarget({ namespace: applicationDetail?.namespace, page: 0 }).then((re) => {
this.setState({ targetList: re.deliveryTargets });
getDeliveryTarget({ project: applicationDetail?.project?.name, page: 0 }).then((re) => {
this.setState({ targetList: re.targets });
});
}
};
Expand Down
18 changes: 9 additions & 9 deletions src/layout/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export default function Content() {
exact
path="/"
render={() => {
return <Redirect to="/applications"></Redirect>;
return <Redirect to="/applications" />;
}}
/>
<Route exact path="/applications" component={Application} />
<Route
exact
path="/applications/:appName"
render={(props: any) => {
return <Redirect to={`/applications/${props.match.params.appName}/config`}></Redirect>;
return <Redirect to={`/applications/${props.match.params.appName}/config`} />;
}}
/>
<Route
Expand All @@ -36,7 +36,7 @@ export default function Content() {
render={(props: any) => {
return (
<ApplicationLayout {...props}>
<ApplicationConfig {...props}></ApplicationConfig>
<ApplicationConfig {...props} />
</ApplicationLayout>
);
}}
Expand All @@ -47,7 +47,7 @@ export default function Content() {
render={(props: any) => {
return (
<ApplicationLayout {...props}>
<ApplicationWorkflow {...props}></ApplicationWorkflow>
<ApplicationWorkflow {...props} />
</ApplicationLayout>
);
}}
Expand All @@ -58,7 +58,7 @@ export default function Content() {
render={(props: any) => {
return (
<ApplicationLayout {...props}>
<ApplicationRevisionList {...props}></ApplicationRevisionList>
<ApplicationRevisionList {...props} />
</ApplicationLayout>
);
}}
Expand All @@ -70,7 +70,7 @@ export default function Content() {
return (
<Redirect
to={`/applications/${props.match.params.appName}/envbinding/${props.match.params.envName}/instances`}
></Redirect>
/>
);
}}
/>
Expand All @@ -80,7 +80,7 @@ export default function Content() {
render={(props: any) => {
return (
<ApplicationLayout {...props}>
<ApplicationInstanceList {...props}></ApplicationInstanceList>
<ApplicationInstanceList {...props} />
</ApplicationLayout>
);
}}
Expand All @@ -91,12 +91,12 @@ export default function Content() {
render={(props: any) => {
return (
<ApplicationLayout {...props}>
<ApplicationMonitor {...props}></ApplicationMonitor>
<ApplicationMonitor {...props} />
</ApplicationLayout>
);
}}
/>
<Route path="/deliveryTargets" component={DeliveryTargetList} />
<Route path="/targets" component={DeliveryTargetList} />
<Route path="/clusters" component={Clusters} />
<Route path="/addons" component={Addons} />
<Route path="/notFound" component={NotFound} />
Expand Down
2 changes: 1 addition & 1 deletion src/layout/LeftMenu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function getLeftSider(pathname) {
},
{
className: isDeliveryTargetURL,
link: '/deliveryTargets',
link: '/targets',
iconType: 'box',
navName: 'Targets',
},
Expand Down
9 changes: 5 additions & 4 deletions src/model/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

import { listWorkFlow } from '../api/workflows';

import { getNamespaceList } from '../api/namespace';
import { getProjectList } from '../api/project';

export default {
namespace: 'application',
Expand Down Expand Up @@ -108,17 +108,18 @@ export default {
action.callback(appContent);
}
},

*createApplicationPlan(action, { call, put }) {
const result = yield call(createApplication, action.payload);
if (action.callback && result) {
action.callback(result);
}
},

*getProjectList(action, { call, put }) {
// use namespace data as projects
const result = yield call(getNamespaceList, action.payload);
const result = yield call(getProjectList, action.payload);
if (result) {
yield put({ type: 'updateProjectList', payload: result.namespaces });
yield put({ type: 'updateProjectList', payload: result.projects });
}
},

Expand Down
10 changes: 5 additions & 5 deletions src/model/deliveryTarget.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getDeliveryTarget, createDeliveryTarget } from '../api/deliveryTarget';
import { getDeliveryTarget, createDeliveryTarget } from '../api/target';

export interface QueryDeliveryTarget {
query?: string;
page?: number;
pageSize?: number;
namespace?: string;
project?: string;
}

interface DeliveryTargetState {
Expand Down Expand Up @@ -60,12 +60,12 @@ const DeliveryTargets: ModelsType = {
reducers: {
updateDeliveryTargets(
state: DeliveryTargetState,
{ payload }: { payload: { deliveryTargets: {}; total: number } },
{ payload }: { payload: { targets: {}; total: number } },
) {
const { deliveryTargets = [], total = 0 } = payload;
const { targets = [], total = 0 } = payload;
return {
...state,
deliveryTargets,
deliveryTargets: targets,
total,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class EditProperties extends React.Component<Props, State> {
});
dispatch({
type: 'uischema/setAppNamespace',
payload: applicationDetail?.namespace,
payload: applicationDetail?.project?.namespace,
});
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/ApplicationConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ class ApplicationConfig extends Component<Props, State> {
<Col span={12}>
<Item
label={<Translation>Project</Translation>}
value={applicationDetail && applicationDetail.namespace}
value={
applicationDetail &&
(applicationDetail.project?.alias
? applicationDetail.project?.alias
: applicationDetail.project?.name)
}
/>
</Col>
</Row>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ApplicationInstanceList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ApplicationInstanceList extends React.Component<Props, State> {
const conponentName = applicationStatus.services[0].name;
const param = {
appName: envs[0].appDeployName || appName + '-' + envName,
appNs: applicationDetail.namespace,
appNs: applicationDetail.project?.namespace || '',
name: conponentName,
cluster: '',
clusterNs: '',
Expand Down Expand Up @@ -234,7 +234,7 @@ class ApplicationInstanceList extends React.Component<Props, State> {
if (applicationDetail.applicationType == 'common') {
const param = {
appName: envs[0].appDeployName || appName + '-' + envName,
appNs: applicationDetail.namespace,
appNs: applicationDetail.project?.namespace || '',
name: conponentName,
cluster: '',
clusterNs: '',
Expand All @@ -261,7 +261,7 @@ class ApplicationInstanceList extends React.Component<Props, State> {
} else if (applicationDetail?.applicationType == 'cloud') {
const param = {
appName: envs[0].appDeployName || appName + '-' + envName,
appNs: applicationDetail.namespace,
appNs: applicationDetail.project?.namespace || '',
};
this.setState({ loading: true });
listCloudResources(param)
Expand Down
Loading

0 comments on commit e4630e7

Please sign in to comment.