Skip to content

Commit 2896bba

Browse files
Merge pull request #9317 from liu-samuel/settings-tabs-conversion
Convert application settings tabs and subtabs
2 parents 1f5c90e + dbc1bee commit 2896bba

16 files changed

+193
-66
lines changed

app/controllers/ops_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,7 @@ def settings_replace_right_cell(nodetype, presenter)
685685
@edit ? _("Editing Schedule \"%{name}\"") % {:name => @schedule.name} : _("Schedule \"%{name}\"") % {:name => @schedule.name}
686686
end
687687
else
688-
if %w[accordion_select change_tab tree_select].include?(params[:action]) &&
689-
params[:tab_id] != "settings_advanced"
688+
if %w[accordion_select change_tab tree_select].include?(params[:action])
690689
presenter.replace(:ops_tabs, r[:partial => "all_tabs"])
691690
elsif %w[zone_delete].include?(params[:pressed])
692691
presenter.replace(:ops_tabs, r[:partial => "all_tabs"])

app/controllers/ops_controller/settings/common.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ def settings_get_info(nodetype = x_node)
859859
nodes = nodetype.downcase.split("-")
860860
case nodes[0]
861861
when "root"
862+
@settings_tab, @settings_tab_length = settings_tab_index_by_name(@sb[:active_tab])
863+
@subtab = settings_tags_tab_index_by_name(@sb[:active_subtab])
862864
@right_cell_text = _("%{product} Region \"%{name}\"") %
863865
{:name => "#{MiqRegion.my_region.description} [#{MiqRegion.my_region.region}]",
864866
:product => Vmdb::Appliance.PRODUCT_NAME}
@@ -870,9 +872,9 @@ def settings_get_info(nodetype = x_node)
870872
@in_a_form = true
871873
when "settings_tags"
872874
case @sb[:active_subtab]
873-
when "settings_co_categories"
875+
when "settings_my_company_categories"
874876
category_get_all
875-
when "settings_co_tags"
877+
when "settings_my_company_tags"
876878
# dont hide the disabled categories, so user can remove tags from the disabled ones
877879
cats = Classification.categories.sort_by(&:description) # Get the categories, sort by name
878880
@cats = {} # Classifications array for first chooser
@@ -887,15 +889,15 @@ def settings_get_info(nodetype = x_node)
887889
@edit[:key] = "#{@sb[:active_tab]}_edit__#{@sb[:selected_server_id]}"
888890
add_flash(_("Locate and upload a file to start the import process"), :info)
889891
@in_a_form = true
890-
when "settings_import" # Import tab
892+
when "settings_import_variables" # Import tab
891893
@edit = {}
892894
@edit[:new] = {}
893895
@edit[:key] = "#{@sb[:active_tab]}_edit__#{@sb[:selected_server_id]}"
894896
@edit[:new][:upload_type] = nil
895897
@sb[:good] = nil unless @sb[:show_button]
896898
add_flash(_("Choose the type of custom variables to be imported"), :info)
897899
@in_a_form = true
898-
when "settings_label_tag_mapping"
900+
when "settings_map_tags"
899901
label_tag_mapping_get_all
900902
end
901903
when "settings_help_menu"

app/controllers/ops_controller/settings/upload.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def upload_form_field_changed
6060
@sb[:good] = nil
6161
render :update do |page|
6262
page << javascript_prologue
63-
page.replace_html("settings_import", :partial => "settings_import_tab")
63+
page.replace_html("import_variables", :partial => "settings_import_tab")
6464
end
6565
end
6666

app/helpers/ops_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module OpsHelper
99
include SettingsLabelTagMappingHelper
1010
include SettingsScheduleHelper
1111
include SettingsServerDescHelper
12+
include SettingsTabsHelper
13+
include SettingsTagsHelper
1214
include SettingsUsersHelper
1315
include SettingsZoneHelper
1416
include SettingsRbacTagHelper

app/helpers/settings_tabs_helper.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module SettingsTabsHelper
2+
SETTINGS_TAB_IDS = %w[
3+
settings_details
4+
settings_cu_collection
5+
settings_tags
6+
settings_replication
7+
settings_help_menu
8+
settings_advanced
9+
]
10+
11+
def settings_tab_configuration
12+
[:details, :cu_collection, :tags, :replication, :help_menu, :advanced]
13+
end
14+
15+
def settings_tab_content(key_name, &block)
16+
if settings_tabs_types[key_name]
17+
tag.div(:id => "settings_#{key_name}", :class => 'tab_content', &block)
18+
end
19+
end
20+
21+
def settings_tab_index_by_name(name)
22+
[SETTINGS_TAB_IDS.index(name) || -1, SETTINGS_TAB_IDS.length]
23+
end
24+
25+
private
26+
27+
def settings_tabs_types
28+
{
29+
:details => _('Details'),
30+
:cu_collection => _('C & U Collection'),
31+
:tags => _('Tags'),
32+
:replication => _('Replication'),
33+
:help_menu => _('Help Menu'),
34+
:advanced => _('Advanced'),
35+
}
36+
end
37+
end

app/helpers/settings_tags_helper.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module SettingsTagsHelper
2+
3+
SETTINGS_TAGS_TABS_IDS = %w[
4+
settings_my_company_categories
5+
settings_my_company_tags
6+
settings_import_tags
7+
settings_import_variables
8+
settings_map_tags
9+
]
10+
11+
def settings_tags_configuration
12+
[:my_company_categories, :my_company_tags, :import_tags, :import_variables, :map_tags]
13+
end
14+
15+
def settings_tags_content(key_name, &block)
16+
if settings_tags_types[key_name]
17+
tag.div(:id => key_name, :class => 'tab_content', &block)
18+
end
19+
end
20+
21+
def settings_tags_tab_index_by_name(name)
22+
SETTINGS_TAGS_TABS_IDS.index(name) || -1
23+
end
24+
25+
private
26+
27+
def settings_tags_types
28+
{
29+
:my_company_categories => _('My Company Categories'),
30+
:my_company_tags => _('My Company Tags'),
31+
:import_tags => _('Import Tags'),
32+
:import_variables => _('Import Variables'),
33+
:map_tags => _('Map Tags'),
34+
}
35+
end
36+
end

app/javascript/components/miq-custom-tab/helper.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,33 @@ const requestInfo = {
2828
network: __('Network'),
2929
};
3030

31+
/** Tab labels used for settings in application settings page. */
32+
const settings = {
33+
details: __('Details'),
34+
cu_collection: __('C & U Collection'),
35+
tags: __('Tags'),
36+
replication: __('Replication'),
37+
help_menu: __('Help'),
38+
advanced: __('Advanced'),
39+
};
40+
41+
const settingsTags = {
42+
my_company_categories: __('My Company Categories'),
43+
my_company_tags: __('My Company Tags'),
44+
import_tags: ('Import Tags'),
45+
import_variables: __('Import Variables'),
46+
map_tags: __('Map Tags'),
47+
};
48+
3149
/** Function to select the tab labels. */
3250
export const labelConfig = (type) => {
3351
const configMap = {
3452
CATALOG_SUMMARY: catalog,
3553
CATALOG_EDIT: catalog,
3654
UTILIZATION: utilization,
3755
CATALOG_REQUEST_INFO: requestInfo,
56+
SETTINGS: settings,
57+
SETTINGS_TAGS: settingsTags,
3858
};
3959

4060
return configMap[type];

app/javascript/components/miq-custom-tab/index.jsx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import { Tabs, Tab } from 'carbon-components-react';
44
import { useDispatch } from 'react-redux';
55
import { miqCustomTabActions } from '../../miq-redux/actions/miq-custom-tab-actions';
66
import { labelConfig, tabText } from './helper';
77

8-
const MiqCustomTab = ({ containerId, tabLabels, type }) => {
8+
const MiqCustomTab = ({
9+
containerId, tabLabels, type, activeTab, subtab, tabLength,
10+
}) => {
911
const dispatch = useDispatch();
1012
const [data, setData] = useState({ loading: false });
13+
const activeTabClassName = 'bx--tabs--scrollable__nav-item--selected';
14+
const selectedClassName = 'bx--tabs__nav-item--selected';
1115

1216
/** Labels used for a Tab found from the 'type'. */
1317
const selectedLabels = labelConfig(type);
@@ -23,6 +27,13 @@ const MiqCustomTab = ({ containerId, tabLabels, type }) => {
2327
{ type: 'CATALOG_EDIT', js: () => name === 'detail' && dispatch(miqCustomTabActions.incrementClickCount()) },
2428
{ type: 'CATALOG_REQUEST_INFO', url: `/miq_request/prov_field_changed?tab_id=${name}&edit_mode=true` },
2529
{ type: 'UTILIZATION' },
30+
{
31+
type: 'SETTINGS',
32+
url: name === 'tags'
33+
? `/ops/change_tab?tab_id=settings_my_company_categories&parent_tab_id=settings_${name}`
34+
: `/ops/change_tab?tab_id=settings_${name}`,
35+
},
36+
{ type: 'SETTINGS_TAGS', url: `/ops/change_tab?parent_tab_id=settings_tags&tab_id=settings_${name}` },
2637
];
2738

2839
const configuration = (name) => tabConfigurations(name).find((item) => item.type === type);
@@ -78,6 +89,7 @@ const MiqCustomTab = ({ containerId, tabLabels, type }) => {
7889

7990
/** Function to handle tab click events. */
8091
const onTabSelect = (name) => {
92+
setData(true);
8193
if (!data.loading) {
8294
miqSparkleOn();
8395
const config = configuration(name);
@@ -91,6 +103,23 @@ const MiqCustomTab = ({ containerId, tabLabels, type }) => {
91103
<Tab key={`tab${label}`} label={`${tabText(selectedLabels, label)}`} onClick={() => onTabSelect(label)} />
92104
));
93105

106+
useEffect(() => {
107+
if (activeTab) {
108+
let elements = document.getElementsByClassName('bx--tabs--scrollable__nav-item');
109+
elements.forEach((element) => {
110+
element.classList.remove(activeTabClassName);
111+
element.classList.remove(selectedClassName);
112+
});
113+
if (subtab !== undefined && subtab !== -1) {
114+
elements[tabLength].classList.remove(activeTabClassName);
115+
elements[subtab + tabLength].classList.add(activeTabClassName);
116+
}
117+
elements[activeTab].classList.add(activeTabClassName);
118+
119+
elements = document.getElementsByClassName('bx--tabs--scrollable__nav-item');
120+
}
121+
}, [data.loading]);
122+
94123
return (
95124
<Tabs className="miq_custom_tabs" id={tabIdentifier('')}>
96125
{renderTabs()}
@@ -104,4 +133,13 @@ MiqCustomTab.propTypes = {
104133
containerId: PropTypes.string.isRequired,
105134
tabLabels: PropTypes.arrayOf(PropTypes.string).isRequired,
106135
type: PropTypes.string.isRequired,
136+
activeTab: PropTypes.number,
137+
subtab: PropTypes.number,
138+
tabLength: PropTypes.number,
139+
};
140+
141+
MiqCustomTab.defaultProps = {
142+
activeTab: undefined,
143+
subtab: undefined,
144+
tabLength: undefined,
107145
};

app/stylesheet/miq-custom-tab.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@
4545
margin-bottom: 0px;
4646
}
4747
}
48+
49+
#settings-tabs-wrapper {
50+
.bx--tab-content {
51+
display: none;
52+
}
53+
}

app/views/ops/_all_tabs.html.haml

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -52,58 +52,45 @@
5252
= render :partial => "settings_list_tab"
5353
- else
5454
= render(:partial => "layouts/flash_msg")
55-
%ul.nav.nav-tabs{'role' => 'tablist'}
56-
= miq_tab_header("settings_details", @sb[:active_tab]) do
57-
= _("Details")
58-
= miq_tab_header("settings_cu_collection", @sb[:active_tab]) do
59-
= _("C & U Collection")
60-
= miq_tab_header("settings_tags", @sb[:active_tab]) do
61-
= _("Tags")
62-
= miq_tab_header("settings_replication", @sb[:active_tab]) do
63-
= _("Replication")
64-
= miq_tab_header("settings_help_menu", @sb[:active_tab]) do
65-
= _("Help Menu")
66-
= miq_tab_header("settings_advanced", @sb[:active_tab]) do
67-
= _("Advanced")
68-
.tab-content
69-
= miq_tab_content("settings_details", @sb[:active_tab]) do
70-
= render :partial => "settings_details_tab"
71-
= miq_tab_content("settings_cu_collection", @sb[:active_tab]) do
72-
= render :partial => "settings_cu_collection_tab"
73-
= miq_tab_content("settings_tags", @sb[:active_tab]) do
74-
#ops_tags_subtabs
75-
%ul.nav.nav-tabs.nav-tabs-pf{:style => 'font-size: 12px'}
76-
= miq_tab_header("settings_co_categories", @sb[:active_subtab]) do
77-
= escape_javascript(current_tenant.name)
78-
= _("Categories")
79-
= miq_tab_header("settings_co_tags", @sb[:active_subtab]) do
80-
= escape_javascript(current_tenant.name)
81-
= _("Tags")
82-
= miq_tab_header("settings_import_tags", @sb[:active_subtab]) do
83-
= _("Import Tags")
84-
= miq_tab_header("settings_import", @sb[:active_subtab]) do
85-
= _("Import Variables")
86-
= miq_tab_header("settings_label_tag_mapping", @sb[:active_subtab]) do
87-
= _("Map Tags")
88-
.tab-content
89-
= miq_tab_content("settings_co_categories", @sb[:active_subtab]) do
90-
= render :partial => "settings_co_categories_tab"
91-
= miq_tab_content("settings_co_tags", @sb[:active_subtab]) do
92-
= render :partial => "settings_co_tags_tab"
93-
= miq_tab_content("settings_import_tags", @sb[:active_subtab]) do
94-
= render :partial => "settings_import_tags_tab"
95-
= miq_tab_content("settings_import", @sb[:active_subtab]) do
96-
= render :partial => "settings_import_tab"
97-
= miq_tab_content("settings_label_tag_mapping", @sb[:active_subtab]) do
98-
= render :partial => "settings_label_tag_mapping_tab"
99-
:javascript
100-
miq_tabs_init("#ops_tags_subtabs", "/ops/change_tab", {parent_tab_id: 'settings_tags'});
101-
= miq_tab_content("settings_replication", @sb[:active_tab]) do
102-
= render :partial => "settings_replication_tab"
103-
= miq_tab_content("settings_help_menu", @sb[:active_tab]) do
104-
= render :partial => "settings_help_menu_tab"
105-
= miq_tab_content("settings_advanced", @sb[:active_tab]) do
106-
= render :partial => "settings_advanced_tab"
55+
#settings-tabs-wrapper
56+
= react('MiqCustomTab', {:containerId => 'settings-tabs',
57+
:tabLabels => settings_tab_configuration,
58+
:type => 'SETTINGS',
59+
:activeTab => @settings_tab,
60+
})
61+
#settings-tabs
62+
= settings_tab_content(:details) do
63+
= render :partial => "settings_details_tab"
64+
= settings_tab_content(:cu_collection) do
65+
= render :partial => "settings_cu_collection_tab"
66+
= settings_tab_content(:tags) do
67+
- if @sb[:active_tab] == 'settings_tags'
68+
#ops_tags_subtabs
69+
%ul.nav.nav-tabs.nav-tabs-pf{:style => 'font-size: 12px'}
70+
= react('MiqCustomTab', {:containerId => 'ops_tags_subtabs',
71+
:tabLabels => settings_tags_configuration,
72+
:type => 'SETTINGS_TAGS',
73+
:activeTab => @settings_tab,
74+
:subtab => @subtab,
75+
:tabLength => @settings_tab_length,
76+
})
77+
.tab-content
78+
= settings_tags_content(:my_company_categories) do
79+
= render :partial => "settings_co_categories_tab"
80+
= settings_tags_content(:my_company_tags) do
81+
= render :partial => "settings_co_tags_tab"
82+
= settings_tags_content(:import_tags) do
83+
= render :partial => "settings_import_tags_tab"
84+
= settings_tags_content(:import_variables) do
85+
= render :partial => "settings_import_tab"
86+
= settings_tags_content(:map_tags) do
87+
= render :partial => "settings_label_tag_mapping_tab"
88+
= settings_tab_content(:replication) do
89+
= render :partial => "settings_replication_tab"
90+
= settings_tab_content(:help_menu) do
91+
= render :partial => "settings_help_menu_tab"
92+
= settings_tab_content(:advanced) do
93+
= render :partial => "settings_advanced_tab"
10794
-# Diagnostics
10895
- when :diagnostics_tree
10996
- if x_node.split("-")[0] == "z"

0 commit comments

Comments
 (0)