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

Update DefaultPage to be more general and add refresh button in web UI #233

Merged
merged 7 commits into from Oct 19, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions ui/src/application/Applications.tsx
Expand Up @@ -13,6 +13,7 @@ import CloudUpload from '@material-ui/icons/CloudUpload';
import React, {ChangeEvent, Component, SFC} from 'react';
import ConfirmDialog from '../common/ConfirmDialog';
import DefaultPage from '../common/DefaultPage';
import Button from '@material-ui/core/Button';
import ToggleVisibility from '../common/ToggleVisibility';
import AddApplicationDialog from './AddApplicationDialog';
import {observer} from 'mobx-react';
Expand Down Expand Up @@ -47,10 +48,16 @@ class Applications extends Component<Stores<'appStore'>> {
return (
<DefaultPage
title="Applications"
buttonTitle="Create Application"
buttonId="create-app"
maxWidth={1000}
fButton={() => (this.createDialog = true)}>
rightControl={
<Button
id="create-app"
variant="contained"
color="primary"
onClick={() => (this.createDialog = true)}>
Create Application
</Button>
}
maxWidth={1000}>
<Grid item xs={12}>
<Paper elevation={6}>
<Table id="app-table">
Expand Down
13 changes: 10 additions & 3 deletions ui/src/client/Clients.tsx
Expand Up @@ -11,6 +11,7 @@ import Edit from '@material-ui/icons/Edit';
import React, {Component, SFC} from 'react';
import ConfirmDialog from '../common/ConfirmDialog';
import DefaultPage from '../common/DefaultPage';
import Button from '@material-ui/core/Button';
import ToggleVisibility from '../common/ToggleVisibility';
import AddClientDialog from './AddClientDialog';
import UpdateDialog from './UpdateClientDialog';
Expand Down Expand Up @@ -42,9 +43,15 @@ class Clients extends Component<Stores<'clientStore'>> {
return (
<DefaultPage
title="Clients"
buttonTitle="Create Client"
buttonId="create-client"
fButton={() => (this.showDialog = true)}>
rightControl={
<Button
id="create-client"
variant="contained"
color="primary"
onClick={() => (this.showDialog = true)}>
Create Client
</Button>
}>
<Grid item xs={12}>
<Paper elevation={6}>
<Table id="client-table">
Expand Down
29 changes: 3 additions & 26 deletions ui/src/common/DefaultPage.tsx
@@ -1,44 +1,21 @@
import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';
import Typography from '@material-ui/core/Typography';
import React, {SFC} from 'react';

interface IProps {
title: string;
buttonTitle?: string;
fButton?: VoidFunction;
buttonDisabled?: boolean;
rightControl?: React.ReactNode;
maxWidth?: number;
hideButton?: boolean;
buttonId?: string;
}

const DefaultPage: SFC<IProps> = ({
title,
buttonTitle,
buttonId,
fButton,
buttonDisabled = false,
maxWidth = 700,
hideButton,
children,
}) => (
const DefaultPage: SFC<IProps> = ({title, rightControl, maxWidth = 700, children}) => (
<main style={{margin: '0 auto', maxWidth}}>
<Grid container spacing={4}>
<Grid item xs={12} style={{display: 'flex'}}>
<Typography variant="h4" style={{flex: 1}}>
{title}
</Typography>
{hideButton ? null : (
<Button
id={buttonId}
variant="contained"
color="primary"
disabled={buttonDisabled}
onClick={fButton}>
{buttonTitle}
</Button>
)}
{rightControl}
</Grid>
{children}
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/common/LoadingSpinner.tsx
Expand Up @@ -5,7 +5,7 @@ import DefaultPage from './DefaultPage';

export default function LoadingSpinner() {
return (
<DefaultPage title="" maxWidth={250} hideButton={true}>
<DefaultPage title="" maxWidth={250}>
<Grid item xs={12} style={{textAlign: 'center'}}>
<CircularProgress size={150} />
</Grid>
Expand Down
26 changes: 22 additions & 4 deletions ui/src/message/Messages.tsx
Expand Up @@ -4,6 +4,7 @@ import Typography from '@material-ui/core/Typography';
import React, {Component} from 'react';
import {RouteComponentProps} from 'react-router';
import DefaultPage from '../common/DefaultPage';
import Button from '@material-ui/core/Button';
import Message from './Message';
import {observer} from 'mobx-react';
import {inject, Stores} from '../inject';
Expand Down Expand Up @@ -61,10 +62,27 @@ class Messages extends Component<IProps & Stores<'messagesStore' | 'appStore'>,
return (
<DefaultPage
title={name}
buttonTitle="Delete All"
buttonId="delete-all"
fButton={() => messagesStore.removeByApp(appId)}
buttonDisabled={!hasMessages}>
rightControl={
<div>
<Button
id="refresh-all"
variant="contained"
disabled={!hasMessages}
color="primary"
onClick={() => messagesStore.refreshByApp(appId)}
style={{marginRight: 5}}>
Refresh
</Button>
<Button
id="delete-all"
variant="contained"
disabled={!hasMessages}
color="primary"
onClick={() => messagesStore.removeByApp(appId)}>
Delete All
</Button>
</div>
}>
{hasMessages ? (
<div style={{width: '100%'}} id="messages">
<ReactInfinite
Expand Down
6 changes: 6 additions & 0 deletions ui/src/message/MessagesStore.ts
Expand Up @@ -100,6 +100,12 @@ export class MessagesStore {
this.createEmptyStatesForApps(this.appStore.getItems());
};

@action
public refreshByApp = async (appId: number) => {
this.clearAll();
this.loadMore(appId);
};

public exists = (id: number) => this.stateOf(id).loaded;

private removeFromList(messages: IMessage[], messageToDelete: IMessage): false | number {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/plugin/PluginDetailView.tsx
Expand Up @@ -70,7 +70,7 @@ class PluginDetailView extends Component<IProps & Stores<'pluginStore'>, IState>
const pluginInfo = this.pluginInfo();
const {name, capabilities} = pluginInfo;
return (
<DefaultPage title={name} hideButton={true} maxWidth={1000}>
<DefaultPage title={name} maxWidth={1000}>
<PanelWrapper name={'Plugin Info'} icon={Info}>
<PluginInfo pluginInfo={pluginInfo} />
</PanelWrapper>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/plugin/Plugins.tsx
Expand Up @@ -25,7 +25,7 @@ class Plugins extends Component<Stores<'pluginStore'>> {
} = this;
const plugins = pluginStore.getItems();
return (
<DefaultPage title="Plugins" hideButton={true} maxWidth={1000}>
<DefaultPage title="Plugins" maxWidth={1000}>
<Grid item xs={12}>
<Paper elevation={6}>
<Table id="plugin-table">
Expand Down
2 changes: 1 addition & 1 deletion ui/src/user/Login.tsx
Expand Up @@ -18,7 +18,7 @@ class Login extends Component<Stores<'currentUser'>> {
public render() {
const {username, password} = this;
return (
<DefaultPage title="Login" maxWidth={250} hideButton={true}>
<DefaultPage title="Login" maxWidth={250}>
<Grid item xs={12} style={{textAlign: 'center'}}>
<Container>
<form onSubmit={this.preventDefault} id="login-form">
Expand Down
13 changes: 10 additions & 3 deletions ui/src/user/Users.tsx
Expand Up @@ -12,6 +12,7 @@ import Edit from '@material-ui/icons/Edit';
import React, {Component, SFC} from 'react';
import ConfirmDialog from '../common/ConfirmDialog';
import DefaultPage from '../common/DefaultPage';
import Button from '@material-ui/core/Button';
import AddEditDialog from './AddEditUserDialog';
import {observer} from 'mobx-react';
import {observable} from 'mobx';
Expand Down Expand Up @@ -69,9 +70,15 @@ class Users extends Component<WithStyles<'wrapper'> & Stores<'userStore'>> {
return (
<DefaultPage
title="Users"
buttonTitle="Create User"
buttonId="create-user"
fButton={() => (this.createDialog = true)}>
rightControl={
<Button
id="create-user"
variant="contained"
color="primary"
onClick={() => (this.createDialog = true)}>
Create User
</Button>
}>
<Grid item xs={12}>
<Paper elevation={6}>
<Table id="user-table">
Expand Down