-
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…
… detail page
- Loading branch information
kmalyjur
committed
Jul 4, 2024
1 parent
356605f
commit a86724a
Showing
12 changed files
with
250 additions
and
14 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
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,132 @@ | ||
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 JobStatusIcon from '../react_app/components/RecentJobsCard/JobStatusIcon'; | ||
import { | ||
columns, | ||
JOB_INVOCATION_HOSTS, | ||
STATUS, | ||
} from './JobInvocationConstants'; | ||
|
||
const JobInvocationHostTable = ({ data }) => { | ||
const { id, task } = data; | ||
const columnNamesKeys = Object.keys(columns); | ||
const apiOptions = { key: JOB_INVOCATION_HOSTS, search: urlSearchQuery }; | ||
const { | ||
searchParam: 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 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: task?.state, | ||
setAPIOptions, | ||
}; | ||
|
||
const { setParamsAndAPI, params } = useSetParamsAndApiAndSearch({ | ||
defaultParams, | ||
apiOptions, | ||
setAPIOptions, | ||
}); | ||
|
||
const { updateSearchQuery } = useBulkSelect({ | ||
results: response?.results || [], | ||
metadata: { | ||
total: response?.total || 0, | ||
page: response?.page, | ||
selectable: response?.subtotal || 0, | ||
}, | ||
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={() => {}} | ||
errorMessage={ | ||
status === STATUS.ERROR && response?.message ? response.message : null | ||
} | ||
isPending={task?.state === STATUS.PENDING} | ||
isDeleteable={false} | ||
> | ||
{response?.results?.map((result, rowIndex) => ( | ||
<Tr key={rowIndex} ouiaId={`table-row-${rowIndex}`}> | ||
{columnNamesKeys.map(k => ( | ||
<Td key={k}> | ||
{k === 'status' ? ( | ||
<JobStatusIcon status={columns[k].status(result.job_status)}> | ||
{columns[k].tableTitle(result.job_status)} | ||
</JobStatusIcon> | ||
) : ( | ||
columns[k].wrapper(result) | ||
)} | ||
</Td> | ||
))} | ||
</Tr> | ||
))} | ||
</Table> | ||
</TableIndexPage> | ||
); | ||
}; | ||
|
||
JobInvocationHostTable.propTypes = { | ||
data: PropTypes.object.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; |
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
6 changes: 1 addition & 5 deletions
6
webpack/__mocks__/foremanReact/components/HostDetails/DetailsCard/DefaultLoaderEmptyState.js
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,8 +1,4 @@ | ||
import React from 'react'; | ||
import { translate as __ } from '../../../common/I18n'; | ||
|
||
const DefaultLoaderEmptyState = () => ( | ||
<span className="disabled-text">{__('Not available')}</span> | ||
); | ||
|
||
const DefaultLoaderEmptyState = () => <div />; | ||
export default DefaultLoaderEmptyState; |