Skip to content

Commit

Permalink
Converted Add/Remove Security groups form to react
Browse files Browse the repository at this point in the history
  • Loading branch information
GilbertCherrie committed Feb 14, 2022
1 parent 70548e4 commit 719010d
Show file tree
Hide file tree
Showing 52 changed files with 560 additions and 1,920 deletions.
16 changes: 0 additions & 16 deletions app/controllers/container_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class ContainerDashboardController < ApplicationController
def data
assert_privileges("container_dashboard_view")

return data_live if params[:live] == 'true'

render :json => {:data => collect_data(params[:id])}
end

Expand Down Expand Up @@ -53,10 +51,6 @@ def refresh_status_data
render :json => {:data => collect_refresh_status_data(params[:id])}
end

def data_live
render :json => collect_live_data(params[:id], params[:query])
end

def project_data
assert_privileges("container_dashboard_view")

Expand Down Expand Up @@ -109,16 +103,6 @@ def collect_refresh_status_data(provider_id)
ContainerDashboardService.new(provider_id, self).refresh_status_data
end

def collect_live_data(provider_id, query)
ems = ExtManagementSystem.find(provider_id)

if ems && ems.connection_configurations.prometheus.try(:endpoint)
PrometheusProxyService.new(provider_id, self).data(query)
else
HawkularProxyService.new(provider_id, self).data(query)
end
end

def collect_project_data(project_id)
ContainerProjectDashboardService.new(project_id, self).all_data
end
Expand Down
12 changes: 0 additions & 12 deletions app/controllers/container_node_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ def textual_group_list
end
helper_method :textual_group_list

def show_ad_hoc_metrics
if @record && @record.try(:ems_id)
ems = find_record_with_rbac(ExtManagementSystem, @record.ems_id)
tags = {:type => "node", :hostname => @record.name}.to_json
redirect_to(polymorphic_path(ems, :display => "ad_hoc_metrics", :tags => tags))
end
end

def self.custom_display_modes
%w[ad_hoc_metrics]
end

def download_data
assert_privileges('container_node_show_list')
super
Expand Down
15 changes: 1 addition & 14 deletions app/controllers/mixins/ems_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ def show_props
drop_breadcrumb(:name => @ems.name + _(" (Properties)"), :url => show_link(@ems, :display => "props"))
end

def show_ad_hoc_metrics
@showtype = "ad_hoc_metrics"
@lastaction = "show_ad_hoc_metrics"
drop_breadcrumb(:name => @ems.name + _(" (Ad hoc Metrics)"), :url => show_link(@ems))
end

def display_storage_managers
nested_list(ManageIQ::Providers::StorageManager, :parent_method => :storage_managers)
end
Expand Down Expand Up @@ -120,7 +114,7 @@ def display_methods
end

def custom_display_modes
%w[props ad_hoc_metrics]
%w[props]
end

def default_show_template
Expand Down Expand Up @@ -182,13 +176,6 @@ def performance_pressed
javascript_redirect(polymorphic_path(@record, :display => "performance"))
end

def ad_hoc_metrics_pressed
@showtype = "ad_hoc_metrics"
@record = find_record_with_rbac(model, params[:id])
drop_breadcrumb(:name => @record.name + _(" (Ad hoc Metrics)"), :url => show_link(@record))
javascript_redirect(polymorphic_path(@record, :display => "ad_hoc_metrics"))
end

# provider_id can be either a provider id or a storage manager id, depending on context
# this method figures the block_storage_manager_id.
def block_storage_manager_id(provider_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ApplicationHelper::Button::ButtonTemplateClone < ApplicationHelper::Button::Basic
needs :@record

def disabled?
@error_message = _('Template cannot be cloned') if @record.type.eql?("ManageIQ::Providers::IbmPowerHmc::InfraManager")
@error_message.present?
end
end
1 change: 0 additions & 1 deletion app/helpers/application_helper/page_layouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def layout_uses_listnav?
].include?(@layout)

return false if %w[
ad_hoc_metrics
consumption
dashboard
dialog_provision
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class ApplicationHelper::Toolbar::CloudVolumeCenter < ApplicationHelper::Toolbar
t = N_('Delete this Cloud Volume'),
t,
:url_parms => 'main_div',
:klass => ApplicationHelper::Button::CatalogItemButton,
:klass => ApplicationHelper::Button::GenericFeatureButtonWithDisable,
:options => {:feature => :delete},
:data => {'function' => 'sendDataWithRx',
'function-data' => {:controller => 'provider_dialogs',
:modal_title => N_('Delete Volume'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class ApplicationHelper::Toolbar::CloudVolumesCenter < ApplicationHelper::Toolba
t = N_('Delete selected Cloud Volumes'),
t,
:url_parms => 'main_div',
:klass => ApplicationHelper::Button::CatalogItemButton,
:klass => ApplicationHelper::Button::PolymorphicConditionalButton,
:options => {:feature => :delete,
:parent_class => "CloudVolume"},
:data => {'function' => 'sendDataWithRx',
'function-data' => {:controller => 'provider_dialogs',
:modal_title => N_('Delete Volumes'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ class ApplicationHelper::Toolbar::ContainerNodeCenter < ApplicationHelper::Toolb
:options => {:entity => N_('Node')},
:klass => ApplicationHelper::Button::ContainerPerf,
),
button(
:ems_container_ad_hoc_metrics,
'fa fa-tachometer fa-1xplus',
N_('Show Ad hoc Metrics for this Provider'),
N_('Ad hoc Metrics'),
:url => "/show",
:url_parms => "?display=ad_hoc_metrics"
),
button(
:ems_container_launch_external_logging,
'ff ff-monitoring fa-lg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ class ApplicationHelper::Toolbar::EmsContainerCenter < ApplicationHelper::Toolba
:klass => ApplicationHelper::Button::ContainerPerf,
:options => {:feature => :performance, :entity => N_('Provider')},
:url_parms => "?display=performance"),
button(
:ems_container_ad_hoc_metrics,
'fa fa-tachometer fa-1xplus',
N_('Show Ad hoc Metrics for this Provider'),
N_('Ad hoc Metrics'),
:klass => ApplicationHelper::Button::GenericFeatureButton,
:options => {:feature => :ad_hoc_metrics},
:url_parms => "?display=ad_hoc_metrics"),
button(
:ems_container_launch_external_logging,
'ff ff-monitoring fa-lg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class ApplicationHelper::Toolbar::TemplateInfrasCenter < ApplicationHelper::Tool
:url_parms => "main_div",
:send_checked => true,
:enabled => false,
:onwhen => "1"),
:onwhen => "1",
:klass => ApplicationHelper::Button::ButtonTemplateClone),
]
),
])
Expand Down
15 changes: 7 additions & 8 deletions app/helpers/miq_ae_class_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,14 @@ def class_field_data(field_data)
end

def class_properties_data(name, record)
data = {:title => _("Properties"), :mode => "class_props"}
rows = [
{:label => _('Fully Qualified Name'), :value => h(name)},
{:label => _('Name'), :value => record.name},
{:label => _('Display Name'), :value => record.display_name},
{:label => _('Description'), :value => record.try(:description)},
{:label => _('Instances'), :value => h(record.ae_instances.length)},
data = {:title => _("Properties"), :mode => "class_props", :clickable => false}
data[:rows] = [
{:cells => {:label => _('Fully Qualified Name'), :value => h(name)}},
{:cells => {:label => _('Name'), :value => record.name}},
{:cells => {:label => _('Display Name'), :value => record.display_name}},
{:cells => {:label => _('Description'), :value => record.try(:description)}},
{:cells => {:label => _('Instances'), :value => h(record.ae_instances.length)}},
]
data[:rows] = rows
miq_structured_list(data)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import { componentTypes, validatorTypes } from '@@ddf';
import { parseCondition } from '@data-driven-forms/react-form-renderer';

const createSchema = (fields, edit, ems, loadSchema) => {
const changeValue = (value, loadSchema, emptySchema) => {
if (value === '-1') {
emptySchema();
} else {
miqSparkleOn();
API.options(`/api/cloud_volumes?ems_id=${value}`).then(loadSchema()).then(miqSparkleOff);
}
};

const storageManagers = (supports) => API.get(`/api/providers?expand=resources&attributes=id,name,${supports}&filter[]=${supports}=true`)
.then(({ resources }) => {
let storageManagersOptions = [];
storageManagersOptions = resources.map(({ id, name }) => ({ label: name, value: id }));
storageManagersOptions.unshift({ label: `<${__('Choose')}>`, value: '-1' });
return storageManagersOptions;
});

const createSchema = (fields, edit, ems, loadSchema, emptySchema) => {
const idx = fields.findIndex((field) => field.name === 'volume_type');
const supports = edit ? 'supports_cloud_volume' : 'supports_cloud_volume_create';

Expand All @@ -12,14 +29,11 @@ const createSchema = (fields, edit, ems, loadSchema) => {
name: 'ems_id',
id: 'ems_id',
label: __('Storage Manager'),
placeholder: __('<Choose>'),
onChange: (value) => API.options(`/api/cloud_volumes?ems_id=${value}`).then(loadSchema()),
loadOptions: () => API.get(`/api/providers?expand=resources&attributes=id,name,${supports}&filter[]=${supports}=true`).then(({ resources }) =>
resources.map(({ id, name }) => ({ value: id, label: name }))),
onChange: (value) => changeValue(value, loadSchema, emptySchema),
loadOptions: () => storageManagers(supports),
isDisabled: edit || ems,
isRequired: true,
validate: [{ type: validatorTypes.REQUIRED }],
includeEmpty: true,
},
{
component: componentTypes.TEXT_FIELD,
Expand All @@ -29,14 +43,6 @@ const createSchema = (fields, edit, ems, loadSchema) => {
isRequired: true,
validate: [{ type: validatorTypes.REQUIRED }],
},
{
component: componentTypes.TEXT_FIELD,
name: 'edit',
id: 'edit',
label: 'edit',
hideField: true,
initialValue: edit || '',
},
...(idx === -1 ? fields : [
...fields.slice(0, idx),
{
Expand Down
44 changes: 32 additions & 12 deletions app/javascript/components/cloud-volume-form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ const CloudVolumeForm = ({ recordId, storageManagerId }) => {
}));
};

const emptySchema = (appendState = {}) => {
const fields = [];
setState((state) => ({
...state,
...appendState,
fields,
}));
};

useEffect(() => {
if (recordId) {
API.get(`/api/cloud_volumes/${recordId}`).then((initialValues) => {
Expand All @@ -30,18 +39,20 @@ const CloudVolumeForm = ({ recordId, storageManagerId }) => {
}, [recordId, storageManagerId]);

const onSubmit = ({ edit: _edit, ...values }) => {
miqSparkleOn();
if (values.ems_id !== '-1') {
miqSparkleOn();

const request = recordId ? API.patch(`/api/cloud_volumes/${recordId}`, values) : API.post('/api/cloud_volumes', values);
request.then(() => {
const message = sprintf(
recordId
? __('Modification of Cloud Volume "%s" has been successfully queued.')
: __('Add of Cloud Volume "%s" has been successfully queued.'),
values.name,
);
miqRedirectBack(message, undefined, '/cloud_volume/show_list');
}).catch(miqSparkleOff);
const request = recordId ? API.patch(`/api/cloud_volumes/${recordId}`, values) : API.post('/api/cloud_volumes', values);
request.then(() => {
const message = sprintf(
recordId
? __('Modification of Cloud Volume "%s" has been successfully queued.')
: __('Add of Cloud Volume "%s" has been successfully queued.'),
values.name,
);
miqRedirectBack(message, undefined, '/cloud_volume/show_list');
}).catch(miqSparkleOff);
}
};

const onCancel = () => {
Expand All @@ -54,11 +65,20 @@ const CloudVolumeForm = ({ recordId, storageManagerId }) => {
miqRedirectBack(message, 'warning', '/cloud_volume/show_list');
};

const validation = (values) => {
const errors = {};
if (values.ems_id === '-1') {
errors.ems_id = __('Please select a storage manager.');
}
return errors;
};

return !isLoading && (
<MiqFormRenderer
schema={createSchema(fields, !!recordId, !!storageManagerId, loadSchema)}
schema={createSchema(fields, !!recordId, !!storageManagerId, loadSchema, emptySchema)}
initialValues={initialValues}
canReset={!!recordId}
validate={validation}
onSubmit={onSubmit}
onReset={() => add_flash(__('All changes have been reset'), 'warn')}
onCancel={onCancel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const ReportDataTable = (props) => {
return (
<>
{
state.total > 0 && hasSearch && renderToolBar()
hasSearch && renderToolBar()
}
{state.total > 0 && (
<MiqDataTable
Expand Down
Loading

0 comments on commit 719010d

Please sign in to comment.