Skip to content

Commit 21fd6cf

Browse files
add domain list in frontend
Co-authored-by: tc-imba <[email protected]> Co-authored-by: Reapor-Yurnero <[email protected]>
1 parent ca317ea commit 21fd6cf

File tree

5 files changed

+137
-10
lines changed

5 files changed

+137
-10
lines changed

projects/sbos-frontend/config/routes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ export default [
111111
component: './Admin/AppList',
112112
access: 'isSiteAdmin',
113113
},
114+
{
115+
name: 'apps',
116+
path: '/admin/domains',
117+
component: './Admin/DomainList',
118+
access: 'isSiteAdmin',
119+
},
114120
]
115121
},
116122
{

projects/sbos-frontend/src/app.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ const Layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
199199
{
200200
path: '/admin/apps',
201201
name: 'apps'
202+
},
203+
{
204+
path: '/admin/domains',
205+
name: 'domains'
202206
}
203207
],
204208
icon: <ThunderboltOutlined />,

projects/sbos-frontend/src/locales/en-US/menu.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ export default {
1111
'menu.domain.profiles': 'Profile Management',
1212
'menu.developer': "Developer",
1313
'menu.developer.apps': "App List",
14-
'menu.admin': "Site Admin",
14+
'menu.admin': "Admin",
1515
'menu.admin.apps': "App Management",
16+
'menu.admin.domains': "Domain Management",
1617
'menu.welcome': 'Welcome',
1718
'menu.more-blocks': 'More Blocks',
1819
'menu.home': 'Home',
19-
'menu.admin': 'Admin',
20-
'menu.admin.sub-page': 'Sub-Page',
20+
// 'menu.admin': 'Admin',
21+
// 'menu.admin.sub-page': 'Sub-Page',
2122
'menu.login': 'Login',
2223
'menu.register': 'Register',
2324
'menu.register-result': 'Register Result',
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import {
2+
ActionType,
3+
ModalForm,
4+
PageContainer,
5+
ProColumns,
6+
ProFormGroup,
7+
ProFormText,
8+
ProTable
9+
} from '@ant-design/pro-components';
10+
import React, {useRef, useState} from 'react';
11+
import {useDomainName} from "@/hooks";
12+
import {
13+
createDomainBrickapiV1DomainsDomainPost,
14+
initDomainBrickapiV1DomainsDomainInitGet,
15+
listDomainsBrickapiV1DomainsGet,
16+
} from "@/services/brick-server-playground/domains";
17+
import {Button, message, Popconfirm} from "antd";
18+
import {PlusOutlined} from "@ant-design/icons";
19+
20+
const DomainList: React.FC = () => {
21+
// const domainName = useDomainName();
22+
const actionRef = useRef<ActionType>();
23+
const [isAddDomainOpen, setIsAddDomainOpen] = useState<boolean>(false);
24+
const [currentDomain, setCurrentDomain] = useState<API.ResourceConstraintRead | undefined>(
25+
undefined,
26+
);
27+
28+
const onClickAddResource = async () => {
29+
setCurrentDomain(undefined);
30+
setIsAddDomainOpen(true);
31+
};
32+
33+
const onClickInitDomain = async(domain: API.DomainRead) => {
34+
const result = await initDomainBrickapiV1DomainsDomainInitGet({domain: domain.name});
35+
if (result.errorCode !== 'Success') {
36+
message.error(`Error: ${result.errorCode}`);
37+
} else {
38+
message.success(`Domain ${domain.name} initialized!`);
39+
}
40+
}
41+
42+
const onFinishAddDomain = async (values: { name: string; }) => {
43+
console.log(values);
44+
const result = await createDomainBrickapiV1DomainsDomainPost(
45+
{ domain: values.name },
46+
);
47+
if (result.errorCode !== 'Success') {
48+
message.error(`Error: ${result.errorCode}`);
49+
}
50+
await actionRef.current?.reload();
51+
setCurrentDomain(undefined);
52+
setIsAddDomainOpen(false);
53+
};
54+
55+
const onCancelAddResource = async () => {
56+
setIsAddDomainOpen(false);
57+
};
58+
59+
60+
const columns: ProColumns<API.DomainRead>[] = [
61+
{
62+
title: 'Name',
63+
dataIndex: 'name',
64+
},
65+
{
66+
title: 'Operations',
67+
valueType: 'option',
68+
render: (text, record, _, action) => [
69+
<a key="add_profile" onClick={() => onClickInitDomain(record)}>
70+
Init
71+
</a>
72+
],
73+
},
74+
];
75+
76+
return (
77+
<PageContainer>
78+
<ProTable<API.DomainRead>
79+
actionRef={actionRef}
80+
columns={columns}
81+
pagination={false}
82+
search={false}
83+
request={async (params, sort, filter) => {
84+
const result = await listDomainsBrickapiV1DomainsGet();
85+
return {
86+
data: result.data?.results || [],
87+
success: true,
88+
total: result.data?.count || 0,
89+
};
90+
}}
91+
toolBarRender={() => [
92+
<Button key="add" type="primary" icon={<PlusOutlined />} onClick={onClickAddResource}>
93+
Create Domain
94+
</Button>,
95+
]}
96+
/>
97+
<ModalForm
98+
title={'Create Domain'}
99+
open={isAddDomainOpen}
100+
onFinish={onFinishAddDomain}
101+
modalProps={{
102+
destroyOnClose: true,
103+
onCancel: onCancelAddResource,
104+
}}
105+
>
106+
<ProFormGroup>
107+
<ProFormText
108+
label="Name"
109+
name="name"
110+
width="md"
111+
rules={[
112+
{
113+
required: true,
114+
message: 'Please enter domain name.',
115+
},
116+
]}
117+
/>
118+
</ProFormGroup>
119+
</ModalForm>
120+
</PageContainer>
121+
);
122+
};
123+
export default DomainList;

projects/sbos-frontend/src/pages/Site/DomainList/index.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)