Skip to content

Commit

Permalink
Added links to and from settings (#306)
Browse files Browse the repository at this point in the history
* Added link to the settings in the header bar

Also, using `user.allow` instead of readOnly.

* display name in menu

* nicer hover

* Added a bunch of small things

See checklist in https://trello.com/c/sS70K4RU/25-settings-view

* Side-drawer now has a viewType prop instead of several others
  • Loading branch information
lorem--ipsum authored and vogievetsky committed Jul 27, 2016
1 parent 33b9f20 commit f559fb9
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 53 deletions.
4 changes: 0 additions & 4 deletions .idea/runConfigurations/Run.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/client/components/cube-header-bar/cube-header-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,12 @@ export class CubeHeaderBar extends React.Component<CubeHeaderBarProps, CubeHeade
}

renderSettingsMenu() {
const { changeTimezone, timezone, customization } = this.props;
const { changeTimezone, timezone, customization, essence } = this.props;
const { settingsMenuOpen } = this.state;
if (!settingsMenuOpen) return null;

return <SettingsMenu
dataCube={essence.dataCube}
timezone={timezone}
timezones={customization.getTimezones()}
changeTimezone={changeTimezone}
Expand Down
9 changes: 5 additions & 4 deletions src/client/components/form-label/form-label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
background: rgba($brand, .22);
cursor: pointer;

&:hover {
background: rgba($brand, .3);
}

&:hover,
&.visible {
background: $brand;

Expand All @@ -47,6 +44,10 @@
}
}

&.visible:hover {
background: darken($brand, 6);
}

&.error {
background: $error;

Expand Down
5 changes: 0 additions & 5 deletions src/client/components/home-header-bar/home-header-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ export class HomeHeaderBar extends React.Component<HomeHeaderBarProps, HomeHeade
render() {
var { user, onNavClick, customization, title } = this.props;

// One day
//<div className="icon-button" onClick={this.handleSettings.bind(this)}>
// <SvgIcon className="not-implemented" svg={require('../../icons/full-settings.svg')}/>
//</div>

var userButton: JSX.Element = null;
if (user) {
userButton = <div className="icon-button user" onClick={this.onUserMenuClick.bind(this)}>
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/router/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class Router extends React.Component<RouterProps, RouterState> {
// Default route
if (crumbs.length === 0) {
let defaultFragment = this.getDefaultFragment(children);
window.location.hash = hash + '/' + defaultFragment;
this.replaceHash(hash + '/' + defaultFragment);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/client/components/settings-menu/settings-menu.mocha.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as TestUtils from 'react-addons-test-utils';
import { Timezone } from 'chronoshift';
import { SettingsMenu } from './settings-menu';
import { findDOMNode } from '../../utils/test-utils/index';
import { DataCubeMock } from '../../../common/models/mocks';


describe('SettingsMenu', () => {
Expand All @@ -29,6 +30,7 @@ describe('SettingsMenu', () => {

var renderedComponent = TestUtils.renderIntoDocument(
<SettingsMenu
dataCube={DataCubeMock.twitter()}
onClose={null}
openOn={openOn}
changeTimezone={() => {}}
Expand Down
23 changes: 23 additions & 0 deletions src/client/components/settings-menu/settings-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,28 @@
@import '../../imports';

.settings-menu {
padding: $padding-compact 0;

.simple-item, .dropdown {
padding: 0 $padding-compact;
}

.simple-item {
cursor: pointer;
line-height: 25px;

&:hover {
background: rgba($brand, 0.12);
}

&.selected {
background: $background-light;
}
}

.separator {
height: 14px;
margin-top: 8px;
border-top: 1px solid $border-extra-light;
}
}
24 changes: 15 additions & 9 deletions src/client/components/settings-menu/settings-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ require('./settings-menu.css');
import * as React from 'react';
import { Timezone } from 'chronoshift';
import { Fn } from '../../../common/utils/general/general';
import { Stage } from '../../../common/models/index';
import { Stage, DataCube } from '../../../common/models/index';
import { STRINGS } from '../../config/constants';
import { BubbleMenu } from '../bubble-menu/bubble-menu';
import { Dropdown } from '../dropdown/dropdown';

export interface SettingsMenuProps extends React.Props<any> {
dataCube: DataCube;
openOn: Element;
onClose: Fn;
changeTimezone?: (timezone: Timezone) => void;
Expand All @@ -49,17 +50,19 @@ export class SettingsMenu extends React.Component<SettingsMenuProps, SettingsMen

renderTimezonesDropdown() {
const { timezone, timezones } = this.props;
return React.createElement(Dropdown, {
label: STRINGS.timezone,
selectedItem: timezone,
renderItem: (d: Timezone) => d.toString().replace(/_/g, ' '),
items: timezones,
onSelect: this.changeTimezone.bind(this)
});
const TimezoneDropdown = Dropdown.specialize<Timezone>();

return <TimezoneDropdown
label={STRINGS.timezone}
selectedItem={timezone}
renderItem={(d: Timezone) => d.toString().replace(/_/g, ' ')}
items={timezones}
onSelect={this.changeTimezone.bind(this)}
/>;
}

render() {
const { openOn, onClose } = this.props;
const { openOn, onClose, dataCube } = this.props;

var stage = Stage.fromSize(240, 200);
return <BubbleMenu
Expand All @@ -69,6 +72,9 @@ export class SettingsMenu extends React.Component<SettingsMenuProps, SettingsMen
openOn={openOn}
onClose={onClose}
>
<a href={`#settings/data_cubes/${dataCube.name}`}><div className="simple-item">Edit this cube</div></a>
<a href="#settings"><div className="simple-item">General settings</div></a>
<div className="separator"/>
{this.renderTimezonesDropdown()}
</BubbleMenu>;
}
Expand Down
1 change: 1 addition & 0 deletions src/client/components/side-drawer/side-drawer.mocha.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe.skip('SideDrawer', () => {
selectedDataCube={null}
onOpenAbout={null}
onClose={null}
viewType="cube"
/>
);

Expand Down
51 changes: 32 additions & 19 deletions src/client/components/side-drawer/side-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export interface SideDrawerProps extends React.Props<any> {
onClose: Fn;
customization?: Customization;
itemHrefFn?: (oldDataCube?: DataCube, newDataCube?: DataCube) => string;
isHome?: boolean;
isCube?: boolean;
isLink?: boolean;
viewType: 'home' | 'cube' | 'link' | 'settings';
}

export interface SideDrawerState {
Expand Down Expand Up @@ -77,15 +75,20 @@ export class SideDrawer extends React.Component<SideDrawerProps, SideDrawerState
window.location.hash = '#';
}

renderOverviewLink() {
const { isHome, isCube, isLink } = this.props;
onOpenSettings() {
window.location.hash = '#settings';
}

if (!isCube && !isLink && !isHome) return null;
renderOverviewLink() {
const { viewType } = this.props;

return <div className="home-container">
<div className={classNames('home-link', {selected: isHome})} onClick={this.onHomeClick.bind(this)}>
<div
className={classNames('home-link', {selected: viewType === 'home'})}
onClick={this.onHomeClick.bind(this)}
>
<SvgIcon svg={require('../../icons/home.svg')}/>
<span>{isCube || isHome ? 'Home' : 'Overview'}</span>
<span>{viewType === 'link' ? 'Overview' : 'Home'}</span>
</div>
</div>;
}
Expand All @@ -104,15 +107,26 @@ export class SideDrawer extends React.Component<SideDrawerProps, SideDrawerState
};
});

var infoAndFeedback = [{
name: 'info',
title: STRINGS.infoAndFeedback,
tooltip: 'Learn more about Pivot',
onClick: () => {
onClose();
onOpenAbout();
var infoAndFeedback = [
{
name: 'settings',
title: STRINGS.settings,
tooltip: 'Settings',
onClick: () => {
onClose();
this.onOpenSettings();
}
},
{
name: 'info',
title: STRINGS.infoAndFeedback,
tooltip: 'Learn more about Pivot',
onClick: () => {
onClose();
onOpenAbout();
}
}
}];
];

var customLogoSvg: string = null;
if (customization && customization.customLogoSvg) {
Expand All @@ -127,9 +141,8 @@ export class SideDrawer extends React.Component<SideDrawerProps, SideDrawerState
navLinks={navLinks}
iconSvg={require('../../icons/full-cube.svg')}
/>
<NavList
navLinks={infoAndFeedback}
/>
<NavList navLinks={infoAndFeedback}/>

</div>;
}
}
7 changes: 6 additions & 1 deletion src/client/components/user-menu/user-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@
@import '../../imports';

.user-menu {

ul.bubble-list {
li.display-name {
pointer-events: none;
color: $text-lighterish;
}
}
}
4 changes: 1 addition & 3 deletions src/client/pivot-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface Config {
version: string;
user: any;
appSettings: AppSettingsJS;
readOnly: boolean;
}

var config: Config = (window as any)['__CONFIG__'];
Expand Down Expand Up @@ -83,8 +82,7 @@ if (config.appSettings.dataCubes.length || view === '#settings') {
{
version,
user: config.user,
appSettings,
readOnly: config.readOnly
appSettings
}
),
container
Expand Down
7 changes: 7 additions & 0 deletions src/client/views/home-view/home-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class HomeView extends React.Component< HomeViewProps, HomeViewState> {
window.location.hash = '#' + cube.name;
}

goToSettings() {
window.location.hash = '#settings';
}

renderCube(cube: DataCube): JSX.Element {
return <ItemCard
key={cube.name}
Expand Down Expand Up @@ -80,6 +84,9 @@ export class HomeView extends React.Component< HomeViewProps, HomeViewState> {
<button className="text-button" onClick={onOpenAbout}>
{STRINGS.infoAndFeedback}
</button>
<div className="icon-button" onClick={this.goToSettings.bind(this)}>
<SvgIcon svg={require('../../icons/full-settings.svg')}/>
</div>
</HomeHeaderBar>

<div className="container">
Expand Down
9 changes: 3 additions & 6 deletions src/client/views/pivot-application/pivot-application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export interface PivotApplicationProps extends React.Props<any> {
user?: User;
maxFilters?: number;
maxSplits?: number;
readOnly?: boolean;
appSettings: AppSettings;
}

Expand Down Expand Up @@ -179,11 +178,11 @@ export class PivotApplication extends React.Component<PivotApplicationProps, Piv
}

getViewTypeFromHash(hash: string): ViewType {
const { readOnly } = this.props;
const { user } = this.props;
const appSettings = this.state.appSettings || this.props.appSettings;
var viewType = this.parseHash(hash)[0];
if (!viewType || viewType === HOME) return appSettings.linkViewConfig ? LINK : HOME;
if (viewType === SETTINGS) return readOnly ? HOME : SETTINGS;
if (viewType === SETTINGS && user.allow['settings']) return SETTINGS;
if (appSettings.linkViewConfig && viewType === LINK) return LINK;
return CUBE;
}
Expand Down Expand Up @@ -304,9 +303,7 @@ export class PivotApplication extends React.Component<PivotApplicationProps, Piv
onClose={closeSideDrawer}
customization={customization}
itemHrefFn={this.sideBarHrefFn}
isCube={viewType === CUBE && !linkViewConfig}
isLink={viewType === LINK || !!linkViewConfig}
isHome={viewType === HOME}
viewType={viewType}
/>;
}

Expand Down

0 comments on commit f559fb9

Please sign in to comment.