From fa8f94efecb3337fcc699971e687afccd5c36a04 Mon Sep 17 00:00:00 2001 From: bowenlan-amzn Date: Mon, 27 Jun 2022 08:08:38 -0700 Subject: [PATCH] Add notification Signed-off-by: bowenlan-amzn --- .../components/CronSchedule/CronSchedule.tsx | 16 +++-- .../components/Notification/Notification.tsx | 59 +++++++++++++++ .../components/Notification/index.ts | 8 +++ .../pages/CreateSnapshotPolicy/constants.ts | 2 +- .../CreateSnapshotPolicy.tsx | 71 +++++++++++-------- .../SnapshotPolicies/SnapshotPolicies.tsx | 3 +- .../SnapshotPolicyDetails.tsx | 3 - .../CreateSnapshotFlyout.tsx | 1 - public/utils/constants.ts | 10 +-- server/services/SnapshotManagementService.ts | 7 +- 10 files changed, 126 insertions(+), 54 deletions(-) create mode 100644 public/pages/CreateSnapshotPolicy/components/Notification/Notification.tsx create mode 100644 public/pages/CreateSnapshotPolicy/components/Notification/index.ts diff --git a/public/pages/CreateSnapshotPolicy/components/CronSchedule/CronSchedule.tsx b/public/pages/CreateSnapshotPolicy/components/CronSchedule/CronSchedule.tsx index 327fed0da..384dc518c 100644 --- a/public/pages/CreateSnapshotPolicy/components/CronSchedule/CronSchedule.tsx +++ b/public/pages/CreateSnapshotPolicy/components/CronSchedule/CronSchedule.tsx @@ -161,13 +161,15 @@ const CronSchedule = ({ {frequencyType === "custom" ? ( <> - - { - onCronExpressionChange(e.target.value); - }} - /> + + + { + onCronExpressionChange(e.target.value); + }} + /> + ) : ( <> diff --git a/public/pages/CreateSnapshotPolicy/components/Notification/Notification.tsx b/public/pages/CreateSnapshotPolicy/components/Notification/Notification.tsx new file mode 100644 index 000000000..f0ea456aa --- /dev/null +++ b/public/pages/CreateSnapshotPolicy/components/Notification/Notification.tsx @@ -0,0 +1,59 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React, { ChangeEvent } from "react"; +import { EuiFormRow, EuiSelect, EuiButton, EuiFlexGroup, EuiFlexItem } from "@elastic/eui"; +import "brace/theme/github"; +import "brace/mode/json"; +import { FeatureChannelList } from "../../../../../server/models/interfaces"; +import CustomLabel from "../../../../components/CustomLabel"; + +interface NotificationProps { + channelId: string; + channels: FeatureChannelList[]; + loadingChannels: boolean; + onChangeChannelId: (value: ChangeEvent) => void; + getChannels: () => void; +} + +const Notification = ({ channelId, channels, loadingChannels, onChangeChannelId, getChannels }: NotificationProps) => { + return ( + <> + + + + + ({ value: channel.config_id, text: channel.name }))} + value={channelId} + onChange={onChangeChannelId} + data-test-subj="create-policy-notification-channel-id" + /> + + + + + + + + Manage channels + + + + + ); +}; + +export default Notification; diff --git a/public/pages/CreateSnapshotPolicy/components/Notification/index.ts b/public/pages/CreateSnapshotPolicy/components/Notification/index.ts new file mode 100644 index 000000000..e53a4f342 --- /dev/null +++ b/public/pages/CreateSnapshotPolicy/components/Notification/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import Notification from "./Notification"; + +export default Notification; diff --git a/public/pages/CreateSnapshotPolicy/constants.ts b/public/pages/CreateSnapshotPolicy/constants.ts index c808ad004..b7aeede8d 100644 --- a/public/pages/CreateSnapshotPolicy/constants.ts +++ b/public/pages/CreateSnapshotPolicy/constants.ts @@ -34,7 +34,7 @@ export const maxAgeUnitOptions = [ { value: "h", text: "Hours" }, ]; -export const DEFAULT_INDEX_OPTIONS = [{ label: "*" }, { label: "-.opendistro_security" }]; +export const DEFAULT_INDEX_OPTIONS = [{ label: "*" }]; export const ERROR_PROMPT = { NAME: "Name must be provided.", diff --git a/public/pages/CreateSnapshotPolicy/containers/CreateSnapshotPolicy/CreateSnapshotPolicy.tsx b/public/pages/CreateSnapshotPolicy/containers/CreateSnapshotPolicy/CreateSnapshotPolicy.tsx index fba981fdb..1ba3d170d 100644 --- a/public/pages/CreateSnapshotPolicy/containers/CreateSnapshotPolicy/CreateSnapshotPolicy.tsx +++ b/public/pages/CreateSnapshotPolicy/containers/CreateSnapshotPolicy/CreateSnapshotPolicy.tsx @@ -38,11 +38,7 @@ import { BREADCRUMBS, ROUTES, SNAPSHOT_MANAGEMENT_DOCUMENTATION_URL } from "../. import { ContentPanel } from "../../../../components/ContentPanel"; import { IndexService, NotificationService, SnapshotManagementService } from "../../../../services"; import { getErrorMessage, wildcardOption } from "../../../../utils/helpers"; -import SnapshotIndicesRepoInput from "../../components/SnapshotIndicesRepoInput/SnapshotIndicesRepoInput"; -import CronSchedule from "../../components/CronSchedule/CronSchedule"; -import SnapshotAdvancedSettings from "../../components/SnapshotAdvancedSettings/SnapshotAdvancedSettings"; import CustomLabel from "../../../../components/CustomLabel"; -import ChannelNotification from "../../../VisualCreatePolicy/components/ChannelNotification"; import { DEFAULT_INDEX_OPTIONS, ERROR_PROMPT, getDefaultSMPolicy, maxAgeUnitOptions as MAX_AGE_UNIT_OPTIONS } from "../../constants"; import { getIncludeGlobalState, @@ -54,6 +50,10 @@ import { } from "../helper"; import { parseCronExpression } from "../../components/CronSchedule/helper"; import { TIMEZONES } from "../../components/CronSchedule/constants"; +import SnapshotIndicesRepoInput from "../../components/SnapshotIndicesRepoInput"; +import CronSchedule from "../../components/CronSchedule"; +import SnapshotAdvancedSettings from "../../components/SnapshotAdvancedSettings"; +import Notification from "../../components/Notification"; interface CreateSMPolicyProps extends RouteComponentProps { snapshotManagementService: SnapshotManagementService; @@ -86,7 +86,7 @@ interface CreateSMPolicyState { deletionScheduleFrequencyType: string; deleteConditionEnabled: boolean; - deletionScheduleEnabled: boolean; + deletionScheduleEnabled: boolean; // whether to use the same schedule as creation advancedSettingsOpen: boolean; @@ -164,6 +164,7 @@ export default class CreateSnapshotPolicy extends Component => { @@ -172,8 +173,7 @@ export default class CreateSnapshotPolicy extends Component ({ label })); const selectedRepoValue = _.get(policy, "snapshot_config.repository", ""); - // TODO SM parse frequency type const { frequencyType: creationScheduleFrequencyType } = parseCronExpression(_.get(policy, "creation.schedule.cron.expression")); const { frequencyType: deletionScheduleFrequencyType } = parseCronExpression(_.get(policy, "deletion.schedule.cron.expression")); + let deleteConditionEnabled = false; + let deletionScheduleEnabled = false; + if (!!_.get(policy, "deletion")) { + deleteConditionEnabled = true; + const creationScheduleExpression = _.get(policy, "creation.schedule.cron.expression"); + const deletionScheduleExpression = _.get(policy, "deletion.schedule.cron.expression"); + if (creationScheduleExpression !== deletionScheduleExpression) deletionScheduleEnabled = true; + } + + const maxAge = policy.deletion?.condition?.max_age; + let maxAgeNum = 1; + let maxAgeUnit = "d"; + if (maxAge) { + maxAgeNum = parseInt(maxAge.substring(0, maxAge.length - 1)); + maxAgeUnit = maxAge[maxAge.length - 1]; + } + this.setState({ policy, policyId: response.response.id, @@ -195,6 +211,10 @@ export default class CreateSnapshotPolicy extends Component { @@ -396,7 +415,6 @@ export default class CreateSnapshotPolicy extends Component => { - console.log(`sm dev get channels`); this.setState({ loadingChannels: true }); try { const { notificationService } = this.props; @@ -417,7 +435,7 @@ export default class CreateSnapshotPolicy extends Component + {deletionScheduleEnabled ? ( ) : null} - {" "} + ) : null} @@ -652,8 +671,8 @@ export default class CreateSnapshotPolicy extends Component ) => { this.setState({ policy: this.setPolicyHelper("notification.conditions.creation", e.target.checked) }); @@ -663,8 +682,8 @@ export default class CreateSnapshotPolicy extends Component ) => { this.setState({ policy: this.setPolicyHelper("notification.conditions.deletion", e.target.checked) }); @@ -674,8 +693,8 @@ export default class CreateSnapshotPolicy extends Component ) => { this.setState({ policy: this.setPolicyHelper("notification.conditions.failure", e.target.checked) }); @@ -683,8 +702,8 @@ export default class CreateSnapshotPolicy extends Component {showNotificationChannel ? ( - { this.setState({ policy: this.setPolicyHelper("snapshot_config.date_format", e.target.value) }); @@ -783,16 +802,6 @@ export default class CreateSnapshotPolicy extends Component { - const maxAge = policy.deletion?.condition?.max_age; - if (maxAge) { - this.setState({ - maxAgeNum: parseInt(maxAge.substring(0, maxAge.length - 1)), - maxAgeUnit: maxAge[maxAge.length - 1], - }); - } - }; - onChangeMaxCount = (e: ChangeEvent) => { // Received NaN for the `value` attribute. If this is expected, cast the value to a string. const maxCount = isNaN(parseInt(e.target.value)) ? undefined : parseInt(e.target.value); diff --git a/public/pages/SnapshotPolicies/containers/SnapshotPolicies/SnapshotPolicies.tsx b/public/pages/SnapshotPolicies/containers/SnapshotPolicies/SnapshotPolicies.tsx index a3cc31cb6..69dbd96a7 100644 --- a/public/pages/SnapshotPolicies/containers/SnapshotPolicies/SnapshotPolicies.tsx +++ b/public/pages/SnapshotPolicies/containers/SnapshotPolicies/SnapshotPolicies.tsx @@ -97,7 +97,7 @@ export default class SnapshotPolicies extends Component { const showSymbol = _.truncate(name, { length: 20 }); return ( @@ -126,6 +126,7 @@ export default class SnapshotPolicies extends Component { return truncateSpan(value); }, diff --git a/public/pages/SnapshotPolicyDetails/containers/SnapshotPolicyDetails/SnapshotPolicyDetails.tsx b/public/pages/SnapshotPolicyDetails/containers/SnapshotPolicyDetails/SnapshotPolicyDetails.tsx index 53f667840..87821a2d2 100644 --- a/public/pages/SnapshotPolicyDetails/containers/SnapshotPolicyDetails/SnapshotPolicyDetails.tsx +++ b/public/pages/SnapshotPolicyDetails/containers/SnapshotPolicyDetails/SnapshotPolicyDetails.tsx @@ -198,8 +198,6 @@ export default class SnapshotPolicyDetails extends Component notiConditions[key]) .join(", "); } - console.log(`sm dev notification ${notiActivities}`); const notificationItems = [ { term: "Notify on snapshot activities", value: notiActivities }, diff --git a/public/pages/Snapshots/components/CreateSnapshotFlyout/CreateSnapshotFlyout.tsx b/public/pages/Snapshots/components/CreateSnapshotFlyout/CreateSnapshotFlyout.tsx index 54a1d12ba..2ab6397d9 100644 --- a/public/pages/Snapshots/components/CreateSnapshotFlyout/CreateSnapshotFlyout.tsx +++ b/public/pages/Snapshots/components/CreateSnapshotFlyout/CreateSnapshotFlyout.tsx @@ -87,7 +87,6 @@ export default class CreateSnapshotFlyout extends Component ({ ...item, repository: repositories[i] })); - // console.log(`sm dev cat snapshot response: ${JSON.stringify(snapshotWithPolicy)}`); snapshots = [...snapshots, ...snapshotWithPolicy]; } @@ -93,7 +89,7 @@ export default class SnapshotManagementService { }, }); } catch (err) { - // TODO SM handle missing snapshot exception, return empty + // If getting a non-existing snapshot, need to handle the missing snapshot exception, and return empty return this.errorResponse(response, err, "getAllSnapshotsWithPolicy"); } }; @@ -176,7 +172,6 @@ export default class SnapshotManagementService { snapshot: id, body: JSON.stringify(request.body), }; - // TODO SM body indices, ignore_unavailable, include_global_state, partial const { callAsCurrentUser: callWithRequest } = this.osDriver.asScoped(request); const resp: CreateSnapshotResponse = await callWithRequest("snapshot.create", params);