-
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 #37630 - Display basic list of hosts on the new job_invocations…
… page
- Loading branch information
kmalyjur
committed
Sep 11, 2024
1 parent
f237a8c
commit e4d6454
Showing
14 changed files
with
333 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,126 @@ | ||
/* eslint-disable camelcase */ | ||
import PropTypes from 'prop-types'; | ||
import React, { useMemo } from 'react'; | ||
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 }) => { | ||
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` | ||
); | ||
|
||
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={() => {}} | ||
emptyMessage={ | ||
status === STATUS_UPPERCASE.RESOLVED && | ||
(response?.results?.length === 0 || | ||
response?.results?.length === undefined) | ||
? 'No hosts found' | ||
: null | ||
} | ||
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, | ||
}; | ||
|
||
JobInvocationHostTable.defaultProps = {}; | ||
|
||
export default JobInvocationHostTable; |
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,10 +1,10 @@ | ||
import { selectAPIResponse } from 'foremanReact/redux/API/APISelectors'; | ||
import { JOB_INVOCATION_KEY } from './JobInvocationConstants'; | ||
import { JOB_INVOCATION_KEY, GET_TASK } from './JobInvocationConstants'; | ||
|
||
export const selectItems = state => | ||
selectAPIResponse(state, JOB_INVOCATION_KEY); | ||
|
||
export const selectTask = state => selectAPIResponse(state, 'GET_TASK'); | ||
export const selectTask = state => selectAPIResponse(state, GET_TASK); | ||
|
||
export const selectTaskCancelable = state => | ||
selectTask(state).available_actions?.cancellable || false; |
Oops, something went wrong.