Merge pull request #723 from david-kalmakoff/issue-721
bug: fixed router navigating to homepage on page loads
This commit is contained in:
commit
7c9d7706eb
|
|
@ -15,7 +15,7 @@ export class CurrentUser {
|
||||||
@observable
|
@observable
|
||||||
public loggedIn = false;
|
public loggedIn = false;
|
||||||
@observable
|
@observable
|
||||||
public authenticating = false;
|
public authenticating = true;
|
||||||
@observable
|
@observable
|
||||||
public user: IUser = {name: 'unknown', admin: false, id: -1};
|
public user: IUser = {name: 'unknown', admin: false, id: -1};
|
||||||
@observable
|
@observable
|
||||||
|
|
@ -80,13 +80,7 @@ export class CurrentUser {
|
||||||
.then((resp: AxiosResponse<IClient>) => {
|
.then((resp: AxiosResponse<IClient>) => {
|
||||||
this.snack(`A client named '${name}' was created for your session.`);
|
this.snack(`A client named '${name}' was created for your session.`);
|
||||||
this.setToken(resp.data.token);
|
this.setToken(resp.data.token);
|
||||||
this.tryAuthenticate()
|
this.tryAuthenticate().catch(() => {
|
||||||
.then(() => {
|
|
||||||
this.authenticating = false;
|
|
||||||
this.loggedIn = true;
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.authenticating = false;
|
|
||||||
console.log(
|
console.log(
|
||||||
'create client succeeded, but authenticated with given token failed'
|
'create client succeeded, but authenticated with given token failed'
|
||||||
);
|
);
|
||||||
|
|
@ -100,6 +94,7 @@ export class CurrentUser {
|
||||||
|
|
||||||
public tryAuthenticate = async (): Promise<AxiosResponse<IUser>> => {
|
public tryAuthenticate = async (): Promise<AxiosResponse<IUser>> => {
|
||||||
if (this.token() === '') {
|
if (this.token() === '') {
|
||||||
|
this.authenticating = false;
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,11 +106,13 @@ export class CurrentUser {
|
||||||
.then((passThrough) => {
|
.then((passThrough) => {
|
||||||
this.user = passThrough.data;
|
this.user = passThrough.data;
|
||||||
this.loggedIn = true;
|
this.loggedIn = true;
|
||||||
|
this.authenticating = false;
|
||||||
this.connectionErrorMessage = null;
|
this.connectionErrorMessage = null;
|
||||||
this.reconnectTime = 7500;
|
this.reconnectTime = 7500;
|
||||||
return passThrough;
|
return passThrough;
|
||||||
})
|
})
|
||||||
.catch((error: AxiosError) => {
|
.catch((error: AxiosError) => {
|
||||||
|
this.authenticating = false;
|
||||||
if (!error || !error.response) {
|
if (!error || !error.response) {
|
||||||
this.connectionError('No network connection or server unavailable.');
|
this.connectionError('No network connection or server unavailable.');
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,13 @@ export abstract class BaseStore<T extends HasID> implements IClearable {
|
||||||
this.items = await this.requestItems().then((items) => items || []);
|
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 => {
|
public getByID = (id: number): T => {
|
||||||
const item = this.getByIDOrUndefined(id);
|
const item = this.getByIDOrUndefined(id);
|
||||||
if (item === undefined) {
|
if (item === undefined) {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import * as config from '../config';
|
||||||
import Container from '../common/Container';
|
import Container from '../common/Container';
|
||||||
import {inject, Stores} from '../inject';
|
import {inject, Stores} from '../inject';
|
||||||
import {IPlugin} from '../types';
|
import {IPlugin} from '../types';
|
||||||
|
import LoadingSpinner from '../common/LoadingSpinner';
|
||||||
|
|
||||||
type IProps = RouteComponentProps<{id: string}>;
|
type IProps = RouteComponentProps<{id: string}>;
|
||||||
|
|
||||||
|
|
@ -42,8 +43,9 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
|
||||||
this.refreshFeatures();
|
this.refreshFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
private refreshFeatures() {
|
private async refreshFeatures() {
|
||||||
return Promise.all([this.refreshConfigurer(), this.refreshDisplayer()]);
|
await this.props.pluginStore.refreshIfMissing(this.pluginID);
|
||||||
|
return await Promise.all([this.refreshConfigurer(), this.refreshDisplayer()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async refreshConfigurer() {
|
private async refreshConfigurer() {
|
||||||
|
|
@ -67,14 +69,16 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const pluginInfo = this.pluginInfo();
|
const pluginInfo = this.props.pluginStore.getByIDOrUndefined(this.pluginID);
|
||||||
const {name, capabilities} = pluginInfo;
|
if (pluginInfo === undefined) {
|
||||||
|
return <LoadingSpinner />;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<DefaultPage title={name} maxWidth={1000}>
|
<DefaultPage title={pluginInfo.name} maxWidth={1000}>
|
||||||
<PanelWrapper name={'Plugin Info'} icon={Info}>
|
<PanelWrapper name={'Plugin Info'} icon={Info}>
|
||||||
<PluginInfo pluginInfo={pluginInfo} />
|
<PluginInfo pluginInfo={pluginInfo} />
|
||||||
</PanelWrapper>
|
</PanelWrapper>
|
||||||
{capabilities.indexOf('configurer') !== -1 ? (
|
{pluginInfo.capabilities.indexOf('configurer') !== -1 ? (
|
||||||
<PanelWrapper
|
<PanelWrapper
|
||||||
name={'Configurer'}
|
name={'Configurer'}
|
||||||
description={'This is the configuration panel for this plugin.'}
|
description={'This is the configuration panel for this plugin.'}
|
||||||
|
|
@ -94,7 +98,7 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
|
||||||
/>
|
/>
|
||||||
</PanelWrapper>
|
</PanelWrapper>
|
||||||
) : null}{' '}
|
) : null}{' '}
|
||||||
{capabilities.indexOf('displayer') !== -1 ? (
|
{pluginInfo.capabilities.indexOf('displayer') !== -1 ? (
|
||||||
<PanelWrapper
|
<PanelWrapper
|
||||||
name={'Displayer'}
|
name={'Displayer'}
|
||||||
description={'This is the information generated by the plugin.'}
|
description={'This is the information generated by the plugin.'}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ const $dialog = selector.form('#add-edit-user-dialog');
|
||||||
|
|
||||||
describe('User', () => {
|
describe('User', () => {
|
||||||
it('does login', async () => await auth.login(page));
|
it('does login', async () => await auth.login(page));
|
||||||
it('navigates to users', async () => {
|
it('navigates to users through window location', async () => {
|
||||||
await page.click('#navigate-users');
|
await page.goto(gotify.url + '/#/users');
|
||||||
await waitForExists(page, selector.heading(), 'Users');
|
await waitForExists(page, selector.heading(), 'Users');
|
||||||
});
|
});
|
||||||
it('has changed url', async () => {
|
it('has changed url', async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue