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

bug: fixed router navigating to homepage on page loads #723

Merged
merged 2 commits into from
Nov 6, 2024
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
21 changes: 9 additions & 12 deletions ui/src/CurrentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CurrentUser {
@observable
public loggedIn = false;
@observable
public authenticating = false;
public authenticating = true;
@observable
public user: IUser = {name: 'unknown', admin: false, id: -1};
@observable
Expand Down Expand Up @@ -80,17 +80,11 @@ export class CurrentUser {
.then((resp: AxiosResponse<IClient>) => {
this.snack(`A client named '${name}' was created for your session.`);
this.setToken(resp.data.token);
this.tryAuthenticate()
.then(() => {
this.authenticating = false;
this.loggedIn = true;
})
.catch(() => {
this.authenticating = false;
console.log(
'create client succeeded, but authenticated with given token failed'
);
});
this.tryAuthenticate().catch(() => {
console.log(
'create client succeeded, but authenticated with given token failed'
);
});
})
.catch(() => {
this.authenticating = false;
Expand All @@ -100,6 +94,7 @@ export class CurrentUser {

public tryAuthenticate = async (): Promise<AxiosResponse<IUser>> => {
Copy link
Member

Choose a reason for hiding this comment

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

The plugin detail page threw an exception because the plugin data wasn't loaded there.

if (this.token() === '') {
this.authenticating = false;
return Promise.reject();
}

Expand All @@ -111,11 +106,13 @@ export class CurrentUser {
.then((passThrough) => {
this.user = passThrough.data;
this.loggedIn = true;
this.authenticating = false;
this.connectionErrorMessage = null;
this.reconnectTime = 7500;
return passThrough;
})
.catch((error: AxiosError) => {
this.authenticating = false;
if (!error || !error.response) {
this.connectionError('No network connection or server unavailable.');
return Promise.reject(error);
Expand Down
7 changes: 7 additions & 0 deletions ui/src/common/BaseStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 11 additions & 7 deletions ui/src/plugin/PluginDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}>;

Expand All @@ -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() {
Expand All @@ -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.'}
Expand All @@ -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.'}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/tests/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const $dialog = selector.form('#add-edit-user-dialog');

describe('User', () => {
it('does login', async () => await auth.login(page));
it('navigates to users', async () => {
await page.click('#navigate-users');
it('navigates to users through window location', async () => {
await page.goto(gotify.url + '/#/users');
await waitForExists(page, selector.heading(), 'Users');
});
it('has changed url', async () => {
Expand Down
Loading