diff --git a/web/gql-queries-generator/doc/queries.graphql b/web/gql-queries-generator/doc/queries.graphql index 8aed3b80d..a004d0da5 100644 --- a/web/gql-queries-generator/doc/queries.graphql +++ b/web/gql-queries-generator/doc/queries.graphql @@ -896,6 +896,10 @@ mutation consoleCloneEnvironment($projectName: String!, $sourceEnvName: String!, } } +query consoleRestartApp($projectName: String!, $envName: String!, $appName: String!) { + core_restartApp(projectName: $projectName, envName: $envName, appName: $appName) +} + mutation consoleCreateApp($projectName: String!, $envName: String!, $app: AppIn!) { core_createApp(projectName: $projectName, envName: $envName, app: $app) { id diff --git a/web/src/apps/console/routes/_main+/$account+/$project+/$environment+/apps/apps-resources.tsx b/web/src/apps/console/routes/_main+/$account+/$project+/$environment+/apps/apps-resources.tsx index 2a34133f3..80148c5ae 100644 --- a/web/src/apps/console/routes/_main+/$account+/$project+/$environment+/apps/apps-resources.tsx +++ b/web/src/apps/console/routes/_main+/$account+/$project+/$environment+/apps/apps-resources.tsx @@ -1,4 +1,9 @@ -import { GearSix, LinkBreak, Link as LinkIcon } from '@jengaicons/react'; +import { + GearSix, + LinkBreak, + Link as LinkIcon, + Repeat, +} from '@jengaicons/react'; import { Link, useOutletContext, useParams } from '@remix-run/react'; import { generateKey, titleCase } from '~/components/utils'; import { @@ -47,7 +52,7 @@ type OnAction = ({ action, item, }: { - action: 'delete' | 'edit' | 'intercept' | 'remove_intercept'; + action: 'delete' | 'edit' | 'intercept' | 'remove_intercept' | 'restart'; item: BaseType; }) => void; @@ -83,7 +88,7 @@ const ExtraButton = ({ onAction, item }: IExtraButton) => { options = [ { label: 'Intercept', - icon: , + icon: , type: 'item', onClick: () => onAction({ action: 'intercept', item }), key: 'intercept', @@ -91,6 +96,18 @@ const ExtraButton = ({ onAction, item }: IExtraButton) => { ...options, ]; } + + options = [ + { + label: 'Restart', + icon: , + type: 'item', + onClick: () => onAction({ action: 'restart', item }), + key: 'restart', + }, + ...options, + ]; + return ; }; @@ -240,6 +257,29 @@ const AppsResources = ({ items = [] }: Omit) => { } } }; + + const restartApp = async (item: BaseType) => { + if (!environment || !project) { + throw new Error('Environment is required!.'); + } + + try { + const { errors } = await api.restartApp({ + appName: parseName(item), + envName: environment, + projectName: project, + }); + + if (errors) { + throw errors[0]; + } + toast.success('App restarted successfully'); + reload(); + } catch (error) { + handleError(error); + } + }; + const props: IResource = { items, onAction: ({ action, item }) => { @@ -247,6 +287,9 @@ const AppsResources = ({ items = [] }: Omit) => { case 'intercept': interceptApp(item, true); break; + case 'restart': + restartApp(item); + break; case 'remove_intercept': interceptApp(item, false); break; diff --git a/web/src/apps/console/server/gql/queries/app-queries.ts b/web/src/apps/console/server/gql/queries/app-queries.ts index 3aed5a5d2..0bcc2c5c5 100644 --- a/web/src/apps/console/server/gql/queries/app-queries.ts +++ b/web/src/apps/console/server/gql/queries/app-queries.ts @@ -14,12 +14,29 @@ import { ConsoleUpdateAppMutationVariables, ConsoleInterceptAppMutation, ConsoleInterceptAppMutationVariables, + ConsoleRestartAppQuery, + ConsoleRestartAppQueryVariables, } from '~/root/src/generated/gql/server'; export type IApp = NN; export type IApps = NN; export const appQueries = (executor: IExecutor) => ({ + restartApp: executor( + gql` + query Query($projectName: String!, $envName: String!, $appName: String!) { + core_restartApp( + projectName: $projectName + envName: $envName + appName: $appName + ) + } + `, + { + transformer: (data: ConsoleRestartAppQuery) => data.core_restartApp, + vars: (_: ConsoleRestartAppQueryVariables) => {}, + } + ), createApp: executor( gql` mutation Core_createApp( @@ -38,7 +55,7 @@ export const appQueries = (executor: IExecutor) => ({ `, { transformer: (data: ConsoleCreateAppMutation) => data.core_createApp, - vars(_: ConsoleCreateAppMutationVariables) { }, + vars(_: ConsoleCreateAppMutationVariables) {}, } ), @@ -62,7 +79,7 @@ export const appQueries = (executor: IExecutor) => ({ transformer: (data: ConsoleUpdateAppMutation) => { return data.core_updateApp; }, - vars(_: ConsoleUpdateAppMutationVariables) { }, + vars(_: ConsoleUpdateAppMutationVariables) {}, } ), interceptApp: executor( @@ -86,7 +103,7 @@ export const appQueries = (executor: IExecutor) => ({ { transformer: (data: ConsoleInterceptAppMutation) => data.core_interceptApp, - vars(_: ConsoleInterceptAppMutationVariables) { }, + vars(_: ConsoleInterceptAppMutationVariables) {}, } ), deleteApp: executor( @@ -105,7 +122,7 @@ export const appQueries = (executor: IExecutor) => ({ `, { transformer: (data: ConsoleDeleteAppMutation) => data.core_deleteApp, - vars(_: ConsoleDeleteAppMutationVariables) { }, + vars(_: ConsoleDeleteAppMutationVariables) {}, } ), getApp: executor( @@ -252,7 +269,7 @@ export const appQueries = (executor: IExecutor) => ({ transformer(data: ConsoleGetAppQuery) { return data.core_getApp; }, - vars(_: ConsoleGetAppQueryVariables) { }, + vars(_: ConsoleGetAppQueryVariables) {}, } ), listApps: executor( @@ -397,7 +414,7 @@ export const appQueries = (executor: IExecutor) => ({ `, { transformer: (data: ConsoleListAppsQuery) => data.core_listApps, - vars(_: ConsoleListAppsQueryVariables) { }, + vars(_: ConsoleListAppsQueryVariables) {}, } ), }); diff --git a/web/src/generated/gql/server.ts b/web/src/generated/gql/server.ts index da413414b..c97ebaed4 100644 --- a/web/src/generated/gql/server.ts +++ b/web/src/generated/gql/server.ts @@ -2311,6 +2311,14 @@ export type ConsoleCloneEnvironmentMutation = { core_cloneEnvironment?: { id: string }; }; +export type ConsoleRestartAppQueryVariables = Exact<{ + projectName: Scalars['String']['input']; + envName: Scalars['String']['input']; + appName: Scalars['String']['input']; +}>; + +export type ConsoleRestartAppQuery = { core_restartApp: boolean }; + export type ConsoleCreateAppMutationVariables = Exact<{ projectName: Scalars['String']['input']; envName: Scalars['String']['input'];