Cascade different refactorings to eliminate global shared state from app paths

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne SavolainenandMikko Aspiala committed 2022-01-05 13:26:49 +02:00
1 parent 908a40975e
commit 9d33fff906
336 files changed
+9105 -3307

No files matched your search

@@ -28,23 +28,31 @@ import { action, computed, makeObservable, observable } from "mobx";
import { observer } from "mobx-react";
import path from "path";
import React from "react";
import * as uuid from "uuid";
import { catalogURL } from "../../../common/routes";
import { appEventBus } from "../../../common/event-bus";
import { appEventBus } from "../../../common/app-event-bus/event-bus";
import { loadConfigFromString, splitConfig } from "../../../common/kube-helpers";
import { docsUrl } from "../../../common/vars";
import { navigate } from "../../navigation";
import { getCustomKubeConfigPath, iter } from "../../utils";
import { iter } from "../../utils";
import { Button } from "../button";
import { Notifications } from "../notifications";
import { SettingLayout } from "../layout/setting-layout";
import { MonacoEditor } from "../monaco-editor";
import { withInjectables } from "@ogre-tools/injectable-react";
import getCustomKubeConfigDirectoryInjectable
from "../../../common/app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable";
interface Option {
config: KubeConfig;
error?: string;
}
interface Dependencies {
getCustomKubeConfigDirectory: (directoryName: string) => string
}
function getContexts(config: KubeConfig): Map<string, Option> {
return new Map(
splitConfig(config)
@@ -56,14 +64,14 @@ function getContexts(config: KubeConfig): Map<string, Option> {
}
@observer
export class AddCluster extends React.Component {
class NonInjectedAddCluster extends React.Component<Dependencies> {
@observable kubeContexts = observable.map<string, Option>();
@observable customConfig = "";
@observable isWaiting = false;
@observable errors: string[] = [];
constructor(props: {}) {
super(props);
constructor(dependencies: Dependencies) {
super(dependencies);
makeObservable(this);
}
@@ -99,7 +107,7 @@ export class AddCluster extends React.Component {
appEventBus.emit({ name: "cluster-add", action: "click" });
try {
const absPath = getCustomKubeConfigPath();
const absPath = this.props.getCustomKubeConfigDirectory(uuid.v4());
await fse.ensureDir(path.dirname(absPath));
await fse.writeFile(absPath, this.customConfig.trim(), { encoding: "utf-8", mode: 0o600 });
@@ -153,3 +161,11 @@ export class AddCluster extends React.Component {
);
}
}
export const AddCluster = withInjectables<Dependencies>(NonInjectedAddCluster, {
getProps: (di) => ({
getCustomKubeConfigDirectory: di.inject(
getCustomKubeConfigDirectoryInjectable,
),
}),
});