-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(HeaderBar): add user account dropdown on header bar
Creates AccountDropdown as the menu list and AccountDropdownTrigger as the dropdown display. Adds accompanying typescript files. Closes DCOS-38940
- Loading branch information
1 parent
cbaf561
commit 84cd37e
Showing
11 changed files
with
190 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Component } from "react"; | ||
|
||
interface AccountDropdownProps { | ||
userName?: null | string; | ||
menuItems?: object; | ||
willAnchorRight?: boolean; | ||
} | ||
|
||
export default class AccountDropdown extends Component<AccountDropdownProps> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Dropdown } from "reactjs-components"; | ||
import React from "react"; | ||
|
||
import AuthStore from "#SRC/js/stores/AuthStore"; | ||
import AccountDropdownTrigger from "./AccountDropdownTrigger"; | ||
|
||
class AccountDropdown extends React.Component { | ||
constructor() { | ||
super(...arguments); | ||
this.userLabel = AuthStore.getUserLabel(); | ||
} | ||
|
||
getMenuItems() { | ||
const menuItems = [ | ||
{ | ||
className: "dropdown-menu-section-header", | ||
html: <label>{this.userLabel}</label>, | ||
id: "header-support", | ||
selectable: false | ||
}, | ||
{ | ||
html: "Sign Out", | ||
id: "sign-out", | ||
onClick: AuthStore.logout | ||
} | ||
]; | ||
|
||
return menuItems; | ||
} | ||
|
||
getTrigger() { | ||
return <AccountDropdownTrigger content={this.userLabel} />; | ||
} | ||
|
||
handleItemSelection(item) { | ||
if (item.onClick) { | ||
item.onClick(); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<Dropdown | ||
trigger={this.getTrigger()} | ||
dropdownMenuClassName="user-account-dropdown-menu dropdown-menu header-bar-dropdown-menu" | ||
dropdownMenuListClassName="user-account-dropdown-list dropdown-menu-list" | ||
items={this.getMenuItems()} | ||
onItemSelection={this.handleItemSelection} | ||
persistentID="dropdown-trigger" | ||
transition={true} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
module.exports = AccountDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import mixin from "reactjs-mixin"; | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
import { StoreMixin } from "mesosphere-shared-reactjs"; | ||
|
||
class AccountDropdownTrigger extends mixin(StoreMixin) { | ||
constructor() { | ||
super(...arguments); | ||
|
||
this.store_listeners = [ | ||
{ | ||
name: "metadata", | ||
events: ["success"], | ||
listenAlways: false | ||
} | ||
]; | ||
} | ||
|
||
componentDidUpdate() { | ||
if (this.props.onUpdate) { | ||
this.props.onUpdate(); | ||
} | ||
} | ||
|
||
render() { | ||
const { content, onTrigger } = this.props; | ||
|
||
// TODO: DCOS-38944 | ||
return ( | ||
<a className="header-bar-dropdown" onClick={onTrigger}> | ||
<span>{content}</span> | ||
</a> | ||
); | ||
} | ||
} | ||
|
||
AccountDropdownTrigger.propTypes = { | ||
content: PropTypes.string.isRequired, | ||
onUpdate: PropTypes.func, | ||
onTrigger: PropTypes.func | ||
}; | ||
|
||
module.exports = AccountDropdownTrigger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import GetSetBaseStore from "./GetSetBaseStore"; | ||
|
||
export default class AuthStore extends GetSetBaseStore { | ||
constructor(); | ||
static login: () => void; | ||
static logout(): void; | ||
static isLoggedIn: () => boolean; | ||
static getUser: () => null | object; | ||
static getUserLabel: () => null | string; | ||
processLoginSuccess: () => void; | ||
processLogoutSuccess: () => void; | ||
static storeID: () => string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { EventEmitter } from "events"; | ||
|
||
export default class BaseStore extends EventEmitter { | ||
addChangeListener: (eventName: string, callback: () => void) => void; | ||
removeChangeListener: (eventName: string, callback: () => void) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import BaseStore from "./BaseStore"; | ||
|
||
export default class GetSetBaseStore extends BaseStore { | ||
get: (key: string) => null | object; | ||
set: (data: object) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters