Skip to content

Commit

Permalink
Merge branch 'master' into help-menu-form-conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-samuel authored Nov 19, 2024
2 parents d93588a + f2c46c5 commit 498c9cc
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 161 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
strategy:
matrix:
ruby-version:
- '3.0'
- '3.1'
- '3.3'
node-version:
- 18
test-suite:
Expand Down Expand Up @@ -63,6 +63,6 @@ jobs:
- name: Run tests
run: bundle exec rake
- name: Report code coverage
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.1' && matrix.test-suite == 'spec' }}
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.3' && matrix.test-suite == 'spec' }}
continue-on-error: true
uses: paambaati/codeclimate-action@v5
32 changes: 0 additions & 32 deletions app/controllers/application_controller/automate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,6 @@ def resolve_button_throw
end
private :resolve_button_throw

# Copy current URI as an automate button
def resolve_button_copy
session[:resolve_object] = copy_hash(@resolve)
head :ok
end
private :resolve_button_copy

# Copy current URI as an automate button
def resolve_button_paste
@resolve = copy_hash(session[:resolve_object])
@edit = session[:edit]
@custom_button = @edit[:custom_button]
@edit[:instance_names] = @resolve[:instance_names]
@edit[:new][:instance_name] = @resolve[:new][:instance_name]
@edit[:new][:object_message] = @resolve[:new][:object_message]
@edit[:new][:object_request] = @resolve[:new][:object_request]
@edit[:new][:attrs] = @resolve[:new][:attrs]
@edit[:new][:target_class] = @resolve[:target_class] = @resolve[:new][:target_class]
@edit[:uri] = @resolve[:uri]
(ApplicationController::AE_MAX_RESOLUTION_FIELDS - @resolve[:new][:attrs].length).times { @edit[:new][:attrs].push([]) }
@changed = (@edit[:new] != @edit[:current])
render :update do |page|
page << javascript_prologue
page.replace_html("main_div", :partial => "shared/buttons/ab_list")
page << javascript_for_miq_button_visibility_changed(@changed)
page << "miqSparkle(false);"
end
end
private :resolve_button_paste

# Copy current URI as an automate button
def resolve_button_simulate
@edit = copy_hash(session[:resolve])
Expand Down Expand Up @@ -126,8 +96,6 @@ def resolve

case params[:button]
when "throw", "retry" then resolve_button_throw
when "copy" then resolve_button_copy
when "paste" then resolve_button_paste
when "simulate" then resolve_button_simulate
else resolve_button_reset_or_none
end
Expand Down
8 changes: 0 additions & 8 deletions app/helpers/application_helper/button/ae_copy_simulate.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
class ApplicationHelper::Toolbar::MiqAeToolsSimulateCenter < ApplicationHelper::Toolbar::Basic
button_group('miq_ae_tools_vmdb', [
button(
:ae_copy_simulate,
'fa fa-files-o fa-lg',
N_('Copy object details for use in a Button'),
N_('Copy'),
:url => "resolve",
:url_parms => "?button=copy",
:klass => ApplicationHelper::Button::AeCopySimulate),
])
end
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ export const KeyValueListComponent = (props) => {
<label htmlFor={input.name} className="bx--label">{label}</label>
<br />
{input.value && input.value.map((pair, index) => (
<div key={pair.key} className="key-value-list-pair">
// eslint-disable-next-line react/no-array-index-key
<div key={index} className="key-value-list-pair">
<TextInput
id={`${input.name}.${index}.key`}
labelText={keyLabel}
Expand Down
24 changes: 14 additions & 10 deletions app/javascript/components/miq-data-table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ const MiqDataTable = ({
isSortable={isSortable}
isSortHeader={sortHeader}
sortDirection={sortDirection}
className={
classNames('miq-data-table-header', (header.contentButton ? 'header-button' : ''), (header.actionCell ? 'action-cell-holder' : ''))
}
className={classNames(
'miq-data-table-header',
header.contentButton ? 'header-button' : '',
header.actionCell ? 'action-cell-holder' : ''
)}
>
{headerLabel(header.header)}
</TableHeader>
Expand Down Expand Up @@ -148,15 +150,17 @@ const MiqDataTable = ({
stickyHeader={stickyHeader}
>
{({
rows, getTableProps, getHeaderProps, getRowProps, getSelectionProps,
rows, headers, getTableProps, getHeaderProps, getRowProps, getSelectionProps,
}) => (
<Table {...getTableProps()}>
<TableHead>
<TableRow>
{rowCheckBox && selectAll(getSelectionProps)}
{renderHeaders(getHeaderProps)}
</TableRow>
</TableHead>
{headers[0] && headers[0].header !== '' ? (
<TableHead>
<TableRow>
{rowCheckBox && selectAll(getSelectionProps)}
{renderHeaders(getHeaderProps)}
</TableRow>
</TableHead>
) : undefined}
<TableBody>
{sortableRows(rows).map((row, index) => {
const item = propRows[index];
Expand Down
72 changes: 72 additions & 0 deletions app/javascript/components/settings-details-tab/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { useState } from 'react';
import MiqDataTable from '../miq-data-table';
import RegionForm from '../region-form';

const settingsDetailsTab = ({
region, scanItemsCount, zonesCount, miqSchedulesCount,
}) => {
const [rows, setRows] = useState([
{
id: '0',
region: {
text: `${region.description} [${region.region}]`,
icon: 'carbon--Db2Database',
},
treeBox: 'settings_tree',
},
{
id: '1',
region: {
text: `${__('Analysis Profiles')} (${scanItemsCount})`,
icon: 'carbon--Search',
},
treeBox: 'settings_tree',
nodeKey: 'xx-sis',
},
{
id: '2',
region: {
text: `${__('Zones')} (${zonesCount})`,
icon: 'carbon--CirclePacking',
},
treeBox: 'settings_tree',
nodeKey: 'xx-z',
},
{
id: '3',
region: {
text: `${__('Schedules')} (${miqSchedulesCount})`,
icon: 'carbon--Time',
},
treeBox: 'settings_tree',
nodeKey: 'xx-msc',
},
]);

const headers = [
{
key: 'region',
header: '',
},
];

const onSelect = (selectedRow) => {
const selected = rows.find((row) => row.id === selectedRow.id);
if (selected.nodeKey) {
miqTreeActivateNode(selected.treeBox, selected.nodeKey);
} else {
setRows((prevRows) => prevRows.filter((row) => row.id !== '0'));
}
};

return (
<div>
{rows.find((row) => row.id === '0') === undefined && (
<RegionForm maxDescLen={255} id={region.id.toString()} />
)}
<MiqDataTable rows={rows} headers={headers} onCellClick={(selectedRow) => onSelect(selectedRow)} />
</div>
);
};

export default settingsDetailsTab;
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ export const KeyValueListComponent = (props) => {
<label htmlFor={input.name} className="bx--label">{label}</label>
<br />
{input.value && input.value.map((pair, index) => (
<div key={pair.key} className="key-value-list-pair">
// eslint-disable-next-line react/no-array-index-key
<div key={index} className="key-value-list-pair">
<TextInput
id={`${input.name}.${index}.key`}
labelText={keyLabel}
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/packs/component-definitions-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ import SettingsCompanyCategories from '../components/settings-company-categories
import SettingsCompanyTags from '../components/settings-company-tags';
import SettingsCompanyTagsEntryForm from '../components/settings-company-tags-entry-form';
import SettingsHelpMenuTab from '../components/settings-help-menu-form';
import SettingsDetailsTab from '../components/settings-details-tab';
import SettingsLabelTagMapping from '../components/settings-label-tag-mapping';
import SettingsTasksForm from '../components/settings-tasks-form';
import SettingsTimeProfileForm from '../components/settings-time-profile-form';
Expand Down Expand Up @@ -317,6 +318,7 @@ ManageIQ.component.addReact('SettingsCompanyCategories', SettingsCompanyCategori
ManageIQ.component.addReact('SettingsCompanyTags', SettingsCompanyTags);
ManageIQ.component.addReact('SettingsCompanyTagsEntryForm', SettingsCompanyTagsEntryForm);
ManageIQ.component.addReact('SettingsHelpMenuTab', SettingsHelpMenuTab);
ManageIQ.component.addReact('SettingsDetailsTab', SettingsDetailsTab);
ManageIQ.component.addReact('SettingsLabelTagMapping', SettingsLabelTagMapping);
ManageIQ.component.addReact('SettingsTasksForm', SettingsTasksForm);
ManageIQ.component.addReact('SettingsTimeProfileForm', SettingsTimeProfileForm);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SettingsDetailsTab Component should render settings details tab 1`] = `
<settingsDetailsTab
miqSchedulesCount={0}
region={
Object {
"description": "Region 3",
"id": 1,
"maintenance_zone_id": 1,
"region": 0,
}
}
scanItemsCount={3}
zonesCount={1}
/>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import fetchMock from 'fetch-mock';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import settingsDetailsTab from '../../components/settings-details-tab';

describe('SettingsDetailsTab Component', () => {
const region = {
id: 1,
region: 0,
description: 'Region 3',
maintenance_zone_id: 1,
};

const scanItemsCount = 3;
const zonesCount = 1;
const miqSchedulesCount = 0;

afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});

it('should render settings details tab', async() => {
const wrapper = shallow(<settingsDetailsTab
region={region}
scanItemsCount={scanItemsCount}
zonesCount={zonesCount}
miqSchedulesCount={miqSchedulesCount}
/>);

await new Promise((resolve) => {
setImmediate(() => {
wrapper.update();
expect(toJson(wrapper)).toMatchSnapshot();
resolve();
});
});
});
});
4 changes: 4 additions & 0 deletions app/stylesheet/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
color: red;
}
}

.bx--front-line {
margin-left: 10px;
}
35 changes: 6 additions & 29 deletions app/views/ops/_settings_details_tab.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,9 @@

%table.table.table-striped.table-bordered.table-hover
%tbody
- unless @edit
%tr
%td.table-view-pf-select{:onclick => remote_function(:url => {:action => 'region_edit', :id => region.id},
:loading => "miqSparkle(true);"),
:title => _("Edit this Region")}
%i.pficon.pficon-regions
%td{:onclick => remote_function(:url => {:action => 'region_edit', :id => region.id},
:loading => "miqSparkle(true);"),
:title => _("Edit this Region")}
= h(region.description)
[#{h(region.region)}]
%tr
%td.table-view-pf-select{:onclick => "miqTreeActivateNode('settings_tree', 'xx-sis');", :title => _("View Analysis Profiles")}
%i.fa.fa-search
%td{:onclick => "miqTreeActivateNode('settings_tree', 'xx-sis');", :title => _("View Analysis Profiles")}
= _("Analysis Profiles")
(#{h(@scan_items.size)})
%tr
%td.table-view-pf-select{:onclick => "miqTreeActivateNode('settings_tree', 'xx-z');", :title => _("View Zones")}
%i.pficon.pficon-zone
%td{:onclick => "miqTreeActivateNode('settings_tree', 'xx-z');", :title => _("View Zones")}
= _("Zones")
(#{h(@zones.size)})
%tr
%td.table-view-pf-select{:onclick => "miqTreeActivateNode('settings_tree', 'xx-msc');", :title => _("View Schedules")}
%i.fa.fa-clock-o
%td{:onclick => "miqTreeActivateNode('settings_tree', 'xx-msc');", :title => _("View Schedules")}
= _("Schedules")
(#{h(@miq_schedules.size)})
= react('SettingsDetailsTab',
:region => region,
:scanItemsCount => @scan_items.size,
:zonesCount => @zones.size,
:miqSchedulesCount => @miq_schedules.size)

21 changes: 0 additions & 21 deletions app/views/shared/buttons/_ab_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
#ab_form
#policy_bar
- if session[:resolve_object].present?
- copied_target_class = session[:resolve_object][:new][:target_class]
- current_target_class = @edit[:new][:target_class]
- if copied_target_class == current_target_class
= link_to({:action => "resolve", :button => "paste"},
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
:remote => true,
"data-method" => :post,
:class => 'btn btn-default',
:title => _("Paste object details for use in a Button.")) do
%i.fa.fa-clipboard
- else
%button.btn.btn-default.disabled{:title => _("Paste is not available, target class differs from the target class of the object copied from the Simulation screen")}
%i.fa.fa-clipboard
- else
%button.btn.btn-default.disabled{:title => _("Paste is not available, no object information has been copied from the Simulation screen")}
%i.fa.fa-clipboard
= render :partial => "layouts/flash_msg"

#custom_button_tabs
%ul.nav.nav-tabs{'role' => 'tablist'}
= miq_tab_header('ab_options_tab', @sb[:active_tab]) do
Expand Down
Loading

0 comments on commit 498c9cc

Please sign in to comment.