-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37836 - Add possibility to display action when table is empty
- Loading branch information
kmalyjur
committed
Sep 18, 2024
1 parent
ca7cca1
commit b900ea7
Showing
14 changed files
with
356 additions
and
24 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 @@ | ||
collection @hosts | ||
|
||
attribute :name, :operatingsystem_id, :operatingsystem_name, :hostgroup_id, :hostgroup_name | ||
|
||
node :job_status do |host| | ||
@host_statuses[host.id] | ||
end | ||
|
||
node :smart_proxy_id do |host| | ||
@smart_proxy_id[host.id] | ||
end | ||
|
||
node :smart_proxy_name do |host| | ||
@smart_proxy_name[host.id] | ||
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
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 |
---|---|---|
|
@@ -38,4 +38,8 @@ | |
height: $chart_size; | ||
} | ||
} | ||
|
||
.job-invocation-host-table-page-section { | ||
padding-top: 0px; | ||
} | ||
|
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,146 @@ | ||
/* eslint-disable camelcase */ | ||
import PropTypes from 'prop-types'; | ||
import React, { useMemo } from 'react'; | ||
import { translate as __, sprintf } from 'foremanReact/common/I18n'; | ||
import { Tr, Td } from '@patternfly/react-table'; | ||
import { foremanUrl } from 'foremanReact/common/helpers'; | ||
import { useAPI } from 'foremanReact/common/hooks/API/APIHooks'; | ||
import { Table } from 'foremanReact/components/PF4/TableIndexPage/Table/Table'; | ||
import TableIndexPage from 'foremanReact/components/PF4/TableIndexPage/TableIndexPage'; | ||
import { useSetParamsAndApiAndSearch } from 'foremanReact/components/PF4/TableIndexPage/Table/TableIndexHooks'; | ||
import { | ||
useBulkSelect, | ||
useUrlParams, | ||
} from 'foremanReact/components/PF4/TableIndexPage/Table/TableHooks'; | ||
import { getControllerSearchProps } from 'foremanReact/constants'; | ||
import Columns, { | ||
JOB_INVOCATION_HOSTS, | ||
STATUS_UPPERCASE, | ||
} from './JobInvocationConstants'; | ||
|
||
const JobInvocationHostTable = ({ id, targeting }) => { | ||
const columns = Columns(); | ||
const columnNamesKeys = Object.keys(columns); | ||
const apiOptions = { key: JOB_INVOCATION_HOSTS, search: urlSearchQuery }; | ||
const { | ||
search: urlSearchQuery = '', | ||
page: urlPage, | ||
per_page: urlPerPage, | ||
} = useUrlParams(); | ||
const defaultParams = { search: urlSearchQuery }; | ||
if (urlPage) defaultParams.page = Number(urlPage); | ||
if (urlPerPage) defaultParams.per_page = Number(urlPerPage); | ||
const { response, status, setAPIOptions } = useAPI( | ||
'get', | ||
`/api/job_invocations/${id}/hosts`, | ||
{ | ||
params: { ...defaultParams, key: JOB_INVOCATION_HOSTS }, | ||
} | ||
); | ||
|
||
const { setParamsAndAPI, params } = useSetParamsAndApiAndSearch({ | ||
defaultParams, | ||
apiOptions, | ||
setAPIOptions, | ||
}); | ||
|
||
const combinedResponse = { | ||
response: { | ||
search: '', | ||
can_create: false, | ||
results: response?.results || [], | ||
total: response?.total || 0, | ||
per_page: response?.perPage, | ||
page: response?.page, | ||
subtotal: response?.subtotal || 0, | ||
message: response?.message || 'error', | ||
}, | ||
status, | ||
setAPIOptions, | ||
}; | ||
|
||
const { updateSearchQuery } = useBulkSelect({ | ||
initialSearchQuery: urlSearchQuery, | ||
}); | ||
|
||
const controller = 'hosts'; | ||
const memoDefaultSearchProps = useMemo( | ||
() => getControllerSearchProps(controller), | ||
[controller] | ||
); | ||
memoDefaultSearchProps.autocomplete.url = foremanUrl( | ||
`/${controller}/auto_complete_search` | ||
); | ||
|
||
const action = { | ||
title: 'View hosts', | ||
url: `/new/hosts?search=${targeting?.search_query}`, | ||
}; | ||
|
||
const getEmptyMessage = () => { | ||
if ( | ||
status === STATUS_UPPERCASE.RESOLVED && | ||
(response?.results?.length === 0 || | ||
response?.results?.length === undefined) | ||
) { | ||
if (targeting?.targeting_type === 'dynamic_query') { | ||
return sprintf( | ||
__( | ||
'The dynamic query is still being processed. You can view the hosts targeted by the query.' | ||
) | ||
); | ||
} | ||
return __('No hosts found'); | ||
} | ||
return null; | ||
}; | ||
|
||
return ( | ||
<TableIndexPage | ||
apiUrl="" | ||
apiOptions={apiOptions} | ||
customSearchProps={memoDefaultSearchProps} | ||
controller="hosts" | ||
creatable={false} | ||
replacementResponse={combinedResponse} | ||
updateSearchQuery={updateSearchQuery} | ||
> | ||
<Table | ||
ouiaId="job-invocation-hosts-table" | ||
columns={columns} | ||
params={params} | ||
setParams={setParamsAndAPI} | ||
itemCount={response?.subtotal} | ||
results={response?.results} | ||
url="" | ||
refreshData={() => {}} | ||
emptyAction={action} | ||
emptyMessage={getEmptyMessage()} | ||
errorMessage={ | ||
status === STATUS_UPPERCASE.ERROR && response?.message | ||
? response.message | ||
: null | ||
} | ||
isPending={status === STATUS_UPPERCASE.PENDING} | ||
isDeleteable={false} | ||
> | ||
{response?.results?.map((result, rowIndex) => ( | ||
<Tr key={rowIndex} ouiaId={`table-row-${rowIndex}`}> | ||
{columnNamesKeys.map(k => ( | ||
<Td key={k}>{columns[k].wrapper(result)}</Td> | ||
))} | ||
</Tr> | ||
))} | ||
</Table> | ||
</TableIndexPage> | ||
); | ||
}; | ||
|
||
JobInvocationHostTable.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
targeting: PropTypes.object.isRequired, | ||
}; | ||
|
||
JobInvocationHostTable.defaultProps = {}; | ||
|
||
export default JobInvocationHostTable; |
Oops, something went wrong.