Skip to content

Commit 7c9d770

Browse files
authored
Merge pull request #723 from david-kalmakoff/issue-721
bug: fixed router navigating to homepage on page loads
2 parents b08b5ae + ad6fc49 commit 7c9d770

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

ui/src/CurrentUser.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class CurrentUser {
1515
@observable
1616
public loggedIn = false;
1717
@observable
18-
public authenticating = false;
18+
public authenticating = true;
1919
@observable
2020
public user: IUser = {name: 'unknown', admin: false, id: -1};
2121
@observable
@@ -80,17 +80,11 @@ export class CurrentUser {
8080
.then((resp: AxiosResponse<IClient>) => {
8181
this.snack(`A client named '${name}' was created for your session.`);
8282
this.setToken(resp.data.token);
83-
this.tryAuthenticate()
84-
.then(() => {
85-
this.authenticating = false;
86-
this.loggedIn = true;
87-
})
88-
.catch(() => {
89-
this.authenticating = false;
90-
console.log(
91-
'create client succeeded, but authenticated with given token failed'
92-
);
93-
});
83+
this.tryAuthenticate().catch(() => {
84+
console.log(
85+
'create client succeeded, but authenticated with given token failed'
86+
);
87+
});
9488
})
9589
.catch(() => {
9690
this.authenticating = false;
@@ -100,6 +94,7 @@ export class CurrentUser {
10094

10195
public tryAuthenticate = async (): Promise<AxiosResponse<IUser>> => {
10296
if (this.token() === '') {
97+
this.authenticating = false;
10398
return Promise.reject();
10499
}
105100

@@ -111,11 +106,13 @@ export class CurrentUser {
111106
.then((passThrough) => {
112107
this.user = passThrough.data;
113108
this.loggedIn = true;
109+
this.authenticating = false;
114110
this.connectionErrorMessage = null;
115111
this.reconnectTime = 7500;
116112
return passThrough;
117113
})
118114
.catch((error: AxiosError) => {
115+
this.authenticating = false;
119116
if (!error || !error.response) {
120117
this.connectionError('No network connection or server unavailable.');
121118
return Promise.reject(error);

ui/src/common/BaseStore.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export abstract class BaseStore<T extends HasID> implements IClearable {
3030
this.items = await this.requestItems().then((items) => items || []);
3131
};
3232

33+
@action
34+
public refreshIfMissing = async (id: number): Promise<void> => {
35+
if (this.getByIDOrUndefined(id) === undefined) {
36+
await this.refresh();
37+
}
38+
};
39+
3340
public getByID = (id: number): T => {
3441
const item = this.getByIDOrUndefined(id);
3542
if (item === undefined) {

ui/src/plugin/PluginDetailView.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as config from '../config';
1616
import Container from '../common/Container';
1717
import {inject, Stores} from '../inject';
1818
import {IPlugin} from '../types';
19+
import LoadingSpinner from '../common/LoadingSpinner';
1920

2021
type IProps = RouteComponentProps<{id: string}>;
2122

@@ -42,8 +43,9 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
4243
this.refreshFeatures();
4344
}
4445

45-
private refreshFeatures() {
46-
return Promise.all([this.refreshConfigurer(), this.refreshDisplayer()]);
46+
private async refreshFeatures() {
47+
await this.props.pluginStore.refreshIfMissing(this.pluginID);
48+
return await Promise.all([this.refreshConfigurer(), this.refreshDisplayer()]);
4749
}
4850

4951
private async refreshConfigurer() {
@@ -67,14 +69,16 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
6769
}
6870

6971
public render() {
70-
const pluginInfo = this.pluginInfo();
71-
const {name, capabilities} = pluginInfo;
72+
const pluginInfo = this.props.pluginStore.getByIDOrUndefined(this.pluginID);
73+
if (pluginInfo === undefined) {
74+
return <LoadingSpinner />;
75+
}
7276
return (
73-
<DefaultPage title={name} maxWidth={1000}>
77+
<DefaultPage title={pluginInfo.name} maxWidth={1000}>
7478
<PanelWrapper name={'Plugin Info'} icon={Info}>
7579
<PluginInfo pluginInfo={pluginInfo} />
7680
</PanelWrapper>
77-
{capabilities.indexOf('configurer') !== -1 ? (
81+
{pluginInfo.capabilities.indexOf('configurer') !== -1 ? (
7882
<PanelWrapper
7983
name={'Configurer'}
8084
description={'This is the configuration panel for this plugin.'}
@@ -94,7 +98,7 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
9498
/>
9599
</PanelWrapper>
96100
) : null}{' '}
97-
{capabilities.indexOf('displayer') !== -1 ? (
101+
{pluginInfo.capabilities.indexOf('displayer') !== -1 ? (
98102
<PanelWrapper
99103
name={'Displayer'}
100104
description={'This is the information generated by the plugin.'}

ui/src/tests/user.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const $dialog = selector.form('#add-edit-user-dialog');
2424

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

0 commit comments

Comments
 (0)