Skip to content

Commit

Permalink
fix: copy to clipboard for article and category
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Jan 21, 2025
1 parent bb53885 commit 5482059
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
13 changes: 8 additions & 5 deletions desk/src/pages/knowledge-base/Article.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
{{ dayjs(article.data.modified).short() }}
</div>
</div>
<Dropdown :options="options" v-if="!editable && !isCustomerPortal">
<Dropdown
:options="articleActions"
v-if="!editable && !isCustomerPortal"
>
<Button variant="ghost">
<template #icon>
<IconMoreHorizontal class="h-4 w-4" />
Expand Down Expand Up @@ -380,7 +383,7 @@ const editorClass = computed(() => {
];
});
const options = computed(() => [
const articleActions = computed(() => [
{
label: "Edit",
icon: "edit",
Expand All @@ -394,11 +397,11 @@ const options = computed(() => [
onClick: () => (moveToModal.value = true),
},
{
label: "Copy",
icon: "copy",
label: "Share",
icon: "link",
onClick: () => {
const url = new URL(window.location.href);
url.pathname = `/helpdesk/kb-help/articles/${props.articleId}`;
url.pathname = `/helpdesk/kb-public/articles/${props.articleId}`;
copyToClipboard(url.href, article.data.title);
},
},
Expand Down
2 changes: 1 addition & 1 deletion desk/src/pages/knowledge-base/Articles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</template>
</LayoutHeader>
<div
class="pt-0 md:pt-3 sm:px-5 w-full flex flex-col gap-2 max-w-4xl 2xl:max-w-5xl"
class="pt-0 sm:px-5 w-full flex flex-col gap-2 max-w-4xl 2xl:max-w-5xl"
>
<div
v-if="articles.data"
Expand Down
12 changes: 11 additions & 1 deletion desk/src/pages/knowledge-base/KnowledgeBaseAgent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import LayoutHeader from "@/components/LayoutHeader.vue";
import ListViewBuilder from "@/components/ListViewBuilder.vue";
import CategoryModal from "@/components/knowledge-base/CategoryModal.vue";
import MoveToCategoryModal from "@/components/knowledge-base/MoveToCategoryModal.vue";
import { createToast } from "@/utils";
import { createToast, copyToClipboard } from "@/utils";
import { Error } from "@/types";
import LucideMerge from "~icons/lucide/merge";
import MergeCategoryModal from "@/components/knowledge-base/MergeCategoryModal.vue";
Expand Down Expand Up @@ -150,6 +150,16 @@ const groupByActions = [
category.id = groupedRow.group.value;
},
},
{
label: "Share",
icon: "link",
onClick: async ({ group }) => {
const { label, value } = group;
const url = new URL(window.location.href);
url.pathname = `/helpdesk/kb-public/${value}`;
await copyToClipboard(url.href, label);
},
},
{
label: "Delete",
icon: "trash-2",
Expand Down
14 changes: 12 additions & 2 deletions desk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,18 @@ export function setupCustomActions(data, obj) {

export const isCustomerPortal = ref(false);

export function copyToClipboard(text: string, message?: string) {
navigator.clipboard.writeText(text);
export async function copyToClipboard(text: string, message?: string) {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(text);
} else {
let input = document.createElement("input");
let body = document.querySelector("body");
body.appendChild(input);
input.value = text;
input.select();
document.execCommand("copy");
input.remove();
}
createToast({
title: "Copied to clipboard",
text: message,
Expand Down

0 comments on commit 5482059

Please sign in to comment.