Skip to content

Commit

Permalink
Update workflow actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ivancorrales committed Mar 4, 2022
1 parent cc527f1 commit 96dd879
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ vendor
temp
.DS_Store
package-lock.json
yarn.lock
13 changes: 6 additions & 7 deletions cmd/client/templatizer-ui/src/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Grid, Paper, Typography } from "@material-ui/core";
import axios, { AxiosResponse } from "axios";
import { AxiosResponse } from "axios";
import { useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { useForm } from "react-hook-form";
import { RepositoryDetails, defaultValues as repoDetailsDefaultValues } from './components/RepositoryDetails';
import { TemplateVars } from './components/TemplateVars';
import { Config, LoadParameters, ProcessTemplate, ProcessTemplateRequest, LoadParametersRequest } from './components/Client';
Expand Down Expand Up @@ -31,27 +31,27 @@ const defaultValues = {
export const TemplatizerForm = () => {

const methods = useForm<IFormInput>({ defaultValues: defaultValues });
const { control, setValue, getValues, formState } = methods;
const { control, setValue, getValues } = methods;
const [showTemplateVars, setTemplateVars] = useState<boolean>(false);

const buildLoadParametersRequest = (): LoadParametersRequest => {
let request: LoadParametersRequest = {
url: getValues('url'),
}
let authMechanism = getValues('authMechanism')
if (authMechanism == 'basic') {
if (authMechanism === 'basic') {
request.auth = {
mechanism: authMechanism,
username: getValues('authUsername'),
password: getValues('authPassword'),
}
} else if (authMechanism == 'token') {
} else if (authMechanism === 'token') {
request.auth = {
mechanism: authMechanism,
token: getValues('authToken'),
}
}
if (getValues('branchDefault') != 'default') {
if (getValues('branchDefault') !== 'default') {
request.branch = getValues('branch')
}
return request
Expand All @@ -77,7 +77,6 @@ export const TemplatizerForm = () => {

ProcessTemplate(request).then((response: AxiosResponse) => {
console.log(response.headers)
let fileName = response.headers["content-disposition"].split("filename=")[1];
const url = window.URL.createObjectURL(new Blob([response.data],
{ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));
const link = document.createElement('a');
Expand Down
4 changes: 2 additions & 2 deletions cmd/client/templatizer-ui/src/components/Client.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosResponse } from "axios";
import axios from "axios";


const API_URL = 'http://localhost:5001/api';
Expand Down Expand Up @@ -38,5 +38,5 @@ export const LoadParameters = (request: LoadParametersRequest) => {
}

export const ProcessTemplate = (request: ProcessTemplateRequest) => {
return axios.post(`${API_URL}/template`, request, {responseType: 'blob'})
return axios.post(`${API_URL}/template`, request, { responseType: 'blob' })
}
10 changes: 5 additions & 5 deletions cmd/client/templatizer-ui/src/components/RepositoryDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, useFormContext } from "react-hook-form";
import { Controller } from "react-hook-form";
import TextField from "@material-ui/core/TextField";
import { FormControl, FormControlLabel, FormLabel, Grid, InputLabel, MenuItem, Radio, RadioGroup, Select, Typography } from "@material-ui/core";
import { FormControlLabel, FormLabel, Grid, Radio, RadioGroup, Typography } from "@material-ui/core";
import { useState } from "react";

interface RepositoryDetailsProps {
Expand Down Expand Up @@ -64,7 +64,7 @@ export const RepositoryDetails: React.FC<RepositoryDetailsProps> = ({
<RadioGroup
aria-labelledby="branch-type"
value={value} onChange={(val) => {
setCustomBranch(val.target.value != 'default');
setCustomBranch(val.target.value !== 'default');
setValue('branchDefault', val.target.value);
}}>
<FormControlLabel
Expand Down Expand Up @@ -118,8 +118,8 @@ export const RepositoryDetails: React.FC<RepositoryDetailsProps> = ({
name="branchDefault"
value={value}
onChange={(val) => {
setTokenAuth(val.target.value == 'token');
setBasicAuth(val.target.value == 'basic');
setTokenAuth(val.target.value === 'token');
setBasicAuth(val.target.value === 'basic');
setValue('authMechanism', val.target.value);
}}>
<FormControlLabel
Expand Down
59 changes: 29 additions & 30 deletions cmd/client/templatizer-ui/src/components/TemplateVars.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Controller, useFormContext } from "react-hook-form";
import { Controller } from "react-hook-form";
import TextField from "@material-ui/core/TextField";
import { FormControl, FormControlLabel, FormLabel, Grid, InputLabel, MenuItem, Radio, RadioGroup, Select, Typography } from "@material-ui/core";
import { useState } from "react";
import { Grid } from "@material-ui/core";
import { Var } from './Client';

interface TemplateVarsProps {
Expand All @@ -25,33 +24,33 @@ export const TemplateVars: React.FC<TemplateVarsProps> = ({
render={({ field: { value, onChange } }) => {

const templateVarsFields = value.variables.map((variable: Var) => {
{
const name = `var_${variable.name}`
setValue(name, variable.default)
return (
<Grid item lg={10}>
<Controller
name={name}
control={control}
render={({
field: { value },
}) => (
<TextField
fullWidth
value={value}
label={variable.name}
helperText={variable.description}
variant="standard"
onChange={(val: any) => {
setValue(name, val.target.value)
updateParam(variable.name, val.target.value)
}}
/>
)}
/>
</Grid>
)
}

const name = `var_${variable.name}`
setValue(name, variable.default)
return (
<Grid item lg={10}>
<Controller
name={name}
control={control}
render={({
field: { value },
}) => (
<TextField
fullWidth
value={value}
label={variable.name}
helperText={variable.description}
variant="standard"
onChange={(val: any) => {
setValue(name, val.target.value)
updateParam(variable.name, val.target.value)
}}
/>
)}
/>
</Grid>
)

});

return (
Expand Down

0 comments on commit 96dd879

Please sign in to comment.