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): delete global plugin failed #1170

Merged
merged 2 commits into from
Dec 31, 2020
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
24 changes: 15 additions & 9 deletions web/src/pages/Plugin/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ const Page: React.FC = () => {
const [name, setName] = useState('');

useEffect(() => {
fetchList().then(({ data }) => {
const plugins: any = {};
// eslint-disable-next-line no-shadow
data.forEach(({ name, value }) => {
plugins[name] = value;
if (!name) {
fetchList().then(({ data }) => {
const plugins: any = {};
// eslint-disable-next-line no-shadow
data.forEach(({ name, value }) => {
plugins[name] = value;
});
setInitialData(plugins);
});
setInitialData(plugins);
});
}, []);
}
}, [name]);

const columns: ProColumns<PluginModule.TransformedPlugin>[] = [
{
Expand Down Expand Up @@ -72,6 +74,7 @@ const Page: React.FC = () => {
const plugins = omit(initialData, [`${record.name}`]);
createOrUpdate({ plugins }).then(() => {
ref.current?.reload();
setName('');
});
}}
okText={formatMessage({ id: 'component.global.confirm' })}
Expand Down Expand Up @@ -99,13 +102,16 @@ const Page: React.FC = () => {
setVisible(false);
}}
onChange={({ formData, codemirrorData }) => {
const disable = !formData.disable;
Copy link
Member

Choose a reason for hiding this comment

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

Switcher

createOrUpdate({
plugins: {
...initialData,
[name]: { ...codemirrorData, ...formData },
[name]: { ...codemirrorData, disable },
},
}).then(() => {
setVisible(false);
setName('');
ref.current?.reload();
});
}}
/>
Expand Down
9 changes: 6 additions & 3 deletions web/src/pages/Plugin/PluginMarket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ import { fetchList, createOrUpdate } from './service';
const PluginMarket: React.FC = () => {
const [initialData, setInitialData] = useState({});

useEffect(() => {
const initPageData = () => {
fetchList().then(({ data }) => {
const plugins: any = {};
data.forEach(({ name, value }) => {
plugins[name] = value;
});
setInitialData(plugins);
});
}

useEffect(() => {
initPageData();
}, []);

return (
Expand All @@ -48,8 +52,7 @@ const PluginMarket: React.FC = () => {
...pluginsData,
},
}).then(() => {
// TODO:
window.location.reload();
initPageData();
Copy link
Member

Choose a reason for hiding this comment

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

then(initPageData)

});
}}
/>
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/Plugin/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export const fetchList = (): Promise<{
}> =>
request<{
data: {
plugins: Record<string, object>;
plugins: Record<string, any>;
};
}>(`/global_rules/${DEFAULT_GLOBAL_RULE_ID}`).then(({ data }) => {
const plugins = Object.entries(data.plugins || {}).map(([name, value]) => ({
const plugins = Object.entries(data.plugins || {}).filter(([, value]) => !value.disable).map(([name, value]) => ({
id: name,
name,
value,
Expand Down