From 549012ae0ccbd1e90b429a9cc65cef4397799255 Mon Sep 17 00:00:00 2001 From: aXenDeveloper Date: Mon, 9 Sep 2024 15:52:24 +0200 Subject: [PATCH 1/2] perf: Delete download language option from AdminCP --- apps/backend/schema.gql | 1 - apps/frontend/src/graphql/types.ts | 7 -- apps/frontend/src/plugins/admin/langs/en.json | 18 ---- .../admin/languages/download/download.dto.ts | 10 -- .../languages/download/download.resolver.ts | 21 ----- .../languages/download/download.service.ts | 94 ------------------- .../core/admin/languages/languages.module.ts | 4 - ...min__core_languages__download.generated.ts | 17 ---- .../admin__core_languages__download.gql | 3 - packages/frontend/src/graphql/types.ts | 7 -- .../core/langs/table/actions/actions.tsx | 45 +-------- .../langs/table/actions/delete/delete.tsx | 30 +++--- .../langs/table/actions/download/content.tsx | 72 -------------- .../langs/table/actions/download/download.tsx | 48 ---------- .../actions/download/hooks/mutation-api.ts | 31 ------ .../table/actions/download/hooks/query-api.ts | 28 ------ .../download/hooks/use-download-lang-admin.ts | 80 ---------------- 17 files changed, 20 insertions(+), 496 deletions(-) delete mode 100644 packages/backend/src/core/admin/languages/download/download.dto.ts delete mode 100644 packages/backend/src/core/admin/languages/download/download.resolver.ts delete mode 100644 packages/backend/src/core/admin/languages/download/download.service.ts delete mode 100644 packages/frontend/src/graphql/mutations/admin/languages/admin__core_languages__download.generated.ts delete mode 100644 packages/frontend/src/graphql/mutations/admin/languages/admin__core_languages__download.gql delete mode 100644 packages/frontend/src/views/admin/views/core/langs/table/actions/download/content.tsx delete mode 100644 packages/frontend/src/views/admin/views/core/langs/table/actions/download/download.tsx delete mode 100644 packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/mutation-api.ts delete mode 100644 packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/query-api.ts delete mode 100644 packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/use-download-lang-admin.ts diff --git a/apps/backend/schema.gql b/apps/backend/schema.gql index 4f364c4dd..de5a5704f 100644 --- a/apps/backend/schema.gql +++ b/apps/backend/schema.gql @@ -226,7 +226,6 @@ type Mutation { admin__core_groups__edit(color: String, content: ContentCreateAdminGroups!, id: Int!, name: [StringLanguageInput!]!): ShowAdminGroups! admin__core_languages__create(allow_in_input: Boolean!, code: String!, locale: String!, name: String!, time_24: Boolean!, timezone: String!): ShowCoreLanguages! admin__core_languages__delete(code: String!): String! - admin__core_languages__download(code: String!, plugins: [String!]!): String! admin__core_languages__edit(allow_in_input: Boolean!, default: Boolean!, enabled: Boolean!, id: Int!, locale: String!, name: String!, time_24: Boolean!, timezone: String!): ShowCoreLanguages! admin__core_main_settings__edit(site_copyright: [StringLanguageInput!]!, site_description: [StringLanguageInput!]!, site_name: String!, site_short_name: String!): EditAdminSettingsObj! admin__core_manifest_metadata__edit(background_color: String!, display: String!, start_url: String!, theme_color: String!): ShowAdminManifestMetadataObj! diff --git a/apps/frontend/src/graphql/types.ts b/apps/frontend/src/graphql/types.ts index 5baa8459d..2734e02c8 100644 --- a/apps/frontend/src/graphql/types.ts +++ b/apps/frontend/src/graphql/types.ts @@ -259,7 +259,6 @@ export type Mutation = { admin__core_groups__edit: ShowAdminGroups; admin__core_languages__create: ShowCoreLanguages; admin__core_languages__delete: Scalars['String']['output']; - admin__core_languages__download: Scalars['String']['output']; admin__core_languages__edit: ShowCoreLanguages; admin__core_main_settings__edit: EditAdminSettingsObj; admin__core_manifest_metadata__edit: ShowAdminManifestMetadataObj; @@ -368,12 +367,6 @@ export type MutationAdmin__Core_Languages__DeleteArgs = { }; -export type MutationAdmin__Core_Languages__DownloadArgs = { - code: Scalars['String']['input']; - plugins: Array; -}; - - export type MutationAdmin__Core_Languages__EditArgs = { allow_in_input: Scalars['Boolean']['input']; default: Scalars['Boolean']['input']; diff --git a/apps/frontend/src/plugins/admin/langs/en.json b/apps/frontend/src/plugins/admin/langs/en.json index 07e5791fd..57dcf7440 100644 --- a/apps/frontend/src/plugins/admin/langs/en.json +++ b/apps/frontend/src/plugins/admin/langs/en.json @@ -446,24 +446,6 @@ "form_confirm_text": "Type the name of the language to confirm.", "success": "Language has been deleted.", "submit": "Yes, delete language" - }, - "download": { - "title": "Download Language - {code}", - "desc": "Choose which plugins language you want to download.", - "all": { - "label": "All", - "desc": "Download language for all plugins." - }, - "plugins": "Plugins", - "search": "Search by name...", - "empty": "No plugins found.", - "selected": "{count, plural, =0 {No plugins} =1 {1 plugin} other {# plugins}} selected", - "submit": "Download" - }, - "update": { - "title": "Update Language - {code}", - "submit": "Update Language", - "success": "Language has been updated." } } }, diff --git a/packages/backend/src/core/admin/languages/download/download.dto.ts b/packages/backend/src/core/admin/languages/download/download.dto.ts deleted file mode 100644 index 9ffa7346b..000000000 --- a/packages/backend/src/core/admin/languages/download/download.dto.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ArgsType, Field } from '@nestjs/graphql'; - -@ArgsType() -export class DownloadCoreAdminLanguagesArgs { - @Field(() => String) - code: string; - - @Field(() => [String]) - plugins: string[]; -} diff --git a/packages/backend/src/core/admin/languages/download/download.resolver.ts b/packages/backend/src/core/admin/languages/download/download.resolver.ts deleted file mode 100644 index 73aecd47f..000000000 --- a/packages/backend/src/core/admin/languages/download/download.resolver.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { CurrentUser, User } from '@/decorators'; -import { AdminAuthGuards } from '@/utils'; -import { UseGuards } from '@nestjs/common'; -import { Args, Mutation, Resolver } from '@nestjs/graphql'; - -import { DownloadCoreAdminLanguagesArgs } from './download.dto'; -import { DownloadAdminCoreLanguageService } from './download.service'; - -@Resolver() -export class DownloadAdminCoreLanguagesResolver { - constructor(private readonly service: DownloadAdminCoreLanguageService) {} - - @Mutation(() => String) - @UseGuards(AdminAuthGuards) - async admin__core_languages__download( - @CurrentUser() user: User, - @Args() args: DownloadCoreAdminLanguagesArgs, - ): Promise { - return this.service.download(user, args); - } -} diff --git a/packages/backend/src/core/admin/languages/download/download.service.ts b/packages/backend/src/core/admin/languages/download/download.service.ts deleted file mode 100644 index 4ade79d80..000000000 --- a/packages/backend/src/core/admin/languages/download/download.service.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { User } from '@/decorators'; -import { CustomError, NotFoundError } from '@/errors'; -import { generateRandomString } from '@/functions/generate-random-string'; -import { InternalDatabaseService } from '@/utils/database/internal_database.service'; -import { Injectable } from '@nestjs/common'; -import * as fs from 'fs'; -import { join } from 'path'; -import * as tar from 'tar'; - -import { - ABSOLUTE_PATHS_BACKEND, - currentUnixDate, - removeSpecialCharacters, -} from '../../../..'; -import { DownloadCoreAdminLanguagesArgs } from './download.dto'; - -@Injectable() -export class DownloadAdminCoreLanguageService { - constructor(private readonly databaseService: InternalDatabaseService) {} - - async download( - { id: userId }: User, - { code, plugins: pluginsToInclude }: DownloadCoreAdminLanguagesArgs, - ): Promise { - const language = - await this.databaseService.db.query.core_languages.findFirst({ - where: (language, { eq }) => eq(language.code, code), - }); - - if (!language) { - throw new NotFoundError('Language'); - } - - // Create temp folder - const tempNameFolder = `${code}-download--${generateRandomString(5)}-${currentUnixDate()}`; - const pathTemp = join( - ABSOLUTE_PATHS_BACKEND.uploads.temp, - 'langs', - tempNameFolder, - ); - if (!fs.existsSync(pathTemp)) { - fs.mkdirSync(pathTemp, { recursive: true }); - } - - const plugins = await this.databaseService.db.query.core_plugins.findMany({ - orderBy: (plugin, { desc }) => desc(plugin.updated), - columns: { - code: true, - }, - }); - - [...plugins, { code: 'admin' }, { code: 'core' }].forEach(plugin => { - const path = join( - ABSOLUTE_PATHS_BACKEND.plugin({ code: plugin.code }).frontend.language, - `${code}.json`, - ); - - if ( - !fs.existsSync(path) || - (pluginsToInclude.length > 0 && !pluginsToInclude.includes(plugin.code)) - ) { - return; - } - - fs.copyFileSync(path, join(pathTemp, `${plugin.code}.json`)); - }); - - const name = removeSpecialCharacters( - `${language.code}--${userId}-${generateRandomString(5)}-${currentUnixDate()}`, - ); - - // Create tgz - try { - await tar.create( - { - gzip: true, - file: join(ABSOLUTE_PATHS_BACKEND.uploads.temp, `${name}.tgz`), - cwd: pathTemp, - }, - ['.'], - ); - - // Remove temp folder - fs.rmSync(pathTemp, { recursive: true }); - } catch (_) { - throw new CustomError({ - code: 'LANGUAGE_DOWNLOAD_ERROR', - message: 'Error creating tgz', - }); - } - - return `${name}.tgz`; - } -} diff --git a/packages/backend/src/core/admin/languages/languages.module.ts b/packages/backend/src/core/admin/languages/languages.module.ts index 2f46626d7..d407cef56 100644 --- a/packages/backend/src/core/admin/languages/languages.module.ts +++ b/packages/backend/src/core/admin/languages/languages.module.ts @@ -4,8 +4,6 @@ import { CreateAdminCoreLanguagesResolver } from './create/create.resolver'; import { CreateAdminCoreLanguageService } from './create/create.service'; import { DeleteAdminCoreLanguagesResolver } from './delete/delete.resolver'; import { DeleteAdminCoreLanguageService } from './delete/delete.service'; -import { DownloadAdminCoreLanguagesResolver } from './download/download.resolver'; -import { DownloadAdminCoreLanguageService } from './download/download.service'; import { EditAdminCoreLanguagesResolver } from './edit/edit.resolver'; import { EditAdminCoreLanguagesService } from './edit/edit.service'; @@ -17,8 +15,6 @@ import { EditAdminCoreLanguagesService } from './edit/edit.service'; EditAdminCoreLanguagesService, DeleteAdminCoreLanguagesResolver, DeleteAdminCoreLanguageService, - DownloadAdminCoreLanguageService, - DownloadAdminCoreLanguagesResolver, ], }) export class AdminLanguagesModule {} diff --git a/packages/frontend/src/graphql/mutations/admin/languages/admin__core_languages__download.generated.ts b/packages/frontend/src/graphql/mutations/admin/languages/admin__core_languages__download.generated.ts deleted file mode 100644 index 361e20ee8..000000000 --- a/packages/frontend/src/graphql/mutations/admin/languages/admin__core_languages__download.generated.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as Types from '../../../types'; - -import gql from 'graphql-tag'; -export type Admin__Core_Languages__DownloadMutationVariables = Types.Exact<{ - code: Types.Scalars['String']['input']; - plugins: Array | Types.Scalars['String']['input']; -}>; - - -export type Admin__Core_Languages__DownloadMutation = { __typename?: 'Mutation', admin__core_languages__download: string }; - - -export const Admin__Core_Languages__Download = gql` - mutation Admin__core_languages__download($code: String!, $plugins: [String!]!) { - admin__core_languages__download(code: $code, plugins: $plugins) -} - `; \ No newline at end of file diff --git a/packages/frontend/src/graphql/mutations/admin/languages/admin__core_languages__download.gql b/packages/frontend/src/graphql/mutations/admin/languages/admin__core_languages__download.gql deleted file mode 100644 index e64a83e87..000000000 --- a/packages/frontend/src/graphql/mutations/admin/languages/admin__core_languages__download.gql +++ /dev/null @@ -1,3 +0,0 @@ -mutation Admin__core_languages__download($code: String!, $plugins: [String!]!) { - admin__core_languages__download(code: $code, plugins: $plugins) -} diff --git a/packages/frontend/src/graphql/types.ts b/packages/frontend/src/graphql/types.ts index 5baa8459d..2734e02c8 100644 --- a/packages/frontend/src/graphql/types.ts +++ b/packages/frontend/src/graphql/types.ts @@ -259,7 +259,6 @@ export type Mutation = { admin__core_groups__edit: ShowAdminGroups; admin__core_languages__create: ShowCoreLanguages; admin__core_languages__delete: Scalars['String']['output']; - admin__core_languages__download: Scalars['String']['output']; admin__core_languages__edit: ShowCoreLanguages; admin__core_main_settings__edit: EditAdminSettingsObj; admin__core_manifest_metadata__edit: ShowAdminManifestMetadataObj; @@ -368,12 +367,6 @@ export type MutationAdmin__Core_Languages__DeleteArgs = { }; -export type MutationAdmin__Core_Languages__DownloadArgs = { - code: Scalars['String']['input']; - plugins: Array; -}; - - export type MutationAdmin__Core_Languages__EditArgs = { allow_in_input: Scalars['Boolean']['input']; default: Scalars['Boolean']['input']; diff --git a/packages/frontend/src/views/admin/views/core/langs/table/actions/actions.tsx b/packages/frontend/src/views/admin/views/core/langs/table/actions/actions.tsx index 9fd3f90bb..392d40ca4 100644 --- a/packages/frontend/src/views/admin/views/core/langs/table/actions/actions.tsx +++ b/packages/frontend/src/views/admin/views/core/langs/table/actions/actions.tsx @@ -1,57 +1,16 @@ -import { Button } from '@/components/ui/button'; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from '@/components/ui/dropdown-menu'; import { ShowCoreLanguages } from '@/graphql/types'; -import { ChevronDown, Trash2 } from 'lucide-react'; -import { useLocale, useTranslations } from 'next-intl'; import React from 'react'; import { DeleteActionsTableLangsCoreAdmin } from './delete/delete'; -import { DownloadActionsTableLangsCoreAdmin } from './download/download'; import { EditActionsTableLangsCoreAdmin } from './edit'; export const ActionsTableLangsCoreAdmin = (data: ShowCoreLanguages) => { - const t = useTranslations('core'); - const locale = useLocale(); - const [isOpenDeleteDialog, setIsOpenDeleteDialog] = React.useState(false); - return ( <> - - - {!data.protected && ( - - - - - - {!data.default && ( - { - setIsOpenDeleteDialog(true); - }} - > - {t('delete')} - - )} - - + {!data.protected && !data.default && ( + )} - - ); }; diff --git a/packages/frontend/src/views/admin/views/core/langs/table/actions/delete/delete.tsx b/packages/frontend/src/views/admin/views/core/langs/table/actions/delete/delete.tsx index bde84ae86..c3405d404 100644 --- a/packages/frontend/src/views/admin/views/core/langs/table/actions/delete/delete.tsx +++ b/packages/frontend/src/views/admin/views/core/langs/table/actions/delete/delete.tsx @@ -1,6 +1,12 @@ -import { AlertDialog, AlertDialogContent } from '@/components/ui/alert-dialog'; +import { + AlertDialog, + AlertDialogContent, + AlertDialogTrigger, +} from '@/components/ui/alert-dialog'; +import { Button } from '@/components/ui/button'; import { Loader } from '@/components/ui/loader'; -import { ShowCoreLanguages } from '@/graphql/types'; +import { Trash2 } from 'lucide-react'; +import { useTranslations } from 'next-intl'; import React from 'react'; const Content = React.lazy(async () => @@ -9,18 +15,18 @@ const Content = React.lazy(async () => })), ); -interface Props extends Pick { - open: boolean; - setOpen: (value: boolean) => void; -} +export const DeleteActionsTableLangsCoreAdmin = ( + props: React.ComponentProps, +) => { + const t = useTranslations('core'); -export const DeleteActionsTableLangsCoreAdmin = ({ - open, - setOpen, - ...props -}: Props) => { return ( - + + + + }> diff --git a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/content.tsx b/packages/frontend/src/views/admin/views/core/langs/table/actions/download/content.tsx deleted file mode 100644 index 0ce5b3f57..000000000 --- a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/content.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import { AutoForm, DependencyType } from '@/components/form/auto-form'; -import { - AutoFormCombobox, - AutoFormComboboxProps, -} from '@/components/form/fields/combobox'; -import { AutoFormSwitch } from '@/components/form/fields/switch'; -import { Button } from '@/components/ui/button'; -import { DialogFooter } from '@/components/ui/dialog'; -import { Loader } from '@/components/ui/loader'; -import { ShowCoreLanguages } from '@/graphql/types'; -import { useTranslations } from 'next-intl'; -import React from 'react'; - -import { useDownloadLangAdmin } from './hooks/use-download-lang-admin'; -export const ContentDownloadActionsTableLangsCoreAdmin = ({ - code, -}: Pick) => { - const t = useTranslations('admin.core.langs.actions.download'); - const { onSubmit, queryPlugins, formSchema, plugins } = useDownloadLangAdmin({ - code, - }); - const { data } = queryPlugins; - - if (queryPlugins.isLoading || !data) { - return ; - } - - return ( - !!provider, - }, - ]} - fields={[ - { - id: 'all', - component: AutoFormSwitch, - label: t('all.label'), - description: t('all.desc'), - }, - { - id: 'plugins', - label: t('plugins'), - component: AutoFormCombobox, - componentProps: { - labels: Object.fromEntries( - plugins.map(plugin => [ - plugin.code, -
- {plugin.name} - {plugin.version} -
, - ]), - ), - multiple: true, - } as AutoFormComboboxProps, - }, - ]} - formSchema={formSchema} - onSubmit={onSubmit} - submitButton={props => ( - - - - )} - /> - ); -}; diff --git a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/download.tsx b/packages/frontend/src/views/admin/views/core/langs/table/actions/download/download.tsx deleted file mode 100644 index 311e907c6..000000000 --- a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/download.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, - DialogTrigger, -} from '@/components/ui/dialog'; -import { Loader } from '@/components/ui/loader'; -import { ShowCoreLanguages } from '@/graphql/types'; -import { Download } from 'lucide-react'; -import { useTranslations } from 'next-intl'; -import React from 'react'; - -const Content = React.lazy(async () => - import('./content').then(module => ({ - default: module.ContentDownloadActionsTableLangsCoreAdmin, - })), -); - -export const DownloadActionsTableLangsCoreAdmin = ( - props: Pick, -) => { - const t = useTranslations('admin.core.langs.actions.download'); - const title = t('title', { code: props.code }); - - return ( - - - - - - - - {title} - {t('desc')} - - - }> - - - - - ); -}; diff --git a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/mutation-api.ts b/packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/mutation-api.ts deleted file mode 100644 index dd9de6b59..000000000 --- a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/mutation-api.ts +++ /dev/null @@ -1,31 +0,0 @@ -'use server'; - -import { fetcher } from '@/graphql/fetcher'; -import { - Admin__Core_Languages__Download, - Admin__Core_Languages__DownloadMutation, - Admin__Core_Languages__DownloadMutationVariables, -} from '@/graphql/mutations/admin/languages/admin__core_languages__download.generated'; -import { revalidatePath } from 'next/cache'; - -export const mutationApi = async ( - variables: Admin__Core_Languages__DownloadMutationVariables, -) => { - try { - const data = await fetcher< - Admin__Core_Languages__DownloadMutation, - Admin__Core_Languages__DownloadMutationVariables - >({ - query: Admin__Core_Languages__Download, - variables, - }); - - revalidatePath('/admin/core/langs', 'page'); - - return { data }; - } catch (error) { - const e = error as Error; - - return { error: e.message }; - } -}; diff --git a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/query-api.ts b/packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/query-api.ts deleted file mode 100644 index 66d11e6a5..000000000 --- a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/query-api.ts +++ /dev/null @@ -1,28 +0,0 @@ -'use server'; - -import { fetcher } from '@/graphql/fetcher'; -import { - Admin__Core_Plugins__Show__Quick, - Admin__Core_Plugins__Show__QuickQuery, - Admin__Core_Plugins__Show__QuickQueryVariables, -} from '@/graphql/queries/admin/languages/admin__core_plugins__show__quick.generated'; - -export const queryApi = async ( - variables: Admin__Core_Plugins__Show__QuickQueryVariables, -) => { - try { - const data = await fetcher< - Admin__Core_Plugins__Show__QuickQuery, - Admin__Core_Plugins__Show__QuickQueryVariables - >({ - query: Admin__Core_Plugins__Show__Quick, - variables, - }); - - return { data }; - } catch (error) { - const e = error as Error; - - return { error: e.message }; - } -}; diff --git a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/use-download-lang-admin.ts b/packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/use-download-lang-admin.ts deleted file mode 100644 index c14a60c38..000000000 --- a/packages/frontend/src/views/admin/views/core/langs/table/actions/download/hooks/use-download-lang-admin.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { useDialog } from '@/components/ui/dialog'; -import { ShowCoreLanguages } from '@/graphql/types'; -import { CONFIG } from '@/helpers/config-with-env'; -import { useSessionAdmin } from '@/hooks/use-session-admin'; -import { useQuery } from '@tanstack/react-query'; -import { useTranslations } from 'next-intl'; -import { toast } from 'sonner'; -import * as z from 'zod'; - -import { mutationApi } from './mutation-api'; -import { queryApi } from './query-api'; - -export const useDownloadLangAdmin = ({ - code, -}: Pick) => { - const t = useTranslations('core'); - const { setOpen } = useDialog(); - const { version } = useSessionAdmin(); - const queryPlugins = useQuery({ - queryKey: ['Admin__Core_Plugins__Show__Quick'], - queryFn: async () => { - const query = await queryApi({}); - - return query.data; - }, - }); - - // TODO: Add plugins from the backend - const plugins = [ - { id: 'core', name: 'Core', version, code: 'core' }, - { - id: 'admin', - name: 'Admin', - version, - code: 'admin', - }, - // ...edges, - ]; - - const formSchema = z - .object({ - all: z.boolean().default(true), - plugins: z - .array( - z.enum(plugins.map(plugin => plugin.code) as [string, ...string[]]), - ) - .default([]), - }) - .refine(data => { - if (data.all) { - return true; - } - - return data.plugins.length > 0; - }); - - const onSubmit = async (values: z.infer) => { - const mutation = await mutationApi({ - code, - plugins: values.all ? [] : values.plugins, - }); - - if (!mutation.data) { - toast.error(t('errors.title'), { - description: t('errors.internal_server_error'), - }); - - return; - } - - window.open( - `${CONFIG.backend_url}/files/${mutation.data.admin__core_languages__download}`, - '_blank', - ); - - setOpen?.(false); - }; - - return { onSubmit, queryPlugins, formSchema, plugins }; -}; From dd17d9f8ac55f6d6bfacf230e262ea2fa6195325 Mon Sep 17 00:00:00 2001 From: aXenDeveloper Date: Mon, 9 Sep 2024 17:29:33 +0200 Subject: [PATCH 2/2] perf: Remove Files status form plugin dev view in AdminCP --- apps/backend/schema.gql | 10 ---- apps/frontend/src/graphql/types.ts | 16 ----- apps/frontend/src/plugins/admin/langs/en.json | 10 ---- .../src/core/admin/plugins/files/files.dto.ts | 28 --------- .../admin/plugins/files/files.resolver.ts | 20 ------- .../core/admin/plugins/files/files.service.ts | 55 ----------------- .../src/core/admin/plugins/plugins.module.ts | 4 -- .../admin__core_plugins__files.generated.ts | 23 -------- .../dev/admin__core_plugins__files.gql | 10 ---- .../core/plugins/views/dev/files-view.tsx | 59 ------------------- .../core/plugins/views/dev/layout/layout.tsx | 3 - .../views/core/plugins/views/dev/slug.tsx | 2 - 12 files changed, 240 deletions(-) delete mode 100644 packages/backend/src/core/admin/plugins/files/files.dto.ts delete mode 100644 packages/backend/src/core/admin/plugins/files/files.resolver.ts delete mode 100644 packages/backend/src/core/admin/plugins/files/files.service.ts delete mode 100644 packages/frontend/src/graphql/queries/admin/plugins/dev/admin__core_plugins__files.generated.ts delete mode 100644 packages/frontend/src/graphql/queries/admin/plugins/dev/admin__core_plugins__files.gql delete mode 100644 packages/frontend/src/views/admin/views/core/plugins/views/dev/files-view.tsx diff --git a/apps/backend/schema.gql b/apps/backend/schema.gql index de5a5704f..087436ffe 100644 --- a/apps/backend/schema.gql +++ b/apps/backend/schema.gql @@ -138,15 +138,6 @@ enum EmailProvider { smtp } -type FilesAdminPluginsObj { - admin_pages: Int! - admin_templates: Int! - databases: Int! - default_page: Boolean! - pages: Int! - templates: Int! -} - type FilesAuthorizationCoreSessions { allow_upload: Boolean! max_storage_for_submit: Int! @@ -294,7 +285,6 @@ type Query { admin__core_manifest_metadata__show: ShowAdminManifestMetadataObj! admin__core_members__show(cursor: Int, first: Int, groups: [Int!], id: Float, last: Int, search: String, sortBy: ShowAdminMembersSortByArgs): ShowAdminMembersObj! admin__core_members__stats_sign_up: [SignUpStatsAdminMembers!]! - admin__core_plugins__files(code: String!): FilesAdminPluginsObj! admin__core_plugins__nav__show(plugin_code: String!): [ShowAdminNavPluginsObj!]! admin__core_plugins__show(code: String, cursor: Int, first: Int, last: Int, search: String, sortBy: ShowAdminPluginsSortByArgs): ShowAdminPluginsObj! admin__core_security__captcha__show: ShowAdminCaptchaSecurityObj! diff --git a/apps/frontend/src/graphql/types.ts b/apps/frontend/src/graphql/types.ts index 2734e02c8..dff204d78 100644 --- a/apps/frontend/src/graphql/types.ts +++ b/apps/frontend/src/graphql/types.ts @@ -161,16 +161,6 @@ export const EmailProvider = { } as const; export type EmailProvider = typeof EmailProvider[keyof typeof EmailProvider]; -export type FilesAdminPluginsObj = { - __typename?: 'FilesAdminPluginsObj'; - admin_pages: Scalars['Int']['output']; - admin_templates: Scalars['Int']['output']; - databases: Scalars['Int']['output']; - default_page: Scalars['Boolean']['output']; - pages: Scalars['Int']['output']; - templates: Scalars['Int']['output']; -}; - export type FilesAuthorizationCoreSessions = { __typename?: 'FilesAuthorizationCoreSessions'; allow_upload: Scalars['Boolean']['output']; @@ -660,7 +650,6 @@ export type Query = { admin__core_manifest_metadata__show: ShowAdminManifestMetadataObj; admin__core_members__show: ShowAdminMembersObj; admin__core_members__stats_sign_up: Array; - admin__core_plugins__files: FilesAdminPluginsObj; admin__core_plugins__nav__show: Array; admin__core_plugins__show: ShowAdminPluginsObj; admin__core_security__captcha__show: ShowAdminCaptchaSecurityObj; @@ -713,11 +702,6 @@ export type QueryAdmin__Core_Members__ShowArgs = { }; -export type QueryAdmin__Core_Plugins__FilesArgs = { - code: Scalars['String']['input']; -}; - - export type QueryAdmin__Core_Plugins__Nav__ShowArgs = { plugin_code: Scalars['String']['input']; }; diff --git a/apps/frontend/src/plugins/admin/langs/en.json b/apps/frontend/src/plugins/admin/langs/en.json index 57dcf7440..02fef5f60 100644 --- a/apps/frontend/src/plugins/admin/langs/en.json +++ b/apps/frontend/src/plugins/admin/langs/en.json @@ -222,16 +222,6 @@ "overview": { "title": "Overview" }, - "files": { - "title": "Files", - "databases": "Databases", - "admin_pages": "Admin Pages", - "admin_templates": "Admin Templates", - "pages": "Pages", - "templates": "Templates", - "default_page": "Default Page", - "file_detected": "{count, plural, =0 {No files} =1 {1 file} other {# files}} detected" - }, "nav": { "title": "Navigation in AdminCP", "lang_key": "Lang Key: ", diff --git a/packages/backend/src/core/admin/plugins/files/files.dto.ts b/packages/backend/src/core/admin/plugins/files/files.dto.ts deleted file mode 100644 index 9e00e42e1..000000000 --- a/packages/backend/src/core/admin/plugins/files/files.dto.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { ArgsType, Field, Int, ObjectType } from '@nestjs/graphql'; - -@ArgsType() -export class FilesAdminPluginsArgs { - @Field(() => String) - code: string; -} - -@ObjectType() -export class FilesAdminPluginsObj { - @Field(() => Int) - admin_pages: number; - - @Field(() => Int) - admin_templates: number; - - @Field(() => Int) - databases: number; - - @Field(() => Boolean) - default_page: boolean; - - @Field(() => Int) - pages: number; - - @Field(() => Int) - templates: number; -} diff --git a/packages/backend/src/core/admin/plugins/files/files.resolver.ts b/packages/backend/src/core/admin/plugins/files/files.resolver.ts deleted file mode 100644 index e68bf5356..000000000 --- a/packages/backend/src/core/admin/plugins/files/files.resolver.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { AdminAuthGuards, OnlyForDevelopment } from '@/utils'; -import { UseGuards } from '@nestjs/common'; -import { Args, Query, Resolver } from '@nestjs/graphql'; - -import { FilesAdminPluginsObj } from './files.dto'; -import { FilesAdminPluginsService } from './files.service'; - -@Resolver() -export class FilesAdminPluginsResolver { - constructor(private readonly service: FilesAdminPluginsService) {} - - @Query(() => FilesAdminPluginsObj) - @UseGuards(AdminAuthGuards) - @UseGuards(OnlyForDevelopment) - async admin__core_plugins__files( - @Args('code', { type: () => String }) code: string, - ): Promise { - return this.service.check({ code }); - } -} diff --git a/packages/backend/src/core/admin/plugins/files/files.service.ts b/packages/backend/src/core/admin/plugins/files/files.service.ts deleted file mode 100644 index 847c3e0eb..000000000 --- a/packages/backend/src/core/admin/plugins/files/files.service.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { NotFoundError } from '@/errors'; -import { InternalDatabaseService } from '@/utils/database/internal_database.service'; -import { Injectable } from '@nestjs/common'; -import * as fs from 'fs'; - -import { ABSOLUTE_PATHS_BACKEND } from '../../../..'; -import { FilesAdminPluginsObj } from './files.dto'; - -@Injectable() -export class FilesAdminPluginsService { - constructor(private readonly databaseService: InternalDatabaseService) {} - - protected async checkNumberOfFiles({ - paths, - }: { - paths: string; - }): Promise { - return fs.existsSync(paths) - ? (await fs.promises.readdir(paths, { recursive: true })).filter( - fileName => fileName.includes('.'), - ).length - : 0; - } - - async check({ code }: { code: string }): Promise { - const plugin = await this.databaseService.db.query.core_plugins.findFirst({ - where: (table, { eq }) => eq(table.code, code), - }); - - if (!plugin) { - throw new NotFoundError('Plugin'); - } - - const pluginPaths = ABSOLUTE_PATHS_BACKEND.plugin({ code }); - - return { - databases: await this.checkNumberOfFiles({ - paths: pluginPaths.database.schema, - }), - admin_pages: await this.checkNumberOfFiles({ - paths: pluginPaths.frontend.admin_pages, - }), - admin_templates: await this.checkNumberOfFiles({ - paths: pluginPaths.frontend.admin_templates, - }), - pages: await this.checkNumberOfFiles({ - paths: pluginPaths.frontend.pages, - }), - default_page: fs.existsSync(pluginPaths.frontend.default_page), - templates: await this.checkNumberOfFiles({ - paths: pluginPaths.frontend.templates, - }), - }; - } -} diff --git a/packages/backend/src/core/admin/plugins/plugins.module.ts b/packages/backend/src/core/admin/plugins/plugins.module.ts index 72749fc35..fea568b39 100644 --- a/packages/backend/src/core/admin/plugins/plugins.module.ts +++ b/packages/backend/src/core/admin/plugins/plugins.module.ts @@ -8,8 +8,6 @@ import { DownloadAdminPluginsResolver } from './download/download.resolver'; import { DownloadAdminPluginsService } from './download/download.service'; import { EditAdminPluginsResolver } from './edit/edit.resolver'; import { EditAdminPluginsService } from './edit/edit.service'; -import { FilesAdminPluginsResolver } from './files/files.resolver'; -import { FilesAdminPluginsService } from './files/files.service'; import { ChangeFilesAdminPluginsService } from './helpers/files/change/change.service'; import { CreateFilesAdminPluginsService } from './helpers/files/create/create-files.service'; import { AdminNavPluginsModule } from './nav/nav-plugins.module'; @@ -32,8 +30,6 @@ import { UploadAdminPluginsService } from './upload/upload.service'; DownloadAdminPluginsService, UploadAdminPluginsResolver, UploadAdminPluginsService, - FilesAdminPluginsService, - FilesAdminPluginsResolver, EditAdminPluginsResolver, EditAdminPluginsService, ], diff --git a/packages/frontend/src/graphql/queries/admin/plugins/dev/admin__core_plugins__files.generated.ts b/packages/frontend/src/graphql/queries/admin/plugins/dev/admin__core_plugins__files.generated.ts deleted file mode 100644 index 1503fd454..000000000 --- a/packages/frontend/src/graphql/queries/admin/plugins/dev/admin__core_plugins__files.generated.ts +++ /dev/null @@ -1,23 +0,0 @@ -import * as Types from '../../../../types'; - -import gql from 'graphql-tag'; -export type Admin__Core_Plugins__FilesQueryVariables = Types.Exact<{ - code: Types.Scalars['String']['input']; -}>; - - -export type Admin__Core_Plugins__FilesQuery = { __typename?: 'Query', admin__core_plugins__files: { __typename?: 'FilesAdminPluginsObj', admin_pages: number, admin_templates: number, databases: number, pages: number, templates: number, default_page: boolean } }; - - -export const Admin__Core_Plugins__Files = gql` - query Admin__core_plugins__files($code: String!) { - admin__core_plugins__files(code: $code) { - admin_pages - admin_templates - databases - pages - templates - default_page - } -} - `; \ No newline at end of file diff --git a/packages/frontend/src/graphql/queries/admin/plugins/dev/admin__core_plugins__files.gql b/packages/frontend/src/graphql/queries/admin/plugins/dev/admin__core_plugins__files.gql deleted file mode 100644 index f2866004d..000000000 --- a/packages/frontend/src/graphql/queries/admin/plugins/dev/admin__core_plugins__files.gql +++ /dev/null @@ -1,10 +0,0 @@ -query Admin__core_plugins__files($code: String!) { - admin__core_plugins__files(code: $code) { - admin_pages - admin_templates - databases - pages - templates - default_page - } -} diff --git a/packages/frontend/src/views/admin/views/core/plugins/views/dev/files-view.tsx b/packages/frontend/src/views/admin/views/core/plugins/views/dev/files-view.tsx deleted file mode 100644 index 315f2e1ec..000000000 --- a/packages/frontend/src/views/admin/views/core/plugins/views/dev/files-view.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import { fetcher } from '@/graphql/fetcher'; -import { - Admin__Core_Plugins__Files, - Admin__Core_Plugins__FilesQuery, - Admin__Core_Plugins__FilesQueryVariables, -} from '@/graphql/queries/admin/plugins/dev/admin__core_plugins__files.generated'; -import { cn } from '@/helpers/classnames'; -import { getTranslations } from 'next-intl/server'; - -const getData = async (variables: Admin__Core_Plugins__FilesQueryVariables) => { - const data = await fetcher< - Admin__Core_Plugins__FilesQuery, - Admin__Core_Plugins__FilesQueryVariables - >({ - query: Admin__Core_Plugins__Files, - variables, - }); - - return data; -}; - -export interface FilesDevPluginAdminViewProps { - params: { code: string }; -} - -export const FilesDevPluginAdminView = async ({ - params: { code }, -}: FilesDevPluginAdminViewProps) => { - const [data, t] = await Promise.all([ - getData({ code }), - getTranslations('admin.core.plugins.dev.files'), - ]); - - return ( -
    - {Object.entries(data.admin__core_plugins__files).map(item => ( -
  • - {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */} - {/* @ts-expect-error */} - {t(item[0])} - - - {t('file_detected', { count: +item[1] })} - -
  • - ))} -
- ); -}; diff --git a/packages/frontend/src/views/admin/views/core/plugins/views/dev/layout/layout.tsx b/packages/frontend/src/views/admin/views/core/plugins/views/dev/layout/layout.tsx index 2d692010d..0e0c196cd 100644 --- a/packages/frontend/src/views/admin/views/core/plugins/views/dev/layout/layout.tsx +++ b/packages/frontend/src/views/admin/views/core/plugins/views/dev/layout/layout.tsx @@ -120,9 +120,6 @@ export const DevPluginAdminLayout = async ({ > {t('overview.title')} - - {t('files.title')} - {t('nav.title')} diff --git a/packages/frontend/src/views/admin/views/core/plugins/views/dev/slug.tsx b/packages/frontend/src/views/admin/views/core/plugins/views/dev/slug.tsx index abea3c406..89aefff7c 100644 --- a/packages/frontend/src/views/admin/views/core/plugins/views/dev/slug.tsx +++ b/packages/frontend/src/views/admin/views/core/plugins/views/dev/slug.tsx @@ -1,7 +1,6 @@ import { SlugViewProps } from '@/views/slug'; import { notFound } from 'next/navigation'; -import { FilesDevPluginAdminView } from './files-view'; import { NavDevPluginAdminView } from './nav/nav'; import { OverviewDevPluginAdminView } from './overview'; @@ -19,7 +18,6 @@ export const SlugDevPluginsAdminView = (props: SlugDevPluginsAdminProps) => { if (!slug[1]) { if (slug[0] === 'overview') return ; - if (slug[0] === 'files') return ; if (slug[0] === 'nav') return ; }