Skip to content

Commit

Permalink
fix(FE): delete global plugin failed (#1170)
Browse files Browse the repository at this point in the history
* fix: delete global plugin failed

* fix: filter disable plugins
  • Loading branch information
LiteSun authored Dec 31, 2020
1 parent c0241ee commit 011634f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
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;
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();
});
}}
/>
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

0 comments on commit 011634f

Please sign in to comment.