Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Jun 24, 2024
2 parents 516ce2c + 9604262 commit f28e1d3
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 121 deletions.
13 changes: 8 additions & 5 deletions ui/console-src/modules/contents/attachments/AttachmentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from "@halo-dev/components";
import { useLocalStorage } from "@vueuse/core";
import { useRouteQuery } from "@vueuse/router";
import { cloneDeep } from "lodash-es";
import type { Ref } from "vue";
import { computed, onMounted, provide, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
Expand Down Expand Up @@ -130,12 +129,16 @@ provide<Ref<Set<Attachment>>>("selectedAttachments", selectedAttachments);
const handleMove = async (group: Group) => {
try {
const promises = Array.from(selectedAttachments.value).map((attachment) => {
const attachmentToUpdate = cloneDeep(attachment);
attachmentToUpdate.spec.groupName = group.metadata.name;
return apiClient.extension.storage.attachment.updateStorageHaloRunV1alpha1Attachment(
return apiClient.extension.storage.attachment.patchStorageHaloRunV1alpha1Attachment(
{
name: attachment.metadata.name,
attachment: attachmentToUpdate,
jsonPatchInner: [
{
op: "add",
path: "/spec/groupName",
value: group.metadata.name,
},
],
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ const handleDelete = () => {
// move attachments to none group
const moveToUnGroupRequests = data.items.map((attachment) => {
attachment.spec.groupName = undefined;
return apiClient.extension.storage.attachment.updateStorageHaloRunV1alpha1Attachment(
return apiClient.extension.storage.attachment.patchStorageHaloRunV1alpha1Attachment(
{
name: attachment.metadata.name,
attachment: attachment,
jsonPatchInner: [
{
op: "remove",
path: "/spec/groupName",
},
],
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
VModal,
} from "@halo-dev/components";
import { useLocalStorage } from "@vueuse/core";
import { ref, watch } from "vue";
import { onMounted, ref } from "vue";
import { useFetchAttachmentGroup } from "../composables/use-attachment-group";
import {
useFetchAttachmentPolicy,
Expand All @@ -32,35 +32,11 @@ const selectedPolicyName = useLocalStorage("attachment-upload-policy", "");
const policyEditingModal = ref(false);
const policyTemplateNameToCreate = ref();
watch(
() => groups.value,
() => {
if (selectedGroupName.value === "") return;
const group = groups.value?.find(
(group) => group.metadata.name === selectedGroupName.value
);
if (!group) {
selectedGroupName.value = groups.value?.length
? groups.value[0].metadata.name
: "";
}
}
);
watch(
() => policies.value,
() => {
const policy = policies.value?.find(
(policy) => policy.metadata.name === selectedPolicyName.value
);
if (!policy) {
selectedPolicyName.value = policies.value?.length
? policies.value[0].metadata.name
: "";
}
onMounted(() => {
if (!selectedPolicyName.value) {
selectedPolicyName.value = policies.value?.[0].metadata.name;
}
);
});
const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
policyTemplateNameToCreate.value = policyTemplate.metadata.name;
Expand Down
20 changes: 12 additions & 8 deletions ui/console-src/modules/contents/comments/CommentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,22 @@ const handleApproveInBatch = async () => {
});
const promises = commentsToUpdate?.map((comment) => {
return apiClient.extension.comment.updateContentHaloRunV1alpha1Comment(
return apiClient.extension.comment.patchContentHaloRunV1alpha1Comment(
{
name: comment.comment.metadata.name,
comment: {
...comment.comment,
spec: {
...comment.comment.spec,
approved: true,
jsonPatchInner: [
{
op: "add",
path: "/spec/approved",
value: true,
},
{
op: "add",
path: "/spec/approvedTime",
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
approvedTime: new Date().toISOString(),
value: new Date().toISOString(),
},
},
],
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import type {
CommentSubjectRefResult,
} from "@halo-dev/console-shared";
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
import { cloneDeep } from "lodash-es";
import { computed, onMounted, provide, ref, type Ref } from "vue";
import { useI18n } from "vue-i18n";
import ReplyCreationModal from "./ReplyCreationModal.vue";
Expand Down Expand Up @@ -91,17 +90,21 @@ const handleApproveReplyInBatch = async () => {
return !reply.reply.spec.approved;
});
const promises = repliesToUpdate?.map((reply) => {
return apiClient.extension.reply.updateContentHaloRunV1alpha1Reply({
return apiClient.extension.reply.patchContentHaloRunV1alpha1Reply({
name: reply.reply.metadata.name,
reply: {
...reply.reply,
spec: {
...reply.reply.spec,
approved: true,
jsonPatchInner: [
{
op: "add",
path: "/spec/approved",
value: true,
},
{
op: "add",
path: "/spec/approvedTime",
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
approvedTime: new Date().toISOString(),
value: new Date().toISOString(),
},
},
],
});
});
await Promise.all(promises || []);
Expand All @@ -118,13 +121,21 @@ const handleApproveReplyInBatch = async () => {
const handleApprove = async () => {
try {
const commentToUpdate = cloneDeep(props.comment.comment);
commentToUpdate.spec.approved = true;
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
commentToUpdate.spec.approvedTime = new Date().toISOString();
await apiClient.extension.comment.updateContentHaloRunV1alpha1Comment({
name: commentToUpdate.metadata.name,
comment: commentToUpdate,
await apiClient.extension.comment.patchContentHaloRunV1alpha1Comment({
name: props.comment.comment.metadata.name,
jsonPatchInner: [
{
op: "add",
path: "/spec/approved",
value: true,
},
{
op: "add",
path: "/spec/approvedTime",
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
value: new Date().toISOString(),
},
],
});
Toast.success(t("core.common.toast.operation_success"));
Expand Down Expand Up @@ -165,21 +176,16 @@ const {
const { mutateAsync: updateCommentLastReadTimeMutate } = useMutation({
mutationKey: ["update-comment-last-read-time"],
mutationFn: async () => {
const { data: latestComment } =
await apiClient.extension.comment.getContentHaloRunV1alpha1Comment({
name: props.comment.comment.metadata.name,
});
if (!latestComment.status?.unreadReplyCount) {
return latestComment;
}
latestComment.spec.lastReadTime = new Date().toISOString();
return apiClient.extension.comment.updateContentHaloRunV1alpha1Comment(
return apiClient.extension.comment.patchContentHaloRunV1alpha1Comment(
{
name: latestComment.metadata.name,
comment: latestComment,
name: props.comment.comment.metadata.name,
jsonPatchInner: [
{
op: "add",
path: "/spec/lastReadTime",
value: new Date().toISOString(),
},
],
},
{
mute: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type { ListedComment, ListedReply } from "@halo-dev/api-client";
import { formatDatetime } from "@/utils/date";
import { apiClient } from "@/utils/api-client";
import { computed, inject, ref, type Ref } from "vue";
import { cloneDeep } from "lodash-es";
import { useI18n } from "vue-i18n";
import { useQueryClient } from "@tanstack/vue-query";
import ReplyCreationModal from "./ReplyCreationModal.vue";
Expand Down Expand Up @@ -71,13 +70,21 @@ const handleDelete = async () => {
const handleApprove = async () => {
try {
const replyToUpdate = cloneDeep(props.reply.reply);
replyToUpdate.spec.approved = true;
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
replyToUpdate.spec.approvedTime = new Date().toISOString();
await apiClient.extension.reply.updateContentHaloRunV1alpha1Reply({
name: replyToUpdate.metadata.name,
reply: replyToUpdate,
await apiClient.extension.reply.patchContentHaloRunV1alpha1Reply({
name: props.reply.reply.metadata.name,
jsonPatchInner: [
{
op: "add",
path: "/spec/approved",
value: true,
},
{
op: "add",
path: "/spec/approvedTime",
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
value: new Date().toISOString(),
},
],
});
Toast.success(t("core.common.toast.operation_success"));
Expand Down
4 changes: 3 additions & 1 deletion ui/console-src/modules/contents/pages/SinglePageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const { mutateAsync: singlePageUpdateMutate } = usePageUpdateMutate();
const { currentUserHasPermission } = usePermission();
// Editor providers
const { editorProviders } = useEditorExtensionPoints();
const { editorProviders, fetchEditorProviders } = useEditorExtensionPoints();
const currentEditorProvider = ref<EditorProvider>();
const storedEditorProviderName = useLocalStorage("editor-provider-name", "");
Expand Down Expand Up @@ -331,6 +331,8 @@ const onSettingPublished = (singlePage: SinglePage) => {
};
onMounted(async () => {
await fetchEditorProviders();
if (routeQueryName.value) {
const { data: singlePage } =
await apiClient.extension.singlePage.getContentHaloRunV1alpha1SinglePage({
Expand Down
4 changes: 3 additions & 1 deletion ui/console-src/modules/contents/posts/PostEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const { mutateAsync: postUpdateMutate } = usePostUpdateMutate();
const { currentUserHasPermission } = usePermission();
// Editor providers
const { editorProviders } = useEditorExtensionPoints();
const { editorProviders, fetchEditorProviders } = useEditorExtensionPoints();
const currentEditorProvider = ref<EditorProvider>();
const storedEditorProviderName = useLocalStorage("editor-provider-name", "");
Expand Down Expand Up @@ -356,6 +356,8 @@ const onSettingPublished = (post: Post) => {
// Get post data when the route contains the name parameter
const name = useRouteQuery<string>("name");
onMounted(async () => {
await fetchEditorProviders();
if (name.value) {
// fetch post
const { data: post } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,11 @@ const handleShowActiveModalAfterInstall = (plugin: Plugin) => {
cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => {
try {
const { data: pluginToUpdate } =
await apiClient.extension.plugin.getPluginHaloRunV1alpha1Plugin({
name: plugin.metadata.name,
});
pluginToUpdate.spec.enabled = true;
await apiClient.extension.plugin.updatePluginHaloRunV1alpha1Plugin({
name: pluginToUpdate.metadata.name,
plugin: pluginToUpdate,
await apiClient.plugin.changePluginRunningState({
name: plugin.metadata.name,
pluginRunningStateRequest: {
enable: true,
},
});
window.location.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ const handleShowActiveModalAfterInstall = (plugin: Plugin) => {
cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => {
try {
const { data: pluginToUpdate } =
await apiClient.extension.plugin.getPluginHaloRunV1alpha1Plugin({
name: plugin.metadata.name,
});
pluginToUpdate.spec.enabled = true;
await apiClient.extension.plugin.updatePluginHaloRunV1alpha1Plugin({
name: pluginToUpdate.metadata.name,
plugin: pluginToUpdate,
await apiClient.plugin.changePluginRunningState({
name: plugin.metadata.name,
pluginRunningStateRequest: {
enable: true,
},
});
window.location.reload();
Expand Down
15 changes: 6 additions & 9 deletions ui/console-src/modules/system/plugins/composables/use-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ComputedRef, Ref } from "vue";
import { computed } from "vue";
import { type Plugin, PluginStatusPhaseEnum } from "@halo-dev/api-client";
import { cloneDeep } from "lodash-es";
import { apiClient } from "@/utils/api-client";
import { Dialog, Toast } from "@halo-dev/components";
import { useI18n } from "vue-i18n";
Expand Down Expand Up @@ -117,14 +116,12 @@ export function usePluginLifeCycle(
if (!plugin.value) return;

try {
if (enabled) {
const pluginToUpdate = cloneDeep(plugin.value);
pluginToUpdate.spec.enabled = false;
await apiClient.extension.plugin.updatePluginHaloRunV1alpha1Plugin({
name: pluginToUpdate.metadata.name,
plugin: pluginToUpdate,
});
}
await apiClient.plugin.changePluginRunningState({
name: plugin.value.metadata.name,
pluginRunningStateRequest: {
enable: false,
},
});

await apiClient.extension.plugin.deletePluginHaloRunV1alpha1Plugin({
name: plugin.value.metadata.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script lang="ts" setup>
import { useEditorExtensionPoints } from "@/composables/use-editor-extension-points";
import type { EditorProvider } from "@halo-dev/console-shared";
import {
VAvatar,
IconExchange,
VAvatar,
VDropdown,
VDropdownItem,
} from "@halo-dev/components";
import type { EditorProvider } from "@halo-dev/console-shared";
withDefaults(
defineProps<{
Expand All @@ -23,7 +23,9 @@ const emit = defineEmits<{
(event: "select", provider: EditorProvider): void;
}>();
const { editorProviders } = useEditorExtensionPoints();
const { editorProviders, fetchEditorProviders } = useEditorExtensionPoints();
fetchEditorProviders();
</script>

<template>
Expand Down
Loading

0 comments on commit f28e1d3

Please sign in to comment.