Skip to content

Commit 1b027a9

Browse files
committed
Login dialog upgrades;
Expand / Collapse TextArea fields on EditRowDialog; Fix for live reload data on EditRowDialog when data is updated on server
1 parent ead4fe8 commit 1b027a9

File tree

5 files changed

+76
-17
lines changed

5 files changed

+76
-17
lines changed

src/components/BrowserMenu/BrowserMenu.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@
111111

112112
&.active {
113113
background: $blue;
114+
115+
&:hover {
116+
background: white;
117+
color: $blue;
118+
}
119+
}
120+
121+
&.greenActive {
122+
background: $green;
123+
124+
&:hover {
125+
background: white;
126+
color: $blue;
127+
}
114128
}
115129
}
116130

src/components/BrowserMenu/MenuItem.react.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
import React from 'react';
99
import styles from 'components/BrowserMenu/BrowserMenu.scss';
1010

11-
let MenuItem = ({ text, disabled, active, onClick }) => {
11+
let MenuItem = ({ text, disabled, active, greenActive, onClick }) => {
1212
let classes = [styles.item];
1313
if (disabled) {
1414
classes.push(styles.disabled);
1515
}
1616
if (active) {
1717
classes.push(styles.active);
1818
}
19+
if (greenActive) {
20+
classes.push(styles.greenActive);
21+
}
1922
return <div className={classes.join(' ')} onClick={disabled ? undefined : onClick}>{text}</div>;
2023
};
2124

src/dashboard/Data/Browser/Browser.react.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class Browser extends DashboardView {
8181
uniqueField: null,
8282

8383
useMasterKey: true,
84+
currentUser: Parse.User.current()
8485
};
8586

8687
this.prefetchData = this.prefetchData.bind(this);
@@ -248,8 +249,12 @@ class Browser extends DashboardView {
248249
if (!!Parse.User.current()) {
249250
Parse.User.logOut();
250251
}
251-
const currentUser = await Parse.User.logIn(username, password);
252-
this.setState({ currentUser: currentUser, useMasterKey: false }, () => this.refresh());
252+
try {
253+
const currentUser = await Parse.User.logIn(username, password);
254+
this.setState({ currentUser: currentUser, useMasterKey: false }, () => this.refresh());
255+
} catch (error) {
256+
throw error;
257+
}
253258
}
254259

255260
async logout() {

src/dashboard/Data/Browser/BrowserToolbar.react.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ let BrowserToolbar = ({
270270
<MenuItem text={'Class Level Permissions'} onClick={showCLP} />
271271
<MenuItem text={'Protected Fields'} onClick={showProtected} />
272272
<Separator />
273-
<MenuItem text={'Test ACL - Login'} onClick={showLogin} active={!!currentUser} />
274-
{currentUser ? <MenuItem text={'Use Master Key'} onClick={toggleMasterKeyUsage} active={useMasterKey} /> : <noscript />}
273+
<MenuItem text={currentUser ? 'Switch Parse.User' : 'Browse as Parse.User'} onClick={showLogin} active={!!currentUser} />
274+
{currentUser ? <MenuItem text={useMasterKey ? <span>Browsing with <b>Master Key</b></span> : <span>Browse with <s>Master Key</s></span>} onClick={toggleMasterKeyUsage} active={!!currentUser} greenActive={useMasterKey} /> : <noscript />}
275+
{currentUser ? <MenuItem text={<span>Logout (<b>{currentUser.get("username")}</b>)</span>} onClick={logout} active={!!currentUser} /> : <noscript />}
275276
</BrowserMenu>
276277
) : (
277278
<noscript />

src/dashboard/Data/Browser/LoginDialog.react.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ import React from "react";
22
import ParseApp from "lib/ParseApp";
33
import PropTypes from "prop-types";
44
import Modal from "components/Modal/Modal.react";
5-
import Button from "components/Button/Button.react";
65
import LoginRow from "components/LoginRow/LoginRow.react";
6+
import Notification from "dashboard/Data/Browser/Notification.react";
77

88
export default class LoginDialog extends React.Component {
99
constructor(props) {
1010
super(props);
1111
this.state = {
1212
open: false,
1313
username: "",
14-
password: "",
14+
password: ""
1515
};
1616

1717
this.handleOpen = this.handleOpen.bind(this);
1818
this.handleClose = this.handleClose.bind(this);
1919
this.login = this.login.bind(this);
20+
this.handleKeyDown = this.handleKeyDown.bind(this);
2021
}
2122

2223
handleOpen() {
@@ -27,27 +28,45 @@ export default class LoginDialog extends React.Component {
2728
this.setState({ open: false });
2829
}
2930

30-
login() {
31+
async login() {
3132
const { username, password } = this.state;
32-
this.props.login(username, password);
33-
this.handleClose();
33+
if (!!username && !!password) {
34+
try {
35+
await this.props.login(username, password);
36+
this.handleClose();
37+
} catch (error) {
38+
this.setState({ error: error.message });
39+
setTimeout(() => {
40+
this.setState({ error: null });
41+
}, 3500);
42+
}
43+
}
44+
}
45+
46+
handleKeyDown(event) {
47+
// Number 13 is the "Enter" key on the keyboard
48+
if (event.keyCode === 13) {
49+
// Cancel the default action, if needed
50+
event.preventDefault();
51+
// Trigger the button element with a click
52+
this.login();
53+
}
3454
}
3555

3656
render() {
37-
const { currentUser, logout } = this.props;
38-
const { open, username, password } = this.state;
57+
const { currentUser } = this.props;
58+
const { open } = this.state;
3959

4060
return (
4161
open && (
4262
<Modal
4363
type={Modal.Types.INFO}
44-
title="Test ACL"
64+
title={currentUser ? "Switch Parse.User" : "Login as Parse.User"}
4565
subtitle={
4666
<div style={{ paddingTop: "5px" }}>
4767
{currentUser && (
4868
<p>
49-
Logged in as <strong>{currentUser.get("username")}</strong>{" "}
50-
<Button value={"Logout"} color="white" onClick={logout} />
69+
Logged in as <strong>{currentUser.get("username")}</strong>
5170
</p>
5271
)}
5372
</div>
@@ -59,12 +78,29 @@ export default class LoginDialog extends React.Component {
5978
>
6079
<LoginRow
6180
label="Username"
62-
input={<input onChange={e => this.setState({username: e.nativeEvent.target.value})} />}
81+
input={
82+
<input
83+
onChange={e =>
84+
this.setState({ username: e.nativeEvent.target.value })
85+
}
86+
onKeyDown={this.handleKeyDown}
87+
autoFocus
88+
/>
89+
}
6390
/>
6491
<LoginRow
6592
label="Password"
66-
input={<input onChange={e => this.setState({password: e.nativeEvent.target.value})} type="password" />}
93+
input={
94+
<input
95+
onChange={e =>
96+
this.setState({ password: e.nativeEvent.target.value })
97+
}
98+
type="password"
99+
onKeyDown={this.handleKeyDown}
100+
/>
101+
}
67102
/>
103+
<Notification note={this.state.error} isErrorNote={true} />
68104
</Modal>
69105
)
70106
);

0 commit comments

Comments
 (0)