From 3995f4a7248a1aec8836a4833acedc6cfd28bd95 Mon Sep 17 00:00:00 2001 From: Ben Cooke Date: Wed, 26 Apr 2023 15:34:29 -0400 Subject: [PATCH] [MM-52339] Top playbooks missing from insights (#23076) Automatic Merge --- .../channels/insights/insights_spec.ts | 48 +++++++++++++++++++ server/playbooks/server/api/playbooks.go | 22 ++------- .../insights/insights.tsx | 22 +++++---- 3 files changed, 64 insertions(+), 28 deletions(-) create mode 100644 e2e-tests/cypress/tests/integration/channels/insights/insights_spec.ts diff --git a/e2e-tests/cypress/tests/integration/channels/insights/insights_spec.ts b/e2e-tests/cypress/tests/integration/channels/insights/insights_spec.ts new file mode 100644 index 0000000000..9d3de5d6d1 --- /dev/null +++ b/e2e-tests/cypress/tests/integration/channels/insights/insights_spec.ts @@ -0,0 +1,48 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +// *************************************************************** +// - [#] indicates a test step (e.g. # Go to a page) +// - [*] indicates an assertion (e.g. * Check the title) +// - Use element ID when selecting an element. Create one if none. +// *************************************************************** +// Stage: @prod + +describe('Insights', () => { + let teamA; + + before(() => { + cy.shouldHaveFeatureFlag('InsightsEnabled', true); + + cy.apiInitSetup().then(({team}) => { + teamA = team; + }); + }); + it('Check all the cards exist', () => { + cy.apiAdminLogin(); + + // # Go to the Insights view + cy.visit(`/${teamA.name}/activity-and-insights`); + + // * Check top channels exists + cy.get('.top-channels-card').should('exist'); + + // * Check top threads exists + cy.get('.top-threads-card').should('exist'); + + // * Check top boards exists because product mode is enabled + cy.get('.top-boards-card').should('exist'); + + // * Check top reactions exists + cy.get('.top-reactions-card').should('exist'); + + // * Check top dms exists + cy.get('.top-dms-card').should('exist'); + + // * Check least active channels exists + cy.get('.least-active-channels-card').should('exist'); + + // * Check top playbooks exists because product mode is enabled + cy.get('.top-playbooks-card').should('exist'); + }); +}); diff --git a/server/playbooks/server/api/playbooks.go b/server/playbooks/server/api/playbooks.go index af9f60a459..6a87d5a74c 100644 --- a/server/playbooks/server/api/playbooks.go +++ b/server/playbooks/server/api/playbooks.go @@ -10,14 +10,12 @@ import ( "net/url" "strconv" "strings" - "time" "github.com/gorilla/mux" "github.com/mattermost/mattermost-server/server/v8/model" "github.com/mattermost/mattermost-server/server/v8/playbooks/server/app" "github.com/mattermost/mattermost-server/server/v8/playbooks/server/config" "github.com/mattermost/mattermost-server/server/v8/playbooks/server/playbooks" - "github.com/mattermost/mattermost-server/server/v8/playbooks/server/timeutils" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -693,14 +691,8 @@ func (h *PlaybookHandler) getTopPlaybooksForUser(c *Context, w http.ResponseWrit h.HandleErrorWithCode(w, c.logger, http.StatusBadRequest, "unable to get user", err) return } - timezone, err := timeutils.GetUserTimezone(user) - if err != nil { - h.HandleErrorWithCode(w, c.logger, http.StatusBadRequest, "unable to get user timezone", err) - return - } - if timezone == nil { - timezone = time.Now().UTC().Location() - } + timezone := user.GetTimezoneLocation() + // get unix time for duration startTime, appErr := model.GetStartOfDayForTimeRange(timeRange, timezone) if appErr != nil { @@ -750,14 +742,8 @@ func (h *PlaybookHandler) getTopPlaybooksForTeam(c *Context, w http.ResponseWrit h.HandleErrorWithCode(w, c.logger, http.StatusBadRequest, "unable to get user", err) return } - timezone, err := timeutils.GetUserTimezone(user) - if err != nil { - h.HandleErrorWithCode(w, c.logger, http.StatusBadRequest, "unable to get user timezone", err) - return - } - if timezone == nil { - timezone = time.Now().UTC().Location() - } + timezone := user.GetTimezoneLocation() + // get unix time for duration startTime, appErr := model.GetStartOfDayForTimeRange(timeRange, timezone) if appErr != nil { diff --git a/webapp/channels/src/components/activity_and_insights/insights/insights.tsx b/webapp/channels/src/components/activity_and_insights/insights/insights.tsx index 50ca7b71a6..736e63769d 100644 --- a/webapp/channels/src/components/activity_and_insights/insights/insights.tsx +++ b/webapp/channels/src/components/activity_and_insights/insights/insights.tsx @@ -16,7 +16,6 @@ import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {selectLhsItem} from 'actions/views/lhs'; -import {GlobalState} from 'types/store'; import {LhsItemType, LhsPage} from 'types/store/lhs'; import {CardSizes, InsightsWidgetTypes, TimeFrame, TimeFrames} from '@mattermost/types/insights'; @@ -41,17 +40,20 @@ type SelectOption = { const Insights = () => { const dispatch = useDispatch(); - - // check if either of focalboard plugin or boards product is enabled - const focalboardPluginEnabled = useSelector((state: GlobalState) => state.plugins.plugins?.focalboard); - let focalboardProductEnabled = false; const products = useProducts(); - if (products) { - focalboardProductEnabled = products.some((product) => product.pluginId === suitePluginIds.focalboard || product.pluginId === suitePluginIds.boards); - } - const focalboardEnabled = focalboardPluginEnabled || focalboardProductEnabled; - const playbooksEnabled = useSelector((state: GlobalState) => state.plugins.plugins?.playbooks); + let focalboardEnabled = false; + let playbooksEnabled = false; + if (products) { + products.forEach((product) => { + if (product.pluginId === suitePluginIds.boards) { + focalboardEnabled = true; + } else if (product.pluginId === suitePluginIds.playbooks) { + playbooksEnabled = true; + } + }); + } + const currentUserId = useSelector(getCurrentUserId); const currentTeamId = useSelector(getCurrentTeamId);