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

fix(FE): Redirect plugin should not show in route step3 #1276

Merged
merged 6 commits into from
Jan 13, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ context('Create and Delete Route', () => {
// go to step3
cy.contains('Next').click();

// redirect plugin should not display in route step3
const nameSelector = '[data-cy-plugin-name]';
cy.get(nameSelector).then((cards) => {
[...cards].forEach(card => {
expect(card.innerText).to.not.equal('redirect')
});
});

// config prometheus plugin
cy.contains('.ant-card', 'prometheus').within(() => {
cy.get('button').first().click();
Expand Down
8 changes: 5 additions & 3 deletions web/src/components/Plugin/PluginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import { orderBy } from 'lodash';

import PluginDetail from './PluginDetail';
import { fetchList } from './service';
import { PLUGIN_ICON_LIST } from './data'
import { PLUGIN_ICON_LIST, PLUGIN_FILTER_LIST } from './data'
import defaultPluginImg from '../../../public/static/default-plugin.png';

type Props = {
readonly?: boolean;
type?: 'global' | 'scoped';
initialData?: PluginComponent.Data;
schemaType?: PluginComponent.Schema;
referPage?: PluginComponent.ReferPage;
onChange?: (data: PluginComponent.Data) => void;
};

Expand All @@ -49,6 +50,7 @@ const PluginPage: React.FC<Props> = ({
readonly = false,
initialData = {},
schemaType = 'route',
referPage = '',
type = 'scoped',
onChange = () => { },
}) => {
Expand All @@ -59,8 +61,8 @@ const PluginPage: React.FC<Props> = ({
const firstUpperCase = ([first, ...rest]: string) => first.toUpperCase() + rest.join('');
useEffect(() => {
fetchList().then((data) => {
setPluginList(data);

const filteredData = data.filter((item) => !(PLUGIN_FILTER_LIST[item.name] && PLUGIN_FILTER_LIST[item.name].list.includes(referPage)));
setPluginList(filteredData);
const categoryList: string[] = [];
data.forEach((item) => {
if (!categoryList.includes(firstUpperCase(item.type))) {
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/Plugin/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ export const PLUGIN_ICON_LIST: Record<string, any> = {
'openid-connect': <IconFont name="iconicons8-openid" />,
'kafka-logger': <IconFont name="iconApache_kafka" />,
};

// This list is used to filter out plugins that cannot be displayed in the plugins list.
export const PLUGIN_FILTER_LIST: Record<string, { list: PluginComponent.ReferPage[] }> =
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
{
redirect: { list: ['route'] } // Filter out the redirect plugin on the route page.
}
4 changes: 3 additions & 1 deletion web/src/components/Plugin/typing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
declare namespace PluginComponent {
type Data = object;

type Schema = '' | 'route' | 'consumer' | 'service';
type Schema = '' | 'route' | 'consumer';

type Meta = {
name: string;
Expand All @@ -27,4 +27,6 @@ declare namespace PluginComponent {
version: number;
consumer_schema?: object;
};

type ReferPage = '' | 'route' | 'consumer' | 'service' | 'plugin'
}
1 change: 1 addition & 0 deletions web/src/pages/Route/components/Step3/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const Page: React.FC<Props> = ({ data, onChange, readonly = false, isForceHttps
<PluginPage
initialData={plugins}
schemaType="route"
referPage='route'
onChange={(pluginsData) => onChange({ plugins: pluginsData, script: {} })}
/>
)}
Expand Down