Skip to content

Commit

Permalink
fix: article page for customer portal
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Oct 2, 2024
1 parent b6dff21 commit 219d8f2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 39 deletions.
75 changes: 56 additions & 19 deletions desk/src/pages/KnowledgeBaseArticle.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div class="flex h-full flex-col overflow-hidden">
<PageTitle v-if="!route.meta.public">
<PageTitle>
<template #title>
<Breadcrumbs :items="breadcrumbs" />
</template>
<template #right>
<template #right v-if="!route.meta.public">
<component
:is="actionsComponent"
:status="article.data?.status"
Expand Down Expand Up @@ -33,12 +33,13 @@
editor-class="prose-f"
@change="articleContent = $event"
>
<template #top>
<template #top v-if="!route.meta.public">
<component
:is="topComponent"
v-model:title="articleTitle"
v-bind="options__"
/>

<TextEditorFixedMenu
v-if="editMode"
class="-ml-1"
Expand Down Expand Up @@ -122,45 +123,82 @@ const router = useRouter();
const authStore = useAuthStore();
const isNew = props.articleId === "new";
const editMode = ref(isNew);
const categoryId = computed(() => route.query.category);
const subCategoryId = computed(() => route.query.subCategory);
const categoryId = computed(() => router.currentRoute.value.query.category);
const subCategoryId = computed(
() => router.currentRoute.value.query.subCategory
);
const isCustomerPortal = computed(() => route.meta.public);
const breadcrumbs = computed(() => {
const items = [
const agentPortalItems = [
{
label: options__.value.categoryName,
route: {
name: AGENT_PORTAL_KNOWLEDGE_BASE_CATEGORY,
params: { categoryId: options__.value.categoryId },
},
},
{
label: options__.value.subCategoryName,
route: {
name: AGENT_PORTAL_KNOWLEDGE_BASE_SUB_CATEGORY,
params: {
categoryId: options__.value.categoryId,
subCategoryId: options__.value.subCategoryId,
},
];
// if (options__.value.subCategoryId !== options__.value.categoryId) {
agentPortalItems.push({
label: options__.value.subCategoryName,
route: {
name: AGENT_PORTAL_KNOWLEDGE_BASE_SUB_CATEGORY,
params: {
categoryId: options__.value.categoryId,
subCategoryId:
options__.value.subCategoryId || options__.value.categoryId,
},
},
];
});
// }
if (!isNew) {
items.push({
agentPortalItems.push({
label: article.data?.title,
route: {
name: AGENT_PORTAL_KNOWLEDGE_BASE_ARTICLE,
params: {
articleId: article.data?.name,
},
},
});
}
if (!isCustomerPortal.value) {
return agentPortalItems;
}
const customerPortalItems = [
{
label: "Knowledge Base",
route: {
name: "KnowledgeBasePublicNew",
},
},
];
if (options__.value.categoryId) {
customerPortalItems.push({
label: options__.value.categoryName,
route: {
name: "KnowledgeBasePublicNew",
query: { category: options__.value.categoryId },
},
});
}
if (options__.value.subCategoryId) {
customerPortalItems.push({
label: options__.value.subCategoryName,
route: {
name: "KnowledgeBasePublicNew",
query: {
category: options__.value.categoryId,
subCategory: options__.value.subCategoryId,
},
},
});
}
return items;
return customerPortalItems;
});
const placeholder = computed(() =>
editMode.value ? "Write something..." : "Content is empty"
Expand All @@ -175,7 +213,6 @@ const actionsComponent = computed(() => {
});
const topComponent = computed(() => {
if (route.meta.public) return KnowledgeBaseArticleTopPublic;
if (isNew) return KnowledgeBaseArticleTopNew;
if (editMode.value) return KnowledgeBaseArticleTopEdit;
return KnowledgeBaseArticleTopView;
Expand Down Expand Up @@ -208,7 +245,7 @@ const category = createDocumentResource({
const subCategory = createDocumentResource({
doctype: "HD Article Category",
name: subCategoryId.value,
auto: true,
auto: subCategoryId.value !== categoryId.value ? true : false,
});
const options__ = computed(() => ({
Expand Down
35 changes: 18 additions & 17 deletions desk/src/pages/knowledge-base-v2/KnowledgeBasePublic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
</template>

<script setup lang="ts">
import { ref, watch, computed, Ref } from "vue";
import { ref, watch, computed } from "vue";
import { LayoutHeader } from "@/components";
import KnowledgeBaseSidebar from "@/components/knowledge-base-v2/KnowledgeBaseSidebar.vue";
import KnowledgeBaseCategory from "@/components/knowledge-base-v2/KnowledgeBaseCategory.vue";
import { useRouter } from "vue-router";
import { Breadcrumbs } from "frappe-ui";
import { Breadcrumbs, createResource, call } from "frappe-ui";
import { reactive } from "vue";
const router = useRouter();
const defaultCategory = computed(
Expand All @@ -48,21 +49,21 @@ const breadcrumbs = computed(() => {
// return items;
// TODO: Add category and subcategory name to breadcrumbs
if (category) {
items.push({
label: category,
route: {
name: "KnowledgeBasePublicNew",
query: { category },
},
});
}
if (subCategory) {
items.push({
label: subCategory,
route: { name: "KnowledgeBasePublicNew", query: { subCategory } },
});
}
// if (category) {
// items.push({
// label: category,
// route: {
// name: "KnowledgeBasePublicNew",
// query: { category },
// },
// });
// }
// if (subCategory) {
// items.push({
// label: subCategory,
// route: { name: "KnowledgeBasePublicNew", query: { subCategory } },
// });
// }
return items;
});
Expand Down
1 change: 1 addition & 0 deletions desk/src/pages/knowledge-base/KnowledgeBaseSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
:is-expanded="true"
:label="category.category_name"
:on-click="() => toCategory(category.name)"
class="truncate"
/>
</div>
<KnowledgeBaseCategoryNew
Expand Down
3 changes: 1 addition & 2 deletions desk/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ const routes = [
{
path: "articles/:articleId?",
name: "KBArticlePublicNew",
component: () =>
import("@/pages/knowledge-base-v2/KnowledgeBaseArticle.vue"),
component: () => import("@/pages/KnowledgeBaseArticle.vue"),
props: true,
},
],
Expand Down
2 changes: 1 addition & 1 deletion helpdesk/helpdesk/doctype/hd_article/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_article(name: str):
author = frappe.get_cached_doc("User", article["author"])
sub_category = frappe.get_cached_doc("HD Article Category", article["category"])
category = frappe.get_cached_doc(
"HD Article Category", sub_category.parent_category
"HD Article Category", sub_category.get("parent_category", article["category"])
)

return {
Expand Down

0 comments on commit 219d8f2

Please sign in to comment.