Update UI to take environment variables from user #6

Merged
nabarun merged 6 commits from iv-env-ui into main 2024-10-21 11:05:36 +00:00
6 changed files with 67 additions and 31 deletions
Showing only changes of commit 9461bd04f1 - Show all commits

View File

@ -211,8 +211,15 @@ export const createResolvers = async (service: Service): Promise<any> => {
organizationSlug, organizationSlug,
data, data,
lrn, lrn,
auctionParams auctionParams,
}: { organizationSlug: string; data: AddProjectFromTemplateInput; lrn: string; auctionParams: AuctionParams }, environmentVariables
}: {
organizationSlug: string;
data: AddProjectFromTemplateInput;
lrn: string;
auctionParams: AuctionParams,
environmentVariables: { environments: string[]; key: string; value: string }[];
},
context: any, context: any,
) => { ) => {
try { try {
@ -221,7 +228,8 @@ export const createResolvers = async (service: Service): Promise<any> => {
organizationSlug, organizationSlug,
data, data,
lrn, lrn,
auctionParams auctionParams,
environmentVariables
); );
} catch (err) { } catch (err) {
log(err); log(err);
@ -235,12 +243,26 @@ export const createResolvers = async (service: Service): Promise<any> => {
organizationSlug, organizationSlug,
data, data,
lrn, lrn,
auctionParams auctionParams,
}: { organizationSlug: string; data: DeepPartial<Project>; lrn: string; auctionParams: AuctionParams }, environmentVariables
}: {
organizationSlug: string;
data: DeepPartial<Project>;
lrn: string;
auctionParams: AuctionParams,
environmentVariables: { environments: string[]; key: string; value: string }[];
},
context: any, context: any,
) => { ) => {
try { try {
return await service.addProject(context.user, organizationSlug, data, lrn, auctionParams); return await service.addProject(
context.user,
organizationSlug,
data,
lrn,
auctionParams,
environmentVariables
);
} catch (err) { } catch (err) {
log(err); log(err);
throw err; throw err;

View File

@ -271,12 +271,14 @@ type Mutation {
data: AddProjectFromTemplateInput data: AddProjectFromTemplateInput
lrn: String lrn: String
auctionParams: AuctionParams auctionParams: AuctionParams
environmentVariables: [AddEnvironmentVariableInput!]
): Project! ): Project!
addProject( addProject(
organizationSlug: String! organizationSlug: String!
data: AddProjectInput! data: AddProjectInput!
lrn: String lrn: String
auctionParams: AuctionParams auctionParams: AuctionParams
environmentVariables: [AddEnvironmentVariableInput!]
): Project! ): Project!
updateProject(projectId: String!, data: UpdateProjectInput): Boolean! updateProject(projectId: String!, data: UpdateProjectInput): Boolean!
redeployToProd(deploymentId: String!): Boolean! redeployToProd(deploymentId: String!): Boolean!

View File

@ -784,7 +784,8 @@ export class Service {
organizationSlug: string, organizationSlug: string,
data: AddProjectFromTemplateInput, data: AddProjectFromTemplateInput,
lrn?: string, lrn?: string,
auctionParams?: AuctionParams auctionParams?: AuctionParams,
environmentVariables?: { environments: string[]; key: string; value: string }[],
): Promise<Project | undefined> { ): Promise<Project | undefined> {
try { try {
const octokit = await this.getOctokit(user.id); const octokit = await this.getOctokit(user.id);
@ -815,7 +816,7 @@ export class Service {
repository: gitRepo.data.full_name, repository: gitRepo.data.full_name,
// TODO: Set selected template // TODO: Set selected template
template: 'webapp', template: 'webapp',
}, lrn, auctionParams); }, lrn, auctionParams, environmentVariables);
if (!project || !project.id) { if (!project || !project.id) {
throw new Error('Failed to create project from template'); throw new Error('Failed to create project from template');
@ -833,7 +834,8 @@ export class Service {
organizationSlug: string, organizationSlug: string,
data: DeepPartial<Project>, data: DeepPartial<Project>,
lrn?: string, lrn?: string,
auctionParams?: AuctionParams auctionParams?: AuctionParams,
environmentVariables?: { environments: string[]; key: string; value: string }[],
): Promise<Project | undefined> { ): Promise<Project | undefined> {
const organization = await this.db.getOrganization({ const organization = await this.db.getOrganization({
where: { where: {
@ -844,8 +846,11 @@ export class Service {
throw new Error('Organization does not exist'); throw new Error('Organization does not exist');
} }
const project = await this.db.addProject(user, organization.id, data); const project = await this.db.addProject(user, organization.id, data);4
log(`Project created ${project.id}`);
if(environmentVariables) {
await this.addEnvironmentVariables(project.id, environmentVariables);
}
const octokit = await this.getOctokit(user.id); const octokit = await this.getOctokit(user.id);
const [owner, repo] = project.repository.split('/'); const [owner, repo] = project.repository.split('/');

View File

@ -3,7 +3,7 @@ import { useForm, Controller } from 'react-hook-form';
import { FormProvider, FieldValues } from 'react-hook-form'; import { FormProvider, FieldValues } from 'react-hook-form';
import { useNavigate, useSearchParams } from 'react-router-dom'; import { useNavigate, useSearchParams } from 'react-router-dom';
import { useMediaQuery } from 'usehooks-ts'; import { useMediaQuery } from 'usehooks-ts';
import { AuctionParams } from 'gql-client'; import { AddEnvironmentVariableInput, AuctionParams } from 'gql-client';
import { import {
ArrowRightCircleFilledIcon, ArrowRightCircleFilledIcon,
@ -55,7 +55,7 @@ const Configure = () => {
const isTabletView = useMediaQuery('(min-width: 720px)'); // md: const isTabletView = useMediaQuery('(min-width: 720px)'); // md:
const buttonSize = isTabletView ? { size: 'lg' as const } : {}; const buttonSize = isTabletView ? { size: 'lg' as const } : {};
const createProject = async (data: FieldValues): Promise<string> => { const createProject = async (data: FieldValues, envVariables: AddEnvironmentVariableInput[]): Promise<string> => {
setIsLoading(true); setIsLoading(true);
let projectId: string | null = null; let projectId: string | null = null;
@ -81,13 +81,15 @@ const Configure = () => {
isPrivate, isPrivate,
}; };
const { addProjectFromTemplate } = await client.addProjectFromTemplate( const { addProjectFromTemplate } = await client.addProjectFromTemplate(
orgSlug!, orgSlug!,
projectData, projectData,
lrn, lrn,
auctionParams auctionParams,
); envVariables
projectId = addProjectFromTemplate.id; );
projectId = addProjectFromTemplate.id;
} else { } else {
const { addProject } = await client.addProject( const { addProject } = await client.addProject(
orgSlug!, orgSlug!,
@ -98,7 +100,8 @@ const Configure = () => {
template: 'webapp', template: 'webapp',
}, },
lrn, lrn,
auctionParams auctionParams,
envVariables
); );
projectId = addProject.id; projectId = addProject.id;
@ -134,12 +137,12 @@ const Configure = () => {
}; };
}); });
const projectId = await createProject(createFormData); const projectId = await createProject(createFormData, environmentVariables);
const { addEnvironmentVariables: isEnvironmentVariablesAdded } = const { environmentVariables: isEnvironmentVariablesAdded } =
await client.addEnvironmentVariables(projectId, environmentVariables); await client.getEnvironmentVariables(projectId);
if (isEnvironmentVariablesAdded) { if (isEnvironmentVariablesAdded.length > 0) {
toast({ toast({
id: id:
createFormData.variables.length > 1 createFormData.variables.length > 1

View File

@ -233,6 +233,7 @@ export class GQLClient {
data: types.AddProjectFromTemplateInput, data: types.AddProjectFromTemplateInput,
lrn?: string, lrn?: string,
auctionParams?: types.AuctionParams, auctionParams?: types.AuctionParams,
environmentVariables?: types.AddEnvironmentVariableInput[]
): Promise<types.AddProjectFromTemplateResponse> { ): Promise<types.AddProjectFromTemplateResponse> {
const result = await this.client.mutate({ const result = await this.client.mutate({
mutation: mutations.addProjectFromTemplate, mutation: mutations.addProjectFromTemplate,
@ -240,7 +241,8 @@ export class GQLClient {
organizationSlug, organizationSlug,
data, data,
lrn, lrn,
auctionParams auctionParams,
environmentVariables
}, },
}); });
@ -252,6 +254,7 @@ export class GQLClient {
data: types.AddProjectInput, data: types.AddProjectInput,
lrn?: string, lrn?: string,
auctionParams?: types.AuctionParams, auctionParams?: types.AuctionParams,
environmentVariables?: types.AddEnvironmentVariableInput[]
): Promise<types.AddProjectResponse> { ): Promise<types.AddProjectResponse> {
const result = await this.client.mutate({ const result = await this.client.mutate({
mutation: mutations.addProject, mutation: mutations.addProject,
@ -259,7 +262,8 @@ export class GQLClient {
organizationSlug, organizationSlug,
data, data,
lrn, lrn,
auctionParams auctionParams,
environmentVariables
}, },
}); });

View File

@ -49,16 +49,16 @@ export const updateDeploymentToProd = gql`
`; `;
export const addProjectFromTemplate = gql` export const addProjectFromTemplate = gql`
mutation ($organizationSlug: String!, $data: AddProjectFromTemplateInput, $lrn: String, $auctionParams: AuctionParams) { mutation ($organizationSlug: String!, $data: AddProjectFromTemplateInput, $lrn: String, $auctionParams: AuctionParams, $environmentVariables: [AddEnvironmentVariableInput!]) {
addProjectFromTemplate(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionParams: $auctionParams) { addProjectFromTemplate(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionParams: $auctionParams, environmentVariables: $environmentVariables) {
id id
} }
} }
`; `;
export const addProject = gql` export const addProject = gql`
mutation ($organizationSlug: String!, $data: AddProjectInput!, $lrn: String, $auctionParams: AuctionParams) { mutation ($organizationSlug: String!, $data: AddProjectInput!, $lrn: String, $auctionParams: AuctionParams, $environmentVariables: [AddEnvironmentVariableInput!]) {
addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionParams: $auctionParams) { addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionParams: $auctionParams, environmentVariables: $environmentVariables) {
id id
} }
} }