From d2f8a873ec17e7fb06045a0e23c7326b49395d8f Mon Sep 17 00:00:00 2001 From: Aleksandr Gorodetskii Date: Thu, 18 May 2023 12:41:13 +0300 Subject: [PATCH] GUI Issue #3221: Postpone lifecycle rule action --- .../notification-actions/actions.js | 18 ++++++++- .../notification-actions/index.js | 2 +- .../DataStorageLifeCycleRulesPostpone.js | 40 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 client/src/models/dataStorage/lifeCycleRules/DataStorageLifeCycleRulesPostpone.js diff --git a/client/src/components/main/notification/notification-actions/actions.js b/client/src/components/main/notification/notification-actions/actions.js index 2974c32b5c..f4e1f78e47 100644 --- a/client/src/components/main/notification/notification-actions/actions.js +++ b/client/src/components/main/notification/notification-actions/actions.js @@ -20,6 +20,8 @@ import StopPipeline from '../../../../models/pipelines/StopPipeline'; import ResumePipeline from '../../../../models/pipelines/ResumePipeline'; import PausePipeline from '../../../../models/pipelines/PausePipeline'; import TerminatePipeline from '../../../../models/pipelines/TerminatePipeline'; +import DataStorageLifeCycleRulesPostpone +from '../../../../models/dataStorage/lifeCycleRules/DataStorageLifeCycleRulesPostpone'; import {canPauseRun, canStopRun} from '../../../runs/actions'; import RunStatuses from '../../../special/run-status-icon/run-statuses'; @@ -101,8 +103,20 @@ const ACTIONS = { }, postponeLifecycleRule: { key: 'Postpone', - actionFn: ({notification, router}) => { - router && router.push(`/${notification.storagePath}`); + actionFn: async ({notification = {}, callback}) => { + const details = (notification.resources || [])[0] || {}; + const hide = message.loading('Postpone...', -1); + const request = new DataStorageLifeCycleRulesPostpone({ + datastorageId: details.entityId, + ruleId: details.storageRuleId, + path: details.storagePath + }); + await request.fetch(); + if (request.error) { + message.error(request.error); + } + hide(); + callback && callback(); }, available: () => true }, diff --git a/client/src/components/main/notification/notification-actions/index.js b/client/src/components/main/notification/notification-actions/index.js index 6ddc9e33f6..aa4bda0548 100644 --- a/client/src/components/main/notification/notification-actions/index.js +++ b/client/src/components/main/notification/notification-actions/index.js @@ -88,7 +88,7 @@ class NotificationActions extends React.Component { ], [NOTIFICATION_TYPES.DATASTORAGE_LIFECYCLE_ACTION]: [ ACTIONS.openDatastorage, - ACTIONS.postponeLifecycleAction + ACTIONS.postponeLifecycleRule ], [NOTIFICATION_TYPES.FULL_NODE_POOL]: [ ACTIONS.openPoolsUsage diff --git a/client/src/models/dataStorage/lifeCycleRules/DataStorageLifeCycleRulesPostpone.js b/client/src/models/dataStorage/lifeCycleRules/DataStorageLifeCycleRulesPostpone.js new file mode 100644 index 0000000000..f06bdc3ff0 --- /dev/null +++ b/client/src/models/dataStorage/lifeCycleRules/DataStorageLifeCycleRulesPostpone.js @@ -0,0 +1,40 @@ +/* + * Copyright 2017-2022 EPAM Systems, Inc. (https://www.epam.com/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Remote from '../../basic/Remote'; + +const DEFAULT_DAYS = 14; + +export default class DataStorageLifeCycleRulesPostpone extends Remote { + url; + + constructor ({ + datastorageId, + ruleId, + path, + days = DEFAULT_DAYS, + force = false + }) { + super(); + const parts = [ + path !== undefined && `path=${encodeURIComponent(path)}`, + days !== undefined && `days=${days}`, + force !== undefined && `force=${force}` + ].filter(Boolean); + const query = `?${parts.join('&')}`; + this.url = `/datastorage/${datastorageId}/lifecycle/rule/${ruleId}/prolong${query}`; + } +}