LiteSun commented on code in PR #2506:
URL: https://github.com/apache/apisix-dashboard/pull/2506#discussion_r926193851
##########
web/src/components/Plugin/service.ts:
##########
@@ -17,39 +17,49 @@
import { omit } from 'lodash';
import { request } from 'umi';
-import { PLUGIN_LIST, PluginType } from './data';
+import type { PluginItem } from './data';
+import { PLUGIN_LIST, PluginType, PluginState } from './data';
const cached: {
list: PluginComponent.Meta[];
} = {
list: [],
};
-export const fetchList = () => {
+export const fetchList = async ({ enablePluginList = {} } = {}) => {
+ let res: PluginItem[];
if (cached.list.length) {
- return Promise.resolve(cached.list);
- }
-
- return request<Res<PluginComponent.Meta[]>>('/plugins?all=true').then((data)
=> {
- const typedData = data.data.map((item) => ({
- ...item,
- type: PLUGIN_LIST[item.name]?.type || 'other',
- originType: item.type,
- hidden: PLUGIN_LIST[item.name]?.hidden || false,
- }));
+ res = cached.list;
+ } else {
+ res = await
request<Res<PluginComponent.Meta[]>>('/plugins?all=true').then((data) => {
+ const typedData = data.data.map((item) => ({
+ ...item,
+ type: PLUGIN_LIST[item.name]?.type || 'other',
+ originType: item.type,
+ hidden: PLUGIN_LIST[item.name]?.hidden || false,
+ }));
- let finalList: PluginComponent.Meta[] = [];
+ let finalList: PluginComponent.Meta[] = [];
- Object.values(PluginType).forEach((type) => {
- finalList = finalList.concat(typedData.filter((item) => item.type ===
type));
- });
+ Object.values(PluginType).forEach((type) => {
+ finalList = finalList.concat(typedData.filter((item) => item.type ===
type));
+ });
- if (cached.list.length === 0) {
- cached.list = finalList;
- }
+ if (cached.list.length === 0) {
+ cached.list = finalList;
+ }
- return finalList;
+ return finalList;
+ });
+ }
+ res.map((item) => {
Review Comment:
```suggestion
res.forEach((item) => {xxxx}
```
##########
web/src/components/Plugin/service.ts:
##########
@@ -17,39 +17,49 @@
import { omit } from 'lodash';
import { request } from 'umi';
-import { PLUGIN_LIST, PluginType } from './data';
+import type { PluginItem } from './data';
+import { PLUGIN_LIST, PluginType, PluginState } from './data';
const cached: {
list: PluginComponent.Meta[];
} = {
list: [],
};
-export const fetchList = () => {
+export const fetchList = async ({ enablePluginList = {} } = {}) => {
+ let res: PluginItem[];
if (cached.list.length) {
- return Promise.resolve(cached.list);
- }
-
- return request<Res<PluginComponent.Meta[]>>('/plugins?all=true').then((data)
=> {
- const typedData = data.data.map((item) => ({
- ...item,
- type: PLUGIN_LIST[item.name]?.type || 'other',
- originType: item.type,
- hidden: PLUGIN_LIST[item.name]?.hidden || false,
- }));
+ res = cached.list;
+ } else {
+ res = await
request<Res<PluginComponent.Meta[]>>('/plugins?all=true').then((data) => {
+ const typedData = data.data.map((item) => ({
+ ...item,
+ type: PLUGIN_LIST[item.name]?.type || 'other',
+ originType: item.type,
+ hidden: PLUGIN_LIST[item.name]?.hidden || false,
+ }));
- let finalList: PluginComponent.Meta[] = [];
+ let finalList: PluginComponent.Meta[] = [];
- Object.values(PluginType).forEach((type) => {
- finalList = finalList.concat(typedData.filter((item) => item.type ===
type));
- });
+ Object.values(PluginType).forEach((type) => {
+ finalList = finalList.concat(typedData.filter((item) => item.type ===
type));
+ });
- if (cached.list.length === 0) {
- cached.list = finalList;
- }
+ if (cached.list.length === 0) {
+ cached.list = finalList;
+ }
- return finalList;
+ return finalList;
+ });
+ }
+ res.map((item) => {
+ const isEnable = enablePluginList[item.name]?.disable === false;
+ // eslint-disable-next-line no-param-reassign
+ item.state = isEnable ? PluginState.enable : PluginState.disable;
+ return item;
Review Comment:
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]