Skip to content

Commit 2d0a968

Browse files
authored
fix create service (#190)
* fix: destroy modal after create Signed-off-by: warjiang <[email protected]> * fix: update table field for ingress resource Signed-off-by: warjiang <[email protected]> * fix: delete service resources Signed-off-by: warjiang <[email protected]> --------- Signed-off-by: warjiang <[email protected]>
1 parent 3d0967b commit 2d0a968

File tree

6 files changed

+112
-24
lines changed

6 files changed

+112
-24
lines changed

ui/apps/dashboard/locales/en-US.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,10 @@
175175
"7afddf70e5c82fab8fa935458b53174a": "Add",
176176
"236513393327bd6b098056314f8676ac": "Edit Override Policy",
177177
"781a90424b3d02153bc979e0f90179aa": "{{name}} Detail",
178-
"1af8d577b89a4caf0e4b30734bbf7143": "Do you want to delete {{name}} Override Policy?"
178+
"1af8d577b89a4caf0e4b30734bbf7143": "Do you want to delete {{name}} Override Policy?",
179+
"1ed71b1211f5d2ba41e4a23331985c7c": "Failed to delete service",
180+
"04a691b377c91da599d5b4b62b0cb114": "create successfully",
181+
"a889286a51f3adab3cfb6913f2b0ac2e": "create failed",
182+
"55aa6366c0d09a392d8acf54c4c4b837": "update successfully",
183+
"930442e2f423436f9db3d8e91f648e93": "update failed"
179184
}

ui/apps/dashboard/locales/zh-CN.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,10 @@
174174
"7afddf70e5c82fab8fa935458b53174a": "新增覆盖策略",
175175
"236513393327bd6b098056314f8676ac": "编辑覆盖策略",
176176
"781a90424b3d02153bc979e0f90179aa": "{{name}} 策略详情",
177-
"1af8d577b89a4caf0e4b30734bbf7143": "确认要删除 {{name}} 覆盖策略么"
177+
"1af8d577b89a4caf0e4b30734bbf7143": "确认要删除 {{name}} 覆盖策略么",
178+
"1ed71b1211f5d2ba41e4a23331985c7c": "删除服务失败",
179+
"04a691b377c91da599d5b4b62b0cb114": "创建成功",
180+
"a889286a51f3adab3cfb6913f2b0ac2e": "创建失败",
181+
"55aa6366c0d09a392d8acf54c4c4b837": "更新成功",
182+
"930442e2f423436f9db3d8e91f648e93": "更新失败"
178183
}

ui/apps/dashboard/src/pages/multicloud-resource-manage/service/components/ingress-table.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ const IngressTable: FC<ServiceTableProps> = (props) => {
127127
title={i18nInstance.t('6163856192e115e6b914d6fb8c4fd82c', {
128128
name: r.objectMeta.name,
129129
})}
130-
onConfirm={async () => {}}
130+
onConfirm={() => {
131+
onDeleteIngressContent(r);
132+
}}
131133
okText={i18nInstance.t(
132134
'e83a256e4f5bb4ff8b3d804b5473217a',
133135
'确认',
@@ -147,7 +149,7 @@ const IngressTable: FC<ServiceTableProps> = (props) => {
147149
},
148150
];
149151
const { data, isLoading } = useQuery({
150-
queryKey: ['GetServices', selectedWorkSpace, searchText],
152+
queryKey: ['GetIngress', selectedWorkSpace, searchText],
151153
queryFn: async () => {
152154
const services = await GetIngress({
153155
namespace: selectedWorkSpace,
@@ -163,7 +165,7 @@ const IngressTable: FC<ServiceTableProps> = (props) => {
163165
}
164166
columns={columns}
165167
loading={isLoading}
166-
dataSource={data?.services || []}
168+
dataSource={data?.items || []}
167169
/>
168170
);
169171
};

ui/apps/dashboard/src/pages/multicloud-resource-manage/service/components/service-editor-modal.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ import i18nInstance from '@/utils/i18n';
1818
import { FC, useEffect, useState } from 'react';
1919
import { Form, Modal, Select } from 'antd';
2020
import Editor from '@monaco-editor/react';
21-
import { parse, stringify } from 'yaml';
21+
import { parse } from 'yaml';
2222
import _ from 'lodash';
23-
import { PutResource } from '@/services/unstructured';
24-
import { CreateDeployment } from '@/services/workload';
23+
import { CreateResource, PutResource } from '@/services/unstructured';
2524
import { IResponse, ServiceKind } from '@/services/base.ts';
2625
export interface NewWorkloadEditorModalProps {
2726
mode: 'create' | 'edit' | 'detail';
@@ -59,18 +58,17 @@ const ServiceEditorModal: FC<NewWorkloadEditorModalProps> = (props) => {
5958
try {
6059
const yamlObject = parse(content) as Record<string, string>;
6160
const kind = _.get(yamlObject, 'kind');
62-
const namespace = _.get(yamlObject, 'metadata.namespace');
61+
const namespace = _.get(yamlObject, 'metadata.namespace', 'default');
6362
const name = _.get(yamlObject, 'metadata.name');
6463
if (mode === 'create') {
65-
if (kind.toLowerCase() === 'deployment') {
66-
const ret = await CreateDeployment({
67-
namespace,
68-
name,
69-
content: stringify(yamlObject),
70-
});
71-
await onOk(ret);
72-
setContent('');
73-
}
64+
const ret = await CreateResource({
65+
kind,
66+
name,
67+
namespace: namespace,
68+
content: yamlObject,
69+
});
70+
await onOk(ret);
71+
setContent('');
7472
} else {
7573
const ret = await PutResource({
7674
kind,

ui/apps/dashboard/src/pages/multicloud-resource-manage/service/index.tsx

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
import i18nInstance from '@/utils/i18n';
1818
import Panel from '@/components/panel';
19-
import { Button, Input, Segmented, Select } from 'antd';
19+
import { App, Button, Input, Segmented, Select } from 'antd';
2020
import { ServiceKind } from '@/services/base';
2121
import { Icons } from '@/components/icons';
2222
import { useCallback, useState } from 'react';
@@ -26,6 +26,8 @@ import ServiceEditorModal from './components/service-editor-modal';
2626
import { stringify } from 'yaml';
2727
import IngressTable from '@/pages/multicloud-resource-manage/service/components/ingress-table';
2828
import useNamespace from '@/hooks/use-namespace.ts';
29+
import { useQueryClient } from '@tanstack/react-query';
30+
import { DeleteResource } from '@/services/unstructured.ts';
2931
const ServicePage = () => {
3032
const [filter, setFilter] = useState<{
3133
selectedWorkSpace: string;
@@ -53,6 +55,8 @@ const ServicePage = () => {
5355
content: '',
5456
});
5557
}, []);
58+
const { message: messageApi } = App.useApp();
59+
const queryClient = useQueryClient();
5660
return (
5761
<Panel>
5862
<div className={'flex flex-row justify-between mb-4'}>
@@ -153,7 +157,29 @@ const ServicePage = () => {
153157
});
154158
toggleShowModal(true);
155159
}}
156-
onDeleteServiceContent={() => {}}
160+
onDeleteServiceContent={async (r) => {
161+
try {
162+
const ret = await DeleteResource({
163+
kind: r.typeMeta.kind,
164+
name: r.objectMeta.name,
165+
namespace: r.objectMeta.namespace,
166+
});
167+
if (ret.code !== 200) {
168+
await messageApi.error(
169+
i18nInstance.t(
170+
'1ed71b1211f5d2ba41e4a23331985c7c',
171+
'删除服务失败',
172+
),
173+
);
174+
}
175+
await queryClient.invalidateQueries({
176+
queryKey: ['GetServices'],
177+
exact: false,
178+
});
179+
} catch (e) {
180+
console.log('error', e);
181+
}
182+
}}
157183
/>
158184
)}
159185
{filter.kind === ServiceKind.Ingress && (
@@ -168,16 +194,68 @@ const ServicePage = () => {
168194
});
169195
toggleShowModal(true);
170196
}}
171-
onDeleteIngressContent={() => {}}
197+
onDeleteIngressContent={async (r) => {
198+
try {
199+
const ret = await DeleteResource({
200+
kind: r.typeMeta.kind,
201+
name: r.objectMeta.name,
202+
namespace: r.objectMeta.namespace,
203+
});
204+
if (ret.code !== 200) {
205+
await messageApi.error(
206+
i18nInstance.t(
207+
'1ed71b1211f5d2ba41e4a23331985c7c',
208+
'删除服务失败',
209+
),
210+
);
211+
}
212+
await queryClient.invalidateQueries({
213+
queryKey: ['GetIngress'],
214+
exact: false,
215+
});
216+
} catch (e) {
217+
console.log('error', e);
218+
}
219+
}}
172220
/>
173221
)}
174222

175223
<ServiceEditorModal
176224
mode={editorState.mode}
177225
open={showModal}
178226
serviceContent={editorState.content}
179-
onOk={(ret) => {
180-
console.log(ret);
227+
onOk={async (ret) => {
228+
if (ret.code === 200) {
229+
await messageApi.success(
230+
editorState.mode === 'edit'
231+
? i18nInstance.t('55aa6366c0d09a392d8acf54c4c4b837', '更新成功')
232+
: i18nInstance.t(
233+
'04a691b377c91da599d5b4b62b0cb114',
234+
'创建成功',
235+
),
236+
);
237+
toggleShowModal(false);
238+
resetEditorState();
239+
// invalidate react query
240+
await queryClient.invalidateQueries({
241+
queryKey: [
242+
filter.kind === ServiceKind.Service
243+
? 'GetServices'
244+
: 'GetIngress',
245+
filter.selectedWorkSpace,
246+
filter.searchText,
247+
],
248+
});
249+
} else {
250+
await messageApi.error(
251+
editorState.mode === 'edit'
252+
? i18nInstance.t('930442e2f423436f9db3d8e91f648e93', '更新失败')
253+
: i18nInstance.t(
254+
'a889286a51f3adab3cfb6913f2b0ac2e',
255+
'创建失败',
256+
),
257+
);
258+
}
181259
}}
182260
onCancel={() => {
183261
resetEditorState();

ui/apps/dashboard/src/services/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export async function GetIngress(params: {
103103
listMeta: {
104104
totalItems: number;
105105
};
106-
services: Ingress[];
106+
items: Ingress[];
107107
}>
108108
>(url, {
109109
params: convertDataSelectQuery(requestData),

0 commit comments

Comments
 (0)