refactor: method parameters of api client (#605)

<!--  Thanks for sending a pull request!  Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->

#### What type of PR is this?

/kind improvement
/milestone 2.0

<!--
添加其中一个类别:
Add one of the following kinds:

/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind optimization

适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:

/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:

修改 api-client 的请求参数结构,改为所有参数由一个对象包裹,而不是将各个参数作为方法的参数,防止因为后端参数结构发生改变,或者生成 api-client 时参数顺序发生改变导致请求异常。如:

```diff
await apiClient.extension.storage.group.updatestorageHaloRunV1alpha1Group(
-        formState.value.metadata.name,
-        formState.value
+        {
+          name: formState.value.metadata.name,
+          group: formState.value,
+        }
      );
```

#### Which issue(s) this PR fixes:

<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.

用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
None

#### Screenshots:

<!--
如果此 PR 有 UI 的改动,最好截图说明这个 PR 的改动。
If there are UI changes to this PR, it is best to take a screenshot to illustrate the changes to this PR.

eg.

Before:

![screenshot-before](https://user-images.githubusercontent.com/screenshot.png)

After:

![screenshot-after](https://user-images.githubusercontent.com/screenshot.png)
-->

None

#### Special notes for your reviewer:

/cc @halo-dev/sig-halo-admin 

#### Does this PR introduce a user-facing change?

<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->

```release-note
None
```
pull/603/head^2
Ryan Wang 2022-09-06 10:26:11 +08:00 committed by GitHub
parent 3f53680e7b
commit cd33946ca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 316 additions and 273 deletions

View File

@ -33,7 +33,7 @@
"@formkit/themes": "1.0.0-beta.10",
"@formkit/vue": "1.0.0-beta.10",
"@halo-dev/admin-shared": "workspace:*",
"@halo-dev/api-client": "^0.0.13",
"@halo-dev/api-client": "^0.0.14",
"@halo-dev/components": "workspace:*",
"@halo-dev/richtext-editor": "^0.0.0-alpha.5",
"@tiptap/extension-character-count": "2.0.0-beta.31",

View File

@ -38,7 +38,7 @@
"homepage": "https://github.com/halo-dev/halo-admin/tree/next/shared/components#readme",
"license": "MIT",
"dependencies": {
"@halo-dev/api-client": "^0.0.13",
"@halo-dev/api-client": "^0.0.14",
"@halo-dev/components": "workspace:*",
"axios": "^0.27.2"
},

View File

@ -46,9 +46,9 @@ export function useSettingForm(
return;
}
try {
const response = await apiClient.extension.setting.getv1alpha1Setting(
settingName.value
);
const response = await apiClient.extension.setting.getv1alpha1Setting({
name: settingName.value,
});
settings.value = response.data as FormKitSetting;
} catch (e) {
console.error(e);
@ -63,7 +63,9 @@ export function useSettingForm(
}
try {
const response = await apiClient.extension.configMap.getv1alpha1ConfigMap(
configMapName.value
{
name: configMapName.value,
}
);
configMap.value = response.data;
@ -105,14 +107,14 @@ export function useSettingForm(
});
if (!configMap.value.metadata.creationTimestamp) {
await apiClient.extension.configMap.createv1alpha1ConfigMap(
configMap.value
);
await apiClient.extension.configMap.createv1alpha1ConfigMap({
configMap: configMap.value,
});
} else {
await apiClient.extension.configMap.updatev1alpha1ConfigMap(
configMap.value.metadata.name,
configMap.value
);
await apiClient.extension.configMap.updatev1alpha1ConfigMap({
configMap: configMap.value,
name: configMap.value.metadata.name,
});
}
} catch (e) {
console.error(e);

View File

@ -59,9 +59,9 @@ const { settings, handleFetchSettings } = useSettingForm(
const handleFetchPlugin = async () => {
try {
const response =
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin(
route.params.name as string
);
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
name: route.params.name as string,
});
plugin.value = response.data;
} catch (e) {
console.error(e);

View File

@ -13,7 +13,7 @@ importers:
'@formkit/themes': 1.0.0-beta.10
'@formkit/vue': 1.0.0-beta.10
'@halo-dev/admin-shared': workspace:*
'@halo-dev/api-client': ^0.0.13
'@halo-dev/api-client': ^0.0.14
'@halo-dev/components': workspace:*
'@halo-dev/richtext-editor': ^0.0.0-alpha.5
'@iconify-json/vscode-icons': ^1.1.11
@ -92,7 +92,7 @@ importers:
'@formkit/themes': 1.0.0-beta.10_tailwindcss@3.1.8
'@formkit/vue': 1.0.0-beta.10_wwmyxdjqen5bmh3tr2meig5lki
'@halo-dev/admin-shared': link:packages/shared
'@halo-dev/api-client': 0.0.13
'@halo-dev/api-client': 0.0.14
'@halo-dev/components': link:packages/components
'@halo-dev/richtext-editor': 0.0.0-alpha.5_vue@3.2.37
'@tiptap/extension-character-count': 2.0.0-beta.31
@ -194,12 +194,12 @@ importers:
packages/shared:
specifiers:
'@halo-dev/api-client': ^0.0.13
'@halo-dev/api-client': ^0.0.14
'@halo-dev/components': workspace:*
axios: ^0.27.2
vite-plugin-dts: ^1.4.1
dependencies:
'@halo-dev/api-client': 0.0.13
'@halo-dev/api-client': 0.0.14
'@halo-dev/components': link:../components
axios: 0.27.2
devDependencies:
@ -2125,8 +2125,8 @@ packages:
- windicss
dev: false
/@halo-dev/api-client/0.0.13:
resolution: {integrity: sha512-RP7f8OaB2JS9y6diJpjozhxo/tx5CaQD2FpWj9udoSsWheySR7Tc+wqOMgkhP51xQskhTXRmV9m2pOg6qzFKwA==}
/@halo-dev/api-client/0.0.14:
resolution: {integrity: sha512-Qh0/l2f5e8lxBgAU2brN28F3CzZTlxGUGY0puUGbuDRYqEENbQ5pGTHG3CzuiG4it4Pn16xSTCXICO6M9m9X4A==}
dev: false
/@halo-dev/richtext-editor/0.0.0-alpha.5_vue@3.2.37:

View File

@ -164,7 +164,9 @@ async function loadCurrentUser() {
const { data: user } = await apiClient.user.getCurrentUserDetail();
app.provide<User>("currentUser", user);
const { data: currentPermissions } = await apiClient.user.getPermissions("-");
const { data: currentPermissions } = await apiClient.user.getPermissions({
name: "-",
});
const roleStore = useRoleStore();
roleStore.$patch({
permissions: currentPermissions,

View File

@ -96,8 +96,10 @@ const handleMove = async (group: Group) => {
name: group.metadata.name,
};
return apiClient.extension.storage.attachment.updatestorageHaloRunV1alpha1Attachment(
attachment.metadata.name,
attachmentToUpdate
{
name: attachment.metadata.name,
attachment: attachmentToUpdate,
}
);
});

View File

@ -39,9 +39,9 @@ watchEffect(async () => {
return;
}
const { data } =
await apiClient.extension.storage.policy.getstorageHaloRunV1alpha1Policy(
policyRef.name
);
await apiClient.extension.storage.policy.getstorageHaloRunV1alpha1Policy({
name: policyRef.name,
});
policy.value = data;
}
});

View File

@ -51,12 +51,16 @@ const handleSave = async () => {
saving.value = true;
if (isUpdateMode.value) {
await apiClient.extension.storage.group.updatestorageHaloRunV1alpha1Group(
formState.value.metadata.name,
formState.value
{
name: formState.value.metadata.name,
group: formState.value,
}
);
} else {
await apiClient.extension.storage.group.createstorageHaloRunV1alpha1Group(
formState.value
{
group: formState.value,
}
);
}
onVisibleChange(false);

View File

@ -97,12 +97,16 @@ const handleSave = async () => {
if (isUpdateMode.value) {
await apiClient.extension.storage.policy.updatestorageHaloRunV1alpha1Policy(
formState.value.metadata.name,
formState.value
{
name: formState.value.metadata.name,
policy: formState.value,
}
);
} else {
await apiClient.extension.storage.policy.createstorageHaloRunV1alpha1Policy(
formState.value
{
policy: formState.value,
}
);
}
@ -151,7 +155,9 @@ watch(
if (formState.value.spec.templateRef?.name) {
const { data } =
await apiClient.extension.storage.policyTemplate.getstorageHaloRunV1alpha1PolicyTemplate(
formState.value.spec.templateRef.name
{
name: formState.value.spec.templateRef.name,
}
);
policyTemplate.value = data;
}

View File

@ -54,9 +54,11 @@ const onVisibleChange = (visible: boolean) => {
const uploadHandler = computed(() => {
return (file, config) =>
apiClient.extension.storage.attachment.uploadAttachment(
file,
selectedPolicy.value?.metadata.name as string,
props.group?.metadata.name as string,
{
file,
policyName: selectedPolicy.value?.metadata.name as string,
groupName: props.group?.metadata.name as string,
},
config
);
});

View File

@ -71,9 +71,11 @@ const selectedAttachments = ref<Set<Attachment>>(new Set<Attachment>());
const uploadHandler = computed(() => {
return (file, config) =>
apiClient.extension.storage.attachment.uploadAttachment(
file,
selectedPolicy.value,
selectedGroup.value,
{
file,
policyName: selectedPolicy.value,
groupName: selectedGroup.value,
},
config
);
});
@ -83,7 +85,9 @@ const onUploaded = async (response: AxiosResponse) => {
const { data } =
await apiClient.extension.storage.attachment.getstorageHaloRunV1alpha1Attachment(
attachment.metadata.name
{
name: attachment.metadata.name,
}
);
attachments.value.add(data);
selectedAttachments.value.add(data);
@ -107,7 +111,9 @@ const handleDelete = async (attachment: Attachment) => {
onConfirm: async () => {
try {
await apiClient.extension.storage.attachment.deletestorageHaloRunV1alpha1Attachment(
attachment.metadata.name
{
name: attachment.metadata.name,
}
);
attachments.value.delete(attachment);
selectedAttachments.value.delete(attachment);

View File

@ -63,16 +63,14 @@ export function useAttachmentControl(filterOptions?: {
try {
loading.value = true;
const { data } =
await apiClient.extension.storage.attachment.searchAttachments(
policy?.value?.metadata.name,
keyword?.value,
group?.value?.metadata.name,
user?.value?.metadata.name,
attachments.value.size,
attachments.value.page,
[],
[]
);
await apiClient.extension.storage.attachment.searchAttachments({
policy: policy?.value?.metadata.name,
displayName: keyword?.value,
group: group?.value?.metadata.name,
uploadedBy: user?.value?.metadata.name,
page: attachments.value.page,
size: attachments.value.size,
});
attachments.value = data;
} catch (e) {
console.error("Failed to fetch attachments", e);
@ -138,7 +136,9 @@ export function useAttachmentControl(filterOptions?: {
const promises = Array.from(selectedAttachments.value).map(
(attachment) => {
return apiClient.extension.storage.attachment.deletestorageHaloRunV1alpha1Attachment(
attachment.metadata.name
{
name: attachment.metadata.name,
}
);
}
);

View File

@ -155,13 +155,15 @@ const handleSave = async () => {
}
if (isUpdateMode.value) {
const { data } = await apiClient.post.updateDraftPost(
formState.value.post.metadata.name,
formState.value
);
const { data } = await apiClient.post.updateDraftPost({
name: formState.value.post.metadata.name,
postRequest: formState.value,
});
formState.value.post = data;
} else {
const { data } = await apiClient.post.draftPost(formState.value);
const { data } = await apiClient.post.draftPost({
postRequest: formState.value,
});
formState.value.post = data;
name.value = data.metadata.name;
}
@ -178,9 +180,9 @@ const handleFetchContent = async () => {
if (!formState.value.post.spec.headSnapshot) {
return;
}
const { data } = await apiClient.content.obtainSnapshotContent(
formState.value.post.spec.headSnapshot
);
const { data } = await apiClient.content.obtainSnapshotContent({
snapshotName: formState.value.post.spec.headSnapshot,
});
formState.value.content = data;
};
@ -201,9 +203,9 @@ onMounted(async () => {
if (name.value) {
// fetch post
const { data: post } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post(
name.value as string
);
await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
name: name.value as string,
});
formState.value.post = post;
// fetch post content

View File

@ -76,11 +76,11 @@ const handleFetchPosts = async () => {
);
}
const { data } = await apiClient.post.listPosts(
posts.value.page,
posts.value.size,
labelSelector
);
const { data } = await apiClient.post.listPosts({
page: posts.value.page,
size: posts.value.size,
labelSelector,
});
posts.value = data;
} catch (e) {
console.error("Failed to fetch posts", e);
@ -103,7 +103,9 @@ const handlePaginationChange = ({
const handleOpenSettingModal = async (post: Post) => {
const { data } = await apiClient.extension.post.getcontentHaloRunV1alpha1Post(
post.metadata.name
{
name: post.metadata.name,
}
);
selectedPost.value = data;
settingModal.value = true;
@ -122,9 +124,9 @@ const handleSelectPrevious = async () => {
);
if (index > 0) {
const { data } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post(
items[index - 1].post.metadata.name
);
await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
name: items[index - 1].post.metadata.name,
});
selectedPost.value = data;
return;
}
@ -142,9 +144,9 @@ const handleSelectNext = async () => {
);
if (index < items.length - 1) {
const { data } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post(
items[index + 1].post.metadata.name
);
await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
name: items[index + 1].post.metadata.name,
});
selectedPost.value = data;
return;
}
@ -189,10 +191,10 @@ const handleDelete = async (post: Post) => {
onConfirm: async () => {
const postToUpdate = cloneDeep(post);
postToUpdate.spec.deleted = true;
await apiClient.extension.post.updatecontentHaloRunV1alpha1Post(
postToUpdate.metadata.name,
postToUpdate
);
await apiClient.extension.post.updatecontentHaloRunV1alpha1Post({
name: postToUpdate.metadata.name,
post: postToUpdate,
});
await handleFetchPosts();
},
});
@ -207,9 +209,9 @@ watchEffect(async () => {
return;
}
const { data: content } = await apiClient.content.obtainSnapshotContent(
selectedPost.value.spec.headSnapshot
);
const { data: content } = await apiClient.content.obtainSnapshotContent({
snapshotName: selectedPost.value.spec.headSnapshot,
});
selectedPostWithContent.value = {
post: selectedPost.value,

View File

@ -49,10 +49,10 @@ const handleUpdateInBatch = useDebounceFn(async () => {
const categoriesToUpdate = convertTreeToCategories(categoriesTreeToUpdate);
try {
const promises = categoriesToUpdate.map((category) =>
apiClient.extension.category.updatecontentHaloRunV1alpha1Category(
category.metadata.name,
category
)
apiClient.extension.category.updatecontentHaloRunV1alpha1Category({
name: category.metadata.name,
category: category,
})
);
await Promise.all(promises);
} catch (e) {

View File

@ -64,14 +64,14 @@ const handleSaveCategory = async () => {
try {
saving.value = true;
if (isUpdateMode.value) {
await apiClient.extension.category.updatecontentHaloRunV1alpha1Category(
formState.value.metadata.name,
formState.value
);
await apiClient.extension.category.updatecontentHaloRunV1alpha1Category({
name: formState.value.metadata.name,
category: formState.value,
});
} else {
await apiClient.extension.category.createcontentHaloRunV1alpha1Category(
formState.value
);
await apiClient.extension.category.createcontentHaloRunV1alpha1Category({
category: formState.value,
});
}
onVisibleChange(false);
} catch (e) {

View File

@ -25,10 +25,10 @@ export function usePostCategory(): usePostCategoryReturn {
try {
loading.value = true;
const { data } =
await apiClient.extension.category.listcontentHaloRunV1alpha1Category(
0,
0
);
await apiClient.extension.category.listcontentHaloRunV1alpha1Category({
page: 0,
size: 0,
});
categories.value = data.items;
categoriesTree.value = buildCategoriesTree(data.items);
} catch (e) {
@ -46,7 +46,9 @@ export function usePostCategory(): usePostCategoryReturn {
onConfirm: async () => {
try {
await apiClient.extension.category.deletecontentHaloRunV1alpha1Category(
category.metadata.name
{
name: category.metadata.name,
}
);
} catch (e) {
console.error("Failed to delete tag", e);

View File

@ -106,14 +106,16 @@ const handleSave = async () => {
formState.value.content.content = formState.value.content.raw;
if (isUpdateMode.value) {
const { data } = await apiClient.post.updateDraftPost(
formState.value.post.metadata.name,
formState.value
);
const { data } = await apiClient.post.updateDraftPost({
name: formState.value.post.metadata.name,
postRequest: formState.value,
});
formState.value.post = data;
emit("saved", formState.value);
} else {
const { data } = await apiClient.post.draftPost(formState.value);
const { data } = await apiClient.post.draftPost({
postRequest: formState.value,
});
formState.value.post = data;
emit("saved", formState.value);
}
@ -133,15 +135,15 @@ const handlePublish = async () => {
// Get latest version post
const { data: latestData } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post(
formState.value.post.metadata.name
);
await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
name: formState.value.post.metadata.name,
});
formState.value.post = latestData;
// Publish post
const { data } = await apiClient.post.publishPost(
formState.value.post.metadata.name
);
const { data } = await apiClient.post.publishPost({
name: formState.value.post.metadata.name,
});
formState.value.post = data;
emit("saved", formState.value);
} catch (e) {
@ -158,16 +160,16 @@ const handlePublishCanceling = async () => {
// Update published spec = false
const postToUpdate = cloneDeep(formState.value);
postToUpdate.post.spec.published = false;
await apiClient.post.updateDraftPost(
postToUpdate.post.metadata.name,
postToUpdate
);
await apiClient.post.updateDraftPost({
name: postToUpdate.post.metadata.name,
postRequest: postToUpdate,
});
// Get latest version post
const { data: latestData } =
await apiClient.extension.post.getcontentHaloRunV1alpha1Post(
formState.value.post.metadata.name
);
await apiClient.extension.post.getcontentHaloRunV1alpha1Post({
name: formState.value.post.metadata.name,
});
formState.value.post = latestData;
emit("saved", formState.value);

View File

@ -89,7 +89,9 @@ const queryName = useRouteQuery("name");
onMounted(async () => {
if (queryName.value) {
const { data } = await apiClient.extension.tag.getcontentHaloRunV1alpha1Tag(
queryName.value as string
{
name: queryName.value as string,
}
);
selectedTag.value = data;
editingModal.value = true;

View File

@ -68,14 +68,14 @@ const handleSaveTag = async () => {
try {
saving.value = true;
if (isUpdateMode.value) {
await apiClient.extension.tag.updatecontentHaloRunV1alpha1Tag(
formState.value.metadata.name,
formState.value
);
await apiClient.extension.tag.updatecontentHaloRunV1alpha1Tag({
name: formState.value.metadata.name,
tag: formState.value,
});
} else {
await apiClient.extension.tag.createcontentHaloRunV1alpha1Tag(
formState.value
);
await apiClient.extension.tag.createcontentHaloRunV1alpha1Tag({
tag: formState.value,
});
}
onVisibleChange(false);
} catch (e) {

View File

@ -21,7 +21,10 @@ export function usePostTag(): usePostTagReturn {
try {
loading.value = true;
const { data } =
await apiClient.extension.tag.listcontentHaloRunV1alpha1Tag(0, 0);
await apiClient.extension.tag.listcontentHaloRunV1alpha1Tag({
page: 0,
size: 0,
});
tags.value = data.items;
} catch (e) {
@ -38,9 +41,9 @@ export function usePostTag(): usePostTagReturn {
confirmType: "danger",
onConfirm: async () => {
try {
await apiClient.extension.tag.deletecontentHaloRunV1alpha1Tag(
tag.metadata.name
);
await apiClient.extension.tag.deletecontentHaloRunV1alpha1Tag({
name: tag.metadata.name,
});
} catch (e) {
console.error("Failed to delete tag", e);
} finally {

View File

@ -46,12 +46,11 @@ const handleFetchMenuItems = async () => {
const menuItemNames = Array.from(selectedMenu.value.spec.menuItems)?.map(
(item) => item
);
const { data } = await apiClient.extension.menuItem.listv1alpha1MenuItem(
0,
0,
[],
[`name=(${menuItemNames.join(",")})`]
);
const { data } = await apiClient.extension.menuItem.listv1alpha1MenuItem({
page: 0,
size: 0,
fieldSelector: [`name=(${menuItemNames.join(",")})`],
});
menuItems.value = data.items;
// Build the menu tree
menuTreeItems.value = buildMenuItemsTree(data.items);
@ -71,17 +70,14 @@ const onMenuItemSaved = async (menuItem: MenuItem) => {
const menuToUpdate = cloneDeep(selectedMenu.value);
if (menuToUpdate) {
const menuItemsToUpdate = Array.from(
cloneDeep(menuToUpdate.spec.menuItems) || new Set<string>()
);
const menuItemsToUpdate = cloneDeep(menuToUpdate.spec.menuItems) || [];
menuItemsToUpdate.push(menuItem.metadata.name);
// @ts-ignore
menuToUpdate.spec.menuItems = Array.from(new Set(menuItemsToUpdate));
await apiClient.extension.menu.updatev1alpha1Menu(
menuToUpdate.metadata.name,
menuToUpdate
);
menuToUpdate.spec.menuItems = menuItemsToUpdate;
await apiClient.extension.menu.updatev1alpha1Menu({
name: menuToUpdate.metadata.name,
menu: menuToUpdate,
});
}
await menuListRef.value.handleFetchMenus();
@ -93,10 +89,10 @@ const handleUpdateInBatch = useDebounceFn(async () => {
const menuItemsToUpdate = convertTreeToMenuItems(menuTreeItemsToUpdate);
try {
const promises = menuItemsToUpdate.map((menuItem) =>
apiClient.extension.menuItem.updatev1alpha1MenuItem(
menuItem.metadata.name,
menuItem
)
apiClient.extension.menuItem.updatev1alpha1MenuItem({
name: menuItem.metadata.name,
menuItem,
})
);
await Promise.all(promises);
} catch (e) {
@ -113,9 +109,9 @@ const handleDelete = async (menuItem: MenuTreeItem) => {
description: "删除后将无法恢复",
confirmType: "danger",
onConfirm: async () => {
await apiClient.extension.menuItem.deletev1alpha1MenuItem(
menuItem.metadata.name
);
await apiClient.extension.menuItem.deletev1alpha1MenuItem({
name: menuItem.metadata.name,
});
const childrenNames = getChildrenNames(menuItem);
@ -127,7 +123,9 @@ const handleDelete = async (menuItem: MenuTreeItem) => {
confirmType: "danger",
onConfirm: async () => {
const promises = childrenNames.map((name) =>
apiClient.extension.menuItem.deletev1alpha1MenuItem(name)
apiClient.extension.menuItem.deletev1alpha1MenuItem({
name,
})
);
await Promise.all(promises);
},

View File

@ -28,7 +28,6 @@ const emit = defineEmits<{
const initialFormState: Menu = {
spec: {
displayName: "",
// @ts-ignore
menuItems: [],
},
apiVersion: "v1alpha1",
@ -49,14 +48,14 @@ const handleCreateMenu = async () => {
try {
saving.value = true;
if (isUpdateMode.value) {
await apiClient.extension.menu.updatev1alpha1Menu(
formState.value.metadata.name,
formState.value
);
await apiClient.extension.menu.updatev1alpha1Menu({
name: formState.value.metadata.name,
menu: formState.value,
});
} else {
const { data } = await apiClient.extension.menu.createv1alpha1Menu(
formState.value
);
const { data } = await apiClient.extension.menu.createv1alpha1Menu({
menu: formState.value,
});
emit("created", data);
}
onVisibleChange(false);

View File

@ -29,7 +29,7 @@ const initialFormState: MenuItem = {
spec: {
displayName: "",
href: "",
children: new Set([]),
children: [],
priority: 0,
},
apiVersion: "v1alpha1",
@ -50,23 +50,19 @@ const handleSaveMenuItem = async () => {
try {
saving.value = true;
// TODO Array
// @ts-ignore
formState.value.spec.children = Array.from(formState.value.spec.children);
if (isUpdateMode.value) {
const { data } =
await apiClient.extension.menuItem.updatev1alpha1MenuItem(
formState.value.metadata.name,
formState.value
);
await apiClient.extension.menuItem.updatev1alpha1MenuItem({
name: formState.value.metadata.name,
menuItem: formState.value,
});
onVisibleChange(false);
emit("saved", data);
} else {
const { data } =
await apiClient.extension.menuItem.createv1alpha1MenuItem(
formState.value
);
await apiClient.extension.menuItem.createv1alpha1MenuItem({
menuItem: formState.value,
});
onVisibleChange(false);
emit("saved", data);
}

View File

@ -72,10 +72,15 @@ const handleDeleteMenu = async (menu: Menu) => {
confirmType: "danger",
onConfirm: async () => {
try {
await apiClient.extension.menu.deletev1alpha1Menu(menu.metadata.name);
await apiClient.extension.menu.deletev1alpha1Menu({
name: menu.metadata.name,
});
const deleteItemsPromises = Array.from(menu.spec.menuItems || []).map(
(item) => apiClient.extension.menuItem.deletev1alpha1MenuItem(item)
(item) =>
apiClient.extension.menuItem.deletev1alpha1MenuItem({
name: item,
})
);
await Promise.all(deleteItemsPromises);
@ -151,7 +156,7 @@ defineExpose({
{{ menu.spec?.displayName }}
</span>
<span class="block text-xs text-gray-400">
{{ Array.from(menu.spec.menuItems || new Set()).length }}
{{ menu.spec.menuItems?.length || 0 }}
个菜单项
</span>
</span>

View File

@ -92,10 +92,10 @@ exports[`convertMenuTreeItemToMenuItem > should match snapshot 1`] = `
"version": 12,
},
"spec": {
"children": Set {
"children": [
"caeef383-3828-4039-9114-6f9ad3b4a37e",
"ded1943d-9fdb-4563-83ee-2f04364872e0",
},
],
"displayName": "文章分类",
"href": "https://ryanc.cc/categories",
"priority": 1,
@ -113,9 +113,9 @@ exports[`convertMenuTreeItemToMenuItem > should match snapshot 2`] = `
"version": 1,
},
"spec": {
"children": Set {
"children": [
"96b636bb-3e4a-44d1-8ea7-f9da9e876f45",
},
],
"displayName": "Java",
"href": "https://ryanc.cc/categories/java",
"priority": 1,

View File

@ -15,7 +15,6 @@ const rawMenuItems: MenuItem[] = [
spec: {
displayName: "文章分类",
href: "https://ryanc.cc/categories",
// @ts-ignore
children: [
"caeef383-3828-4039-9114-6f9ad3b4a37e",
"ded1943d-9fdb-4563-83ee-2f04364872e0",
@ -34,7 +33,6 @@ const rawMenuItems: MenuItem[] = [
spec: {
displayName: "Halo",
href: "https://ryanc.cc/categories/halo",
// @ts-ignore
children: [],
priority: 0,
},
@ -50,7 +48,6 @@ const rawMenuItems: MenuItem[] = [
spec: {
displayName: "Java",
href: "https://ryanc.cc/categories/java",
// @ts-ignore
children: ["96b636bb-3e4a-44d1-8ea7-f9da9e876f45"],
priority: 1,
},
@ -66,7 +63,6 @@ const rawMenuItems: MenuItem[] = [
spec: {
displayName: "Spring Boot",
href: "https://ryanc.cc/categories/spring-boot",
// @ts-ignore
children: [],
priority: 0,
},
@ -82,7 +78,6 @@ const rawMenuItems: MenuItem[] = [
spec: {
displayName: "首页",
href: "https://ryanc.cc/",
// @ts-ignore
children: [],
priority: 0,
},
@ -259,11 +254,9 @@ describe("convertMenuTreeItemToMenuItem", () => {
).toBe("文章分类");
expect(
convertMenuTreeItemToMenuItem(menuTreeItems[1]).spec.children
).toStrictEqual(
new Set([
"caeef383-3828-4039-9114-6f9ad3b4a37e",
"ded1943d-9fdb-4563-83ee-2f04364872e0",
])
);
).toStrictEqual([
"caeef383-3828-4039-9114-6f9ad3b4a37e",
"ded1943d-9fdb-4563-83ee-2f04364872e0",
]);
});
});

View File

@ -128,7 +128,6 @@ export function buildMenuItemsTree(menuItems: MenuItem[]): MenuTreeItem[] {
menuItem.spec.children.forEach((child) => {
parentMap[child] = menuItem.metadata.name;
});
// @ts-ignore
menuItem.spec.children = [];
});
@ -212,7 +211,6 @@ export function convertTreeToMenuItems(menuTreeItems: MenuTreeItem[]) {
...node,
spec: {
...node.spec,
// @ts-ignore
children: children.map((child) => child.metadata.name),
},
});
@ -261,7 +259,7 @@ export function convertMenuTreeItemToMenuItem(
...menuTreeItem,
spec: {
...menuTreeItem.spec,
children: new Set(childNames),
children: childNames,
},
};
}

View File

@ -59,9 +59,9 @@ const handleUninstall = async (theme: Theme) => {
description: "删除后将无法恢复。",
onConfirm: async () => {
try {
await apiClient.extension.theme.deletethemeHaloRunV1alpha1Theme(
theme.metadata.name
);
await apiClient.extension.theme.deletethemeHaloRunV1alpha1Theme({
name: theme.metadata.name,
});
} catch (e) {
console.error("Failed to uninstall theme", e);
} finally {

View File

@ -26,7 +26,9 @@ export function useThemeLifeCycle(theme: Ref<Theme>): useThemeLifeCycleReturn {
loading.value = true;
const { data } = await apiClient.extension.configMap.getv1alpha1ConfigMap(
"system"
{
name: "system",
}
);
if (!data.data?.theme) {
@ -36,9 +38,9 @@ export function useThemeLifeCycle(theme: Ref<Theme>): useThemeLifeCycleReturn {
const themeConfig = JSON.parse(data.data.theme);
const { data: themeData } =
await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme(
themeConfig.active
);
await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme({
name: themeConfig.active,
});
theme.value = themeData;
activatedTheme.value = themeData;
@ -56,7 +58,9 @@ export function useThemeLifeCycle(theme: Ref<Theme>): useThemeLifeCycleReturn {
onConfirm: async () => {
try {
const { data: systemConfigMap } =
await apiClient.extension.configMap.getv1alpha1ConfigMap("system");
await apiClient.extension.configMap.getv1alpha1ConfigMap({
name: "system",
});
if (systemConfigMap.data) {
const themeConfigToUpdate = JSON.parse(
@ -65,10 +69,10 @@ export function useThemeLifeCycle(theme: Ref<Theme>): useThemeLifeCycleReturn {
themeConfigToUpdate.active = theme.value?.metadata?.name;
systemConfigMap.data["theme"] = JSON.stringify(themeConfigToUpdate);
await apiClient.extension.configMap.updatev1alpha1ConfigMap(
"system",
systemConfigMap
);
await apiClient.extension.configMap.updatev1alpha1ConfigMap({
name: "system",
configMap: systemConfigMap,
});
}
} catch (e) {
console.error("Failed to active theme", e);

View File

@ -20,9 +20,11 @@ const pluginRoleTemplates = ref<Role[]>([]);
const handleFetchRoles = async () => {
try {
const { data } = await apiClient.extension.role.listv1alpha1Role(0, 0, [
`${pluginLabels.NAME}=${plugin.value.metadata.name}`,
]);
const { data } = await apiClient.extension.role.listv1alpha1Role({
page: 0,
size: 0,
labelSelector: [`${pluginLabels.NAME}=${plugin.value.metadata.name}`],
});
pluginRoleTemplates.value = data.items;
} catch (e) {
console.error(e);

View File

@ -33,12 +33,11 @@ const handleFetchPlugins = async () => {
}
const { data } =
await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin(
0,
0,
[],
fieldSelector
);
await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin({
page: 0,
size: 0,
fieldSelector,
});
plugins.value = data.items;
} catch (e) {
console.error("Fail to fetch plugins", e);

View File

@ -48,15 +48,15 @@ const server = {
onConfirm: async () => {
try {
const { data: pluginToUpdate } =
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin(
plugin.metadata.name
);
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
name: plugin.metadata.name,
});
pluginToUpdate.spec.enabled = true;
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin(
pluginToUpdate.metadata.name,
pluginToUpdate
);
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
name: pluginToUpdate.metadata.name,
plugin: pluginToUpdate,
});
window.location.reload();
} catch (e) {

View File

@ -32,10 +32,10 @@ export function usePluginLifeCycle(
onConfirm: async () => {
try {
pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled;
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin(
pluginToUpdate.metadata.name,
pluginToUpdate
);
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
name: pluginToUpdate.metadata.name,
plugin: pluginToUpdate,
});
} catch (e) {
console.error(e);
} finally {
@ -64,15 +64,15 @@ export function usePluginLifeCycle(
if (enabled) {
const pluginToUpdate = cloneDeep(plugin.value);
pluginToUpdate.spec.enabled = false;
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin(
pluginToUpdate.metadata.name,
pluginToUpdate
);
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
name: pluginToUpdate.metadata.name,
plugin: pluginToUpdate,
});
}
await apiClient.extension.plugin.deletepluginHaloRunV1alpha1Plugin(
plugin.value.metadata.name
);
await apiClient.extension.plugin.deletepluginHaloRunV1alpha1Plugin({
name: plugin.value.metadata.name,
});
} catch (e) {
console.error(e);
} finally {

View File

@ -42,9 +42,9 @@ watch(
const handleFetchRole = async () => {
try {
const response = await apiClient.extension.role.getv1alpha1Role(
route.params.name as string
);
const response = await apiClient.extension.role.getv1alpha1Role({
name: route.params.name as string,
});
formState.value = response.data;
selectedRoleTemplates.value = new Set(
JSON.parse(

View File

@ -61,7 +61,9 @@ const handleDelete = async (role: Role) => {
confirmType: "danger",
onConfirm: async () => {
try {
await apiClient.extension.role.deletev1alpha1Role(role.metadata.name);
await apiClient.extension.role.deletev1alpha1Role({
name: role.metadata.name,
});
} catch (e) {
console.error("Failed to delete role", e);
}

View File

@ -57,9 +57,11 @@ export function useFetchRole(): useFetchRoleReturn {
const handleFetchRoles = async () => {
try {
loading.value = true;
const { data } = await apiClient.extension.role.listv1alpha1Role(0, 0, [
`!${roleLabels.TEMPLATE}`,
]);
const { data } = await apiClient.extension.role.listv1alpha1Role({
page: 0,
size: 0,
labelSelector: [`!${roleLabels.TEMPLATE}`],
});
roles.value = data.items;
} catch (e) {
console.error("Failed to fetch roles", e);
@ -94,12 +96,14 @@ export function useRoleForm(): useRoleFormReturn {
try {
saving.value = true;
if (isUpdateMode.value) {
await apiClient.extension.role.updatev1alpha1Role(
formState.value.metadata.name,
formState.value
);
await apiClient.extension.role.updatev1alpha1Role({
name: formState.value.metadata.name,
role: formState.value,
});
} else {
await apiClient.extension.role.createv1alpha1Role(formState.value);
await apiClient.extension.role.createv1alpha1Role({
role: formState.value,
});
}
} catch (e) {
console.error(e);
@ -233,10 +237,11 @@ export function useRoleTemplateSelection(): useRoleTemplateSelectionReturn {
*/
const handleFetchRoles = async () => {
try {
const { data } = await apiClient.extension.role.listv1alpha1Role(0, 0, [
`${roleLabels.TEMPLATE}=true`,
"!halo.run/hidden",
]);
const { data } = await apiClient.extension.role.listv1alpha1Role({
page: 0,
size: 0,
labelSelector: [`${roleLabels.TEMPLATE}=true`, "!halo.run/hidden"],
});
roleTemplates.value = data.items;
} catch (e) {
console.error(e);

View File

@ -38,10 +38,10 @@ const selectedUser = ref<User | null>(null);
const handleFetchUsers = async () => {
try {
const { data } = await apiClient.extension.user.listv1alpha1User(
users.value.page,
users.value.size
);
const { data } = await apiClient.extension.user.listv1alpha1User({
page: users.value.page,
size: users.value.size,
});
users.value = data;
} catch (e) {
console.error(e);

View File

@ -148,22 +148,24 @@ const handleCreateUser = async () => {
let user: User;
if (isUpdateMode.value) {
const response = await apiClient.extension.user.updatev1alpha1User(
formState.value.user.metadata.name,
formState.value.user
);
const response = await apiClient.extension.user.updatev1alpha1User({
name: formState.value.user.metadata.name,
user: formState.value.user,
});
user = response.data;
} else {
const response = await apiClient.extension.user.createv1alpha1User(
formState.value.user
);
const response = await apiClient.extension.user.createv1alpha1User({
user: formState.value.user,
});
user = response.data;
}
if (selectedRole.value) {
await apiClient.user.grantPermission(user.metadata.name, {
// @ts-ignore
roles: [selectedRole.value],
await apiClient.user.grantPermission({
name: user.metadata.name,
grantRequest: {
roles: [selectedRole.value],
},
});
}

View File

@ -56,12 +56,15 @@ const handleChangePassword = async () => {
delete changePasswordRequest.password_confirm;
if (props.user?.metadata.name === currentUser?.metadata.name) {
await apiClient.user.changePassword("-", changePasswordRequest);
await apiClient.user.changePassword({
name: "-",
changePasswordRequest,
});
} else {
await apiClient.user.changePassword(
props.user?.metadata.name || "",
changePasswordRequest
);
await apiClient.user.changePassword({
name: props.user?.metadata.name || "",
changePasswordRequest,
});
}
handleVisibleChange(false);

View File

@ -28,9 +28,9 @@ const { params } = useRoute();
const handleFetchUser = async () => {
try {
const { data } = await apiClient.extension.user.getv1alpha1User(
params.name as string
);
const { data } = await apiClient.extension.user.getv1alpha1User({
name: params.name as string,
});
user.value = data;
} catch (e) {
console.error(e);

View File

@ -11,8 +11,8 @@ export const useRoleStore = defineStore({
state: (): RoleStoreState => ({
roles: [],
permissions: {
roles: new Set<Role>([]),
uiPermissions: new Set<string>([]),
roles: [],
uiPermissions: [],
},
}),
});