|
|
@@ -4,6 +4,7 @@ import ReactModal from 'react-modal';
|
|
|
|
|
|
import { Context } from '../../shared/Context';
|
|
|
import api from '../../shared/api';
|
|
|
+import { ProjectType } from '../../shared/types';
|
|
|
|
|
|
import Sidebar from './sidebar/Sidebar';
|
|
|
import Dashboard from './dashboard/Dashboard';
|
|
|
@@ -16,6 +17,8 @@ import ClusterInstructionsModal from './modals/ClusterInstructionsModal';
|
|
|
import IntegrationsModal from './modals/IntegrationsModal';
|
|
|
import IntegrationsInstructionsModal from './modals/IntegrationsInstructionsModal';
|
|
|
import NewProject from './new-project/NewProject';
|
|
|
+import Navbar from './navbar/Navbar';
|
|
|
+import Provisioner from './new-project/Provisioner';
|
|
|
|
|
|
type PropsType = {
|
|
|
logOut: () => void
|
|
|
@@ -27,7 +30,7 @@ type StateType = {
|
|
|
currentView: string,
|
|
|
|
|
|
// Track last project id for refreshing clusters on project change
|
|
|
- prevProjectId: number | null
|
|
|
+ prevProjectId: number | null,
|
|
|
};
|
|
|
|
|
|
export default class Home extends Component<PropsType, StateType> {
|
|
|
@@ -38,6 +41,27 @@ export default class Home extends Component<PropsType, StateType> {
|
|
|
prevProjectId: null as number | null,
|
|
|
}
|
|
|
|
|
|
+ // Possibly consolidate into context (w/ ProjectSection + NewProject)
|
|
|
+ getProjects = () => {
|
|
|
+ let { user, currentProject, projects, setProjects } = this.context;
|
|
|
+ api.getProjects('<token>', {}, { id: user.userId }, (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err)
|
|
|
+ } else if (res.data) {
|
|
|
+ setProjects(res.data);
|
|
|
+ if (res.data.length > 0 && !currentProject) {
|
|
|
+ this.context.setCurrentProject(res.data[0]);
|
|
|
+ } else if (res.data.length === 0) {
|
|
|
+ this.setState({ currentView: 'new-project' });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ componentDidMount() {
|
|
|
+ this.getProjects();
|
|
|
+ }
|
|
|
+
|
|
|
componentDidUpdate(prevProps: PropsType) {
|
|
|
if (prevProps !== this.props && this.context.currentProject) {
|
|
|
|
|
|
@@ -91,7 +115,7 @@ export default class Home extends Component<PropsType, StateType> {
|
|
|
} else if (currentView === 'dashboard') {
|
|
|
return (
|
|
|
<DashboardWrapper>
|
|
|
- <Dashboard />
|
|
|
+ <Dashboard setCurrentView={(x: string) => this.setState({ currentView: x })} />
|
|
|
</DashboardWrapper>
|
|
|
);
|
|
|
} else if (currentView === 'integrations') {
|
|
|
@@ -100,6 +124,8 @@ export default class Home extends Component<PropsType, StateType> {
|
|
|
return (
|
|
|
<NewProject setCurrentView={(x: string) => this.setState({ currentView: x })} />
|
|
|
);
|
|
|
+ } else if (currentView === 'provisioner') {
|
|
|
+ return <Provisioner />
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
@@ -109,6 +135,25 @@ export default class Home extends Component<PropsType, StateType> {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ renderSidebar = () => {
|
|
|
+ if (this.context.projects.length > 0) {
|
|
|
+
|
|
|
+ // Force sidebar closed on first provision
|
|
|
+ if (this.state.currentView === 'provisioner' && this.state.forceSidebar) {
|
|
|
+ this.setState({ forceSidebar: false });
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Sidebar
|
|
|
+ forceSidebar={this.state.forceSidebar}
|
|
|
+ setWelcome={(x: boolean) => this.setState({ showWelcome: x })}
|
|
|
+ setCurrentView={(x: string) => this.setState({ currentView: x })}
|
|
|
+ currentView={this.state.currentView}
|
|
|
+ />
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
let { currentModal, setCurrentModal, currentProject } = this.context;
|
|
|
return (
|
|
|
@@ -146,15 +191,10 @@ export default class Home extends Component<PropsType, StateType> {
|
|
|
<IntegrationsInstructionsModal />
|
|
|
</ReactModal>
|
|
|
|
|
|
- <Sidebar
|
|
|
- logOut={this.props.logOut}
|
|
|
- forceSidebar={this.state.forceSidebar}
|
|
|
- setWelcome={(x: boolean) => this.setState({ showWelcome: x })}
|
|
|
- setCurrentView={(x: string) => this.setState({ currentView: x })}
|
|
|
- currentView={this.state.currentView}
|
|
|
- />
|
|
|
+ {this.renderSidebar()}
|
|
|
|
|
|
<ViewWrapper>
|
|
|
+ <Navbar logOut={this.props.logOut} />
|
|
|
{this.renderContents()}
|
|
|
</ViewWrapper>
|
|
|
</StyledHome>
|
|
|
@@ -164,25 +204,6 @@ export default class Home extends Component<PropsType, StateType> {
|
|
|
|
|
|
Home.contextType = Context;
|
|
|
|
|
|
-const MediumModalStyles = {
|
|
|
- overlay: {
|
|
|
- backgroundColor: 'rgba(0,0,0,0.6)',
|
|
|
- zIndex: 2,
|
|
|
- },
|
|
|
- content: {
|
|
|
- borderRadius: '7px',
|
|
|
- border: 0,
|
|
|
- width: '760px',
|
|
|
- maxWidth: '80vw',
|
|
|
- margin: '0 auto',
|
|
|
- height: '575px',
|
|
|
- top: 'calc(50% - 289px)',
|
|
|
- backgroundColor: '#202227',
|
|
|
- animation: 'floatInModal 0.5s 0s',
|
|
|
- overflow: 'visible',
|
|
|
- },
|
|
|
-};
|
|
|
-
|
|
|
const SmallModalStyles = {
|
|
|
overlay: {
|
|
|
backgroundColor: 'rgba(0,0,0,0.6)',
|