From b9aa4444b3ed87026cd060e9a062ba80e7373afa Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Wed, 1 Jun 2022 11:13:10 +0530 Subject: [PATCH] feat: Allow users to create dashboard apps to give agents more context (#4761) --- .../v1/accounts/dashboard_apps_controller.rb | 44 +++++ app/javascript/dashboard/api/dashboardApps.js | 9 + .../dashboard/api/specs/dashboardApps.spec.js | 13 ++ .../components/widgets/DashboardApp/Frame.vue | 64 +++++++ .../widgets/conversation/ConversationBox.vue | 57 ++++++- .../i18n/locale/en/conversation.json | 1 + app/javascript/dashboard/store/index.js | 14 +- .../dashboard/store/modules/dashboardApps.js | 54 ++++++ .../specs/dashboardApps/actions.spec.js | 21 +++ .../specs/dashboardApps/getters.spec.js | 29 ++++ .../specs/dashboardApps/mutations.spec.js | 20 +++ .../dashboard/store/mutation-types.js | 4 + .../widget/store/modules/contacts.js | 5 +- app/models/account.rb | 13 +- app/models/dashboard_app.rb | 49 ++++++ app/models/user.rb | 3 +- .../dashboard_apps/create.json.jbuilder | 1 + .../dashboard_apps/index.json.jbuilder | 3 + .../dashboard_apps/show.json.jbuilder | 1 + .../dashboard_apps/update.json.jbuilder | 1 + .../v1/models/_dashboard_app.json.jbuilder | 4 + config/routes.rb | 2 +- .../20220525141844_create_dashboard_apps.rb | 11 ++ db/schema.rb | 15 +- .../dashboard_apps_controller_spec.rb | 158 ++++++++++++++++++ spec/factories/dashboard_app.rb | 10 ++ 26 files changed, 585 insertions(+), 21 deletions(-) create mode 100644 app/controllers/api/v1/accounts/dashboard_apps_controller.rb create mode 100644 app/javascript/dashboard/api/dashboardApps.js create mode 100644 app/javascript/dashboard/api/specs/dashboardApps.spec.js create mode 100644 app/javascript/dashboard/components/widgets/DashboardApp/Frame.vue create mode 100644 app/javascript/dashboard/store/modules/dashboardApps.js create mode 100644 app/javascript/dashboard/store/modules/specs/dashboardApps/actions.spec.js create mode 100644 app/javascript/dashboard/store/modules/specs/dashboardApps/getters.spec.js create mode 100644 app/javascript/dashboard/store/modules/specs/dashboardApps/mutations.spec.js create mode 100644 app/models/dashboard_app.rb create mode 100644 app/views/api/v1/accounts/dashboard_apps/create.json.jbuilder create mode 100644 app/views/api/v1/accounts/dashboard_apps/index.json.jbuilder create mode 100644 app/views/api/v1/accounts/dashboard_apps/show.json.jbuilder create mode 100644 app/views/api/v1/accounts/dashboard_apps/update.json.jbuilder create mode 100644 app/views/api/v1/models/_dashboard_app.json.jbuilder create mode 100644 db/migrate/20220525141844_create_dashboard_apps.rb create mode 100644 spec/controllers/api/v1/accounts/dashboard_apps_controller_spec.rb create mode 100644 spec/factories/dashboard_app.rb diff --git a/app/controllers/api/v1/accounts/dashboard_apps_controller.rb b/app/controllers/api/v1/accounts/dashboard_apps_controller.rb new file mode 100644 index 000000000..a8d7ebcb9 --- /dev/null +++ b/app/controllers/api/v1/accounts/dashboard_apps_controller.rb @@ -0,0 +1,44 @@ +class Api::V1::Accounts::DashboardAppsController < Api::V1::Accounts::BaseController + before_action :fetch_dashboard_apps, except: [:create] + before_action :fetch_dashboard_app, only: [:show, :update, :destroy] + + def index; end + + def show; end + + def create + @dashboard_app = Current.account.dashboard_apps.create!( + permitted_payload.merge(user_id: Current.user.id) + ) + end + + def update + @dashboard_app.update!(permitted_payload) + end + + def destroy + @dashboard_app.destroy! + head :no_content + end + + private + + def fetch_dashboard_apps + @dashboard_apps = Current.account.dashboard_apps + end + + def fetch_dashboard_app + @dashboard_app = @dashboard_apps.find(permitted_params[:id]) + end + + def permitted_payload + params.require(:dashboard_app).permit( + :title, + content: [:url, :type] + ) + end + + def permitted_params + params.permit(:id) + end +end diff --git a/app/javascript/dashboard/api/dashboardApps.js b/app/javascript/dashboard/api/dashboardApps.js new file mode 100644 index 000000000..b22ab698e --- /dev/null +++ b/app/javascript/dashboard/api/dashboardApps.js @@ -0,0 +1,9 @@ +import ApiClient from './ApiClient'; + +class DashboardAppsAPI extends ApiClient { + constructor() { + super('dashboard_apps', { accountScoped: true }); + } +} + +export default new DashboardAppsAPI(); diff --git a/app/javascript/dashboard/api/specs/dashboardApps.spec.js b/app/javascript/dashboard/api/specs/dashboardApps.spec.js new file mode 100644 index 000000000..f3196ae2a --- /dev/null +++ b/app/javascript/dashboard/api/specs/dashboardApps.spec.js @@ -0,0 +1,13 @@ +import dashboardAppsAPI from '../dashboardApps'; +import ApiClient from '../ApiClient'; + +describe('#dashboardAppsAPI', () => { + it('creates correct instance', () => { + expect(dashboardAppsAPI).toBeInstanceOf(ApiClient); + expect(dashboardAppsAPI).toHaveProperty('get'); + expect(dashboardAppsAPI).toHaveProperty('show'); + expect(dashboardAppsAPI).toHaveProperty('create'); + expect(dashboardAppsAPI).toHaveProperty('update'); + expect(dashboardAppsAPI).toHaveProperty('delete'); + }); +}); diff --git a/app/javascript/dashboard/components/widgets/DashboardApp/Frame.vue b/app/javascript/dashboard/components/widgets/DashboardApp/Frame.vue new file mode 100644 index 000000000..0c2c0e8ed --- /dev/null +++ b/app/javascript/dashboard/components/widgets/DashboardApp/Frame.vue @@ -0,0 +1,64 @@ +