diff --git a/app/controllers/service_controller.rb b/app/controllers/service_controller.rb index 13447d902f52..efdae615811d 100644 --- a/app/controllers/service_controller.rb +++ b/app/controllers/service_controller.rb @@ -33,6 +33,8 @@ def button service_retire when 'service_retire_now' service_retire_now + when 'service_reconfigure' + javascript_redirect(:action => 'service_reconfigure', :id => params[:id]) when "custom_button" @display == 'generic_objects' ? generic_object_custom_buttons : custom_buttons else @@ -74,16 +76,18 @@ def edit checked[0] = params[:id] if checked.blank? && params[:id] @service = find_record_with_rbac(Service, checked[0]) @in_a_form = true - drop_breadcrumb(:name => _("Edit Service\"%{name}\"") % {:name => @service.name}, :url => "/service/edit/#{@service.id}") + drop_breadcrumb(:name => _("Edit Service \"%{name}\"") % {:name => @service.name}, :url => "/service/edit/#{@service.id}") end def service_reconfigure - service = Service.find_by(:id => params[:id]) + assert_privileges('service_reconfigure') + + service = find_record_with_rbac(Service, params[:id]) service_template = service.service_template resource_action = service_template.resource_actions.find_by(:action => 'Reconfigure') if service_template - - @right_cell_text = _("Reconfigure Service \"%{name}\"") % {:name => service.name} - dialog_locals = {:resource_action_id => resource_action.id, :target_id => service.id} + @dialog_locals = {:resource_action_id => resource_action.id, :target_id => service.id} + @in_a_form = true + drop_breadcrumb(:name => _("Reconfigure Service \"%{name}\"") % {:name => service.name}, :url => "/service/service_reconfigure/#{service.id}") end def service_form_fields diff --git a/app/helpers/miq_ae_class_helper.rb b/app/helpers/miq_ae_class_helper.rb index 75f9a62bfe9f..a0b9791733b9 100644 --- a/app/helpers/miq_ae_class_helper.rb +++ b/app/helpers/miq_ae_class_helper.rb @@ -341,6 +341,17 @@ def method_details(ae_method, sb_data) }) end + def method_built_in_data(ae_method) + rows = [ + row_data('', {:input => 'code_mirror', :props => {:mode => 'ruby', :payload => ae_method.data}}) + ] + miq_structured_list({ + :title => _('Data'), + :mode => "method_built_in_data", + :rows => rows + }) + end + private def row_data(label, value) diff --git a/app/javascript/components/miq-structured-list/helpers.js b/app/javascript/components/miq-structured-list/helpers.js index 17500ec559e0..f38e4dc6b86e 100644 --- a/app/javascript/components/miq-structured-list/helpers.js +++ b/app/javascript/components/miq-structured-list/helpers.js @@ -8,6 +8,8 @@ export const InputTypes = { CHECKBOX: 'checkbox', COMPONENT: 'component', DROPDOWN: 'dropdown', + CODEMIRROR: 'code_mirror', + MARKDOWN: 'markdown', }; export const DynamicReactComponents = { diff --git a/app/javascript/components/miq-structured-list/miq-structured-list-body/value-tags/miq-structured-list-inputs.jsx b/app/javascript/components/miq-structured-list/miq-structured-list-body/value-tags/miq-structured-list-inputs.jsx index 2cc7fafeb8b8..c423d4d691e1 100644 --- a/app/javascript/components/miq-structured-list/miq-structured-list-body/value-tags/miq-structured-list-inputs.jsx +++ b/app/javascript/components/miq-structured-list/miq-structured-list-body/value-tags/miq-structured-list-inputs.jsx @@ -1,6 +1,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Checkbox, TextArea, Dropdown } from 'carbon-components-react'; +import { Controlled as CodeMirror } from 'react-codemirror2'; +import ReactMarkdown from 'react-markdown'; import { DynamicReactComponents, InputTypes } from '../../helpers'; /** Component to render textarea / checkbox / react components */ @@ -34,6 +36,30 @@ const MiqStructuredListInputs = ({ value, action }) => { /> ); + /** Function to render the code mirror component. */ + const renderCodeMirrorComponent = ({ props: { mode, payload } }) => ( + + ); + /** Function to render the MarkDown component. + * eg: Service / Catalogs / Catalog Items / [Item] / Details tab. + */ + const renderMarkdown = ({ props: { content } }) => ( + + {content} + + ); + switch (value.input) { case InputTypes.TEXTAREA: return renderTextArea(value); @@ -43,6 +69,10 @@ const MiqStructuredListInputs = ({ value, action }) => { return renderDynamicComponent(value); case InputTypes.DROPDOWN: return renderDropDownComponent(value); + case InputTypes.CODEMIRROR: + return renderCodeMirrorComponent(value); + case InputTypes.MARKDOWN: + return renderMarkdown(value); default: return null; } diff --git a/app/javascript/components/miq-structured-list/miq-structured-list-body/value-types/miq-structured-list-object.jsx b/app/javascript/components/miq-structured-list/miq-structured-list-body/value-types/miq-structured-list-object.jsx index bfe800097951..131d1aa1d227 100644 --- a/app/javascript/components/miq-structured-list/miq-structured-list-body/value-types/miq-structured-list-object.jsx +++ b/app/javascript/components/miq-structured-list/miq-structured-list-body/value-types/miq-structured-list-object.jsx @@ -6,20 +6,24 @@ import MiqStructuredListConditionalTag from '../value-tags/miq-structured-list-c /** Usage eg: Automation / Embeded Automate / Generic Objects / item * Properties has no links & Relationships have links */ -const MiqStructuredListObject = ({ row, clickEvents, onClick }) => ( - - - -); +const MiqStructuredListObject = ({ row, clickEvents, onClick }) => { + const isContent = row.label || (row.value && row.value.input); + return (( + + + + )); +}; export default MiqStructuredListObject; MiqStructuredListObject.propTypes = { row: PropTypes.shape({ label: PropTypes.string, + value: PropTypes.oneOfType([PropTypes.any]), title: PropTypes.string, }), clickEvents: PropTypes.bool.isRequired, diff --git a/app/javascript/spec/action-form/__snapshots__/action-form.spec.js.snap b/app/javascript/spec/action-form/__snapshots__/action-form.spec.js.snap index 8676fa810bfb..ad1b9de21b65 100644 --- a/app/javascript/spec/action-form/__snapshots__/action-form.spec.js.snap +++ b/app/javascript/spec/action-form/__snapshots__/action-form.spec.js.snap @@ -8411,7 +8411,6 @@ exports[`Action Form Component should render adding a new action 1`] = ` > `; +exports[`Structured list component should render code mirror component 1`] = ` + + + + 'user', :level => level, :message => message) + end", + }, + }, + }, + ] + } + /> + + + +`; + exports[`Structured list component should render miq policy data without double escaping strings 1`] = ` { />); expect(toJson(wrapper)).toMatchSnapshot(); }); + + it('should render code mirror component', () => { + const onClick = jest.fn(); + const wrapper = shallow(); + expect(toJson(wrapper)).toMatchSnapshot(); + }); }); diff --git a/app/javascript/spec/physical-storage-form/__snapshots__/physical-storage-form.spec.js.snap b/app/javascript/spec/physical-storage-form/__snapshots__/physical-storage-form.spec.js.snap index 41b82f0e7327..91c7a2ce64f9 100644 --- a/app/javascript/spec/physical-storage-form/__snapshots__/physical-storage-form.spec.js.snap +++ b/app/javascript/spec/physical-storage-form/__snapshots__/physical-storage-form.spec.js.snap @@ -3318,7 +3318,6 @@ exports[`Physical storage form component should render editing form variant 1`] >