Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make comment and reply list item operations extendable #6438

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ import {
import type {
CommentSubjectRefProvider,
CommentSubjectRefResult,
OperationItem
} from "@halo-dev/console-shared";
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
import { computed, onMounted, provide, ref, type Ref } from "vue";
import { computed, onMounted, provide, ref, type Ref, toRefs, markRaw } from "vue";
import { useI18n } from "vue-i18n";
import ReplyCreationModal from "./ReplyCreationModal.vue";
import ReplyListItem from "./ReplyListItem.vue";
import { useOperationItemExtensionPoint } from "@console/composables/use-operation-extension-points";
import EntityDropdownItems from "@/components/entity/EntityDropdownItems.vue";

const { currentUserHasPermission } = usePermission();
const { t } = useI18n();
Expand All @@ -50,6 +53,8 @@ const props = withDefaults(
}
);

const { comment } = toRefs(props);

const hoveredReply = ref<ListedReply>();
const showReplies = ref(false);
const replyModal = ref(false);
Expand Down Expand Up @@ -293,6 +298,35 @@ const subjectRefResult = computed(() => {
}
return subjectRef.resolve(subject);
});

const { operationItems } = useOperationItemExtensionPoint<ListedComment>(
"comment:list-item:operation:create",
comment,
computed((): OperationItem<ListedComment>[] => [
{
priority: 0,
component: markRaw(VDropdownItem),
label: t("core.comment.operations.approve_comment_in_batch.button"),
action: handleApprove,
hidden: props.comment?.comment.spec.approved,
},
{
priority: 10,
component: markRaw(VDropdownItem),
label: t("core.comment.operations.approve_applies_in_batch.button"),
action: handleApproveReplyInBatch,
},
{
priority: 20,
component: markRaw(VDropdownItem),
props: {
type: "danger",
},
label: t("core.common.buttons.delete"),
action: handleDelete,
},
])
);
</script>

<template>
Expand Down Expand Up @@ -419,18 +453,7 @@ const subjectRefResult = computed(() => {
v-if="currentUserHasPermission(['system:comments:manage'])"
#dropdownItems
>
<VDropdownItem
v-if="!comment?.comment.spec.approved"
@click="handleApprove"
>
{{ $t("core.comment.operations.approve_comment_in_batch.button") }}
</VDropdownItem>
<VDropdownItem @click="handleApproveReplyInBatch">
{{ $t("core.comment.operations.approve_applies_in_batch.button") }}
</VDropdownItem>
<VDropdownItem type="danger" @click="handleDelete">
{{ $t("core.common.buttons.delete") }}
</VDropdownItem>
<EntityDropdownItems :dropdown-items="operationItems" :item="comment" />
</template>

<template v-if="showReplies" #footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import {
VStatusDot,
VTag,
} from "@halo-dev/components";
import type { OperationItem } from "@halo-dev/console-shared";
import { useQueryClient } from "@tanstack/vue-query";
import { computed, inject, ref, type Ref } from "vue";
import { computed, inject, ref, type Ref, toRefs, markRaw } from "vue";
import { useI18n } from "vue-i18n";
import ReplyCreationModal from "./ReplyCreationModal.vue";
import { useOperationItemExtensionPoint } from "@console/composables/use-operation-extension-points";
import EntityDropdownItems from "@/components/entity/EntityDropdownItems.vue";

const { t } = useI18n();
const queryClient = useQueryClient();
Expand All @@ -33,6 +36,8 @@ const props = withDefaults(
}
);

const { reply } = toRefs(props);

const quoteReply = computed(() => {
const { quoteReply: replyName } = props.reply.reply.spec;

Expand Down Expand Up @@ -119,6 +124,31 @@ function onReplyCreationModalClose() {
});
replyModal.value = false;
}

const { operationItems } = useOperationItemExtensionPoint<ListedReply>(
"reply:list-item:operation:create",
reply,
computed((): OperationItem<ListedReply>[] => [
{
priority: 0,
component: markRaw(VDropdownItem),
label: t("core.comment.operations.approve_reply.button"),
permissions: ['system:comments:manage'],
action: handleApprove,
hidden: props.reply?.reply.spec.approved,
},
{
priority: 10,
component: markRaw(VDropdownItem),
props: {
type: "danger",
},
label: t("core.common.buttons.delete"),
permissions: ['system:comments:manage'],
action: handleDelete,
},
])
);
</script>

<template>
Expand Down Expand Up @@ -214,20 +244,7 @@ function onReplyCreationModalClose() {
</VEntityField>
</template>
<template #dropdownItems>
<VDropdownItem
v-if="!reply?.reply.spec.approved"
v-permission="['system:comments:manage']"
@click="handleApprove"
>
{{ $t("core.comment.operations.approve_reply.button") }}
</VDropdownItem>
<VDropdownItem
v-permission="['system:comments:manage']"
type="danger"
@click="handleDelete"
>
{{ $t("core.common.buttons.delete") }}
</VDropdownItem>
<EntityDropdownItems :dropdown-items="operationItems" :item="reply" />
</template>
</VEntity>
</template>
2 changes: 2 additions & 0 deletions ui/docs/extension-points/entity-listitem-operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
目前支持扩展的数据列表:

- 文章:`"post:list-item:operation:create"?: (post: Ref<ListedPost>) => | OperationItem<ListedPost>[] | Promise<OperationItem<ListedPost>[]>`
- 评论:`"comment:list-item:operation:create"?: (comment: Ref<ListedComment>) => | OperationItem<ListedComment>[] | Promise<OperationItem<ListedComment>[]>`
- 回复:`"reply:list-item:operation:create"?: (reply: Ref<ListedReply>) => | OperationItem<ListedReply>[] | Promise<OperationItem<ListedReply>[]>`
- 插件:`"plugin:list-item:operation:create"?: (plugin: Ref<Plugin>) => | OperationItem<Plugin>[] | Promise<OperationItem<Plugin>[]>`
- 备份:`"backup:list-item:operation:create"?: (backup: Ref<Backup>) => | OperationItem<Backup>[] | Promise<OperationItem<Backup>[]>`
- 主题:`"theme:list-item:operation:create"?: (theme: Ref<Theme>) => | OperationItem<Theme>[] | Promise<OperationItem<Theme>[]>`
Expand Down
10 changes: 10 additions & 0 deletions ui/packages/shared/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {
ListedPost,
Plugin,
Theme,
ListedComment,
ListedReply
} from "@halo-dev/api-client";
import type { AnyExtension } from "@halo-dev/richtext-editor";
import type { Component, Ref } from "vue";
Expand Down Expand Up @@ -52,6 +54,14 @@ export interface ExtensionPoint {
post: Ref<ListedPost>
) => OperationItem<ListedPost>[];

"comment:list-item:operation:create"?: (
comment: Ref<ListedComment>
) => OperationItem<ListedComment>[];

"reply:list-item:operation:create"?: (
reply: Ref<ListedReply>
) => OperationItem<ListedReply>[];

"plugin:list-item:operation:create"?: (
plugin: Ref<Plugin>
) => OperationItem<Plugin>[];
Expand Down
Loading