-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
listing, removing the methods and refactorign the code
- Loading branch information
Showing
7 changed files
with
299 additions
and
131 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
49 changes: 49 additions & 0 deletions
49
app/javascript/components/AeInlineMethod/FilterNamespace.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,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { TextInput, Select, SelectItem } from 'carbon-components-react'; | ||
import { noSelect } from './helper'; | ||
|
||
const FilterNamespace = ({ domains, filterOnChange }) => { | ||
/** Function to render the search text. */ | ||
const renderSearchText = () => ( | ||
<TextInput | ||
id="search-method" | ||
labelText={__('Search')} | ||
placeholder={__('Search with Name or Relative path')} | ||
onChange={(event) => filterOnChange({ text: event.target.value || noSelect })} | ||
/> | ||
); | ||
|
||
/** Function to render the domain items in a drop-down list. */ | ||
const renderDomainList = () => ( | ||
<Select | ||
id="domain_id" | ||
labelText="Select a domain" | ||
defaultValue="option" | ||
onChange={(event) => filterOnChange({ selectedDomain: event.target.value })} | ||
> | ||
<SelectItem value={noSelect} text="None" /> | ||
{ | ||
domains.map((domain) => <SelectItem key={domain.id} value={domain.id} text={domain.name} />) | ||
} | ||
</Select> | ||
); | ||
|
||
return ( | ||
<div className="inline-filters"> | ||
{renderSearchText()} | ||
{domains && renderDomainList()} | ||
</div> | ||
); | ||
}; | ||
|
||
export default FilterNamespace; | ||
|
||
FilterNamespace.propTypes = { | ||
domains: PropTypes.arrayOf(PropTypes.any), | ||
filterOnChange: PropTypes.func.isRequired, | ||
}; | ||
|
||
FilterNamespace.defaultProps = { | ||
domains: undefined, | ||
}; |
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,59 @@ | ||
export const namespaceUrls = { | ||
aeMethodsUrl: '/miq_ae_class/ae_methods', | ||
aeDomainsUrl: '/miq_ae_class/ae_domains', | ||
}; | ||
|
||
export const noSelect = 'NONE'; | ||
|
||
/** Headers needed for the data-table list. */ | ||
export const methodSelectorHeaders = [ | ||
{ | ||
key: 'name', | ||
header: 'Name', | ||
}, | ||
{ | ||
key: 'path', | ||
header: 'Relative path', | ||
}, | ||
]; | ||
|
||
export const methodListHeaders = [ | ||
...methodSelectorHeaders, | ||
{ key: 'delete', header: __('Delete') }, | ||
]; | ||
|
||
/** Function to format the method data needed for the data-table list. */ | ||
export const formatMethods = (methods) => (methods.map((item) => ({ | ||
id: item.id.toString(), | ||
name: { text: item.name, icon: 'icon node-icon fa-ruby' }, | ||
path: item.relative_path, | ||
}))); | ||
|
||
const deleteMethodButton = () => ({ | ||
is_button: true, | ||
title: __('Delete'), | ||
text: __('Delete'), | ||
alt: __('Delete'), | ||
kind: 'ghost', | ||
callback: 'removeMethod', | ||
}); | ||
|
||
export const formatListMethods = (methods) => (methods.map((item, index) => ({ | ||
id: item.id.toString(), | ||
name: { text: item.name, icon: 'icon node-icon fa-ruby' }, | ||
path: item.relative_path, | ||
delete: deleteMethodButton(item, index), | ||
}))); | ||
|
||
/** Function to return a conditional URL based on the selected filters. */ | ||
export const searchUrl = (selectedDomain, text) => { | ||
const queryParams = []; | ||
if (selectedDomain && selectedDomain !== noSelect) { | ||
queryParams.push(`domain_id=${selectedDomain}`); | ||
} | ||
if (text && text !== noSelect) { | ||
queryParams.push(`search=${text}`); | ||
} | ||
const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : ''; | ||
return `${namespaceUrls.aeMethodsUrl}${queryString}`; | ||
}; |
Oops, something went wrong.