Skip to content

Commit 2a7b7b0

Browse files
douglasmuraokadavimacedo
authored andcommitted
Fix: Can't switch (dropdown list) between servers #1045 (#1125)
1 parent b5a24f9 commit 2a7b7b0

File tree

5 files changed

+93
-146
lines changed

5 files changed

+93
-146
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import styles from 'components/Sidebar/Sidebar.scss';
3+
4+
export default ({ name, onClick }) => (
5+
<div className={styles.currentApp} onClick={onClick}>
6+
{name}
7+
</div>
8+
);

src/components/Sidebar/AppsMenu.react.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* the root directory of this source tree.
77
*/
88
import AppBadge from 'components/AppBadge/AppBadge.react';
9+
import AppName from 'components/Sidebar/AppName.react';
910
import html from 'lib/htmlString';
1011
import { Link } from 'react-router-dom';
1112
import React from 'react';
@@ -14,21 +15,21 @@ import { unselectable } from 'stylesheets/base.scss';
1415

1516
let AppsMenu = ({ apps, current, height, onSelect }) => (
1617
<div style={{ height }} className={[styles.appsMenu, unselectable].join(' ')}>
17-
<div className={styles.currentApp} onClick={onSelect.bind(null, current.slug)}>
18-
{current.name}
19-
</div>
18+
<AppName name={current.name} onClick={onSelect.bind(null, current.slug)} />
2019
<div className={styles.menuSection}>All Apps</div>
21-
{apps.map((app) => {
22-
if (app.slug === current.slug) {
23-
return null;
24-
}
25-
return (
26-
<Link to={{ pathname: html`/apps/${app.slug}/browser` }} key={app.slug} className={styles.menuRow}>
27-
{app.name}
28-
<AppBadge production={app.production} />
29-
</Link>
30-
);
31-
})}
20+
<div className={styles.appListContainer}>
21+
{apps.map((app) => {
22+
if (app.slug === current.slug) {
23+
return null;
24+
}
25+
return (
26+
<Link to={{ pathname: html`/apps/${app.slug}/browser` }} key={app.slug} className={styles.menuRow}>
27+
{app.name}
28+
<AppBadge production={app.production} />
29+
</Link>
30+
);
31+
})}
32+
</div>
3233
</div>
3334
);
3435

src/components/Sidebar/AppsSelector.react.js

Lines changed: 0 additions & 94 deletions
This file was deleted.

src/components/Sidebar/Sidebar.react.js

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
*/
88
import PropTypes from 'lib/PropTypes';
99
import AppsManager from 'lib/AppsManager';
10-
import AppsSelector from 'components/Sidebar/AppsSelector.react';
10+
import AppsMenu from 'components/Sidebar/AppsMenu.react';
11+
import AppName from 'components/Sidebar/AppName.react';
1112
import FooterMenu from 'components/Sidebar/FooterMenu.react';
12-
import React from 'react';
13+
import React, { useState } from 'react';
14+
import ParseApp from 'lib/ParseApp';
1315
import SidebarHeader from 'components/Sidebar/SidebarHeader.react';
1416
import SidebarSection from 'components/Sidebar/SidebarSection.react';
1517
import SidebarSubItem from 'components/Sidebar/SidebarSubItem.react';
@@ -26,7 +28,8 @@ const Sidebar = ({
2628
appSelector,
2729
primaryBackgroundColor,
2830
secondaryBackgroundColor
29-
}) => {
31+
}, { currentApp }) => {
32+
const [ appsMenuOpen, setAppsMenuOpen ] = useState(false);
3033
const _subMenu = subsections => {
3134
if (!subsections) {
3235
return null;
@@ -53,35 +56,54 @@ const Sidebar = ({
5356

5457
const apps = [].concat(AppsManager.apps()).sort((a, b) => (a.name < b.name ? -1 : (a.name > b.name ? 1 : 0)));
5558

59+
let sidebarContent;
60+
if (appsMenuOpen) {
61+
sidebarContent = (
62+
<AppsMenu
63+
apps={apps}
64+
current={currentApp}
65+
onSelect={() => setAppsMenuOpen(false)} />
66+
);
67+
} else {
68+
sidebarContent = (
69+
<>
70+
{appSelector && (
71+
<div className={styles.apps}>
72+
<AppName name={currentApp.name} onClick={() => setAppsMenuOpen(true)} />
73+
</div>
74+
)}
75+
<div className={styles.content}>
76+
{sections.map(({
77+
name,
78+
icon,
79+
style,
80+
link,
81+
subsections,
82+
}) => {
83+
const active = name === section;
84+
return (
85+
<SidebarSection
86+
key={name}
87+
name={name}
88+
icon={icon}
89+
style={style}
90+
link={prefix + link}
91+
active={active}
92+
primaryBackgroundColor={primaryBackgroundColor}
93+
secondaryBackgroundColor={secondaryBackgroundColor}
94+
>
95+
{active ? _subMenu(subsections) : null}
96+
</SidebarSection>
97+
);
98+
})}
99+
</div>
100+
</>
101+
)
102+
}
103+
56104
return <div className={styles.sidebar}>
57105
<SidebarHeader />
58-
{appSelector ? <AppsSelector apps={apps} /> : null}
59-
60-
<div className={styles.content}>
61-
{sections.map(({
62-
name,
63-
icon,
64-
style,
65-
link,
66-
subsections,
67-
}) => {
68-
const active = name === section;
69-
return (
70-
<SidebarSection
71-
key={name}
72-
name={name}
73-
icon={icon}
74-
style={style}
75-
link={prefix + link}
76-
active={active}
77-
primaryBackgroundColor={primaryBackgroundColor}
78-
secondaryBackgroundColor={secondaryBackgroundColor}
79-
>
80-
{active ? _subMenu(subsections) : null}
81-
</SidebarSection>
82-
);
83-
})}
84-
</div>
106+
{sidebarContent}
85107
<div className={styles.footer}>
86108
<a target='_blank' href='http://parseplatform.org/'>Open Source Hub</a>
87109
<a target='_blank' href='https://github.com/parse-community'>GitHub</a>
@@ -92,7 +114,7 @@ const Sidebar = ({
92114
}
93115

94116
Sidebar.contextTypes = {
95-
generatePath: PropTypes.func
117+
currentApp: PropTypes.instanceOf(ParseApp)
96118
};
97119

98120
export default Sidebar;

src/components/Sidebar/Sidebar.scss

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
*/
88
@import 'stylesheets/globals.scss';
99

10+
$headerHeight: 48px;
11+
$menuSectionHeight: 24px;
12+
$sidebarMenuItemHeight: 48px;
13+
$footerHeight: 36px;
14+
1015
.sidebar {
1116
position: fixed;
1217
width: 300px;
@@ -54,21 +59,21 @@
5459
.content {
5560
position: absolute;
5661
overflow-y: auto;
57-
top: 48px;
62+
top: $headerHeight;
5863
right: 0;
5964
bottom: 36px;
6065
left: 0;
6166
}
6267

6368
.apps + .content {
64-
top: 96px;
69+
top: $headerHeight + $sidebarMenuItemHeight;
6570
}
6671

6772
.footer {
6873
@include NotoSansFont;
6974
position: absolute;
7075
background: #05283c;
71-
height: 36px;
76+
height: $footerHeight;
7277
line-height: 18px;
7378
padding: 9px 0;
7479
text-align: center;
@@ -102,7 +107,7 @@
102107

103108
.header {
104109
background: #05283c;
105-
height: 48px;
110+
height: $headerHeight;
106111
padding: 10px 14px;
107112

108113
:global(.icon) {
@@ -116,7 +121,7 @@
116121
@include ellipsis();
117122
display: block;
118123
background: #094162;
119-
height: 48px;
124+
height: $sidebarMenuItemHeight;
120125
padding: 10px 14px;
121126

122127
color: white;
@@ -179,11 +184,16 @@
179184
.menuRow:hover {
180185
background: #0c5582;
181186
}
187+
188+
.appListContainer {
189+
overflow-y: auto;
190+
height: calc(100vh - #{$headerHeight} - #{$menuSectionHeight} - #{$sidebarMenuItemHeight} - #{$footerHeight});
191+
}
182192
}
183193

184194
.menuSection {
185195
@include DosisFont;
186-
height: 24px;
196+
height: $menuSectionHeight;
187197
line-height: 24px;
188198
background: #0c5582;
189199
color: #84A5BC;
@@ -233,7 +243,7 @@
233243

234244
.section_header {
235245
display: block;
236-
height: 48px;
246+
height: $sidebarMenuItemHeight;
237247
font-size: 18px;
238248
line-height: 28px;
239249
padding: 12px 14px;

0 commit comments

Comments
 (0)