Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views management refactoring #669

Merged
merged 54 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7d3e876
part 1
ixrock Aug 5, 2020
8925186
part 2
ixrock Aug 6, 2020
a78d5a0
cluster-view battling -- part 1 (iframe failing support nodeintegration)
ixrock Aug 6, 2020
5452fdb
ipc-refactoring, fixes
ixrock Aug 6, 2020
09c765c
cluster-view battling -- part 2
ixrock Aug 7, 2020
2287332
cluster-view battling -- part 3
ixrock Aug 7, 2020
2894f31
fixes
ixrock Aug 7, 2020
1204e9e
fix menu navigation
ixrock Aug 7, 2020
3e86729
cluster-view bugfixing, attempt 100500..
ixrock Aug 7, 2020
9818c07
Fixing Cluster Settings layout (#651)
aleksfront Aug 7, 2020
795a98c
base-migration-branch merge-fix
ixrock Aug 7, 2020
7364cb7
cluster-view reworks
ixrock Aug 8, 2020
0b80032
todo/fixme: hide active view on disconnect
ixrock Aug 8, 2020
ceca2d7
moved some runtime deps from dev-deps-list in package.json
ixrock Aug 10, 2020
8e6d886
cluster-view fixes
ixrock Aug 10, 2020
7b5092d
cluster-view more fixes & UX optimizations
ixrock Aug 10, 2020
6f6680b
fix: cluster-manager initial loading, redirect to startPage from any …
ixrock Aug 10, 2020
4ef26be
fix: handle navigation from global menu
ixrock Aug 10, 2020
d2be0e4
more fixes
ixrock Aug 10, 2020
8e626ee
Fix CRD api parsing (#622)
nevalla Jul 31, 2020
b3f97a6
Fix Resource Quota Rendering (#624)
Nokel81 Aug 4, 2020
6293dad
adding port-forward for containers in pods (#528)
jim-docker Aug 7, 2020
3a50255
use the Kubernetes regex for matching system names (#659)
Nokel81 Aug 7, 2020
df764ca
Removing legacy browserCheck() utility
aleksfront Aug 10, 2020
26e93e7
Revert select box-shadow (outline) color
aleksfront Aug 10, 2020
aa63624
Allowing to save prometheus service address
aleksfront Aug 10, 2020
bb382d2
Improving code readabilty
aleksfront Aug 10, 2020
503888a
Setting overflow:hidden on lens-view elem (#664)
aleksfront Aug 10, 2020
39391e7
Fixing broken/missing icons (#665)
aleksfront Aug 10, 2020
6c40d33
fix menu/navigation
ixrock Aug 10, 2020
93b42ff
moar random fixes
ixrock Aug 10, 2020
631826a
clean up
ixrock Aug 10, 2020
916a101
Fix Cluster Settings style specificity
aleksfront Aug 11, 2020
ae3fdea
fix: navigate to cluster-settings page from clusters-menu
ixrock Aug 11, 2020
260bbbd
Revert system menu layout (#671)
nevalla Aug 12, 2020
e7d4317
fix: navigating to cluster-view from common-view
ixrock Aug 12, 2020
7903eba
revering user-store refactoring
ixrock Aug 12, 2020
f5a978e
moving cluster-settings view lens-app views (common)
ixrock Aug 12, 2020
2228957
reverted cluster-manager.ts/getClusterForRequest()
ixrock Aug 12, 2020
77066ee
Adding unit tests to ClusterStore (#678)
aleksfront Aug 13, 2020
c4ae765
Navigate to landing page on cluster disconnect
aleksfront Aug 13, 2020
bc339e4
Add Cluster page visual fixes
aleksfront Aug 13, 2020
877fe18
Improve isUrl validator
aleksfront Aug 13, 2020
1987c12
Fixing Cluster Settings typo
aleksfront Aug 13, 2020
161b356
fix: use `env NODE_ENV=production` for `yarn compile`
ixrock Aug 13, 2020
8275e15
prod-build fix
ixrock Aug 13, 2020
a28d671
extracting missing localization
ixrock Aug 13, 2020
38aefc5
Reconnecting cluster after selection (#685)
aleksfront Aug 14, 2020
50a2e1f
fix: skip redefining global `__static` in tests
ixrock Aug 14, 2020
fb124ad
Preferences section restyling (#700)
aleksfront Aug 17, 2020
0353ee7
Replace webview to iframe (#701)
ixrock Aug 17, 2020
948421b
Fix integration tests (#698)
nevalla Aug 18, 2020
07c3143
Minor WizardLayout fix
aleksfront Aug 18, 2020
fe42219
Merge branch 'vue_react_migration' into views_management_refactoring
nevalla Aug 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
part 2
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
  • Loading branch information
ixrock authored and nevalla committed Aug 18, 2020
commit 8925186be6a6238cfc1db0e6ecbe36eeac9367e3
5 changes: 0 additions & 5 deletions src/common/cluster-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
this.activeClusterId = newClusters.has(activeCluster) ? activeCluster : null;
this.clusters.replace(newClusters);
this.removedClusters.replace(removedClusters);

// "auto-select" first cluster if available
if (!this.activeClusterId && newClusters.size) {
this.activeClusterId = Array.from(newClusters.values())[0].id;
}
}

toJSON(): ClusterStoreModel {
Expand Down
11 changes: 1 addition & 10 deletions src/common/workspace-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, computed, observable, reaction, toJS } from "mobx";
import { action, computed, observable, toJS } from "mobx";
import { BaseStore } from "./base-store";
import { clusterStore } from "./cluster-store"

Expand All @@ -22,15 +22,6 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
super({
configName: "lens-workspace-store",
});

// switch to first available cluster in current workspace
reaction(() => this.currentWorkspaceId, workspaceId => {
const clusters = clusterStore.getByWorkspaceId(workspaceId);
const activeClusterInWorkspace = clusters.some(cluster => cluster.id === clusterStore.activeClusterId);
if (!activeClusterInWorkspace) {
clusterStore.activeClusterId = clusters.length ? clusters[0].id : null;
}
})
}

@observable currentWorkspaceId = WorkspaceStore.defaultId;
Expand Down
7 changes: 1 addition & 6 deletions src/main/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ export class Cluster implements ClusterModel {
@observable allowedNamespaces: string[] = [];
@observable allowedResources: string[] = [];

@computed get host() {
const proxyHost = new URL(this.kubeProxyUrl).host;
return `${this.id}.${proxyHost}`
}

constructor(model: ClusterModel) {
this.updateModel(model);
}
Expand Down Expand Up @@ -223,7 +218,7 @@ export class Cluster implements ClusterModel {
json: true,
timeout: 5000,
headers: {
Host: this.host, // provide cluster-id for ClusterManager.getClusterForRequest()
Host: `${this.id}.${new URL(this.kubeProxyUrl).host}`, // required in ClusterManager.getClusterForRequest()
...(options.headers || {}),
},
})
Expand Down
1 change: 1 addition & 0 deletions src/main/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class WindowManager {
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
webviewTag: true,
},
});
this.windowState.manage(this.mainView);
Expand Down
36 changes: 19 additions & 17 deletions src/renderer/components/cluster-manager/cluster-manager.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
import "./cluster-manager.scss"
import React from "react";
import { Redirect, Route, Switch } from "react-router";
import { observer } from "mobx-react";
import { ClustersMenu } from "./clusters-menu";
import { BottomBar } from "./bottom-bar";
import { cssNames, IClassName } from "../../utils";
import { ClusterId } from "../../../common/cluster-store";
import { Route, Switch } from "react-router";
import { LandingPage, landingRoute } from "../+landing-page";
import { LandingPage, landingRoute, landingURL } from "../+landing-page";
import { Preferences, preferencesRoute } from "../+preferences";
import { Workspaces, workspacesRoute } from "../+workspaces";
import { AddCluster, addClusterRoute } from "../+add-cluster";
import { ClusterStatus } from "./cluster-status";
import { clusterStatusRoute } from "./cluster-status.route";

interface Props {
className?: IClassName;
contentClass?: IClassName;
}
import { ClusterView } from "./cluster-view";
import { clusterViewRoute, clusterViewURL } from "./cluster-view.route";
import { clusterStore } from "../../../common/cluster-store";

@observer
export class ClusterManager extends React.Component<Props> {
activateView(clusterId: ClusterId) {
export class ClusterManager extends React.Component {
get startUrl() {
const { activeClusterId } = clusterStore;
if (activeClusterId) {
return clusterViewURL({
params: {
clusterId: activeClusterId
}
})
}
return landingURL()
}

render() {
const { className } = this.props;
return (
<div className={cssNames("ClusterManager", className)}>
<div className="ClusterManager">
<div id="draggable-top"/>
<div id="lens-view">
<Switch>
<Route component={LandingPage} {...landingRoute}/>
<Route component={Preferences} {...preferencesRoute}/>
<Route component={Workspaces} {...workspacesRoute}/>
<Route component={AddCluster} {...addClusterRoute}/>
<Route component={ClusterStatus} {...clusterStatusRoute}/>
<Route render={() => <p>Lens</p>}/>
<Route component={ClusterView} {...clusterViewRoute}/>
<Redirect exact from="/" to={this.startUrl}/>
</Switch>
</div>
<ClustersMenu/>
Expand Down

This file was deleted.

30 changes: 15 additions & 15 deletions src/renderer/components/cluster-manager/cluster-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ import type { KubeAuthProxyLog } from "../../../main/kube-auth-proxy";

import "./cluster-status.scss"
import React from "react";
import { disposeOnUnmount, observer } from "mobx-react";
import { observer } from "mobx-react";
import { ipcRenderer } from "electron";
import { autorun, computed, observable } from "mobx";
import { computed, observable } from "mobx";
import { clusterIpc } from "../../../common/cluster-ipc";
import { Icon } from "../icon";
import { Button } from "../button";
import { cssNames } from "../../utils";
import { navigate } from "../../navigation";
import { Cluster } from "../../../main/cluster";
import { ClusterId, clusterStore } from "../../../common/cluster-store";

interface Props {
clusterId: ClusterId;
}

@observer
export class ClusterStatus extends React.Component {
export class ClusterStatus extends React.Component<Props> {
@observable authOutput: KubeAuthProxyLog[] = [];
@observable isReconnecting = false;

// fixme
@computed get clusterId() {
return this.props.clusterId;
}

@computed get cluster(): Cluster {
return null;
return clusterStore.getById(this.clusterId);
}

@computed get hasErrors(): boolean {
return this.authOutput.some(({ error }) => error) || !!this.cluster.failureReason;
}

@disposeOnUnmount
autoRedirectToMain = autorun(() => {
if (this.cluster.accessible && !this.hasErrors) {
navigate("/");
}
})

async componentDidMount() {
if (this.cluster.disconnected) {
return;
Expand All @@ -48,11 +48,11 @@ export class ClusterStatus extends React.Component {
}

componentWillUnmount() {
ipcRenderer.removeAllListeners(`kube-auth:${this.cluster.id}`);
ipcRenderer.removeAllListeners(`kube-auth:${this.clusterId}`);
}

async refreshClusterState() {
return clusterIpc.activate.invokeFromRenderer();
return clusterIpc.activate.invokeFromRenderer(this.clusterId);
}

reconnect = async () => {
Expand Down
22 changes: 22 additions & 0 deletions src/renderer/components/cluster-manager/cluster-view.route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { matchPath, RouteProps } from "react-router";
import { buildURL, navigation } from "../../navigation";

export interface IClusterViewRouteParams {
clusterId: string;
}

export const clusterViewRoute: RouteProps = {
path: "/cluster/:clusterId"
}

export const clusterViewURL = buildURL<IClusterViewRouteParams>(clusterViewRoute.path)

export function getMatchedClusterId(): string {
const matched = matchPath<IClusterViewRouteParams>(navigation.location.pathname, {
...clusterViewRoute,
exact: true,
})
if (matched) {
return matched.params.clusterId;
}
}
10 changes: 10 additions & 0 deletions src/renderer/components/cluster-manager/cluster-view.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.ClusterView {
width: 100%;
height: 100%;
border: 0;
//display: none;

&.loaded {
display: block;
}
}
46 changes: 46 additions & 0 deletions src/renderer/components/cluster-manager/cluster-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from "react";
import { autorun, computed, observable } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";
import { ClusterId, clusterStore } from "../../../common/cluster-store";
import { getMatchedClusterId } from "./cluster-view.route";
import { Cluster } from "../../../main/cluster";

@observer
export class ClusterView extends React.Component {
static views = observable.map<ClusterId, /*HTMLIFrameElement*/ any>()
static isLoaded = observable.map<ClusterId, boolean>()

@computed get cluster() {
return clusterStore.getById(getMatchedClusterId())
}

@computed get clusterView() {
return ClusterView.views.get(this.cluster?.id)
}

componentDidMount() {
disposeOnUnmount(this, [
autorun(() => this.activateView(this.cluster))
])
}

activateView = (cluster: Cluster) => {
if (!cluster || ClusterView.views.has(cluster.id)) {
return;
}
const view = document.createElement("webview");
view.className = "ClusterView"
view.src = `${location.protocol}://${cluster.id}.${location.host}`
view.onload = () => console.log('CLUSTER VIEW READY!', cluster);
document.body.appendChild(view);
ClusterView.views.set(cluster.id, view);
}

render() {
const { cluster } = this;
if (cluster && cluster.accessible) {

}
return "";
}
}
18 changes: 6 additions & 12 deletions src/renderer/components/cluster-manager/clusters-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { landingURL } from "../+landing-page";
import { Tooltip } from "../tooltip";
import { ConfirmDialog } from "../confirm-dialog";
import { clusterIpc } from "../../../common/cluster-ipc";
import { clusterStatusURL } from "./cluster-status.route";
import { clusterViewURL, getMatchedClusterId } from "./cluster-view.route";

// fixme: allow to rearrange clusters with drag&drop

Expand All @@ -32,12 +32,9 @@ interface Props {
export class ClustersMenu extends React.Component<Props> {
@observable showHint = true;

showCluster = (clusterId: ClusterId) => {
if (clusterStore.activeClusterId === clusterId) {
navigate("/"); // redirect to index
} else {
clusterStore.activeClusterId = clusterId;
}
activateCluster = (clusterId: ClusterId) => {
clusterStore.activeClusterId = clusterId;
navigate(clusterViewURL({ params: { clusterId } }))
}

addCluster = () => {
Expand All @@ -57,9 +54,6 @@ export class ClustersMenu extends React.Component<Props> {
label: _i18n._(t`Disconnect`),
click: async () => {
await clusterIpc.disconnect.invokeFromRenderer(cluster.id);
if (cluster.id === clusterStore.activeClusterId) {
navigate(clusterStatusURL());
}
}
}))
}
Expand Down Expand Up @@ -110,8 +104,8 @@ export class ClustersMenu extends React.Component<Props> {
key={cluster.id}
showErrors={true}
cluster={cluster}
isActive={cluster.id === clusterStore.activeClusterId}
onClick={() => this.showCluster(cluster.id)}
isActive={cluster.id === getMatchedClusterId()}
onClick={() => this.activateCluster(cluster.id)}
onContextMenu={() => this.showContextMenu(cluster)}
/>
)
Expand Down