From 23778a1981df2d71599d13949856d347686e399a Mon Sep 17 00:00:00 2001 From: EduardZaydler <117674342+EduardZaydler@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:38:38 +0700 Subject: [PATCH] provided subscription editor with config state (#500) --- .../SubscriptionEditor/SubscriptionEditor.tsx | 350 +++++++++--------- 1 file changed, 177 insertions(+), 173 deletions(-) diff --git a/src/Components/SubscriptionEditor/SubscriptionEditor.tsx b/src/Components/SubscriptionEditor/SubscriptionEditor.tsx index cdac342d..d24a58bd 100644 --- a/src/Components/SubscriptionEditor/SubscriptionEditor.tsx +++ b/src/Components/SubscriptionEditor/SubscriptionEditor.tsx @@ -1,4 +1,4 @@ -import * as React from "react"; +import React, { FC } from "react"; import { Toggle } from "@skbkontur/react-ui/components/Toggle"; import { Checkbox } from "@skbkontur/react-ui/components/Checkbox"; import { ValidationWrapperV1, tooltip, ValidationInfo } from "@skbkontur/react-ui-validations"; @@ -11,6 +11,8 @@ import TagDropdownSelect from "../TagDropdownSelect/TagDropdownSelect"; import ScheduleEdit from "../ScheduleEdit/ScheduleEdit"; import CodeRef from "../CodeRef/CodeRef"; import HelpTooltip from "../HelpTooltip/HelpTooltip"; +import { ConfigState } from "../../store/selectors"; +import { useAppSelector } from "../../store/hooks"; import classNames from "classnames/bind"; import styles from "./SubscriptionEditor.less"; @@ -19,177 +21,29 @@ const cn = classNames.bind(styles); export type SubscriptionInfo = Omit; -type Props = { +type TSubscriptionEditorProps = { subscription: Subscription | SubscriptionInfo; onChange: (subscriptionInfo: Partial) => void; tags: Array; contacts: Array; }; -export default class SubscriptionEditor extends React.Component { - render(): React.ReactNode { - const { subscription, contacts, onChange, tags } = this.props; - const { plotting = { enabled: true, theme: "light" } } = subscription; - const isAllTagsToggleVisible: boolean = - this.context?.featureFlags?.isSubscriptionToAllTagsAvailable ?? true; - const isAddPlottingVisible: boolean = - this.context?.featureFlags?.isPlottingAvailable ?? true; - return ( -
-
-
Target delivery channels:
-
- - onChange({ contacts: contactIds })} - availableContacts={contacts} - /> - -
-
-
-
- Tags:{" "} - - Notification will be sent if trigger contains ALL of - selected tags. - -
-
- - { - onChange({ - tags: nextTags, - }); - }} - availableTags={tags} - isDisabled={subscription.any_tags} - /> - -
-
- {isAllTagsToggleVisible && ( -
- - - onChange({ - any_tags: checked, - tags: checked ? [] : subscription.tags, - }) - } - > - All tags - - {" "} - - You will be subscribed to ALL existing tags. May cause increased loads - and alert spamming. - -
- )} -
-
Delivery schedule:
-
- onChange({ sched: value })} - /> -
-
-
- onChange({ throttling: checked })} - > - Throttle messages - {" "} - - If trigger emit to many events they will be grouped into single message. - -
-
- onChange({ ignore_recoverings: checked })} - > - Send notifications when triggers degraded only - {" "} - - {this.renderDegradationExplanation()} - -
-
- onChange({ ignore_warnings: checked })} - > - Do not send WARN notifications - {" "} - - {this.renderWarnExclusionExplanation()} - -
- {isAddPlottingVisible && ( -
- - onChange({ plotting: { ...plotting, enabled: checked } }) - } - > - Add graph to notification - - {plotting.enabled && ( -
- -
- )} -
- )} -
- onChange({ enabled: checked })} - > - Enabled - {" "} -
-
- ); - } +const SubscriptionEditor: FC = ({ + subscription, + contacts, + onChange, + tags, +}) => { + const { config } = useAppSelector(ConfigState); + + const { plotting = { enabled: true, theme: "light" } } = subscription; - renderDegradationExplanation = (): React.ReactElement => ( + const isAllTagsToggleVisible: boolean = + config?.featureFlags?.isSubscriptionToAllTagsAvailable ?? true; + + const isAddPlottingVisible: boolean = config?.featureFlags?.isPlottingAvailable ?? true; + + const renderDegradationExplanation = (): React.ReactElement => (
Only following state switches triggers notification:
@@ -213,7 +67,7 @@ export default class SubscriptionEditor extends React.Component {
); - renderWarnExclusionExplanation = (): React.ReactElement => ( + const renderWarnExclusionExplanation = (): React.ReactElement => (
Do not triggers notification on following switches:
@@ -225,8 +79,7 @@ export default class SubscriptionEditor extends React.Component {
); - validateContacts(): ValidationInfo | null { - const { subscription } = this.props; + const validateContacts = (): ValidationInfo | null => { if (subscription.contacts.length === 0) { return { message: "Please add one or more delivery channels", @@ -234,10 +87,9 @@ export default class SubscriptionEditor extends React.Component { }; } return null; - } + }; - validateTags(): ValidationInfo | null { - const { subscription } = this.props; + const validateTags = (): ValidationInfo | null => { if (subscription.tags.length === 0 && !subscription.any_tags) { return { message: "Please add one or more tags", @@ -245,5 +97,157 @@ export default class SubscriptionEditor extends React.Component { }; } return null; - } -} + }; + + return ( +
+
+
Target delivery channels:
+
+ + onChange({ contacts: contactIds })} + availableContacts={contacts} + /> + +
+
+
+
+ Tags:{" "} + + Notification will be sent if trigger contains ALL of + selected tags. + +
+
+ + { + onChange({ + tags: nextTags, + }); + }} + availableTags={tags} + isDisabled={subscription.any_tags} + /> + +
+
+ {isAllTagsToggleVisible && ( +
+ + + onChange({ + any_tags: checked, + tags: checked ? [] : subscription.tags, + }) + } + > + All tags + + {" "} + + You will be subscribed to ALL existing tags. May cause increased loads and + alert spamming. + +
+ )} +
+
Delivery schedule:
+
+ onChange({ sched: value })} + /> +
+
+
+ onChange({ throttling: checked })} + > + Throttle messages + {" "} + + If trigger emit to many events they will be grouped into single message. + +
+
+ onChange({ ignore_recoverings: checked })} + > + Send notifications when triggers degraded only + {" "} + {renderDegradationExplanation()} +
+
+ onChange({ ignore_warnings: checked })} + > + Do not send WARN notifications + {" "} + {renderWarnExclusionExplanation()} +
+ {isAddPlottingVisible && ( +
+ + onChange({ plotting: { ...plotting, enabled: checked } }) + } + > + Add graph to notification + + {plotting.enabled && ( +
+ +
+ )} +
+ )} +
+ onChange({ enabled: checked })} + > + Enabled + {" "} +
+
+ ); +}; + +export default SubscriptionEditor;