-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f493067
commit fc17035
Showing
8 changed files
with
213 additions
and
45 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 |
---|---|---|
@@ -1,3 +1,26 @@ | ||
module ConfigurationHelper | ||
include_concern 'ConfigurationViewHelper' | ||
|
||
def settings_tab_configuration | ||
[:Visual, :Default, :Time].map do |item| | ||
{:name => item, :text => settings_tabs_types[item]} | ||
end | ||
end | ||
|
||
def settings_tab_content(key_name, &block) | ||
if settings_tabs_types[key_name] | ||
class_name = key_name == :summary ? 'tab_content active' : 'tab_content' | ||
tag.div(:id => key_name, :class => class_name, &block) | ||
end | ||
end | ||
|
||
private | ||
|
||
def settings_tabs_types | ||
{ | ||
:Visual => _('Visual'), | ||
:Default => _('Default Filters'), | ||
:Time => _('Time Profiles'), | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export const checkForFormChanges = () => { | ||
let type = 'old'; // 'old' | 'angular' | 'tagging' | 'react' | ||
let dirty = false; | ||
const ignore = !!document.getElementById('ignore_form_changes'); | ||
|
||
if (ManageIQ.redux.store.getState().FormButtons && ManageIQ.redux.store.getState().FormButtons.in_a_form) { | ||
type = 'react'; | ||
} | ||
|
||
switch (type) { | ||
case 'react': | ||
dirty = !ManageIQ.redux.store.getState().FormButtons.pristine; | ||
break; | ||
|
||
default: | ||
dirty = $('#buttons_on').is(':visible'); | ||
break; | ||
} | ||
|
||
if (dirty && !ignore) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; |
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,99 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Tab, Tabs, Modal } from 'carbon-components-react'; | ||
import { checkForFormChanges } from './helper'; | ||
|
||
const CustomURLTabs = ({ | ||
tabs, path, currentTab, checkForChanges, | ||
}) => { | ||
const [tabsList, setTabsList] = useState([]); | ||
const [selectedTab, setSelectedTab] = useState(0); | ||
const [showConfirm, setShowConfirm] = useState(false); | ||
const [url, setUrl] = useState(); | ||
|
||
const onTabClick = (id) => { | ||
if (currentTab !== id) { | ||
if (checkForChanges && checkForFormChanges()) { | ||
setUrl(`${path}${id}?uib-tab=${id}`); | ||
setShowConfirm(true); | ||
document.getElementById(id).parentElement.classList.add('bx--tabs--scrollable__nav-item--selected'); | ||
} else { | ||
window.location.replace(`${path}${id}?uib-tab=${id}`); | ||
} | ||
} | ||
}; | ||
|
||
const fixTabStyling = () => { | ||
const selectedTabs = []; | ||
document.getElementsByClassName('bx--tabs--scrollable__nav-item--selected').forEach((element) => { | ||
selectedTabs.push(element); | ||
}); | ||
selectedTabs.forEach((tab) => { | ||
tab.classList.remove('bx--tabs--scrollable__nav-item--selected'); | ||
}); | ||
document.getElementsByClassName('selected')[0].classList.add('bx--tabs--scrollable__nav-item--selected'); | ||
}; | ||
|
||
useEffect(() => { | ||
const tempTabs = []; | ||
tabs.forEach((tab, index) => { | ||
if (tab[0] === currentTab) { | ||
setSelectedTab(parseInt(index, 10)); | ||
} | ||
|
||
tempTabs.push( | ||
<Tab | ||
key={tab[0]} | ||
id={tab[0]} | ||
className={`${tab[0]}` === currentTab ? 'selected' : 'not-selected'} | ||
label={__(tab[1])} | ||
onClick={() => onTabClick(tab[0])} | ||
/> | ||
); | ||
}); | ||
setTabsList(tempTabs); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (showConfirm) { | ||
document.getElementsByClassName('selected')[0].classList.remove('bx--tabs--scrollable__nav-item--selected'); | ||
} else if (document.getElementsByClassName('selected').length > 0) { | ||
fixTabStyling(); | ||
} | ||
}, [showConfirm]); | ||
|
||
return ( | ||
<div> | ||
<Modal | ||
open={showConfirm} | ||
primaryButtonText={__('OK')} | ||
secondaryButtonText={__('Cancel')} | ||
onRequestClose={() => setShowConfirm(false)} | ||
onRequestSubmit={() => window.location.replace(url)} | ||
onSecondarySubmit={() => { | ||
setShowConfirm(false); | ||
fixTabStyling(); | ||
}} | ||
> | ||
{__('Abandon changes?')} | ||
</Modal> | ||
<Tabs selected={selectedTab}> | ||
{tabsList} | ||
</Tabs> | ||
</div> | ||
); | ||
}; | ||
|
||
CustomURLTabs.propTypes = { | ||
tabs: PropTypes.arrayOf(String).isRequired, | ||
path: PropTypes.string.isRequired, | ||
currentTab: PropTypes.string, | ||
checkForChanges: PropTypes.bool, | ||
}; | ||
|
||
CustomURLTabs.defaultProps = { | ||
currentTab: '0', | ||
checkForChanges: false, | ||
}; | ||
|
||
export default CustomURLTabs; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -632,6 +632,7 @@ | |
], | ||
:post => %w[ | ||
button | ||
change_tab | ||
filters_field_changed | ||
theme_changed | ||
timeprofile_delete | ||
|