fix: loading plugin detail view by url

This commit is contained in:
Jannis Mattheis 2024-11-06 18:09:48 +01:00
parent 13d59eb04d
commit ad6fc49515
2 changed files with 18 additions and 7 deletions

View File

@ -30,6 +30,13 @@ export abstract class BaseStore<T extends HasID> implements IClearable {
this.items = await this.requestItems().then((items) => items || []);
};
@action
public refreshIfMissing = async (id: number): Promise<void> => {
if (this.getByIDOrUndefined(id) === undefined) {
await this.refresh();
}
};
public getByID = (id: number): T => {
const item = this.getByIDOrUndefined(id);
if (item === undefined) {

View File

@ -16,6 +16,7 @@ import * as config from '../config';
import Container from '../common/Container';
import {inject, Stores} from '../inject';
import {IPlugin} from '../types';
import LoadingSpinner from '../common/LoadingSpinner';
type IProps = RouteComponentProps<{id: string}>;
@ -42,8 +43,9 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
this.refreshFeatures();
}
private refreshFeatures() {
return Promise.all([this.refreshConfigurer(), this.refreshDisplayer()]);
private async refreshFeatures() {
await this.props.pluginStore.refreshIfMissing(this.pluginID);
return await Promise.all([this.refreshConfigurer(), this.refreshDisplayer()]);
}
private async refreshConfigurer() {
@ -67,14 +69,16 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
}
public render() {
const pluginInfo = this.pluginInfo();
const {name, capabilities} = pluginInfo;
const pluginInfo = this.props.pluginStore.getByIDOrUndefined(this.pluginID);
if (pluginInfo === undefined) {
return <LoadingSpinner />;
}
return (
<DefaultPage title={name} maxWidth={1000}>
<DefaultPage title={pluginInfo.name} maxWidth={1000}>
<PanelWrapper name={'Plugin Info'} icon={Info}>
<PluginInfo pluginInfo={pluginInfo} />
</PanelWrapper>
{capabilities.indexOf('configurer') !== -1 ? (
{pluginInfo.capabilities.indexOf('configurer') !== -1 ? (
<PanelWrapper
name={'Configurer'}
description={'This is the configuration panel for this plugin.'}
@ -94,7 +98,7 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
/>
</PanelWrapper>
) : null}{' '}
{capabilities.indexOf('displayer') !== -1 ? (
{pluginInfo.capabilities.indexOf('displayer') !== -1 ? (
<PanelWrapper
name={'Displayer'}
description={'This is the information generated by the plugin.'}