From ba4f5cb47dd84d61a335be3d66476d4455ba7651 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 9 Jul 2020 10:53:01 +0300 Subject: [PATCH] workspaces: extract bottom-bar to separated component Signed-off-by: Roman --- src/common/cluster-store.ts | 21 ++++---- src/common/user-store.ts | 19 ++++--- src/common/workspace-store.ts | 25 +++++---- src/main/index.ts | 14 ++--- .../components/+workspaces/bottom-bar.scss | 10 ++++ .../components/+workspaces/bottom-bar.tsx | 52 +++++++++++++++++++ .../components/+workspaces/workspaces.scss | 22 +++----- .../components/+workspaces/workspaces.tsx | 49 ++--------------- 8 files changed, 115 insertions(+), 97 deletions(-) create mode 100644 src/renderer/components/+workspaces/bottom-bar.scss create mode 100644 src/renderer/components/+workspaces/bottom-bar.tsx diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index b36dafe0d5..8040db190e 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -1,4 +1,4 @@ -import { action, observable, toJS } from "mobx"; +import { action, computed, observable, toJS } from "mobx"; import { v4 as uuid } from "uuid" import { BaseStore } from "./base-store"; import { Cluster } from "../main/cluster"; @@ -38,10 +38,6 @@ export interface ClusterPreferences { } export class ClusterStore extends BaseStore { - @observable activeCluster: ClusterId; - @observable clusters = observable.map(); - @observable removedClusters = observable.map(); - private constructor() { super({ configName: "lens-cluster-store", @@ -52,14 +48,20 @@ export class ClusterStore extends BaseStore { }); } + @observable activeCluster: ClusterId; + @observable removedClusters = observable.map(); + @observable clusters = observable.map(); + + @computed get clustersList() { + return Array.from(this.clusters.values()); + } + getById(id: ClusterId): Cluster { return this.clusters.get(id); } getByWorkspaceId(workspaceId: string): Cluster[] { - return Array.from(this.clusters.values()).filter(cluster => { - return cluster.workspace === workspaceId; - }) + return this.clustersList.filter(cluster => cluster.workspace === workspaceId) } @action @@ -116,10 +118,9 @@ export class ClusterStore extends BaseStore { } toJSON(): ClusterStoreModel { - const clusters = Array.from(this.clusters).map(([id, cluster]) => cluster.toJSON()); return toJS({ activeCluster: this.activeCluster, - clusters: clusters, + clusters: this.clustersList.map(cluster => cluster.toJSON()), }, { recurseEverything: true }) diff --git a/src/common/user-store.ts b/src/common/user-store.ts index 46cbe8f763..efc36a3771 100644 --- a/src/common/user-store.ts +++ b/src/common/user-store.ts @@ -20,16 +20,7 @@ export interface UserPreferences { } export class UserStore extends BaseStore { - @observable lastSeenAppVersion = "0.0.0" - @observable seenContexts = observable.set(); - - @observable preferences: UserPreferences = { - allowTelemetry: true, - colorTheme: "dark", - downloadMirror: "default", - }; - - protected constructor() { + private constructor() { super({ configName: "lens-user-store", confOptions: { @@ -43,6 +34,14 @@ export class UserStore extends BaseStore { }); } + @observable lastSeenAppVersion = "0.0.0" + @observable seenContexts = observable.set(); + @observable preferences: UserPreferences = { + allowTelemetry: true, + colorTheme: "dark", + downloadMirror: "default", + }; + get hasNewAppVersion() { return semver.gt(getAppVersion(), this.lastSeenAppVersion); } diff --git a/src/common/workspace-store.ts b/src/common/workspace-store.ts index bc396df394..bf8cdcf90c 100644 --- a/src/common/workspace-store.ts +++ b/src/common/workspace-store.ts @@ -1,4 +1,4 @@ -import { action, observable } from "mobx"; +import { action, computed, observable, toJS } from "mobx"; import { BaseStore } from "./base-store"; import { clusterStore } from "./cluster-store" @@ -18,6 +18,12 @@ export interface Workspace { export class WorkspaceStore extends BaseStore { static readonly defaultId: WorkspaceId = "default" + private constructor() { + super({ + configName: "lens-workspace-store", + }); + } + @observable currentWorkspace = WorkspaceStore.defaultId; @observable workspaces = observable.map({ @@ -27,10 +33,8 @@ export class WorkspaceStore extends BaseStore { } }); - private constructor() { - super({ - configName: "lens-workspace-store", - }); + @computed get workspacesList() { + return Array.from(this.workspaces.values()); } getById(id: WorkspaceId): Workspace { @@ -82,11 +86,12 @@ export class WorkspaceStore extends BaseStore { } toJSON(): WorkspaceStoreModel { - const { currentWorkspace, workspaces } = this; - return { - currentWorkspace: currentWorkspace, - workspaces: Array.from(workspaces.values()), - } + return toJS({ + currentWorkspace: this.currentWorkspace, + workspaces: this.workspacesList, + }, { + recurseEverything: true + }) } } diff --git a/src/main/index.ts b/src/main/index.ts index 39da0e194c..84b50f78ad 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -7,7 +7,7 @@ import { appName, appProto, isMac, staticDir, staticProto } from "../common/vars import path from "path" import { format as formatUrl } from "url" import initMenu from "./menu" -import * as proxy from "./proxy" +import { LensProxy, listen } from "./proxy" import { WindowManager } from "./window-manager"; import { ClusterManager } from "./cluster-manager"; import AppUpdater from "./app-updater" @@ -21,9 +21,9 @@ import { workspaceStore } from "../common/workspace-store"; import { tracker } from "../common/tracker"; import logger from "./logger" -let windowManager: WindowManager = null; -let clusterManager: ClusterManager = null; -let proxyServer: proxy.LensProxy = null; +let windowManager: WindowManager; +let clusterManager: ClusterManager; +let proxyServer: LensProxy; mangleProxyEnv() if (app.commandLine.getSwitchValue("proxy-server") !== "") { @@ -68,7 +68,7 @@ async function main() { // run proxy try { - proxyServer = proxy.listen(port, clusterManager) + proxyServer = listen(port, clusterManager) } catch (error) { logger.error(`Could not start proxy (127.0.0:${port}): ${error.message}`) await dialog.showErrorBox("Lens Error", `Could not start proxy (127.0.0:${port}): ${error.message || "unknown error"}`) @@ -85,7 +85,9 @@ async function main() { windowManager.loadURL(vmURL) } -app.on("ready", main) +// Events + +app.on("ready", main); app.on('window-all-closed', function () { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q diff --git a/src/renderer/components/+workspaces/bottom-bar.scss b/src/renderer/components/+workspaces/bottom-bar.scss new file mode 100644 index 0000000000..1dc5d8fb17 --- /dev/null +++ b/src/renderer/components/+workspaces/bottom-bar.scss @@ -0,0 +1,10 @@ +.WorkspacesBottomBar { + font-size: $font-size-small; + background-color: #3d90ce; + padding: $padding / 2 $padding; + color: white; + + #workspace { + cursor: pointer; + } +} diff --git a/src/renderer/components/+workspaces/bottom-bar.tsx b/src/renderer/components/+workspaces/bottom-bar.tsx new file mode 100644 index 0000000000..a142335fdb --- /dev/null +++ b/src/renderer/components/+workspaces/bottom-bar.tsx @@ -0,0 +1,52 @@ +import "./bottom-bar.scss" + +import React from "react"; +import { observable } from "mobx"; +import { observer } from "mobx-react"; +import { Link } from "react-router-dom"; +import { Trans } from "@lingui/macro"; +import { Icon } from "../icon"; +import { Menu, MenuItem } from "../menu"; +import { prevDefault } from "../../utils"; +import { workspaceStore } from "../../../common/workspace-store"; + +// todo: remove dummy actions + console.log + +@observer +export class WorkspacesBottomBar extends React.Component { + @observable menuVisible = false; + + render() { + const { currentWorkspace, workspacesList } = workspaceStore; + return ( +
+
+ {currentWorkspace} +
+ this.menuVisible = true} + close={() => this.menuVisible = false} + > + console.log('/navigate: workspaces page'))}> + Workspaces + + {workspacesList.map(workspace => { + const { id, name, description } = workspace; + return ( + console.log(`navigate: /workspaces/${id}`)} title={description}> + {name} + + ) + })} + +
+ ) + } +} diff --git a/src/renderer/components/+workspaces/workspaces.scss b/src/renderer/components/+workspaces/workspaces.scss index 1f67f4c7af..13af93816c 100644 --- a/src/renderer/components/+workspaces/workspaces.scss +++ b/src/renderer/components/+workspaces/workspaces.scss @@ -5,29 +5,21 @@ grid-template-columns: min-content 1fr; height: 100%; - > .draggable-top { + .draggable-top { @include set-draggable; grid-area: draggable; } - > .ClusterMenu { - grid-area: menu; - } - - > .lens-container { + #lens-view { grid-area: lens-view; } - > .bottom-bar { - grid-area: bottom-bar; - font-size: $font-size-small; - background-color: #3d90ce; - padding: $padding / 2 $padding; - color: white; + .ClusterMenu { + grid-area: menu; + } - #workspace { - cursor: pointer; - } + .WorkspacesBottomBar { + grid-area: bottom-bar; } } diff --git a/src/renderer/components/+workspaces/workspaces.tsx b/src/renderer/components/+workspaces/workspaces.tsx index 5af336a872..ed4f105f2d 100644 --- a/src/renderer/components/+workspaces/workspaces.tsx +++ b/src/renderer/components/+workspaces/workspaces.tsx @@ -1,61 +1,18 @@ import "./workspaces.scss" import React from "react"; -import { observable } from "mobx"; -import { observer } from "mobx-react"; -import { Link } from "react-router-dom"; -import { Trans } from "@lingui/macro"; -import { workspaceStore } from "../../../common/workspace-store"; -import { Icon } from "../icon"; import { ClustersMenu } from "./clusters-menu"; -import { Menu, MenuItem } from "../menu"; -import { prevDefault } from "../../utils"; +import { WorkspacesBottomBar } from "./bottom-bar"; // todo: support `workspaceId` in URL -@observer export class Workspaces extends React.Component { - @observable menuVisible = false; - render() { - const { currentWorkspace, workspaces } = workspaceStore; return (
- +
- -
- {/*todo: replace with BrowserView */} -
- -
-
- {currentWorkspace} -
- this.menuVisible = true} - close={() => this.menuVisible = false} - > - console.log('/navigate: workspaces page'))}> - Workspaces - - {Array.from(workspaces.values()).map(workspace => { - const { id, name, description } = workspace; - return ( - console.log(`navigate: /workspaces/${id}`)} title={description}> - {name} - - ) - })} - -
+
) }