From 20f356858348f7d71d6fe1a51d16aaac9fe0c569 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Mon, 8 Aug 2022 15:47:32 +0530 Subject: [PATCH] feat: Portals store integration (#5185) --- .codeclimate.yml | 1 + .../dashboard/api/helpCenter/articles.js | 13 +- .../dashboard/api/helpCenter/portals.js | 7 - .../dashboard/api/specs/article.spec.js | 29 + .../dashboard/api/specs/portals.spec.js | 13 + .../dashboard/i18n/locale/en/helpCenter.json | 2 + .../helpcenter/components/ArticleItem.vue | 6 +- .../helpcenter/components/ArticleTable.vue | 1 + .../components/HelpCenterLayout.vue | 235 ++------ .../helpcenter/components/PortalListItem.vue | 28 +- .../components/PortalListItemTable.vue | 13 +- .../helpcenter/components/PortalPopover.vue | 20 +- .../helpcenter/components/PortalSwitch.vue | 26 +- .../helpcenter/mixins/portalMixin.js | 4 + .../mixins/specs/portalMixin.spec.js | 10 +- .../pages/articles/ListAllArticles.vue | 46 +- .../pages/portals/ListAllPortals.vue | 156 ++--- app/javascript/dashboard/store/index.js | 4 + .../modules/helpCenterArticles/actions.js | 12 +- .../modules/helpCenterCategories/index.js | 2 +- .../modules/helpCenterPortals/actions.js | 21 +- .../modules/helpCenterPortals/getters.js | 9 +- .../store/modules/helpCenterPortals/index.js | 6 + .../modules/helpCenterPortals/mutations.js | 23 +- .../helpCenterPortals/specs/actions.spec.js | 37 +- .../helpCenterPortals/specs/fixtures.js | 65 +- .../helpCenterPortals/specs/getters.spec.js | 5 + .../helpCenterPortals/specs/mutations.spec.js | 29 + app/javascript/shared/constants/locales.js | 566 ++++++++++++++++++ .../accounts/articles/_article.json.jbuilder | 6 +- 30 files changed, 982 insertions(+), 413 deletions(-) create mode 100644 app/javascript/dashboard/api/specs/article.spec.js create mode 100644 app/javascript/dashboard/api/specs/portals.spec.js create mode 100644 app/javascript/shared/constants/locales.js diff --git a/.codeclimate.yml b/.codeclimate.yml index 916b98510..974681a09 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -53,3 +53,4 @@ exclude_patterns: - 'app/javascript/dashboard/i18n/index.js' - 'app/javascript/widget/i18n/index.js' - 'app/javascript/survey/i18n/index.js' + - 'app/javascript/shared/constants/locales.js' diff --git a/app/javascript/dashboard/api/helpCenter/articles.js b/app/javascript/dashboard/api/helpCenter/articles.js index c252ce4c2..3f3ab3a49 100644 --- a/app/javascript/dashboard/api/helpCenter/articles.js +++ b/app/javascript/dashboard/api/helpCenter/articles.js @@ -1,9 +1,18 @@ -import ApiClient from '../ApiClient'; +/* global axios */ -class ArticlesAPI extends ApiClient { +import PortalsAPI from './portals'; + +class ArticlesAPI extends PortalsAPI { constructor() { super('articles', { accountScoped: true }); } + + getArticles({ pageNumber, portalSlug, locale, status, author_id }) { + let baseUrl = `${this.url}/${portalSlug}/articles?page=${pageNumber}&locale=${locale}`; + if (status !== undefined) baseUrl += `&status=${status}`; + if (author_id) baseUrl += `&author_id=${author_id}`; + return axios.get(baseUrl); + } } export default new ArticlesAPI(); diff --git a/app/javascript/dashboard/api/helpCenter/portals.js b/app/javascript/dashboard/api/helpCenter/portals.js index 1df4d2554..594050cdf 100644 --- a/app/javascript/dashboard/api/helpCenter/portals.js +++ b/app/javascript/dashboard/api/helpCenter/portals.js @@ -1,16 +1,9 @@ -/* global axios */ import ApiClient from '../ApiClient'; class PortalsAPI extends ApiClient { constructor() { super('portals', { accountScoped: true }); } - - getArticles({ pageNumber, portalSlug, locale }) { - return axios.get( - `${this.url}/${portalSlug}/articles?page=${pageNumber}&locale=${locale}` - ); - } } export default PortalsAPI; diff --git a/app/javascript/dashboard/api/specs/article.spec.js b/app/javascript/dashboard/api/specs/article.spec.js new file mode 100644 index 000000000..a60a784c0 --- /dev/null +++ b/app/javascript/dashboard/api/specs/article.spec.js @@ -0,0 +1,29 @@ +import articlesAPI from '../helpCenter/articles'; +import ApiClient from 'dashboard/api/helpCenter/portals'; +import describeWithAPIMock from './apiSpecHelper'; + +describe('#PortalAPI', () => { + it('creates correct instance', () => { + expect(articlesAPI).toBeInstanceOf(ApiClient); + expect(articlesAPI).toHaveProperty('get'); + expect(articlesAPI).toHaveProperty('show'); + expect(articlesAPI).toHaveProperty('create'); + expect(articlesAPI).toHaveProperty('update'); + expect(articlesAPI).toHaveProperty('delete'); + expect(articlesAPI).toHaveProperty('getArticles'); + }); + describeWithAPIMock('API calls', context => { + it('#getArticles', () => { + articlesAPI.getArticles({ + pageNumber: 1, + portalSlug: 'room-rental', + locale: 'en-US', + status: 'published', + author_id: '1', + }); + expect(context.axiosMock.get).toHaveBeenCalledWith( + '/api/v1/portals/room-rental/articles?page=1&locale=en-US&status=published&author_id=1' + ); + }); + }); +}); diff --git a/app/javascript/dashboard/api/specs/portals.spec.js b/app/javascript/dashboard/api/specs/portals.spec.js new file mode 100644 index 000000000..8d6968cb7 --- /dev/null +++ b/app/javascript/dashboard/api/specs/portals.spec.js @@ -0,0 +1,13 @@ +import PortalsAPI from '../helpCenter/portals'; +import ApiClient from '../ApiClient'; +const portalAPI = new PortalsAPI(); +describe('#PortalAPI', () => { + it('creates correct instance', () => { + expect(portalAPI).toBeInstanceOf(ApiClient); + expect(portalAPI).toHaveProperty('get'); + expect(portalAPI).toHaveProperty('show'); + expect(portalAPI).toHaveProperty('create'); + expect(portalAPI).toHaveProperty('update'); + expect(portalAPI).toHaveProperty('delete'); + }); +}); diff --git a/app/javascript/dashboard/i18n/locale/en/helpCenter.json b/app/javascript/dashboard/i18n/locale/en/helpCenter.json index 6004f4e29..15792bc97 100644 --- a/app/javascript/dashboard/i18n/locale/en/helpCenter.json +++ b/app/javascript/dashboard/i18n/locale/en/helpCenter.json @@ -31,7 +31,9 @@ "NEW_BUTTON": "New Portal", "ACTIVE_BADGE": "active", "CHOOSE_LOCALE_LABEL": "Choose a locale", + "LOADING_MESSAGE": "Loading portals...", "ARTICLES_LABEL": "articles", + "NO_PORTALS_MESSAGE": "There are no available portals", "ADD_NEW_LOCALE": "Add a new locale", "POPOVER": { "TITLE": "Portals", diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleItem.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleItem.vue index e88c1eafc..3c1f9cdf9 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleItem.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleItem.vue @@ -15,7 +15,7 @@ - {{ category }} + {{ category.name }} {{ readCount }}