-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #35287 - Create column selector on host index page
- Loading branch information
Showing
7 changed files
with
136 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ColumnSelectorHelper | ||
def get_selected_columns | ||
User.current.table_preferences.find_by_name(auto_complete_controller_name)&.columns || [] | ||
end | ||
|
||
def mount_column_selector | ||
url = "#{api_users_path}/#{User.current[:id]}/table_preferences/#{auto_complete_controller_name}" | ||
react_component("ColumnSelector", data: { | ||
url: url, | ||
controller: auto_complete_controller_name, | ||
selected: get_selected_columns, | ||
columns: ["Power", "Name", "Operating system", "Model", "Owner", "Host group", "Last report", "Comment"], | ||
}) | ||
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
91 changes: 91 additions & 0 deletions
91
webpack/assets/javascripts/react_app/components/ColumnSelector/ColumnSelector.js
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,91 @@ | ||
import React, { useState } from 'react'; | ||
import { isEqual } from 'lodash'; | ||
import { PropTypes } from 'prop-types'; | ||
import { | ||
Button, | ||
Select, | ||
SelectOption, | ||
SelectVariant, | ||
} from '@patternfly/react-core'; | ||
import { translate as __ } from '../../common/I18n'; | ||
import './column-selector.scss'; | ||
|
||
const ColumnSelector = props => { | ||
const { | ||
data: { url, controller, selected, columns }, | ||
} = props; | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
const [selectedColumns, setSelectedColumns] = useState(selected); | ||
|
||
const onToggle = isExpanded => { | ||
setIsOpen(isExpanded); | ||
}; | ||
|
||
const onSelect = (event, selection) => { | ||
if (selectedColumns.find(i => i === selection)) { | ||
setSelectedColumns(selectedColumns.filter(e => e !== selection)); | ||
} else { | ||
setSelectedColumns([...selectedColumns, selection]); | ||
} | ||
}; | ||
|
||
const onChange = event => { | ||
const allColumns = new Set(columns).add(__('Select All')); | ||
if (isEqual([...allColumns], selectedColumns)) { | ||
setSelectedColumns([]); | ||
} else { | ||
setSelectedColumns([...allColumns]); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="pf-c-select-input"> | ||
<div className="column-selector pf-c-input-group" id="column-selector"> | ||
<Select | ||
variant={SelectVariant.checkbox} | ||
onToggle={onToggle} | ||
isOpen={isOpen} | ||
onSelect={onSelect} | ||
isCheckboxSelectionBadgeHidden | ||
selections={selectedColumns} | ||
placeholderText={__('Filter Columns')} | ||
controller={controller} | ||
url={url} | ||
> | ||
<SelectOption onChange={onChange} value={__('Select All')} /> | ||
{columns.map((option, index) => ( | ||
<SelectOption key={index} value={option} /> | ||
))} | ||
</Select> | ||
<Button | ||
id="btn-filter" | ||
variant="secondary" | ||
className="pull-right" | ||
> | ||
{__('Filter')} | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
ColumnSelector.propTypes = { | ||
data: PropTypes.shape({ | ||
controller: PropTypes.string, | ||
url: PropTypes.string, | ||
selected: PropTypes.arrayOf(PropTypes.string), | ||
columns: PropTypes.arrayOf(PropTypes.string), | ||
}), | ||
}; | ||
|
||
ColumnSelector.defaultProps = { | ||
data: { | ||
controller: null, | ||
url: null, | ||
selected: [], | ||
columns: [], | ||
}, | ||
}; | ||
|
||
export default ColumnSelector; |
13 changes: 13 additions & 0 deletions
13
webpack/assets/javascripts/react_app/components/ColumnSelector/column-selector.scss
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,13 @@ | ||
.column-selector { | ||
width: 100%; | ||
|
||
label { | ||
font-size: 16px; | ||
height: 36px; | ||
border-bottom-color: var(--pf-global--BorderColor--200); | ||
border-top-color: var(--pf-global--BorderColor--300); | ||
border-left-color: var(--pf-global--BorderColor--300); | ||
border-left-width: 0.7px; | ||
border-top-width: 0; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
webpack/assets/javascripts/react_app/components/ColumnSelector/index.js
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,3 @@ | ||
import ColumnSelector from './ColumnSelector'; | ||
|
||
export default ColumnSelector; |
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