Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga committed Jan 23, 2025
1 parent f0002f3 commit d0952ff
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 149 deletions.
34 changes: 15 additions & 19 deletions app/controllers/api/v2/template_invocations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ module Api
module V2
class TemplateInvocationsController < ::Api::V2::BaseController
include RemoteExecutionHelper
include JobInvocationsHelper

before_action :find_job_invocation, :only => %w{template_invocations}
before_action :find_job_invocation, :only => %w{template_invocations show_template_invocation_by_host}
before_action :find_host, :only => %w{show_template_invocation_by_host}

api :GET, '/job_invocations/:job_invocation_id/template_invocations',
N_('List template invocations belonging to job invocation')
Expand All @@ -24,18 +26,10 @@ def resource_scope
end
end

api :GET, '/hosts/:host_id/job_invocation/:job_invocation_id/show_template_invocation/'
api :GET, 'show_template_invocation_by_host/:host_id/job_invocation/:id'
param :host_id, :identifier, :required => true
param :job_invocation_id, :identifier, :required => true
param :id, :identifier, :required => true, :desc => N_('Job invocation id')
def show_template_invocation_by_host
@host = Host.find(params[:host_id])
@job_invocation = JobInvocation.find(params[:job_invocation_id])
if @host.nil?
render :json => { :error => _('Host not found') }, :status => :bad_request
end
if @job_invocation.nil?
render :json => { :error => _('Job invocation not found') }, :status => :bad_request
end
@template_invocation = @job_invocation.template_invocations.find { |template_inv| template_inv.host_id == @host.id }
@template = TemplateInvocation.find(@template_invocation.id)
if @template_invocation.nil? || @template.nil?
Expand All @@ -44,17 +38,13 @@ def show_template_invocation_by_host
@template_invocation_task = @template_invocation.run_host_job_task

lines = normalize_line_sets(@template_invocation_task.main_action.live_output)
input_values_with_template_input = @template_invocation.input_values.joins(:template_input).as_json(include: :template_input)
transformed_input_values = input_values_with_template_input.map do |input_value|
template_input = input_value['template_input']
value = template_input["hidden_value"] ? '*' * 5 : input_value["value"]
# input_values_with_template_input = @template_invocation.input_values.joins(:template_input).as_json(include: :template_input)
transformed_input_values = @template_invocation.input_values.joins(:template_input).map do |input_value|
{
name: input_value['template_input']['name'],
value: value,
name: input_value&.template_input&.name,
value: input_safe_value(input_value)
}
end
# :permission => :view_foreman_tasks
# :permission => :cancel_job_invocations
auto_refresh = @job_invocation.task.try(:pending?)
finished = @job_invocation.status_label == 'failed' || @job_invocation.status_label == 'succeeded' || @job_invocation.status_label == 'cancelled'
render :json => { :output => lines, :preview => template_invocation_preview(@template_invocation, @host), :input_values => transformed_input_values, :job_invocation_description => @job_invocation.description, :task_id => @template_invocation_task.id, :task_cancellable => @template_invocation_task.cancellable?, :host_name => @host.name, :permissions => {
Expand All @@ -68,6 +58,12 @@ def show_template_invocation_by_host

private

def find_host
@host = Host.find(params[:host_id])
rescue ActiveRecord::RecordNotFound
not_found({ :error => { :message => (_("Host with id '%{id}' was not found") % { :id => params['host_id'] }) } })
end

def template_invocation_preview(template_invocation, host)
if host.nil?
return {
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

resources :remote_execution_features, :only => [:show, :index, :update]

get 'show_template_invocation_by_host/:host_id/job_invocation/:job_invocation_id', to: 'template_invocations#show_template_invocation_by_host'
get 'show_template_invocation_by_host/:host_id/job_invocation/:id', to: 'template_invocations#show_template_invocation_by_host'
end
end
end
5 changes: 5 additions & 0 deletions webpack/JobInvocationDetail/JobInvocationConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ const Columns = () => {
},
weight: 5,
},
actions: {
title: '',
weight: 6,
wrapper: () => null,
},
};
};

Expand Down
4 changes: 4 additions & 0 deletions webpack/JobInvocationDetail/JobInvocationHostTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Columns, {
} from './JobInvocationConstants';
import { TemplateInvocation } from './TemplateInvocation';
import { OpenAlInvocations, PopupAlert } from './OpenAlInvocations';
import { RowActions } from './TemplateInvocationComponents/TemplateActionButtons';

const JobInvocationHostTable = ({ id, targeting, finished, autoRefresh }) => {
const columns = Columns();
Expand Down Expand Up @@ -222,6 +223,9 @@ const JobInvocationHostTable = ({ id, targeting, finished, autoRefresh }) => {
{columnNamesKeys.slice(1).map(k => (
<Td key={k}>{columns[k].wrapper(result)}</Td>
))}
<Td isActionCell>
<RowActions hostID={result.id} jobID={id} />
</Td>
</Tr>
<Tr
isExpanded={isHostExpanded(result.id)}
Expand Down
1 change: 1 addition & 0 deletions webpack/JobInvocationDetail/OpenAlInvocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const OpenAlInvocations = ({ results, id, setShowAlert }) => {
<Button
variant="link"
isInline
aria-label="open all template invocations in a new tab"
ouiaId="template-invocation-new-tab-button"
onClick={() => {
if (results.length <= 3) {
Expand Down
5 changes: 2 additions & 3 deletions webpack/JobInvocationDetail/TemplateInvocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ export const TemplateInvocation = ({
showTemplatePreview={showTemplatePreview}
showCommand={showCommand}
setShowCommand={setCommand}
newTabUrl={
isInTableView ? templateInvocationPageUrl(hostID, jobID) : null
}
newTabUrl={templateInvocationPageUrl(hostID, jobID)}
isInTableView={isInTableView}
copyToClipboard={
<CopyToClipboard
fullOutput={output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const OutputToggleGroup = ({
showCommand,
setShowCommand,
newTabUrl,
isInTableView,
copyToClipboard,
taskID,
jobID,
Expand Down Expand Up @@ -102,15 +103,17 @@ export const OutputToggleGroup = ({
)}
</ToggleGroup>
</FlexItem>
<TemplateActionButtons
taskID={taskID}
jobID={jobID}
hostID={hostID}
taskCancellable={taskCancellable}
permissions={permissions}
/>
{isInTableView ? null : (
<TemplateActionButtons
taskID={taskID}
jobID={jobID}
hostID={hostID}
taskCancellable={taskCancellable}
permissions={permissions}
/>
)}
<FlexItem>{copyToClipboard}</FlexItem>
{newTabUrl && (
{isInTableView && (
<FlexItem>
<Button
title={__('Open in new tab')}
Expand Down Expand Up @@ -142,10 +145,12 @@ OutputToggleGroup.propTypes = {
setShowCommand: PropTypes.func.isRequired,
newTabUrl: PropTypes.string,
copyToClipboard: PropTypes.node.isRequired,
isInTableView: PropTypes.bool,
...TemplateActionButtons.propTypes,
};

OutputToggleGroup.defaultProps = {
newTabUrl: null,
isInTableView: false,
...TemplateActionButtons.defaultProps,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { translate as __ } from 'foremanReact/common/I18n';

export const PreviewTemplate = ({ inputValues }) =>
inputValues.length ? (
<TableComposable ouiaId="template-invocation-preview-table" isStriped>
<TableComposable
ouiaId="template-invocation-preview-table"
isStriped
variant="compact"
>
<Thead>
<Tr ouiaId="template-invocation-preview-table-head">
<Th modifier="fitContent">{__('User input')}</Th>
Expand Down
Loading

0 comments on commit d0952ff

Please sign in to comment.