Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix outputFormats in model conversion #127

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/job-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ function RefillButton(props: {
props.job.runtime_environment_name
);
if (jobOutputFormats && outputFormats) {
newModel.outputFormats = outputFormats.filter(of =>
jobOutputFormats.some(jof => of.name === jof)
);
newModel.outputFormats = outputFormats
.filter(of => jobOutputFormats.some(jof => of.name === jof))
.map(of => of.name);
}

// Switch the view to the form.
Expand Down
4 changes: 2 additions & 2 deletions src/components/output-format-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type OutputFormatPickerProps = {
environment: string;
environmentList: Scheduler.IRuntimeEnvironment[];
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
value: IOutputFormat[];
value: string[];
};

export function outputFormatsForEnvironment(
Expand Down Expand Up @@ -51,7 +51,7 @@ export function OutputFormatPicker(
key={idx}
control={
<Checkbox
defaultChecked={props.value.some(sof => of.name === sof.name)}
defaultChecked={props.value.some(sof => of.name === sof)}
id={`${props.id}-${of.name}`}
value={of.name}
onChange={props.onChange}
Expand Down
30 changes: 7 additions & 23 deletions src/mainviews/create-job.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import {
import { ParametersPicker } from '../components/parameters-picker';
import { Scheduler, SchedulerService } from '../handler';
import { useTranslator } from '../hooks';
import {
ICreateJobModel,
IJobParameter,
IOutputFormat,
ListJobsView
} from '../model';
import { ICreateJobModel, IJobParameter, ListJobsView } from '../model';
import { Scheduler as SchedulerTokens } from '../tokens';

import Button from '@mui/material/Button';
Expand Down Expand Up @@ -168,10 +163,10 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
const isChecked = event.target.checked;

const wasChecked: boolean = props.model.outputFormats
? props.model.outputFormats.some(of => of.name === formatName)
? props.model.outputFormats.some(of => of === formatName)
: false;

const oldOutputFormats: IOutputFormat[] = props.model.outputFormats || [];
const oldOutputFormats: string[] = props.model.outputFormats || [];

// Go from unchecked to checked
if (isChecked && !wasChecked) {
Expand All @@ -180,15 +175,15 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
if (newFormat) {
props.handleModelChange({
...props.model,
outputFormats: [...oldOutputFormats, newFormat]
outputFormats: [...oldOutputFormats, newFormat.name]
});
}
}
// Go from checked to unchecked
else if (!isChecked && wasChecked) {
props.handleModelChange({
...props.model,
outputFormats: oldOutputFormats.filter(of => of.name !== formatName)
outputFormats: oldOutputFormats.filter(of => of !== formatName)
});
}

Expand Down Expand Up @@ -561,6 +556,7 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
input_uri: props.model.inputFile,
output_prefix: props.model.outputPath,
runtime_environment_name: props.model.environment,
output_formats: props.model.outputFormats,
compute_type: props.model.computeType,
idempotency_token: props.model.idempotencyToken,
tags: props.model.tags,
Expand All @@ -571,12 +567,6 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
jobOptions.parameters = serializeParameters(props.model.parameters);
}

if (props.model.outputFormats !== undefined) {
jobOptions.output_formats = props.model.outputFormats.map(
entry => entry.name
);
}

api.createJob(jobOptions).then(response => {
// Switch to the list view with "Job List" active
props.showListView('Job');
Expand All @@ -597,7 +587,7 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
output_prefix: props.model.outputPath,
runtime_environment_name: props.model.environment,
compute_type: props.model.computeType,
// idempotency_token is in the form, but not in Scheduler.ICreateJobDefinition
output_formats: props.model.outputFormats,
tags: props.model.tags,
runtime_environment_parameters: props.model.runtimeEnvironmentParameters,
schedule: props.model.schedule,
Expand All @@ -610,12 +600,6 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
);
}

if (props.model.outputFormats !== undefined) {
jobDefinitionOptions.output_formats = props.model.outputFormats.map(
entry => entry.name
);
}

api.createJobDefinition(jobDefinitionOptions).then(response => {
// Switch to the list view with "Job Definition List" active
props.showListView('JobDefinition');
Expand Down
1 change: 1 addition & 0 deletions src/mainviews/detail-view/job-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function JobDetail(props: IJobDetailProps): JSX.Element {
outputPath: props.model.outputPrefix ?? '',
environment: props.model.environment,
parameters: props.model.parameters,
outputFormats: props.model.outputFormats,
createType: 'Job',
scheduleInterval: 'weekday',
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
Expand Down
9 changes: 4 additions & 5 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export interface ICreateJobModel {
createType: 'Job' | 'JobDefinition';
runtimeEnvironmentParameters?: { [key: string]: number | string };
parameters?: IJobParameter[];
outputFormats?: IOutputFormat[];
// List of values for output formats; labels are specified by the environment
outputFormats?: string[];
computeType?: string;
idempotencyToken?: string;
tags?: string[];
Expand Down Expand Up @@ -151,7 +152,6 @@ export function convertDescribeJobtoJobDetail(
}
);

// TODO: Convert outputFormats
return {
createType: 'Job',
jobId: dj.job_id,
Expand All @@ -162,7 +162,7 @@ export function convertDescribeJobtoJobDetail(
environment: dj.runtime_environment_name,
runtimeEnvironmentParameters: dj.runtime_environment_parameters,
parameters: jdParameters,
outputFormats: [],
outputFormats: dj.output_formats,
computeType: dj.compute_type,
idempotencyToken: dj.idempotency_token,
tags: dj.tags,
Expand All @@ -188,7 +188,6 @@ export function convertDescribeDefinitiontoDefinition(
}
);

// TODO: Convert outputFormats
return {
name: dj.name ?? '',
jobName: '',
Expand All @@ -200,7 +199,7 @@ export function convertDescribeDefinitiontoDefinition(
environment: dj.runtime_environment_name,
runtimeEnvironmentParameters: dj.runtime_environment_parameters,
parameters: jdParameters,
outputFormats: [],
outputFormats: dj.output_formats,
computeType: dj.compute_type,
tags: dj.tags,
active: dj.active ? 'IN_PROGRESS' : 'STOPPED',
Expand Down