Skip to content

Commit

Permalink
Merge pull request #139 from warjiang/feature/ui-for-service
Browse files Browse the repository at this point in the history
UI for service
  • Loading branch information
karmada-bot authored Oct 19, 2024
2 parents e48b695 + 273b033 commit f3c2928
Show file tree
Hide file tree
Showing 10 changed files with 673 additions and 8 deletions.
6 changes: 4 additions & 2 deletions ui/apps/dashboard/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,7 @@
"f2224910b0d022374967254002eb756f": "Successfully edited scheduling strategy",
"5863fd1d291adf46d804f5801a79d0e1": "Editing scheduling strategy failed",
"79d5c80e3be24682145aa9246df18b40": "Is it a cluster?",
"85fe5099f6807dada65d274810933389": "Cluster"
}
"85fe5099f6807dada65d274810933389": "Cluster",
"c7961c290ec86485d8692f3c09b4075b": "New services added",
"8f3747c057d893862fbe4b7980e9b451": "Service Name"
}
6 changes: 4 additions & 2 deletions ui/apps/dashboard/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,7 @@
"f2224910b0d022374967254002eb756f": "编辑调度策略成功",
"5863fd1d291adf46d804f5801a79d0e1": "编辑调度策略失败",
"79d5c80e3be24682145aa9246df18b40": "集群么?",
"85fe5099f6807dada65d274810933389": "集群"
}
"85fe5099f6807dada65d274810933389": "集群",
"c7961c290ec86485d8692f3c09b4075b": "新增服务",
"8f3747c057d893862fbe4b7980e9b451": "服务名称"
}
2 changes: 1 addition & 1 deletion ui/apps/dashboard/src/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Header from './header';
import Sidebar from './sidebar';
import { cn } from '@/utils/cn.ts';
import { useAuth } from '@/components/auth';
import { getSidebarWidth } from '@/utils/i18n.tsx';
import { getSidebarWidth } from '@/utils/i18n';
import { useWindowSize } from "@uidotdev/usehooks";

const { Sider: AntdSider, Content: AntdContent } = AntdLayout;
Expand Down
2 changes: 1 addition & 1 deletion ui/apps/dashboard/src/layout/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { useMatches, useNavigate } from 'react-router-dom';
import { FC, useMemo } from 'react';
import _ from 'lodash';
import { getSidebarWidth } from '@/utils/i18n.tsx';
import { getSidebarWidth } from '@/utils/i18n';
import { cn } from '@/utils/cn.ts';
import { useQuery } from '@tanstack/react-query';
import { GetDashboardConfig, menuConfig } from '@/services/dashboard-config.ts';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import i18nInstance from '@/utils/i18n';
import { Button, Popconfirm, Space, Table, TableColumnProps, Tag } from 'antd';
import {
extractPropagationPolicy,
GetIngress,
Ingress,
} from '@/services/service.ts';
import TagList from '@/components/tag-list';
import { FC } from 'react';
import { useQuery } from '@tanstack/react-query';
import { GetResource } from '@/services/unstructured.ts';
interface ServiceTableProps {
labelTagNum?: number;
selectedWorkSpace: string;
searchText: string;
onViewIngressContent: (r: any) => void;
onDeleteIngressContent: (r: Ingress) => void;
}
const IngressTable: FC<ServiceTableProps> = (props) => {
const {
labelTagNum,
selectedWorkSpace,
searchText,
onViewIngressContent,
onDeleteIngressContent,
} = props;
const columns: TableColumnProps<Ingress>[] = [
{
title: i18nInstance.t('a4b28a416f0b6f3c215c51e79e517298'),
key: 'namespaceName',
width: 200,
render: (_, r) => {
return r.objectMeta.namespace;
},
},
{
title: i18nInstance.t('d7ec2d3fea4756bc1642e0f10c180cf5', '名称'),
key: 'ingressName',
width: 300,
render: (_, r) => {
return r.objectMeta.name;
},
},
{
title: i18nInstance.t('1f7be0a924280cd098db93c9d81ecccd'),
key: 'labelName',
align: 'left',
width: '30%',
render: (_, r) => {
if (!r?.objectMeta?.labels) {
return '-';
}
const params = Object.keys(r.objectMeta.labels).map((key) => {
return {
key: `${r.objectMeta.name}-${key}`,
value: `${key}:${r.objectMeta.labels[key]}`,
};
});
return <TagList tags={params} maxLen={labelTagNum} />;
},
},
{
title: i18nInstance.t('8a99082b2c32c843d2241e0ba60a3619'),
key: 'propagationPolicies',
render: (_, r) => {
const pp = extractPropagationPolicy(r);
return pp ? <Tag>{pp}</Tag> : '-';
},
},
{
title: i18nInstance.t('eaf8a02d1b16fcf94302927094af921f'),
key: 'overridePolicies',
width: 150,
render: () => {
return '-';
},
},
{
title: i18nInstance.t('2b6bc0f293f5ca01b006206c2535ccbc'),
key: 'op',
width: 200,
render: (_, r) => {
return (
<Space.Compact>
<Button
size={'small'}
type="link"
onClick={async () => {
const ret = await GetResource({
kind: r.typeMeta.kind,
name: r.objectMeta.name,
namespace: r.objectMeta.namespace,
});
onViewIngressContent(ret?.data);
}}
>
{i18nInstance.t('607e7a4f377fa66b0b28ce318aab841f')}
</Button>
<Button
size={'small'}
type="link"
onClick={() => {
onDeleteIngressContent(r);
}}
>
{i18nInstance.t('95b351c86267f3aedf89520959bce689')}
</Button>

<Popconfirm
placement="topRight"
title={`${i18nInstance.t('fc763fd5ddf637fe4ba1ac59e10b8d3a', '确认要删除')}${r.objectMeta.name}${i18nInstance.t('627ce40030fcda39210cca054bb77775', '工作负载么')}`}
onConfirm={async () => {}}
okText={i18nInstance.t('e83a256e4f5bb4ff8b3d804b5473217a')}
cancelText={i18nInstance.t('625fb26b4b3340f7872b411f401e754c')}
>
<Button size={'small'} type="link" danger>
{i18nInstance.t('2f4aaddde33c9b93c36fd2503f3d122b')}
</Button>
</Popconfirm>
</Space.Compact>
);
},
},
];
const { data, isLoading } = useQuery({
queryKey: ['GetServices', selectedWorkSpace, searchText],
queryFn: async () => {
const services = await GetIngress({
namespace: selectedWorkSpace,
keyword: searchText,
});
return services.data || {};
},
});
return (
<Table
rowKey={(r: Ingress) =>
`${r.objectMeta.namespace}-${r.objectMeta.name}` || ''
}
columns={columns}
loading={isLoading}
dataSource={data?.services || []}
/>
);
};
export default IngressTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import i18nInstance from '@/utils/i18n';
import { FC, useEffect, useState } from 'react';
import { Modal } from 'antd';
import Editor from '@monaco-editor/react';
import { parse, stringify } from 'yaml';
import _ from 'lodash';
import { PutResource } from '@/services/unstructured';
import { CreateDeployment } from '@/services/workload';
import { IResponse } from '@/services/base.ts';
export interface NewWorkloadEditorModalProps {
mode: 'create' | 'edit';
open: boolean;
serviceContent?: string;
onOk: (ret: IResponse<any>) => Promise<void> | void;
onCancel: () => Promise<void> | void;
}
const ServiceEditorModal: FC<NewWorkloadEditorModalProps> = (props) => {
const { mode, open, serviceContent = '', onOk, onCancel } = props;
const [content, setContent] = useState<string>(serviceContent);
useEffect(() => {
console.log('workloadContent', serviceContent);
setContent(serviceContent);
}, [serviceContent]);
function handleEditorChange(value: string | undefined) {
setContent(value || '');
}
return (
<Modal
title={`${mode === 'create' ? i18nInstance.t('66ab5e9f24c8f46012a25c89919fb191') : i18nInstance.t('95b351c86267f3aedf89520959bce689')}${i18nInstance.t('c3bc562e9ffcae6029db730fe218515c', '工作负载')}`}
open={open}
width={1000}
okText={i18nInstance.t('38cf16f2204ffab8a6e0187070558721')}
cancelText={i18nInstance.t('625fb26b4b3340f7872b411f401e754c')}
destroyOnClose={true}
onOk={async () => {
// await onOk()
try {
const yamlObject = parse(content) as Record<string, string>;
const kind = _.get(yamlObject, 'kind');
const namespace = _.get(yamlObject, 'metadata.namespace');
const name = _.get(yamlObject, 'metadata.name');
if (mode === 'create') {
if (kind.toLowerCase() === 'deployment') {
const ret = await CreateDeployment({
namespace,
name,
content: stringify(yamlObject),
});
await onOk(ret);
setContent('');
}
} else {
const ret = await PutResource({
kind,
name,
namespace,
content: yamlObject,
});
await onOk(ret);
setContent('');
}
} catch (e) {
console.log('e', e);
}
}}
onCancel={async () => {
await onCancel();
setContent('');
}}
>
<Editor
height="600px"
defaultLanguage="yaml"
value={content}
theme="vs-dark"
options={{
theme: 'vs-dark',
lineNumbers: 'on',
minimap: {
enabled: false,
},
}}
onChange={handleEditorChange}
/>
</Modal>
);
};
export default ServiceEditorModal;
Loading

0 comments on commit f3c2928

Please sign in to comment.