From 8c88344170fd2a5a49db4fb9c1745c9bb6b2216b Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Thu, 22 Dec 2022 18:51:24 +0530 Subject: [PATCH] chore: Helpcenter improvements (#6098) --- .../components/HelpCenterLayout.vue | 20 +++++++++++++++++++ .../helpcenter/components/PortalListItem.vue | 6 ++++-- .../helpcenter/components/PortalSwitch.vue | 5 ++++- .../helpcenter/pages/articles/EditArticle.vue | 1 + .../helpcenter/pages/articles/NewArticle.vue | 1 + 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue index 8c806f23b..f61085d60 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue @@ -227,6 +227,26 @@ export default { }, }, + watch: { + '$route.name'() { + const routeName = this.$route?.name; + const routeParams = this.$route?.params; + const updateMetaInAllPortals = routeName === 'list_all_portals'; + const updateMetaInEditArticle = + routeName === 'edit_article' && routeParams?.recentlyCreated; + const updateMetaInLocaleArticles = + routeName === 'list_all_locale_articles' && + routeParams?.recentlyDeleted; + if ( + updateMetaInAllPortals || + updateMetaInEditArticle || + updateMetaInLocaleArticles + ) { + this.fetchPortalAndItsCategories(); + } + }, + }, + mounted() { window.addEventListener('resize', this.handleResize); this.handleResize(); diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItem.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItem.vue index 956827c18..2282ebd37 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItem.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItem.vue @@ -236,8 +236,10 @@ export default { }); }, articleCount() { - const { all_articles_count: count } = this.portal.meta; - return count; + const { allowed_locales: allowedLocales } = this.portal.config; + return allowedLocales.reduce((acc, locale) => { + return acc + locale.articles_count; + }, 0); }, }, methods: { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue index 4442150c5..30f3fb4ff 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue @@ -105,7 +105,10 @@ export default { return this.portal?.config?.allowed_locales; }, articlesCount() { - return this.portal?.meta?.all_articles_count; + const { allowed_locales: allowedLocales } = this.portal.config; + return allowedLocales.reduce((acc, locale) => { + return acc + locale.articles_count; + }, 0); }, }, mounted() { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue index 1dba3a1d4..ff737913f 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue @@ -151,6 +151,7 @@ export default { params: { portalSlug: this.selectedPortalSlug, locale: this.locale, + recentlyDeleted: true, }, }); } catch (error) { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/NewArticle.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/NewArticle.vue index 865c87c3a..a7c8d9c21 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/NewArticle.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/NewArticle.vue @@ -87,6 +87,7 @@ export default { articleSlug: articleId, portalSlug: this.selectedPortalSlug, locale: this.locale, + recentlyCreated: true, }, }); } catch (error) {