mirror of https://github.com/halo-dev/halo
refactor: improve part of the post operation logic using the patch api (#6464)
#### What type of PR is this? /area ui /kind improvement /milestone 2.19.x #### What this PR does / why we need it: 使用 patch 接口重构文章的恢复、可见性修改等逻辑。 #### Which issue(s) this PR fixes: None #### Special notes for your reviewer: 测试文章删除、恢复、可见性修改功能是否符合预期。 #### Does this PR introduce a user-facing change? ```release-note 使用 patch 接口重构文章的恢复、可见性修改等逻辑。 ```pull/6470/head
parent
d78547f963
commit
d011beb89b
|
@ -23,7 +23,6 @@ import {
|
||||||
VStatusDot,
|
VStatusDot,
|
||||||
} from "@halo-dev/components";
|
} from "@halo-dev/components";
|
||||||
import { useQuery } from "@tanstack/vue-query";
|
import { useQuery } from "@tanstack/vue-query";
|
||||||
import { cloneDeep } from "lodash-es";
|
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import PostTag from "./tags/components/PostTag.vue";
|
import PostTag from "./tags/components/PostTag.vue";
|
||||||
|
@ -132,11 +131,15 @@ const handleRecovery = async (post: Post) => {
|
||||||
confirmText: t("core.common.buttons.confirm"),
|
confirmText: t("core.common.buttons.confirm"),
|
||||||
cancelText: t("core.common.buttons.cancel"),
|
cancelText: t("core.common.buttons.cancel"),
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
const postToUpdate = cloneDeep(post);
|
await coreApiClient.content.post.patchPost({
|
||||||
postToUpdate.spec.deleted = false;
|
name: post.metadata.name,
|
||||||
await coreApiClient.content.post.updatePost({
|
jsonPatchInner: [
|
||||||
name: postToUpdate.metadata.name,
|
{
|
||||||
post: postToUpdate,
|
op: "add",
|
||||||
|
path: "/spec/deleted",
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await refetch();
|
await refetch();
|
||||||
|
@ -157,23 +160,23 @@ const handleRecoveryInBatch = async () => {
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
selectedPostNames.value.map((name) => {
|
selectedPostNames.value.map((name) => {
|
||||||
const post = posts.value?.find(
|
const isPostExist = posts.value?.some(
|
||||||
(item) => item.post.metadata.name === name
|
(item) => item.post.metadata.name === name
|
||||||
)?.post;
|
);
|
||||||
|
|
||||||
if (!post) {
|
if (!isPostExist) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return coreApiClient.content.post.updatePost({
|
return coreApiClient.content.post.patchPost({
|
||||||
name: post.metadata.name,
|
name: name,
|
||||||
post: {
|
jsonPatchInner: [
|
||||||
...post,
|
{
|
||||||
spec: {
|
op: "add",
|
||||||
...post.spec,
|
path: "/spec/deleted",
|
||||||
deleted: false,
|
value: false,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -185,6 +185,7 @@ const { startFields, endFields } = useEntityFieldItemExtensionPoint<ListedPost>(
|
||||||
priority: 30,
|
priority: 30,
|
||||||
position: "end",
|
position: "end",
|
||||||
component: markRaw(VisibleField),
|
component: markRaw(VisibleField),
|
||||||
|
permissions: ["system:posts:manage"],
|
||||||
props: {
|
props: {
|
||||||
post: props.post,
|
post: props.post,
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,24 +17,21 @@ withDefaults(
|
||||||
|
|
||||||
const { mutate: changeVisibleMutation } = useMutation({
|
const { mutate: changeVisibleMutation } = useMutation({
|
||||||
mutationFn: async (post: Post) => {
|
mutationFn: async (post: Post) => {
|
||||||
const { data } = await coreApiClient.content.post.getPost({
|
return await coreApiClient.content.post.patchPost({
|
||||||
name: post.metadata.name,
|
name: post.metadata.name,
|
||||||
});
|
jsonPatchInner: [
|
||||||
data.spec.visible = data.spec.visible === "PRIVATE" ? "PUBLIC" : "PRIVATE";
|
|
||||||
await coreApiClient.content.post.updatePost(
|
|
||||||
{
|
{
|
||||||
name: post.metadata.name,
|
op: "add",
|
||||||
post: data,
|
path: "/spec/visible",
|
||||||
|
value: post.spec.visible === "PRIVATE" ? "PUBLIC" : "PRIVATE",
|
||||||
},
|
},
|
||||||
{
|
],
|
||||||
mute: true,
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
await queryClient.invalidateQueries({ queryKey: ["posts"] });
|
|
||||||
},
|
},
|
||||||
retry: 3,
|
retry: 3,
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
Toast.success(t("core.common.toast.operation_success"));
|
Toast.success(t("core.common.toast.operation_success"));
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["posts"] });
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
Toast.error(t("core.common.toast.operation_failed"));
|
Toast.error(t("core.common.toast.operation_failed"));
|
||||||
|
|
Loading…
Reference in New Issue