Skip to content

Commit

Permalink
✨ Added restart for app
Browse files Browse the repository at this point in the history
  • Loading branch information
abdheshnayak committed Feb 9, 2024
1 parent 5e948b2 commit 3df7db4
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 9 deletions.
4 changes: 4 additions & 0 deletions web/gql-queries-generator/doc/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -47,7 +52,7 @@ type OnAction = ({
action,
item,
}: {
action: 'delete' | 'edit' | 'intercept' | 'remove_intercept';
action: 'delete' | 'edit' | 'intercept' | 'remove_intercept' | 'restart';
item: BaseType;
}) => void;

Expand Down Expand Up @@ -83,14 +88,26 @@ const ExtraButton = ({ onAction, item }: IExtraButton) => {
options = [
{
label: 'Intercept',
icon: <LinkIcon size={iconSize} />,
icon: <Repeat size={iconSize} />,
type: 'item',
onClick: () => onAction({ action: 'intercept', item }),
key: 'intercept',
},
...options,
];
}

options = [
{
label: 'Restart',
icon: <LinkIcon size={iconSize} />,
type: 'item',
onClick: () => onAction({ action: 'restart', item }),
key: 'restart',
},
...options,
];

return <ResourceExtraAction options={options} />;
};

Expand Down Expand Up @@ -240,13 +257,39 @@ const AppsResources = ({ items = [] }: Omit<IResource, 'onAction'>) => {
}
}
};

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 }) => {
switch (action) {
case 'intercept':
interceptApp(item, true);
break;
case 'restart':
restartApp(item);
break;
case 'remove_intercept':
interceptApp(item, false);
break;
Expand Down
29 changes: 23 additions & 6 deletions web/src/apps/console/server/gql/queries/app-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,29 @@ import {
ConsoleUpdateAppMutationVariables,
ConsoleInterceptAppMutation,
ConsoleInterceptAppMutationVariables,
ConsoleRestartAppQuery,
ConsoleRestartAppQueryVariables,
} from '~/root/src/generated/gql/server';

export type IApp = NN<ConsoleGetAppQuery['core_getApp']>;
export type IApps = NN<ConsoleListAppsQuery['core_listApps']>;

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(
Expand All @@ -38,7 +55,7 @@ export const appQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: ConsoleCreateAppMutation) => data.core_createApp,
vars(_: ConsoleCreateAppMutationVariables) { },
vars(_: ConsoleCreateAppMutationVariables) {},
}
),

Expand All @@ -62,7 +79,7 @@ export const appQueries = (executor: IExecutor) => ({
transformer: (data: ConsoleUpdateAppMutation) => {
return data.core_updateApp;
},
vars(_: ConsoleUpdateAppMutationVariables) { },
vars(_: ConsoleUpdateAppMutationVariables) {},
}
),
interceptApp: executor(
Expand All @@ -86,7 +103,7 @@ export const appQueries = (executor: IExecutor) => ({
{
transformer: (data: ConsoleInterceptAppMutation) =>
data.core_interceptApp,
vars(_: ConsoleInterceptAppMutationVariables) { },
vars(_: ConsoleInterceptAppMutationVariables) {},
}
),
deleteApp: executor(
Expand All @@ -105,7 +122,7 @@ export const appQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: ConsoleDeleteAppMutation) => data.core_deleteApp,
vars(_: ConsoleDeleteAppMutationVariables) { },
vars(_: ConsoleDeleteAppMutationVariables) {},
}
),
getApp: executor(
Expand Down Expand Up @@ -252,7 +269,7 @@ export const appQueries = (executor: IExecutor) => ({
transformer(data: ConsoleGetAppQuery) {
return data.core_getApp;
},
vars(_: ConsoleGetAppQueryVariables) { },
vars(_: ConsoleGetAppQueryVariables) {},
}
),
listApps: executor(
Expand Down Expand Up @@ -397,7 +414,7 @@ export const appQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: ConsoleListAppsQuery) => data.core_listApps,
vars(_: ConsoleListAppsQueryVariables) { },
vars(_: ConsoleListAppsQueryVariables) {},
}
),
});
8 changes: 8 additions & 0 deletions web/src/generated/gql/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down

0 comments on commit 3df7db4

Please sign in to comment.