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

✨ Added restart for app #88

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 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',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (llm): The icon for the 'Restart' action seems to be a repeat icon, which might not intuitively convey the action of restarting. Consider using an icon that more closely represents the restart action to improve user experience.

onClick: () => onAction({ action: 'intercept', item }),
key: 'intercept',
},
...options,
];
}

options = [
{
label: 'Restart',
icon: <LinkIcon size={iconSize} />,
type: 'item',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (llm): It appears that the 'Restart' action is using the 'LinkIcon', which might not accurately represent the action. Consider using a more appropriate icon to enhance clarity and user experience.

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!.');
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (llm): The error message 'Environment is required!.' contains an unnecessary punctuation mark. Consider removing the extra period for grammatical correctness.


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 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) => {},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (llm): The 'vars' function for 'restartApp' is defined but does not seem to be used. If this is intentional for future use or extensibility, consider adding a comment to clarify its purpose and avoid confusion.

}
),
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 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
Loading