Skip to content

Commit fdcc4bc

Browse files
fix some bugs in deployment
1 parent 79d173c commit fdcc4bc

File tree

15 files changed

+287
-102
lines changed

15 files changed

+287
-102
lines changed

projects/sbos-frontend/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default defineConfig({
9797
default: 'en-US',
9898
antd: true,
9999
// default true, when it is true, will use `navigator.language` overwrite default
100-
baseNavigator: true,
100+
baseNavigator: false,
101101
},
102102
/**
103103
* @name antd 插件

projects/sbos-frontend/config/routes.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ export default [
2424
},
2525
{
2626
path: '/welcome',
27+
layout: true,
2728
name: 'welcome',
2829
icon: 'smile',
2930
component: './Welcome',
3031
},
3132
{
3233
// path: '/domain',
3334
name: 'domain',
35+
layout: true,
3436
icon: 'smile',
3537
// component: './Domain/DomainList',
3638
routes: [
@@ -94,6 +96,7 @@ export default [
9496
},
9597
{
9698
name: 'developer',
99+
layout: true,
97100
routes: [
98101
{
99102
name: 'apps',
@@ -104,6 +107,7 @@ export default [
104107
},
105108
{
106109
name: 'admin',
110+
layout: true,
107111
routes: [
108112
{
109113
name: 'apps',
@@ -119,29 +123,6 @@ export default [
119123
},
120124
]
121125
},
122-
{
123-
path: '/admin',
124-
name: 'admin',
125-
icon: 'crown',
126-
access: 'isSiteAdmin',
127-
routes: [
128-
{
129-
path: '/admin',
130-
redirect: '/admin/sub-page',
131-
},
132-
{
133-
path: '/admin/sub-page',
134-
name: 'sub-page',
135-
component: './Admin',
136-
},
137-
],
138-
},
139-
{
140-
name: 'list.table-list',
141-
icon: 'table',
142-
path: '/list',
143-
component: './TableList',
144-
},
145126
{
146127
path: '/',
147128
redirect: '/welcome',

projects/sbos-frontend/src/access.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export default function access(
55
initialState: { currentUser?: API.UserRead; currentDomainUser?: API.DomainUserRead } | undefined,
66
) {
77
const { currentUser, currentDomainUser } = initialState ?? {};
8-
const isSiteAdmin = currentUser && currentUser.isSuperuser;
9-
const isDomainAdmin = isSiteAdmin || (currentDomainUser && currentDomainUser.isAdmin);
8+
const isSiteAdmin: boolean = currentUser && currentUser.isSuperuser || false;
9+
const isDomainAdmin: boolean = isSiteAdmin || (currentDomainUser && currentDomainUser.isAdmin) || false;
1010
return {
1111
isSiteAdmin,
1212
isDomainAdmin,

projects/sbos-frontend/src/app.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,22 @@ const Layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
193193
],
194194
icon: <CodeOutlined />,
195195
});
196-
menu.push({
197-
name: 'admin',
198-
children: [
199-
{
200-
path: '/admin/apps',
201-
name: 'apps'
202-
},
203-
{
204-
path: '/admin/domains',
205-
name: 'domains'
206-
}
207-
],
208-
icon: <ThunderboltOutlined />,
209-
});
196+
if (access.isSiteAdmin) {
197+
menu.push({
198+
name: 'admin',
199+
children: [
200+
{
201+
path: '/admin/apps',
202+
name: 'apps'
203+
},
204+
{
205+
path: '/admin/domains',
206+
name: 'domains'
207+
}
208+
],
209+
icon: <ThunderboltOutlined/>,
210+
});
211+
}
210212
return menu;
211213
},
212214
},
@@ -225,7 +227,7 @@ const Layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
225227
</Flex>
226228
);
227229
},
228-
actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />],
230+
// actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />],
229231
avatarProps: {
230232
// src: initialState?.currentUser?.avatar,
231233
title: <AvatarName />,

projects/sbos-frontend/src/pages/Admin/AppList/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,9 @@ const AppList: React.FC = () => {
6363
<Card title={app.name} bordered={false}>
6464
<Typography.Paragraph>{app.description}</Typography.Paragraph>
6565
<Flex gap="middle" wrap>
66-
{app.approved ? (
67-
<Button disabled>Approved</Button>
68-
) : (
69-
<Button type="primary" onClick={handleApproveApp}>
70-
Approve
71-
</Button>
72-
)}
66+
<Button type="primary" onClick={handleApproveApp}>
67+
Approve
68+
</Button>
7369
<Button type="primary" onClick={handleBuildApp}>
7470
Build
7571
</Button>

projects/sbos-frontend/src/pages/Domain/Dashboard/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
usersStopAppContainerBrickapiV1UsersDomainsDomainAppsAppStopPost,
1111
} from '@/services/brick-server-playground/users';
1212
import {
13+
CloseCircleOutlined,
1314
ExportOutlined,
1415
PauseCircleOutlined,
1516
PlayCircleOutlined,
@@ -217,20 +218,23 @@ const Dashboard: React.FC = () => {
217218
// history.push(`/domain/${domainUserApp.domain.name}/app/${domainUserApp.app.name}`);
218219
};
219220

221+
const actions = [
222+
<SettingOutlined key="setting" onClick={onClickSettings} />,
223+
];
224+
if (domainUserApp.status !== 'running') {
225+
actions.push(<PlayCircleOutlined key="start" onClick={onClickStart} />);
226+
actions.push(<CloseCircleOutlined key="app" onClick={() => message.error("App is not running!") } />);
227+
} else {
228+
actions.push(<PauseCircleOutlined key="stop" onClick={onClickStop} />);
229+
actions.push(<ExportOutlined key="app" onClick={onClickApp} />);
230+
}
231+
220232
return (
221233
<Col xxl={6} xl={8} lg={8} md={8} sm={12} xs={24} key={domainUserApp.app.id}>
222234
<ProCard
223235
title={domainUserApp.app.name}
224236
bordered={false}
225-
actions={[
226-
<SettingOutlined key="setting" onClick={onClickSettings} />,
227-
domainUserApp.status !== 'running' ? (
228-
<PlayCircleOutlined key="start" onClick={onClickStart} />
229-
) : (
230-
<PauseCircleOutlined key="stop" onClick={onClickStop} />
231-
),
232-
<ExportOutlined key="app" onClick={onClickApp} />,
233-
]}
237+
actions={actions}
234238
>
235239
Status: {domainUserApp?.status}
236240
</ProCard>

projects/sbos-frontend/src/pages/Domain/UserList/index.tsx

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import {
44
addDomainUserBrickapiV1DomainsDomainUsersUserPost,
55
addDomainUserProfileBrickapiV1DomainsDomainUsersUserProfilesPost,
66
deleteDomainUserProfileBrickapiV1DomainsDomainUsersUserProfilesProfileDelete,
7+
deleteDomainUserBrickapiV1DomainsDomainUsersUserDelete,
78
listDomainUserBrickapiV1DomainsDomainUsersGet,
89
updateDomainUserProfileBrickapiV1DomainsDomainUsersUserProfilesProfilePatch,
10+
updateDomainUserBrickapiV1DomainsDomainUsersUserPatch,
911
} from '@/services/brick-server-playground/domains';
1012
import { listProfilesBrickapiV1ProfilesGet } from '@/services/brick-server-playground/profiles';
1113
import { usersListUsersBrickapiV1UsersGet } from '@/services/brick-server-playground/users';
@@ -18,16 +20,18 @@ import {
1820
ProColumns,
1921
ProFormGroup,
2022
ProFormList,
21-
ProFormSelect,
23+
ProFormSelect, ProFormSwitch,
2224
ProFormText,
2325
ProTable,
2426
} from '@ant-design/pro-components';
2527
import { Button, Col, Popconfirm, Row, message } from 'antd';
2628
import hljs from 'highlight.js/lib/core';
2729
import { filter, fromPairs, map } from 'lodash';
2830
import React, { RefObject, useRef, useState } from 'react';
31+
import { useAccess, Access } from 'umi';
2932

3033
const UserList: React.FC = () => {
34+
const access = useAccess();
3135
const domainName = useDomainName();
3236
const actionRef = useRef<ActionType>();
3337
const [isAddUserOpen, setIsAddUserOpen] = useState<boolean>(false);
@@ -44,14 +48,29 @@ const UserList: React.FC = () => {
4448
);
4549

4650
const onClickAddUser = async () => {
51+
setCurrentDomainUser(undefined);
4752
setIsAddUserOpen(true);
4853
};
4954

50-
const onFinishAddUser = async (params: { user: string }) => {
51-
const result = await addDomainUserBrickapiV1DomainsDomainUsersUserPost({
52-
domain: domainName,
53-
user: params.user,
54-
});
55+
56+
const onClickEditUser = async (domainUser: API.DomainUserRead) => {
57+
setCurrentDomainUser(domainUser);
58+
setIsAddUserOpen(true);
59+
}
60+
61+
const onFinishAddUser = async (params: { user: string, is_admin: boolean }) => {
62+
let result;
63+
if (currentDomainUser) {
64+
result = await updateDomainUserBrickapiV1DomainsDomainUsersUserPatch({
65+
domain: domainName,
66+
user: params.user,
67+
}, {isAdmin: params.is_admin});
68+
} else {
69+
result = await addDomainUserBrickapiV1DomainsDomainUsersUserPost({
70+
domain: domainName,
71+
user: params.user,
72+
});
73+
}
5574
if (result.errorCode !== 'Success') {
5675
message.error(`Error: ${result.errorCode}`);
5776
}
@@ -62,6 +81,18 @@ const UserList: React.FC = () => {
6281
const onCancelAddUser = async () => {
6382
setIsAddUserOpen(false);
6483
};
84+
85+
const onClickDeleteUser = async (domainUser: API.DomainUserRead) => {
86+
const result = await deleteDomainUserBrickapiV1DomainsDomainUsersUserDelete({
87+
domain: domainName,
88+
user: domainUser.user.name,
89+
});
90+
if (result.errorCode !== 'Success') {
91+
message.error(`Error: ${result.errorCode}`);
92+
}
93+
actionRef.current?.reload();
94+
};
95+
6596
const onClickEditProfile = async (
6697
profile: API.DomainUserProfileRead,
6798
profileActionRef: RefObject<ActionType>,
@@ -75,11 +106,14 @@ const UserList: React.FC = () => {
75106
profile: API.DomainUserProfileRead,
76107
profileActionRef: RefObject<ActionType>,
77108
) => {
78-
await deleteDomainUserProfileBrickapiV1DomainsDomainUsersUserProfilesProfileDelete({
109+
const result = await deleteDomainUserProfileBrickapiV1DomainsDomainUsersUserProfilesProfileDelete({
79110
domain: domainName,
80111
user: profile.user.name,
81112
profile: profile.profile.id,
82113
});
114+
if (result.errorCode !== 'Success') {
115+
message.error(`Error: ${result.errorCode}`);
116+
}
83117
profileActionRef?.current?.reload();
84118
};
85119
const onFinishEditProfile = async (values: any) => {
@@ -139,12 +173,14 @@ const UserList: React.FC = () => {
139173
title: 'Operations',
140174
valueType: 'option',
141175
render: (text, record, _, action) => [
142-
// <a key="add_profile" onClick={() => onClickAddProfile(record)}>Add Profile</a>,
176+
<Access accessible={access.isSiteAdmin}>
177+
<a key="edit_user" onClick={() => onClickEditUser(record)}>Edit</a>
178+
</Access>,
143179
<Popconfirm
144180
key="delete"
145181
title="Delete the user"
146182
description="Are you sure to delete this user?"
147-
onConfirm={async () => {}}
183+
onConfirm={async () => onClickDeleteUser(record)}
148184
>
149185
<a>Delete</a>
150186
</Popconfirm>,
@@ -195,15 +231,29 @@ const UserList: React.FC = () => {
195231
]}
196232
/>
197233
<ModalForm
198-
title={'Add User to Domain'}
234+
title={currentDomainUser ? 'Edit User in Domain' : 'Add User to Domain'}
199235
open={isAddUserOpen}
200236
onFinish={onFinishAddUser}
201237
modalProps={{
202238
destroyOnClose: true,
203239
onCancel: onCancelAddUser,
204240
}}
205241
>
206-
<ProFormSelect
242+
{currentDomainUser ? <>
243+
<ProFormText
244+
label="User"
245+
name="user"
246+
width="md"
247+
disabled
248+
initialValue={currentDomainUser?.user?.name || ""}
249+
/>
250+
<ProFormSwitch
251+
label="Is Domain Admin"
252+
name="is_admin"
253+
width="md"
254+
initialValue={currentDomainUser?.isAdmin || false}
255+
/>
256+
</> : <ProFormSelect
207257
label="Select a user"
208258
name="user"
209259
request={async () => {
@@ -220,6 +270,8 @@ const UserList: React.FC = () => {
220270
},
221271
]}
222272
/>
273+
}
274+
223275
</ModalForm>
224276
<ModalForm
225277
title="Set Profile Arguments"

0 commit comments

Comments
 (0)