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

Component - Allow undefined values for integers and numbers if input not required #103

Merged

Conversation

jasoncomes
Copy link
Contributor

If you have a non-required number/integer input, the generator currently will clean that to a number which results in 0 if the input is left empty.

Allow for numbers and integers to return undefined if the input is not required.

Before:

const projectApiV3ProjectsProcessingOptionsUpdate = action({
  display: {
    label: "Project Api V 3 Projects Processing Options Update",
    description: "Update the project processing options",
  },
  perform: async (
    context,
    {
      connection,
      id,
      customTemplateS3Key,
      customTemplateS3Bucket,
      standardTemplate,
      tags,
      outputCsHorizontal,
      outputCsVertical,
      outputCsGeoid,
      outputCsGeoidHeight,
      outputs,
    },
  ) => {
    const client = createClient(connection);
    const { data } = await client.put(
      `/project/api/v3/projects/${id}/processing_options/`,
      {
        custom_template_s3_key: customTemplateS3Key,
        custom_template_s3_bucket: customTemplateS3Bucket,
        standard_template: standardTemplate,
        tags,
        output_cs_horizontal: outputCsHorizontal,
        output_cs_vertical: outputCsVertical,
        output_cs_geoid: outputCsGeoid,
        output_cs_geoid_height: outputCsGeoidHeight,
        outputs,
      },
    );
    return { data };
  },
  inputs: {
    connection: input({
      label: "Connection",
      type: "connection",
      required: true,
    }),
    id: input({
      label: "Id",
      type: "string",
      required: true,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
    }),
    customTemplateS3Key: input({
      label: "Custom Template S 3 Key",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
      comments: "The S3 key for a valid pix4dmapper template ",
    }),
    customTemplateS3Bucket: input({
      label: "Custom Template S 3 Bucket",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
      comments: "The S3 bucket for a valid pix4dmapper template ",
    }),
    standardTemplate: input({
      label: "Standard Template",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
    }),
    tags: input({
      label: "Tags",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
      comments: "Project data classifications tags",
    }),
    outputCsHorizontal: input({
      label: "Output Cs Horizontal",
      type: "string",
      required: false,
      clean: (value): number => util.types.toNumber(value),
      comments: "EPSG code of the desired output horizontal coordinate system",
    }),
    outputCsVertical: input({
      label: "Output Cs Vertical",
      type: "string",
      required: false,
      clean: (value): number => util.types.toNumber(value),
      comments: "EPSG code of the desired output vertical coordinate system",
    }),
    outputCsGeoid: input({
      label: "Output Cs Geoid",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
    }),
    outputCsGeoidHeight: input({
      label: "Output Cs Geoid Height",
      type: "string",
      required: false,
      clean: (value): number => util.types.toNumber(value),
    }),
    outputs: input({
      label: "Outputs",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
      comments: "Outputs to be created when processing a project",
    }),
  },
});

After:

const projectApiV3ProjectsProcessingOptionsUpdate = action({
  display: {
    label: "Project Api V 3 Projects Processing Options Update",
    description: "Update the project processing options",
  },
  perform: async (
    context,
    {
      connection,
      id,
      customTemplateS3Key,
      customTemplateS3Bucket,
      standardTemplate,
      tags,
      outputCsHorizontal,
      outputCsVertical,
      outputCsGeoid,
      outputCsGeoidHeight,
      outputs,
    },
  ) => {
    const client = createClient(connection);
    const { data } = await client.put(
      `/project/api/v3/projects/${id}/processing_options/`,
      {
        custom_template_s3_key: customTemplateS3Key,
        custom_template_s3_bucket: customTemplateS3Bucket,
        standard_template: standardTemplate,
        tags,
        output_cs_horizontal: outputCsHorizontal,
        output_cs_vertical: outputCsVertical,
        output_cs_geoid: outputCsGeoid,
        output_cs_geoid_height: outputCsGeoidHeight,
        outputs,
      },
    );
    return { data };
  },
  inputs: {
    connection: input({
      label: "Connection",
      type: "connection",
      required: true,
    }),
    id: input({
      label: "Id",
      type: "string",
      required: true,
      clean: (value): string => util.types.toString(value),
    }),
    customTemplateS3Key: input({
      label: "Custom Template S 3 Key",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
      comments: "The S3 key for a valid pix4dmapper template ",
    }),
    customTemplateS3Bucket: input({
      label: "Custom Template S 3 Bucket",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
      comments: "The S3 bucket for a valid pix4dmapper template ",
    }),
    standardTemplate: input({
      label: "Standard Template",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
    }),
    tags: input({
      label: "Tags",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
      comments: "Project data classifications tags",
    }),
    outputCsHorizontal: input({
      label: "Output Cs Horizontal",
      type: "string",
      required: false,
      clean: (value): number | undefined =>
        util.types.toNumber(value) || undefined,
      comments: "EPSG code of the desired output horizontal coordinate system",
    }),
    outputCsVertical: input({
      label: "Output Cs Vertical",
      type: "string",
      required: false,
      clean: (value): number | undefined =>
        util.types.toNumber(value) || undefined,
      comments: "EPSG code of the desired output vertical coordinate system",
    }),
    outputCsGeoid: input({
      label: "Output Cs Geoid",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
    }),
    outputCsGeoidHeight: input({
      label: "Output Cs Geoid Height",
      type: "string",
      required: false,
      clean: (value): number | undefined =>
        util.types.toNumber(value) || undefined,
    }),
    outputs: input({
      label: "Outputs",
      type: "string",
      required: false,
      clean: (value): string | undefined =>
        util.types.toString(value) || undefined,
      comments: "Outputs to be created when processing a project",
    }),
  },
});

@jasoncomes jasoncomes requested a review from ryanwersal July 30, 2024 20:37
@jasoncomes jasoncomes force-pushed the jc/non-required-integers-numbers-clean-undefined-value branch 4 times, most recently from b9c8a45 to e4ad40d Compare August 5, 2024 22:24
…not required

Remove newlines to reduce noise in mr

Logical grouping
@jasoncomes jasoncomes force-pushed the jc/non-required-integers-numbers-clean-undefined-value branch from e4ad40d to a781ddc Compare August 5, 2024 22:24
@jasoncomes jasoncomes merged commit f7e2469 into main Aug 5, 2024
1 check passed
@jasoncomes jasoncomes deleted the jc/non-required-integers-numbers-clean-undefined-value branch August 5, 2024 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants