From d35f67d2e16239b089448ba095dca548a7f5ab95 Mon Sep 17 00:00:00 2001
From: YANG QIA <2013xile@gmail.com>
Date: Mon, 22 May 2023 17:16:12 +0800
Subject: [PATCH] feat(app): add clear cache button (#1909)
---
.../src/acl/Configuration/RoleConfigure.tsx | 2 +-
packages/core/client/src/locale/zh_CN.ts | 3 +-
packages/core/client/src/user/CurrentUser.tsx | 61 +++++++++++--------
packages/plugins/client/src/server.ts | 6 +-
4 files changed, 42 insertions(+), 30 deletions(-)
diff --git a/packages/core/client/src/acl/Configuration/RoleConfigure.tsx b/packages/core/client/src/acl/Configuration/RoleConfigure.tsx
index c053ee9a3..9068d9025 100644
--- a/packages/core/client/src/acl/Configuration/RoleConfigure.tsx
+++ b/packages/core/client/src/acl/Configuration/RoleConfigure.tsx
@@ -45,7 +45,7 @@ const SnippetCheckboxGroup = connect((props) => {
{t('Allows to configure plugins')}
- {t('Allows to reboot application')}
+ {t('Allows to clear cache, reboot application')}
);
diff --git a/packages/core/client/src/locale/zh_CN.ts b/packages/core/client/src/locale/zh_CN.ts
index 17e7d2690..9b377d511 100644
--- a/packages/core/client/src/locale/zh_CN.ts
+++ b/packages/core/client/src/locale/zh_CN.ts
@@ -782,7 +782,8 @@ export default {
'The application is reloading, please do not close the page.': '应用正在重新加载,请勿关闭页面。',
'Application reloading': '应用重新加载中',
'Reboot Application': '重启应用',
- "Allows to reboot application": "允许重启应用",
+ "Allows to clear cache, reboot application": "允许清除缓存,重启应用",
'The will interrupt service, it may take a few seconds to restart. Are you sure to continue?': '重启将会中断当前服务,这个过程可能需要一点时间,确定要继续吗?',
'Reboot': '重启',
+ 'Clear cache': '清除缓存',
}
diff --git a/packages/core/client/src/user/CurrentUser.tsx b/packages/core/client/src/user/CurrentUser.tsx
index 04982ed69..5efa8db53 100644
--- a/packages/core/client/src/user/CurrentUser.tsx
+++ b/packages/core/client/src/user/CurrentUser.tsx
@@ -29,7 +29,7 @@ export const CurrentUser = () => {
const [visible, setVisible] = useState(false);
const { data } = useCurrentUserContext();
const { allowAll, snippets } = useACLRoleContext();
- const allowReboot = allowAll || snippets?.includes('app');
+ const appAllowed = allowAll || snippets?.includes('app');
const silenceApi = useAPIClient();
const check = async () => {
return await new Promise((resolve) => {
@@ -71,31 +71,42 @@ export const CurrentUser = () => {
- {allowReboot && (
- {
- Modal.confirm({
- title: t('Reboot Application'),
- content: t(
- 'The will interrupt service, it may take a few seconds to restart. Are you sure to continue?',
- ),
- okText: t('Reboot'),
- okButtonProps: {
- danger: true,
- },
- onOk: async () => {
- await api.resource('app').reboot();
- await check();
- window.location.reload();
- },
- });
- }}
- >
- {t('Reboot Application')}
-
+ {appAllowed && (
+ <>
+ {
+ await api.resource('app').clearCache();
+ window.location.reload();
+ }}
+ >
+ {t('Clear Cache')}
+
+ {
+ Modal.confirm({
+ title: t('Reboot Application'),
+ content: t(
+ 'The will interrupt service, it may take a few seconds to restart. Are you sure to continue?',
+ ),
+ okText: t('Reboot'),
+ okButtonProps: {
+ danger: true,
+ },
+ onOk: async () => {
+ await api.resource('app').reboot();
+ await check();
+ window.location.reload();
+ },
+ });
+ }}
+ >
+ {t('Reboot Application')}
+
+
+ >
)}
-
{
diff --git a/packages/plugins/client/src/server.ts b/packages/plugins/client/src/server.ts
index 998f4b766..2f3ec7021 100644
--- a/packages/plugins/client/src/server.ts
+++ b/packages/plugins/client/src/server.ts
@@ -96,7 +96,7 @@ export class ClientPlugin extends Plugin {
this.app.acl.allow('plugins', '*', 'public');
this.app.acl.registerSnippet({
name: 'app',
- actions: ['app:reload', 'app:reboot'],
+ actions: ['app:reboot', 'app:clearCache'],
});
const dialect = this.app.db.sequelize.getDialect();
const locales = require('./locale').default;
@@ -171,8 +171,8 @@ export class ClientPlugin extends Plugin {
.map((item) => item.name);
await next();
},
- async reload(ctx, next) {
- await ctx.app.reload();
+ async clearCache(ctx, next) {
+ await ctx.cache.reset();
await next();
},
reboot(ctx) {