From c57c0c44230681e8b40262aa94054175754717f8 Mon Sep 17 00:00:00 2001 From: Maxim Mordasov Date: Mon, 8 Jan 2024 13:50:19 +0300 Subject: [PATCH] move ms teams related models, containers, components etc to oncall (#3594) # What this PR does Move ms teams related models, containers, components etc to oncall ## Which issue(s) this PR fixes https://github.com/grafana/oncall-private/issues/2144 ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- grafana-plugin/.dockerignore | 1 - grafana-plugin/.gitignore | 1 - .../AlertTemplatesForm.config.ts | 109 +++---- .../AlertTemplatesForm.module.css | 59 ---- .../AlertTemplates/AlertTemplatesForm.tsx | 283 ------------------ .../CommonAlertTemplatesForm.config.ts | 38 +-- .../parts/connectors/MSTeamsConnector.tsx | 74 +++++ .../src/containers/AlertRules/parts/index.tsx | 14 +- .../AlertTemplatesFormContainer.tsx | 80 ----- .../containers/DefaultPageLayout/helper.ts | 2 +- .../IntegrationTemplatesList.config.ts | 34 ++- .../IntegrationTemplatesList.tsx | 249 +++++++-------- .../IntegrationTemplate.tsx | 43 +-- .../MSTeams/MSTeamsInstructions.module.css | 30 ++ .../MSTeams/MSTeamsInstructions.tsx | 133 ++++++++ .../MSTeamsIntegrationButton.module.css | 25 ++ .../MSTeamsIntegrationButton.tsx | 75 +++++ .../OutgoingWebhookForm.tsx | 10 +- .../WebhookPresetIcons.config.tsx | 17 +- .../containers/UserSettings/UserSettings.tsx | 10 +- .../UserSettings/UserSettings.types.ts | 8 +- .../parts/connectors/MSTeamsConnector.tsx | 67 +++++ .../UserSettings/parts/connectors/index.tsx | 2 + .../containers/UserSettings/parts/index.tsx | 16 +- .../tabs/MSTeamsInfo/MSTeamsInfo.module.css | 12 + .../parts/tabs/MSTeamsInfo/MSTeamsInfo.tsx | 51 ++++ grafana-plugin/src/icons/MSTeamsLogo.tsx | 68 +++++ .../src/icons/MachineLearningLogo.tsx | 29 ++ .../models/msteams_channel/msteams_channel.ts | 126 ++++++++ .../msteams_channel/msteams_channel.types.ts | 9 + .../pages/integration/Integration.config.ts | 52 +++- .../pages/integration/Integration.helper.ts | 51 +++- .../src/pages/integration/Integration.tsx | 10 +- .../pages/settings/tabs/ChatOps/ChatOps.tsx | 21 +- .../MSTeamsSettings.module.css | 8 + .../tabs/MSTeamsSettings/MSTeamsSettings.tsx | 147 +++++++++ grafana-plugin/src/state/features.ts | 1 + .../src/state/rootBaseStore/index.ts | 2 + grafana-plugin/tsconfig.json | 4 +- grafana-plugin/webpack.config.js | 6 - 40 files changed, 1264 insertions(+), 713 deletions(-) delete mode 100644 grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.module.css delete mode 100644 grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.tsx create mode 100644 grafana-plugin/src/containers/AlertRules/parts/connectors/MSTeamsConnector.tsx delete mode 100644 grafana-plugin/src/containers/AlertTemplatesFormContainer/AlertTemplatesFormContainer.tsx create mode 100644 grafana-plugin/src/containers/MSTeams/MSTeamsInstructions.module.css create mode 100644 grafana-plugin/src/containers/MSTeams/MSTeamsInstructions.tsx create mode 100644 grafana-plugin/src/containers/MSTeamsIntegrationButton/MSTeamsIntegrationButton.module.css create mode 100644 grafana-plugin/src/containers/MSTeamsIntegrationButton/MSTeamsIntegrationButton.tsx create mode 100644 grafana-plugin/src/containers/UserSettings/parts/connectors/MSTeamsConnector.tsx create mode 100644 grafana-plugin/src/containers/UserSettings/parts/tabs/MSTeamsInfo/MSTeamsInfo.module.css create mode 100644 grafana-plugin/src/containers/UserSettings/parts/tabs/MSTeamsInfo/MSTeamsInfo.tsx create mode 100644 grafana-plugin/src/icons/MSTeamsLogo.tsx create mode 100644 grafana-plugin/src/icons/MachineLearningLogo.tsx create mode 100644 grafana-plugin/src/models/msteams_channel/msteams_channel.ts create mode 100644 grafana-plugin/src/models/msteams_channel/msteams_channel.types.ts create mode 100644 grafana-plugin/src/pages/settings/tabs/ChatOps/tabs/MSTeamsSettings/MSTeamsSettings.module.css create mode 100644 grafana-plugin/src/pages/settings/tabs/ChatOps/tabs/MSTeamsSettings/MSTeamsSettings.tsx diff --git a/grafana-plugin/.dockerignore b/grafana-plugin/.dockerignore index 5ba54898..a2c9574b 100644 --- a/grafana-plugin/.dockerignore +++ b/grafana-plugin/.dockerignore @@ -1,4 +1,3 @@ node_modules -frontend_enterprise .DS_Store playwright-report diff --git a/grafana-plugin/.gitignore b/grafana-plugin/.gitignore index e768d7d7..9d0e1126 100644 --- a/grafana-plugin/.gitignore +++ b/grafana-plugin/.gitignore @@ -13,7 +13,6 @@ yarn-error.log* # This file is generated grafana-plugin.yml -frontend_enterprise # playwright /playwright-report/ diff --git a/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.config.ts b/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.config.ts index 86fc486d..8e4bf0ae 100644 --- a/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.config.ts +++ b/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.config.ts @@ -1,80 +1,45 @@ +import { AppFeature } from 'state/features'; + import { TemplateForEdit, commonTemplateForEdit } from './CommonAlertTemplatesForm.config'; -export interface Template { - name: string; - group: string; -} -export const templateForEdit: { [id: string]: TemplateForEdit } = commonTemplateForEdit; +export const getTemplatesForEdit = (features: Record) => { + if (features[AppFeature.MsTeams]) { + return { ...commonTemplateForEdit, ...additionalTemplateForEdit }; + } + return commonTemplateForEdit; +}; -export const templatesToRender: Template[] = [ - { - name: 'web_title_template', - group: 'web', +const additionalTemplateForEdit: { [id: string]: TemplateForEdit } = { + msteams_title_template: { + name: 'msteams_title_template', + displayName: 'MS Teams title', + description: '', + additionalData: { + chatOpsName: 'msteams', + chatOpsDisplayName: 'MS Teams', + }, + type: 'plain', }, - { - name: 'slack_title_template', - group: 'slack', + msteams_message_template: { + name: 'msteams_message_template', + displayName: 'MS Teams message', + description: '', + additionalData: { + chatOpsName: 'msteams', + chatOpsDisplayName: 'MS Teams', + }, + type: 'plain', }, - { - name: 'sms_title_template', - group: 'sms', + msteams_image_url_template: { + name: 'msteams_image_url_template', + displayName: 'MS Teams image url', + description: '', + additionalData: { + chatOpsName: 'msteams', + chatOpsDisplayName: 'MS Teams', + }, + type: 'plain', }, - { - name: 'phone_call_title_template', - group: 'phone', - }, - { - name: 'email_title_template', - group: 'email', - }, - { - name: 'telegram_title_template', - group: 'telegram', - }, - { - name: 'slack_message_template', - group: 'slack', - }, - { - name: 'web_message_template', - group: 'web', - }, - { - name: 'email_message_template', - group: 'email', - }, - { - name: 'telegram_message_template', - group: 'telegram', - }, - { - name: 'slack_image_url_template', - group: 'slack', - }, - { - name: 'web_image_url_template', - group: 'web', - }, - { - name: 'telegram_image_url_template', - group: 'telegram', - }, - { - name: 'grouping_id_template', - group: 'alert behaviour', - }, - { - name: 'acknowledge_condition_template', - group: 'alert behaviour', - }, - { - name: 'resolve_condition_template', - group: 'alert behaviour', - }, - { - name: 'source_link_template', - group: 'alert behaviour', - }, -]; +}; export const FORM_NAME = 'AlertTemplates'; diff --git a/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.module.css b/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.module.css deleted file mode 100644 index 924951cf..00000000 --- a/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.module.css +++ /dev/null @@ -1,59 +0,0 @@ -.select { - width: 300px; -} - -.templates { - width: 50%; -} - -.borderLeftRightBottom { - border-left: 1px solid rgba(204, 204, 220, 0.15); - border-bottom: 1px solid rgba(204, 204, 220, 0.15); - border-right: 1px solid rgba(204, 204, 220, 0.15); - border-radius: 2px; -} - -.borderRightBottom { - border-bottom: 1px solid rgba(204, 204, 220, 0.15); - border-right: 1px solid rgba(204, 204, 220, 0.15); - border-radius: 2px; -} - -.template-form { - width: 100%; -} - -.templatesInfo { - display: flex; - flex-direction: row; -} - -.templates-editors { - width: 50%; -} - -.select-template { - width: 50% !important; -} - -.collapse { - flex-grow: 1; - width: 100%; -} - -.typographyText { - margin-bottom: 24px; - margin-top: 8px; -} - -.autoresolve-condition section { - border: 1px solid var(--primary-text-link); -} - -.autoresolve-label { - margin-bottom: 0 !important; -} - -.web-title-message { - margin-top: 8px; -} diff --git a/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.tsx b/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.tsx deleted file mode 100644 index 66cf2a3a..00000000 --- a/grafana-plugin/src/components/AlertTemplates/AlertTemplatesForm.tsx +++ /dev/null @@ -1,283 +0,0 @@ -import React, { useCallback, useEffect, useMemo, useState } from 'react'; - -import { SelectableValue } from '@grafana/data'; -import { Label, Button, HorizontalGroup, VerticalGroup, Select, LoadingPlaceholder } from '@grafana/ui'; -import { capitalCase } from 'change-case'; -import cn from 'classnames/bind'; -import { omit } from 'lodash-es'; - -import { templatesToRender, Template } from 'components/AlertTemplates/AlertTemplatesForm.config'; -import { getLabelFromTemplateName } from 'components/AlertTemplates/AlertTemplatesForm.helper'; -import Block from 'components/GBlock/Block'; -import MonacoEditor from 'components/MonacoEditor/MonacoEditor'; -import SourceCode from 'components/SourceCode/SourceCode'; -import Text from 'components/Text/Text'; -import TemplatePreview, { TEMPLATE_PAGE } from 'containers/TemplatePreview/TemplatePreview'; -import { WithPermissionControlTooltip } from 'containers/WithPermissionControl/WithPermissionControlTooltip'; -import { AlertReceiveChannel } from 'models/alert_receive_channel/alert_receive_channel.types'; -import { Alert } from 'models/alertgroup/alertgroup.types'; -import { makeRequest } from 'network'; -import LocationHelper from 'utils/LocationHelper'; -import { UserActions, isUserActionAllowed } from 'utils/authorization'; - -import styles from './AlertTemplatesForm.module.css'; - -const cx = cn.bind(styles); - -interface AlertTemplatesFormProps { - templates: any; - onUpdateTemplates: (values: any) => void; - alertReceiveChannelId: AlertReceiveChannel['id']; - alertGroupId?: Alert['pk']; - demoAlertEnabled: boolean; - handleSendDemoAlertClick: () => void; - templatesRefreshing: boolean; - selectedTemplateName?: string; -} - -const AlertTemplatesForm = (props: AlertTemplatesFormProps) => { - const { - onUpdateTemplates, - templates, - alertReceiveChannelId, - alertGroupId, - demoAlertEnabled, - handleSendDemoAlertClick, - templatesRefreshing, - selectedTemplateName, - } = props; - - const [tempValues, setTempValues] = useState<{ - [key: string]: string | null; - }>({}); - const [activeGroup, setActiveGroup] = useState(); - const [activeTemplate, setActiveTemplate] = useState