Skip to content

Commit 8772314

Browse files
authored
feat(web): hide patList edit button & show copy token button (#609)
* feat(web): hide patList edit button & show copy token button * feat(web): change oss preview link
1 parent 6abee36 commit 8772314

File tree

10 files changed

+84
-29
lines changed

10 files changed

+84
-29
lines changed

web/src/components/EditableTable/EditableTr/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import styles from "../index.module.scss";
77

88
export type TConfiguration = {
99
key: string;
10+
tableHeight?: string;
11+
hiddenEditButton?: boolean;
1012
addButtonText?: string;
1113
editButtonText?: string;
1214
deleteButtonText?: string;

web/src/components/EditableTable/NormalTr/index.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ const NormalTr = function (props: {
2929
{configuration?.operationButtonsRender
3030
? configuration.operationButtonsRender(data)
3131
: null}
32-
<TextButton
33-
className="ml-4"
34-
text={configuration?.editButtonText ? configuration.editButtonText : "编辑"}
35-
onClick={() => onEdit(data[configuration.key])}
36-
/>
32+
{!configuration?.hiddenEditButton ? (
33+
<TextButton
34+
className="mr-4"
35+
text={configuration?.editButtonText ? configuration.editButtonText : "编辑"}
36+
onClick={() => onEdit(data[configuration.key])}
37+
/>
38+
) : null}
3739
<ConfirmButton
3840
onSuccessAction={() => onDelete(data[configuration.key])}
3941
headerText={
@@ -42,7 +44,6 @@ const NormalTr = function (props: {
4244
bodyText={`确定删除该行数据吗?`}
4345
>
4446
<TextButton
45-
className="ml-4"
4647
text={
4748
configuration?.deleteButtonText
4849
? configuration.deleteButtonText

web/src/components/EditableTable/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const EditableTable = function (props: {
6666
return (
6767
<>
6868
<div className="px-4 py-1 mb-2 rounded-md relative border">
69-
<TableContainer h={"250px"} overflowY="auto" ref={tableRef}>
69+
<TableContainer h={configuration?.tableHeight || "250px"} overflowY="auto" ref={tableRef}>
7070
<Table variant="simple">
7171
<Thead>
7272
<Tr>

web/src/layouts/Header/UserSetting/index.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Menu, MenuButton, MenuItem, MenuList } from "@chakra-ui/react";
22

33
import SettingModal from "@/pages/app/setting";
44
import PATList from "@/pages/app/setting/PATList";
5-
65
export default function UserSetting(props: { avator: string; width: number }) {
76
return (
87
<Menu>
@@ -22,7 +21,15 @@ export default function UserSetting(props: { avator: string; width: number }) {
2221
>
2322
<MenuItem>用户设置</MenuItem>
2423
</SettingModal>
25-
<MenuItem>Logout</MenuItem>
24+
<MenuItem
25+
onClick={() => {
26+
localStorage.clear();
27+
(window as any).location.href = (import.meta.env.VITE_SERVER_URL +
28+
"/v1/login") as string;
29+
}}
30+
>
31+
Logout
32+
</MenuItem>
2633
</MenuList>
2734
</Menu>
2835
);

web/src/pages/app/setting/AppEnvList/index.tsx

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Button } from "@chakra-ui/react";
2+
13
import EditableTable from "@/components/EditableTable";
24
import { isExitInList } from "@/utils/format";
35

@@ -8,7 +10,10 @@ import {
810
useEnvironmentQuery,
911
} from "./service";
1012

11-
const AppEnvList = () => {
13+
import useGlobalStore from "@/pages/globalStore";
14+
15+
const AppEnvList = (props: { onClose?: () => {} }) => {
16+
const globalStore = useGlobalStore((state) => state);
1217
const environmentQuery = useEnvironmentQuery();
1318
const delEnvironmentMutation = useDelEnvironmentMutation();
1419
const addEnvironmentMutation = useAddEnvironmentMutation();
@@ -22,6 +27,7 @@ const AppEnvList = () => {
2227
key: "name",
2328
width: "200px",
2429
textWidth: "40",
30+
editable: false,
2531
valiate: [
2632
(data: any) => {
2733
return {
@@ -59,6 +65,7 @@ const AppEnvList = () => {
5965
},
6066
]}
6167
configuration={{
68+
tableHeight: "200px",
6269
key: "name",
6370
addButtonText: "新增环境变量",
6471
}}
@@ -67,6 +74,17 @@ const AppEnvList = () => {
6774
onDelete={(data) => delEnvironmentMutation.mutateAsync({ name: data })}
6875
onCreate={(data) => addEnvironmentMutation.mutateAsync(data)}
6976
/>
77+
<Button
78+
className="w-28 h-8 self-end mt-4"
79+
colorScheme="blue"
80+
type="submit"
81+
onClick={() => {
82+
globalStore.restartCurrentApp();
83+
props.onClose && props.onClose();
84+
}}
85+
>
86+
应用环境变量
87+
</Button>
7088
</div>
7189
</>
7290
);

web/src/pages/app/setting/PATList/index.tsx

+29-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TPAT, useAddPATMutation, useDelPATMutation, usePATQuery } from "./servi
1010

1111
const PATList = () => {
1212
const [formatPATList, setFormatPATList] = useState<TPAT[]>();
13-
13+
const [tokenList, setTokenList] = useState<{ id: string; token: string }[]>([]);
1414
usePATQuery((data) => {
1515
const newPATList = (data || []).map((item: any) => {
1616
return {
@@ -21,8 +21,20 @@ const PATList = () => {
2121
setFormatPATList(newPATList);
2222
});
2323

24-
const delPATMutation = useDelPATMutation();
25-
const addPATMutation = useAddPATMutation();
24+
const delPATMutation = useDelPATMutation(() => {
25+
// const newTokenList = newTokenList.map((token) => {
26+
// return token.id !==
27+
// });
28+
// setTokenList(newTokenList);
29+
});
30+
const addPATMutation = useAddPATMutation((data: any) => {
31+
const newTokenList = [...tokenList];
32+
newTokenList.push({
33+
id: data.id,
34+
token: data.token,
35+
});
36+
setTokenList(newTokenList);
37+
});
2638

2739
const now = new Date();
2840
const dateList = formatDateOption();
@@ -64,21 +76,29 @@ const PATList = () => {
6476
]}
6577
configuration={{
6678
key: "id",
79+
hiddenEditButton: true,
6780
addButtonText: "新增Token",
6881
saveButtonText: "生成Token",
6982
operationButtonsRender: (data: any) => {
70-
return (
71-
<CopyText text={data.name} tip="name复制成功">
83+
const tokenItem = tokenList?.filter((item) => item.id === data.id);
84+
return tokenItem?.length === 1 ? (
85+
<CopyText className="mr-4" text={tokenItem[0].token} tip="token复制成功">
7286
<Button variant={"link"} size="xs" colorScheme={"blue"}>
73-
复制name
87+
复制Token
7488
</Button>
7589
</CopyText>
76-
);
90+
) : null;
7791
},
7892
}}
7993
tableData={formatPATList}
80-
onEdit={(data) => addPATMutation.mutateAsync(data)}
81-
onDelete={(data) => delPATMutation.mutateAsync({ id: data })}
94+
onEdit={async () => {}}
95+
onDelete={async (data) => {
96+
await delPATMutation.mutateAsync({ id: data });
97+
const newTokenList = tokenList.filter((token) => {
98+
return token.id !== data;
99+
});
100+
setTokenList(newTokenList);
101+
}}
82102
onCreate={(data) =>
83103
addPATMutation.mutateAsync({ ...data, expiresIn: Number(data.expiresIn) })
84104
}

web/src/pages/app/setting/PATList/service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ export const usePATQuery = (callback?: (data: any) => void) => {
3131
);
3232
};
3333

34-
export const useAddPATMutation = (callback?: () => void) => {
34+
export const useAddPATMutation = (callback?: (data: any) => void) => {
3535
const queryClient = useQueryClient();
3636
return useMutation((params: TPAT) => AuthControllerPATsCreate(params), {
37-
onSuccess: async () => {
37+
onSuccess: async (data) => {
3838
useGlobalStore.getState().showSuccess("update PAT success");
3939
await queryClient.invalidateQueries(queryKeys.usePATQuery);
40-
callback && callback();
40+
callback && callback(data?.data);
4141
},
4242
});
4343
};

web/src/pages/app/setting/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ const SettingModal = (props: {
6161
<h3 className="ml-2 pb-2 mb-4 font-bold border-gray-200 border-b border-solid">
6262
{item?.name}
6363
</h3>
64-
{item?.component}
64+
{React.cloneElement(item?.component || <></>, {
65+
onClose,
66+
})}
6567
</div>
6668
</div>
6769
</ModalBody>

web/src/pages/app/storages/mods/FileList/index.tsx

+11-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function FileList() {
2020
const { getList, getFileUrl, deleteFile } = useAwsS3();
2121
const { currentStorage, prefix, setPrefix } = useStorageStore();
2222
const bucketName = currentStorage?.metadata.name;
23-
// const bucketType = currentStorage?.spec.policy;
23+
const bucketType = currentStorage?.spec.policy;
2424

2525
const query = useQuery(
2626
["fileList", bucketName, prefix],
@@ -35,8 +35,11 @@ export default function FileList() {
3535
changeDirectory(file);
3636
return;
3737
}
38-
// const fileUrl = bucketType === 'private' ? getFileUrl(bucketName!, file.Key) : `http://${bucketName}.oss.dev.laf.run/${file.Key}`;
39-
const fileUrl = getFileUrl(bucketName!, file.Key);
38+
const fileUrl =
39+
bucketType === "private"
40+
? getFileUrl(bucketName!, file.Key)
41+
: `http://${bucketName}.${(window as any).location.host.replace("www", "oss")}/${file.Key}`;
42+
4043
window.open(fileUrl, "_blank");
4144
};
4245

@@ -113,8 +116,11 @@ export default function FileList() {
113116
<Td isNumeric className="flex justify-end">
114117
<IconWrap
115118
placement="left"
116-
// tooltip={bucketType === 'private' && file.Key ? '临时链接,有效期15分钟' : undefined}
117-
tooltip="临时链接,有效期15分钟"
119+
tooltip={
120+
bucketType === "private" && file.Key
121+
? "临时链接,有效期15分钟"
122+
: undefined
123+
}
118124
onClick={() => viewAppFile(file)}
119125
>
120126
<ViewIcon fontSize={12} />

web/src/pages/globalStore.ts

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ type State = {
2424
currentApp: TApplication | undefined;
2525
setCurrentApp(app: TApplication): void;
2626
init(appid?: string): void;
27-
2827
restartCurrentApp(): void;
2928

3029
currentPageId: string | undefined;

0 commit comments

Comments
 (0)