Adopt JS standards once userinfo data is in frontend (#1930)

This commit is contained in:
Severiano Badajoz
2020-10-16 11:59:28 -07:00
committed by GitHub
parent 242546371b
commit c9f9549118
7 changed files with 24 additions and 25 deletions
+4 -4
View File
@@ -43,12 +43,12 @@ async function configFetch(dispatch) {
async function userInfoFetch(dispatch) { async function userInfoFetch(dispatch) {
return fetchJson("userinfo").then((response) => { return fetchJson("userinfo").then((response) => {
const { userinfo } = response || {}; const { userinfo: userInfo } = response || {};
dispatch({ dispatch({
type: "userinfo load complete", type: "userInfo load complete",
userinfo, userInfo,
}); });
return userinfo; return userInfo;
}); });
} }
@@ -15,7 +15,7 @@ import {
idhash: state.config?.parameters?.["annotations-user-data-idhash"] ?? null, idhash: state.config?.parameters?.["annotations-user-data-idhash"] ?? null,
annotations: state.annotations, annotations: state.annotations,
auth: state.config?.authentication, auth: state.config?.authentication,
userinfo: state.userinfo, userInfo: state.userInfo,
writableCategoriesEnabled: state.config?.parameters?.annotations ?? false, writableCategoriesEnabled: state.config?.parameters?.annotations ?? false,
})) }))
class FilenameDialog extends React.Component { class FilenameDialog extends React.Component {
@@ -97,7 +97,7 @@ class FilenameDialog extends React.Component {
writableCategoriesEnabled, writableCategoriesEnabled,
annotations, annotations,
idhash, idhash,
userinfo, userInfo,
} = this.props; } = this.props;
const { filenameText } = this.state; const { filenameText } = this.state;
@@ -105,7 +105,7 @@ class FilenameDialog extends React.Component {
annotations.promptForFilename && annotations.promptForFilename &&
!annotations.dataCollectionNameIsReadOnly && !annotations.dataCollectionNameIsReadOnly &&
!annotations.dataCollectionName && !annotations.dataCollectionName &&
userinfo.is_authenticated ? ( userInfo.is_authenticated ? (
<Dialog <Dialog
icon="tag" icon="tag"
title="Annotations Collection" title="Annotations Collection"
+4 -4
View File
@@ -15,7 +15,7 @@ import actions from "../../actions";
writableCategoriesEnabled: state.config?.parameters?.annotations ?? false, writableCategoriesEnabled: state.config?.parameters?.annotations ?? false,
schema: state.annoMatrix?.schema, schema: state.annoMatrix?.schema,
ontology: state.ontology, ontology: state.ontology,
userinfo: state.userinfo, userInfo: state.userInfo,
})) }))
class Categories extends React.Component { class Categories extends React.Component {
constructor(props) { constructor(props) {
@@ -132,7 +132,7 @@ class Categories extends React.Component {
writableCategoriesEnabled, writableCategoriesEnabled,
schema, schema,
ontology, ontology,
userinfo, userInfo,
} = this.props; } = this.props;
const ontologyEnabled = ontology?.enabled ?? false; const ontologyEnabled = ontology?.enabled ?? false;
/* all names, sorted in display order. Will be rendered in this order */ /* all names, sorted in display order. Will be rendered in this order */
@@ -213,7 +213,7 @@ class Categories extends React.Component {
{writableCategoriesEnabled ? ( {writableCategoriesEnabled ? (
<Tooltip <Tooltip
content={ content={
userinfo.is_authenticated userInfo.is_authenticated
? "Create a new category" ? "Create a new category"
: "You must be logged in to create new categorical fields" : "You must be logged in to create new categorical fields"
} }
@@ -230,7 +230,7 @@ class Categories extends React.Component {
data-testid="open-annotation-dialog" data-testid="open-annotation-dialog"
onClick={this.handleEnableAnnoMode} onClick={this.handleEnableAnnoMode}
intent="primary" intent="primary"
disabled={!userinfo.is_authenticated} disabled={!userInfo.is_authenticated}
> >
Create new category Create new category
</AnchorButton> </AnchorButton>
+6 -6
View File
@@ -31,11 +31,11 @@ const LOGIN_PROMPT_OFF = "off";
const Auth = React.memo((props) => { const Auth = React.memo((props) => {
const [isPromptOpen, setIsPromptOpen] = useState(shouldShowPrompt()); const [isPromptOpen, setIsPromptOpen] = useState(shouldShowPrompt());
const { auth, userinfo } = props; const { auth, userInfo } = props;
const isAuthenticated = userinfo && userinfo.is_authenticated; const isAuthenticated = userInfo && userInfo.is_authenticated;
window.userinfo = userinfo; window.userInfo = userInfo;
const randomInt = Math.random() * 15; const randomInt = Math.random() * 15;
const sexIndex = Math.floor(randomInt / 5); const sexIndex = Math.floor(randomInt / 5);
@@ -55,7 +55,7 @@ const Auth = React.memo((props) => {
<Menu> <Menu>
<MenuItem <MenuItem
data-testid="user-email" data-testid="user-email"
text={`Logged in as: ${userinfo.email}`} text={`Logged in as: ${userInfo.email}`}
/> />
<MenuItem <MenuItem
data-testid="log-out" data-testid="log-out"
@@ -74,8 +74,8 @@ const Auth = React.memo((props) => {
style={{ padding: 0 }} style={{ padding: 0 }}
> >
{/* eslint-disable-next-line no-constant-condition -- disable profile picture until CSP is tweaked */} {/* eslint-disable-next-line no-constant-condition -- disable profile picture until CSP is tweaked */}
{userinfo?.picture && false ? ( {userInfo?.picture && false ? (
<img alt="profile" size="21px" src={userinfo?.picture} /> <img alt="profile" size="21px" src={userInfo?.picture} />
) : ( ) : (
<span style={{ fontSize: "18px" }}>{scientist}</span> <span style={{ fontSize: "18px" }}>{scientist}</span>
)} )}
+3 -3
View File
@@ -42,7 +42,7 @@ import { getEmbSubsetView } from "../../util/stateManager/viewStackHelpers";
celllist2: state.differential.celllist2, celllist2: state.differential.celllist2,
libraryVersions: state.config?.["library_versions"], libraryVersions: state.config?.["library_versions"],
auth: state.config?.authentication, auth: state.config?.authentication,
userinfo: state.userinfo, userInfo: state.userInfo,
undoDisabled: state["@@undoable/past"].length === 0, undoDisabled: state["@@undoable/past"].length === 0,
redoDisabled: state["@@undoable/future"].length === 0, redoDisabled: state["@@undoable/future"].length === 0,
aboutLink: state.config?.links?.["about-dataset"], aboutLink: state.config?.links?.["about-dataset"],
@@ -217,7 +217,7 @@ class MenuBar extends React.PureComponent {
subsetPossible, subsetPossible,
subsetResetPossible, subsetResetPossible,
enableReembedding, enableReembedding,
userinfo, userInfo,
auth, auth,
} = this.props; } = this.props;
const { pendingClipPercentiles } = this.state; const { pendingClipPercentiles } = this.state;
@@ -244,7 +244,7 @@ class MenuBar extends React.PureComponent {
zIndex: 3, zIndex: 3,
}} }}
> >
<AuthButtons auth={auth} userinfo={userinfo} /> <AuthButtons {...{ auth, userInfo }} />
<UndoRedoReset <UndoRedoReset
dispatch={dispatch} dispatch={dispatch}
undoDisabled={undoDisabled} undoDisabled={undoDisabled}
+2 -2
View File
@@ -4,7 +4,7 @@ import thunk from "redux-thunk";
import cascadeReducers from "./cascade"; import cascadeReducers from "./cascade";
import undoable from "./undoable"; import undoable from "./undoable";
import config from "./config"; import config from "./config";
import userinfo from "./userinfo"; import userInfo from "./userInfo";
import annoMatrix from "./annoMatrix"; import annoMatrix from "./annoMatrix";
import obsCrossfilter from "./obsCrossfilter"; import obsCrossfilter from "./obsCrossfilter";
import categoricalSelection from "./categoricalSelection"; import categoricalSelection from "./categoricalSelection";
@@ -43,7 +43,7 @@ const Reducer = undoable(
["pointDilation", pointDialation], ["pointDilation", pointDialation],
["reembedController", reembedController], ["reembedController", reembedController],
["autosave", autosave], ["autosave", autosave],
["userinfo", userinfo], ["userInfo", userInfo],
]), ]),
[ [
"annoMatrix", "annoMatrix",
@@ -1,4 +1,3 @@
// jshint esversion: 6
const UserInfo = (state = {}, action) => { const UserInfo = (state = {}, action) => {
switch (action.type) { switch (action.type) {
case "initial data load start": case "initial data load start":
@@ -7,12 +6,12 @@ const UserInfo = (state = {}, action) => {
loading: true, loading: true,
error: null, error: null,
}; };
case "userinfo load complete": case "userInfo load complete":
return { return {
...state, ...state,
loading: false, loading: false,
error: null, error: null,
...action.userinfo, ...action.userInfo,
}; };
case "initial data load error": case "initial data load error":
return { return {