-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #36867 - Add host delete & create
Add bulk modal with bulk params add register/create buttons; fix links address UX comments Remove icon from delete action in the toolbar’s kebab In the delete modal as a primary button use just “Delete” (not delete host) To the top part: Add a kebab with legacy UI button Ensure the loading screen doesn't say 'No Results' support foreman_remote_execution slot Refs #36867 - move action to new controller
- Loading branch information
1 parent
8d1f863
commit 2999007
Showing
21 changed files
with
431 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Api | ||
module V2 | ||
class HostsBulkActionsController < V2::BaseController | ||
include Api::Version2 | ||
include Api::V2::BulkHostsExtension | ||
|
||
before_action :find_deletable_hosts, :only => [:bulk_destroy] | ||
|
||
def_param_group :bulk_host_ids do | ||
param :organization_id, :number, :required => true, :desc => N_("ID of the organization") | ||
param :included, Hash, :desc => N_("Hosts to include in the action"), :required => true, :action_aware => true do | ||
param :search, String, :required => false, :desc => N_("Search string describing which hosts to perform the action on") | ||
param :ids, Array, :required => false, :desc => N_("List of host ids to perform the action on") | ||
end | ||
param :excluded, Hash, :desc => N_("Hosts to explicitly exclude in the action."\ | ||
" All other hosts will be included in the action,"\ | ||
" unless an included parameter is passed as well."), :required => true, :action_aware => true do | ||
param :ids, Array, :required => false, :desc => N_("List of host ids to exclude and not perform the action on") | ||
end | ||
end | ||
|
||
api :DELETE, "/hosts/bulk/", N_("Delete multiple hosts") | ||
param_group :bulk_host_ids | ||
def bulk_destroy | ||
process_response @hosts.destroy_all | ||
end | ||
|
||
private | ||
|
||
def find_deletable_hosts | ||
find_bulk_hosts(:destroy_hosts, params) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Api::V2::BulkHostsExtension | ||
extend ActiveSupport::Concern | ||
|
||
def bulk_hosts_relation(permission, org) | ||
relation = ::Host::Managed.authorized(permission) | ||
relation = relation.where(organization: org) if org | ||
relation | ||
end | ||
|
||
def find_bulk_hosts(permission, bulk_params, restrict_to = nil) | ||
# works on a structure of param_group bulk_params and transforms it into a list of systems | ||
bulk_params[:included] ||= {} | ||
bulk_params[:excluded] ||= {} | ||
search_param = bulk_params[:included][:search] || bulk_params[:search] | ||
|
||
if !params[:install_all] && bulk_params[:included][:ids].blank? && search_param.nil? | ||
render_error :custom_error, :status => :bad_request, :locals => { :message => _('No hosts have been specified') } | ||
end | ||
|
||
find_organization | ||
@hosts = bulk_hosts_relation(permission, @organization) | ||
|
||
if bulk_params[:included][:ids].present? | ||
@hosts = @hosts.where(id: bulk_params[:included][:ids]) | ||
end | ||
|
||
if search_param.present? | ||
@hosts = @hosts.search_for(search_param) | ||
end | ||
|
||
@hosts = restrict_to.call(@hosts) if restrict_to | ||
|
||
if bulk_params[:excluded][:ids].present? | ||
@hosts = @hosts.where.not(id: bulk_params[:excluded][:ids]) | ||
end | ||
if @hosts.empty? | ||
render_error :custom_error, :status => :forbidden, :locals => { :message => _('No hosts matched search, or action unauthorized for selected hosts.') } | ||
end | ||
@hosts | ||
end | ||
|
||
def find_organization | ||
@organization ||= Organization.find_by_id(params[:organization_id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/bulkDelete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { visit } from '../../../../foreman_navigation'; | ||
import { foremanUrl } from '../../../common/helpers'; | ||
import { sprintf, translate as __ } from '../../../common/I18n'; | ||
import { openConfirmModal } from '../../ConfirmModal'; | ||
import { APIActions } from '../../../redux/API'; | ||
import './bulkDeleteModal.scss'; | ||
|
||
export const bulkDeleteHosts = ({ | ||
bulkParams, | ||
selectedCount, | ||
destroyVmOnHostDelete, | ||
}) => dispatch => { | ||
const successToast = () => sprintf(__('%s hosts deleted'), selectedCount); | ||
const errorToast = ({ message }) => message; | ||
const url = foremanUrl(`/api/v2/hosts/bulk?search=${bulkParams}`); | ||
|
||
// TODO: Replace with a checkbox instead of a global setting for cascade host destroy | ||
const cascadeMessage = () => | ||
destroyVmOnHostDelete | ||
? __( | ||
'For hosts with compute resources, this will delete the VM and its disks.' | ||
) | ||
: __( | ||
'For hosts with compute resources, VMs and their disks will not be deleted.' | ||
); | ||
|
||
dispatch( | ||
openConfirmModal({ | ||
isWarning: true, | ||
isDireWarning: true, | ||
id: 'bulk-delete-hosts-modal', | ||
title: ( | ||
<FormattedMessage | ||
defaultMessage="Delete {count, plural, one {{singular}} other {{plural}}}?" | ||
values={{ | ||
count: selectedCount, | ||
singular: __('host'), | ||
plural: __('hosts'), | ||
}} | ||
id="bulk-delete-host-count" | ||
/> | ||
), | ||
confirmButtonText: __('Delete'), | ||
onConfirm: () => | ||
dispatch( | ||
APIActions.delete({ | ||
url, | ||
key: `BULK-HOSTS-DELETE`, | ||
successToast, | ||
errorToast, | ||
handleSuccess: () => visit(foremanUrl('/new/hosts')), | ||
}) | ||
), | ||
message: ( | ||
<FormattedMessage | ||
id="bulk-delete-hosts" | ||
values={{ | ||
hostsCount: ( | ||
<strong> | ||
<FormattedMessage | ||
defaultMessage="{count, plural, one {# {singular}} other {# {plural}}}" | ||
values={{ | ||
count: selectedCount, | ||
singular: __('host'), | ||
plural: __('hosts'), | ||
}} | ||
id="bulk-delete-host-count" | ||
/> | ||
</strong> | ||
), | ||
cascade: cascadeMessage(), | ||
settings: ( | ||
<a href={foremanUrl('/settings?search=destroy')}> | ||
{__('Provisioning settings')} | ||
</a> | ||
), | ||
br: <br />, | ||
}} | ||
defaultMessage={__( | ||
'{hostsCount} will be deleted. This action is irreversible. {br}{br} {cascade} {br}{br} This behavior can be changed via global setting "Destroy associated VM on host delete" in {settings}.{br}{br}' | ||
)} | ||
/> | ||
), | ||
}) | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/bulkDeleteModal.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#bulk-delete-hosts-modal { | ||
min-height: 21rem; | ||
.pf-c-check label { | ||
font-size: 14px; | ||
position: relative; | ||
top: 2px; | ||
} | ||
} |
Oops, something went wrong.