Skip to content

Commit

Permalink
Fixes #35287 - Create column selector on host index page
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoprda committed Jul 26, 2022
1 parent 04a93af commit 2b31e54
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/helpers/column_selector_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module ColumnSelectorHelper
def get_table_columns
User.current.table_preferences.find_by_name(auto_complete_controller_name).columns
end

def mount_column_selector
url = send("api_users_path") + "/#{User.current[:id]}/table_preferences/#{auto_complete_controller_name}"
react_component("ColumnSelector", data: {
url: url,
controller: auto_complete_controller_name,
columns: get_table_columns,
})
end
end
6 changes: 6 additions & 0 deletions app/views/layouts/_application_content.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<%= mount_search_bar if searchable? %>
<%= yield(:search_bar) %>&nbsp;
</div>
<% if controller_name == 'hosts' %>
<div class="title_select col-md-4">
<%= mount_column_selector %>
<%= yield(:column_selector) %>&nbsp;
</div>
<% end %>
<div id="title_action" class= <%= searchable? ? "col-md-6" : "col-md-8" %>>
<div class="btn-toolbar pull-right">
<%=h yield(:title_actions) %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { useState } from 'react';
import { PropTypes } from 'prop-types';
import { Select, SelectOption, SelectVariant } from '@patternfly/react-core';

const ColumnSelector = props => {
const {
data: { url, controller, columns },
} = props;
const [isOpen, setIsOpen] = useState(false);
return (
<div className="pf-c-select">
<div className="pf-c-select-group">
<Select
variant={SelectVariant.checkbox}
aria-label="Select Input"
onToggle={setIsOpen}
isOpen={isOpen}
placeholderText="Filter columns"
controller={controller}
url={url}
>
<SelectOption key={columns.name} value="Name" />,
<SelectOption key={columns.os_title} value="Operating system" />,
<SelectOption key={columns.model} value="Model" />,
<SelectOption key={columns.owner} value="Owner" />,
<SelectOption key={columns.hostgroup} value="Host group" />,
<SelectOption key={columns.last_report} value="Last report" />,
<SelectOption key={columns.comment} value="Comment" />
</Select>
</div>
</div>
);
};

ColumnSelector.propTypes = {
data: PropTypes.shape({
controller: PropTypes.string,
url: PropTypes.string,
columns: PropTypes.arrayOf(PropTypes.string),
})
};

ColumnSelector.defaultProps = {
data: {
controller: null,
url: null,
columns: [],
}
};

export default ColumnSelector;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ColumnSelector from './ColumnSelector';
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import FactChart from './FactCharts';
import Pagination from './Pagination';
import AutoComplete from './AutoComplete';
import SearchBar from './SearchBar';
import ColumnSelector from './ColumnSelector';
import Layout from './Layout';
import EmptyState from './common/EmptyState';
import ComponentWrapper from './common/ComponentWrapper/ComponentWrapper';
Expand Down Expand Up @@ -118,6 +119,7 @@ const componentRegistry = {
const coreComponets = [
{ name: 'ReactApp', type: ReactApp },
{ name: 'SearchBar', type: SearchBar },
{ name: 'ColumnSelector', type: ColumnSelector },
{ name: 'AutoComplete', type: AutoComplete },
{ name: 'AreaChart', type: AreaChart },
{ name: 'DonutChart', type: DonutChart },
Expand Down

0 comments on commit 2b31e54

Please sign in to comment.