Skip to content

Commit

Permalink
Search feature for provisioning instance and virtual machines
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffibm committed Apr 18, 2024
1 parent cdfcfc5 commit 0024a7d
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def pre_prov
end
elsif params[:hide_deprecated_templates]
@edit = session[:edit]
@edit[:hide_deprecated_templates] = params[:hide_deprecated_templates] == "true"
@edit[:hide_deprecated_templates] = provisioning_is_cloud? ? params[:hide_deprecated_templates] == "true" : nil
render_updated_templates
else # First time in, build pre-provision screen
set_pre_prov_vars
Expand All @@ -159,6 +159,7 @@ def pre_prov

def render_updated_templates
report_scopes = [:eligible_for_provisioning]
report_scopes.push([:filter_with_name, params[:search_text]])
report_scopes.push(:non_deprecated) if @edit[:hide_deprecated_templates]
options = options_for_provisioning(get_template_kls.to_s, report_scopes)

Expand Down
100 changes: 100 additions & 0 deletions app/javascript/components/filter-provision-instance/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Search32, Close32 } from '@carbon/icons-react';
import { Button, Checkbox, TextInput } from 'carbon-components-react';

/** Component to filter the images at provisioning instances page. */
const FilterProvisionInstance = ({
hideDeprecated, searchText, url, showCheckbox,
}) => {
const [data, setData] = useState({
loading: false,
searchText,
hideDeprecated,
});

useEffect(() => {
if (data.loading) {
$.post(`${url}?search_text=${encodeURIComponent(data.searchText)}&hide_deprecated_templates=${data.hideDeprecated}`);
}
}, [data.loading]);

/** Function to handle the clear button's click event of the search bar. */
const onClear = () => {
const updatedData = searchText ? { loading: true } : {};
setData({ ...data, searchText: '', ...updatedData });
};

/** Function to render the Clear button. */
const renderClear = () => (
<Button
kind="secondary"
disabled={data.loading}
renderIcon={Close32}
iconDescription={__('Clear')}
hasIconOnly
tooltipPosition="bottom"
type="reset"
onClick={onClear}
/>
);

/** Function to render the Lens button. */
const renderLens = () => (
<Button
renderIcon={Search32}
disabled={data.loading}
iconDescription={__('Search')}
hasIconOnly
tooltipPosition="bottom"
className="search_button"
onClick={() => setData({ ...data, loading: true })}
/>
);

return (
<div className="miq-filter-provision-instance">
<div className="col-md-7 checkbox_wrapper">
{
showCheckbox && (
<Checkbox
id="hide_deprecated"
labelText="Hide Deprecated"
disabled={data.loading}
checked={data.hideDeprecated}
onChange={() => setData({ ...data, loading: true, hideDeprecated: !data.hideDeprecated })}
/>
)
}
</div>
<div className="col-md-5 search_bar_wrapper">
<div className="search_bar">
<TextInput
hideLabel
value={data.searchText}
placeholder={__('Search with name')}
labelText={__('Search')}
id="filter_with_name"
disabled={data.loading}
onChange={(event) => setData({ ...data, searchText: event.target.value })}
/>
{ data.searchText && renderClear() }
{ renderLens() }
</div>
</div>
</div>
);
};

export default FilterProvisionInstance;

FilterProvisionInstance.propTypes = {
hideDeprecated: PropTypes.bool,
searchText: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
showCheckbox: PropTypes.bool.isRequired,
};

FilterProvisionInstance.defaultProps = {
hideDeprecated: false,
};
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 @@ -49,6 +49,7 @@ import EditServiceForm from '../components/edit-service-form';
import EvacuateForm from '../components/evacuate-form';
import EventChart from '../components/provider-dashboard-charts/events-bar-chart';
import FilterDropdown from '../components/filter-dropdown';
import FilterProvisionInstance from '../components/filter-provision-instance';
import FirmwareRegistryForm from '../components/firmware-registry/firmware-registry-form';
import FlavorForm from '../components/flavor-form';
import FonticonPicker from '../components/fonticon-picker';
Expand Down Expand Up @@ -219,6 +220,7 @@ ManageIQ.component.addReact('EditServiceForm', EditServiceForm);
ManageIQ.component.addReact('EvacuateForm', EvacuateForm);
ManageIQ.component.addReact('EventChart', EventChart);
ManageIQ.component.addReact('FilterDropdown', FilterDropdown);
ManageIQ.component.addReact('FilterProvisionInstance', FilterProvisionInstance);
ManageIQ.component.addReact('FirmwareRegistryForm', FirmwareRegistryForm);
ManageIQ.component.addReact('FlavorForm', FlavorForm);
ManageIQ.component.addReact('FonticonPicker', FonticonPicker);
Expand Down
2 changes: 1 addition & 1 deletion app/stylesheet/miq-data-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
flex-direction: column;

.provision-instance-list {
height: calc(100vh - 210px);
height: calc(100vh - 255px);
overflow: auto;
}
.provision-instance-actions {
Expand Down
13 changes: 13 additions & 0 deletions app/stylesheet/search-bar.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
.miq-filter-provision-instance {
display: flex;
align-items: center;

.checkbox_wrapper {
padding-left: 0;
}

.search_bar_wrapper {
padding-right: 0;
}
}

.search_bar {
display: flex;

Expand Down
24 changes: 9 additions & 15 deletions app/views/miq_request/_pre_prov.html.haml
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
#pre_prov_div
- typ = request.parameters[:controller] == "vm_cloud" ? ui_lookup(:table => "template_cloud") : ui_lookup(:table => "template_infra")
:ruby
typ = request.parameters[:controller] == "vm_cloud" ? ui_lookup(:table => "template_cloud") : ui_lookup(:table => "template_infra")
show_checkbox = !@edit[:hide_deprecated_templates].nil?
id = @edit[:req_id] || "new"
hide_deprecated_url = url_for_only_path(:action => "vm_pre_prov", :template_klass => params[:template_klass], :id => id.to_s)

%h3
= _("Provision %{what} based on the selected %{type}") % {:what => ui_lookup(:tables => request.parameters[:controller]), :type => typ}
%label
- id = @edit[:req_id] || "new"
- unless @edit[:hide_deprecated_templates].nil?
- hide_depricated_url = url_for_only_path({:action => "vm_pre_prov",
:template_klass => params[:template_klass],
:id => id.to_s,
:hide_deprecated_templates => !@edit[:hide_deprecated_templates]})
%input{:type => "checkbox",
:onclick => "miqAjax('#{hide_depricated_url}')",
:checked => @edit[:hide_deprecated_templates]}
= _('Hide deprecated')

= react('FilterProvisionInstance', {:hideDeprecated => @edit[:hide_deprecated_templates], :searchText => params[:search_text] || '', :url => hide_deprecated_url, :showCheckbox => show_checkbox})

.provision-instance-container
.provision-instance-list
= render :partial => "layouts/x_gtl"

.provision-instance-actions
#pre_prov_form_buttons_div.pull-right
= render :partial => 'layouts/x_edit_buttons', :locals => {:action_url => 'pre_prov',
:continue_button => true,
:no_reset => true}
= render :partial => 'layouts/x_edit_buttons', :locals => {:action_url => 'pre_prov', :continue_button => true, :no_reset => true}
:javascript
$(provisioningListenToRx);

0 comments on commit 0024a7d

Please sign in to comment.