mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
revert move fileNameMigration to index
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
bc30edade0
commit
9dc5872f77
35
src/common/user-store/file-name-migration.injectable.ts
Normal file
35
src/common/user-store/file-name-migration.injectable.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import fse from "fs-extra";
|
||||||
|
import path from "path";
|
||||||
|
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
|
import { isErrnoException } from "../utils";
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
|
const userStoreFileNameMigrationInjectable = getInjectable({
|
||||||
|
id: "user-store-file-name-migration",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const userDataPath = di.inject(directoryForUserDataInjectable);
|
||||||
|
const configJsonPath = path.join(userDataPath, "config.json");
|
||||||
|
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
||||||
|
|
||||||
|
try {
|
||||||
|
fse.moveSync(configJsonPath, lensUserStoreJsonPath);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error && error.message === "dest already exists.") {
|
||||||
|
fse.removeSync(configJsonPath);
|
||||||
|
} else if (isErrnoException(error) && error.code === "ENOENT" && error.path === configJsonPath) {
|
||||||
|
// (No such file or directory)
|
||||||
|
return; // file already moved
|
||||||
|
} else {
|
||||||
|
// pass other errors along
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default userStoreFileNameMigrationInjectable;
|
||||||
@ -3,14 +3,20 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { ipcMain } from "electron";
|
||||||
|
import userStoreFileNameMigrationInjectable from "./file-name-migration.injectable";
|
||||||
import { UserStore } from "./user-store";
|
import { UserStore } from "./user-store";
|
||||||
|
|
||||||
const userStoreInjectable = getInjectable({
|
const userStoreInjectable = getInjectable({
|
||||||
id: "user-store",
|
id: "user-store",
|
||||||
|
|
||||||
instantiate: () => {
|
instantiate: (di) => {
|
||||||
UserStore.resetInstance();
|
UserStore.resetInstance();
|
||||||
|
|
||||||
|
if (ipcMain) {
|
||||||
|
di.inject(userStoreFileNameMigrationInjectable);
|
||||||
|
}
|
||||||
|
|
||||||
return UserStore.createInstance();
|
return UserStore.createInstance();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,6 @@ import hotbarStoreInjectable from "../common/hotbar-store.injectable";
|
|||||||
import applicationMenuItemsInjectable from "./menu/application-menu-items.injectable";
|
import applicationMenuItemsInjectable from "./menu/application-menu-items.injectable";
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import { init } from "@sentry/electron/main";
|
import { init } from "@sentry/electron/main";
|
||||||
import { userStoreFileNameMigration } from "../migrations/user-store";
|
|
||||||
|
|
||||||
async function main(di: DiContainer) {
|
async function main(di: DiContainer) {
|
||||||
app.setName(appName);
|
app.setName(appName);
|
||||||
@ -73,8 +72,6 @@ async function main(di: DiContainer) {
|
|||||||
*/
|
*/
|
||||||
initializeSentryReporting(init);
|
initializeSentryReporting(init);
|
||||||
|
|
||||||
// TODO make this part of the UserStore setup
|
|
||||||
await userStoreFileNameMigration();
|
|
||||||
await di.runSetups();
|
await di.runSetups();
|
||||||
await app.whenReady();
|
await app.whenReady();
|
||||||
|
|
||||||
|
|||||||
@ -1,32 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import fse from "fs-extra";
|
|
||||||
import path from "path";
|
|
||||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
|
||||||
import directoryForUserDataInjectable from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
|
||||||
import { isErrnoException } from "../../common/utils";
|
|
||||||
|
|
||||||
export async function userStoreFileNameMigration() {
|
|
||||||
const di = getLegacyGlobalDiForExtensionApi();
|
|
||||||
|
|
||||||
const userDataPath = di.inject(directoryForUserDataInjectable);
|
|
||||||
const configJsonPath = path.join(userDataPath, "config.json");
|
|
||||||
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
|
||||||
|
|
||||||
try {
|
|
||||||
await fse.move(configJsonPath, lensUserStoreJsonPath);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof Error && error.message === "dest already exists.") {
|
|
||||||
await fse.remove(configJsonPath);
|
|
||||||
} else if (isErrnoException(error) && error.code === "ENOENT" && error.path === configJsonPath) {
|
|
||||||
// (No such file or directory)
|
|
||||||
return; // file already moved
|
|
||||||
} else {
|
|
||||||
// pass other errors along
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -10,11 +10,6 @@ import { joinMigrations } from "../helpers";
|
|||||||
import version210Beta4 from "./2.1.0-beta.4";
|
import version210Beta4 from "./2.1.0-beta.4";
|
||||||
import version500Alpha3 from "./5.0.0-alpha.3";
|
import version500Alpha3 from "./5.0.0-alpha.3";
|
||||||
import version503Beta1 from "./5.0.3-beta.1";
|
import version503Beta1 from "./5.0.3-beta.1";
|
||||||
import { userStoreFileNameMigration } from "./file-name-migration";
|
|
||||||
|
|
||||||
export {
|
|
||||||
userStoreFileNameMigration,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default joinMigrations(
|
export default joinMigrations(
|
||||||
version210Beta4,
|
version210Beta4,
|
||||||
|
|||||||
@ -47,7 +47,6 @@ class NonInjectedHelmChartDetails extends Component<HelmChartDetailsProps & Depe
|
|||||||
|
|
||||||
constructor(props: HelmChartDetailsProps & Dependencies) {
|
constructor(props: HelmChartDetailsProps & Dependencies) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
|
||||||
autoBind(this);
|
autoBind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -64,7 +64,7 @@ function mockLogTabViewModel(tabId: TabId, deps: Partial<LogTabViewModelDependen
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const getOnePodViewModel = (tabId: TabId, deps: Partial<LogTabViewModelDependencies> = {}): LogTabViewModel => {
|
function getOnePodViewModel(tabId: TabId, deps: Partial<LogTabViewModelDependencies> = {}): LogTabViewModel {
|
||||||
const selectedPod = dockerPod;
|
const selectedPod = dockerPod;
|
||||||
|
|
||||||
return mockLogTabViewModel(tabId, {
|
return mockLogTabViewModel(tabId, {
|
||||||
@ -84,7 +84,7 @@ const getOnePodViewModel = (tabId: TabId, deps: Partial<LogTabViewModelDependenc
|
|||||||
},
|
},
|
||||||
...deps,
|
...deps,
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
const getFewPodsTabData = (tabId: TabId, deps: Partial<LogTabViewModelDependencies> = {}): LogTabViewModel => {
|
const getFewPodsTabData = (tabId: TabId, deps: Partial<LogTabViewModelDependencies> = {}): LogTabViewModel => {
|
||||||
const selectedPod = deploymentPod1;
|
const selectedPod = deploymentPod1;
|
||||||
@ -155,74 +155,83 @@ describe("<LogResourceSelector />", () => {
|
|||||||
mockFs.restore();
|
mockFs.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders w/o errors", () => {
|
describe.only("with one pod", () => {
|
||||||
const model = getOnePodViewModel("foobar");
|
let model: LogTabViewModel;
|
||||||
const { container } = render(<LogResourceSelector model={model} />);
|
|
||||||
|
|
||||||
expect(container).toBeInstanceOf(HTMLElement);
|
beforeEach(() => {
|
||||||
|
model = getOnePodViewModel("foobar");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders w/o errors", () => {
|
||||||
|
const { container } = render(<LogResourceSelector model={model} />);
|
||||||
|
|
||||||
|
expect(container).toBeInstanceOf(HTMLElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders proper namespace", async () => {
|
||||||
|
const { findByTestId } = render(<LogResourceSelector model={model} />);
|
||||||
|
const ns = await findByTestId("namespace-badge");
|
||||||
|
|
||||||
|
expect(ns).toHaveTextContent("default");
|
||||||
|
});
|
||||||
|
|
||||||
|
it.only("renders proper selected items within dropdowns", async () => {
|
||||||
|
const { findByText } = render(<LogResourceSelector model={model} />);
|
||||||
|
|
||||||
|
expect(await findByText("dockerExporter")).toBeInTheDocument();
|
||||||
|
expect(await findByText("docker-exporter")).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders proper namespace", async () => {
|
describe("with several pods", () => {
|
||||||
const model = getOnePodViewModel("foobar");
|
let model: LogTabViewModel;
|
||||||
const { findByTestId } = render(<LogResourceSelector model={model} />);
|
|
||||||
const ns = await findByTestId("namespace-badge");
|
|
||||||
|
|
||||||
expect(ns).toHaveTextContent("default");
|
beforeEach(() => {
|
||||||
});
|
model = getFewPodsTabData("foobar");
|
||||||
|
});
|
||||||
|
|
||||||
it("renders proper selected items within dropdowns", async () => {
|
it("renders sibling pods in dropdown", async () => {
|
||||||
const model = getOnePodViewModel("foobar");
|
const { container, findByText } = render(<LogResourceSelector model={model} />);
|
||||||
const { findByText } = render(<LogResourceSelector model={model} />);
|
const selector = container.querySelector<HTMLElement>(".pod-selector");
|
||||||
|
|
||||||
expect(await findByText("dockerExporter")).toBeInTheDocument();
|
assert(selector);
|
||||||
expect(await findByText("docker-exporter")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders sibling pods in dropdown", async () => {
|
selectEvent.openMenu(selector);
|
||||||
const model = getFewPodsTabData("foobar");
|
expect(await findByText("deploymentPod2", { selector: ".pod-selector-menu .Select__option" })).toBeInTheDocument();
|
||||||
const { container, findByText } = render(<LogResourceSelector model={model} />);
|
expect(await findByText("deploymentPod1", { selector: ".pod-selector-menu .Select__option" })).toBeInTheDocument();
|
||||||
const selector = container.querySelector<HTMLElement>(".pod-selector");
|
});
|
||||||
|
|
||||||
assert(selector);
|
it("renders sibling containers in dropdown", async () => {
|
||||||
|
const { findByText, container } = render(<LogResourceSelector model={model} />);
|
||||||
|
const selector = container.querySelector<HTMLElement>(".container-selector");
|
||||||
|
|
||||||
selectEvent.openMenu(selector);
|
assert(selector);
|
||||||
expect(await findByText("deploymentPod2", { selector: ".pod-selector-menu .Select__option" })).toBeInTheDocument();
|
|
||||||
expect(await findByText("deploymentPod1", { selector: ".pod-selector-menu .Select__option" })).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders sibling containers in dropdown", async () => {
|
selectEvent.openMenu(selector);
|
||||||
const model = getFewPodsTabData("foobar");
|
|
||||||
const { findByText, container } = render(<LogResourceSelector model={model} />);
|
|
||||||
const selector = container.querySelector<HTMLElement>(".container-selector");
|
|
||||||
|
|
||||||
assert(selector);
|
expect(await findByText("node-exporter-1")).toBeInTheDocument();
|
||||||
|
expect(await findByText("init-node-exporter")).toBeInTheDocument();
|
||||||
|
expect(await findByText("init-node-exporter-1")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
selectEvent.openMenu(selector);
|
it("renders pod owner as badge", async () => {
|
||||||
|
const { findByText } = render(<LogResourceSelector model={model} />);
|
||||||
|
|
||||||
expect(await findByText("node-exporter-1")).toBeInTheDocument();
|
expect(await findByText("super-deployment", {
|
||||||
expect(await findByText("init-node-exporter")).toBeInTheDocument();
|
exact: false,
|
||||||
expect(await findByText("init-node-exporter-1")).toBeInTheDocument();
|
})).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders pod owner as badge", async () => {
|
it("updates tab name if selected pod changes", async () => {
|
||||||
const model = getFewPodsTabData("foobar");
|
const renameTab = jest.fn();
|
||||||
const { findByText } = render(<LogResourceSelector model={model} />);
|
const { findByText, container } = render(<LogResourceSelector model={model} />);
|
||||||
|
const selector = container.querySelector<HTMLElement>(".pod-selector");
|
||||||
|
|
||||||
expect(await findByText("super-deployment", {
|
assert(selector);
|
||||||
exact: false,
|
|
||||||
})).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("updates tab name if selected pod changes", async () => {
|
selectEvent.openMenu(selector);
|
||||||
const renameTab = jest.fn();
|
userEvent.click(await findByText("deploymentPod2", { selector: ".pod-selector-menu .Select__option" }));
|
||||||
const model = getFewPodsTabData("foobar", { renameTab });
|
expect(renameTab).toBeCalledWith("foobar", "Pod deploymentPod2");
|
||||||
const { findByText, container } = render(<LogResourceSelector model={model} />);
|
});
|
||||||
const selector = container.querySelector<HTMLElement>(".pod-selector");
|
|
||||||
|
|
||||||
assert(selector);
|
|
||||||
|
|
||||||
selectEvent.openMenu(selector);
|
|
||||||
userEvent.click(await findByText("deploymentPod2", { selector: ".pod-selector-menu .Select__option" }));
|
|
||||||
expect(renameTab).toBeCalledWith("foobar", "Pod deploymentPod2");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,17 +11,13 @@ import { observer } from "mobx-react";
|
|||||||
import { Badge } from "../../badge";
|
import { Badge } from "../../badge";
|
||||||
import { Select } from "../../select";
|
import { Select } from "../../select";
|
||||||
import type { LogTabViewModel } from "./logs-view-model";
|
import type { LogTabViewModel } from "./logs-view-model";
|
||||||
import type { IPodContainer, Pod } from "../../../../common/k8s-api/endpoints";
|
import type { Pod } from "../../../../common/k8s-api/endpoints";
|
||||||
import type { GroupBase } from "react-select";
|
import type { GroupBase } from "react-select";
|
||||||
|
|
||||||
export interface LogResourceSelectorProps {
|
export interface LogResourceSelectorProps {
|
||||||
model: LogTabViewModel;
|
model: LogTabViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectOptions(containers: IPodContainer[]) {
|
|
||||||
return containers.map(container => container.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const LogResourceSelector = observer(({ model }: LogResourceSelectorProps) => {
|
export const LogResourceSelector = observer(({ model }: LogResourceSelectorProps) => {
|
||||||
const tabData = model.logTabData.get();
|
const tabData = model.logTabData.get();
|
||||||
|
|
||||||
@ -64,23 +60,23 @@ export const LogResourceSelector = observer(({ model }: LogResourceSelectorProps
|
|||||||
const containerSelectOptions = [
|
const containerSelectOptions = [
|
||||||
{
|
{
|
||||||
label: "Containers",
|
label: "Containers",
|
||||||
options: getSelectOptions(pod.getContainers()),
|
options: pod.getContainers().map(container => container.name),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Init Containers",
|
label: "Init Containers",
|
||||||
options: getSelectOptions(pod.getInitContainers()),
|
options: pod.getInitContainers().map(container => container.name),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="LogResourceSelector flex gaps align-center">
|
<div className="LogResourceSelector flex gaps align-center">
|
||||||
<span>Namespace</span>
|
<span>Namespace</span>
|
||||||
{" "}
|
{" "}
|
||||||
<Badge data-testid="namespace-badge" label={pod.getNs()} />
|
<Badge data-testid="namespace-badge" label={pod.getNs()} />
|
||||||
{
|
{
|
||||||
owner && (
|
owner && (
|
||||||
<>
|
<>
|
||||||
<span>Owner</span>
|
<span>Owner</span>
|
||||||
{" "}
|
{" "}
|
||||||
<Badge data-testid="namespace-badge" label={`${owner.kind} ${owner.name}`} />
|
<Badge data-testid="namespace-badge" label={`${owner.kind} ${owner.name}`} />
|
||||||
</>
|
</>
|
||||||
@ -90,6 +86,7 @@ export const LogResourceSelector = observer(({ model }: LogResourceSelectorProps
|
|||||||
<Select
|
<Select
|
||||||
options={pods}
|
options={pods}
|
||||||
value={pod}
|
value={pod}
|
||||||
|
isClearable={false}
|
||||||
formatOptionLabel={option => option.getName()}
|
formatOptionLabel={option => option.getName()}
|
||||||
onChange={onPodChange}
|
onChange={onPodChange}
|
||||||
className="pod-selector"
|
className="pod-selector"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user