forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search feature for provisioning instance and virtual machines
- Loading branch information
Showing
6 changed files
with
127 additions
and
17 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
100 changes: 100 additions & 0 deletions
100
app/javascript/components/filter-provision-instance/index.jsx
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,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, | ||
}; |
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 |
---|---|---|
@@ -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); |