diff --git a/src/common/catalog-entities/web-link.ts b/src/common/catalog-entities/web-link.ts index 5618120ec1..7c83051c8b 100644 --- a/src/common/catalog-entities/web-link.ts +++ b/src/common/catalog-entities/web-link.ts @@ -7,7 +7,7 @@ import { Environments, getEnvironmentSpecificLegacyGlobalDiForExtensionApi } fro import type { CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog"; import { CatalogCategory, CatalogEntity, categoryVersion } from "../catalog/catalog-entity"; import productNameInjectable from "../vars/product-name.injectable"; -import weblinkStoreInjectable from "../weblink-store.injectable"; +import weblinkStoreInjectable from "../weblinks-store/weblink-store.injectable"; export type WebLinkStatusPhase = "available" | "unavailable"; diff --git a/src/common/vars.ts b/src/common/vars.ts index fe568b5b86..0f697755e4 100644 --- a/src/common/vars.ts +++ b/src/common/vars.ts @@ -55,12 +55,4 @@ export const apiKubePrefix = "/api-kube"; // k8s cluster apis export const issuesTrackerUrl = "https://github.com/lensapp/lens/issues" as string; export const slackUrl = "https://join.slack.com/t/k8slens/shared_invite/zt-wcl8jq3k-68R5Wcmk1o95MLBE5igUDQ" as string; export const supportUrl = "https://docs.k8slens.dev/support/" as string; - -export const lensWebsiteWeblinkId = "lens-website-link"; -export const lensDocumentationWeblinkId = "lens-documentation-link"; -export const lensSlackWeblinkId = "lens-slack-link"; -export const lensTwitterWeblinkId = "lens-twitter-link"; -export const lensBlogWeblinkId = "lens-blog-link"; -export const kubernetesDocumentationWeblinkId = "kubernetes-documentation-link"; - export const docsUrl = "https://docs.k8slens.dev" as string; diff --git a/src/common/weblinks-store/migration-token.ts b/src/common/weblinks-store/migration-token.ts new file mode 100644 index 0000000000..d1cea9334b --- /dev/null +++ b/src/common/weblinks-store/migration-token.ts @@ -0,0 +1,11 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { getInjectionToken } from "@ogre-tools/injectable"; +import type { MigrationDeclaration } from "../base-store/migrations.injectable"; + +export const weblinkStoreMigrationInjectionToken = getInjectionToken({ + id: "weblink-store-migration-token", +}); diff --git a/src/common/weblink-store.injectable.ts b/src/common/weblinks-store/weblink-store.injectable.ts similarity index 51% rename from src/common/weblink-store.injectable.ts rename to src/common/weblinks-store/weblink-store.injectable.ts index f6072318e8..1f8f45e3f2 100644 --- a/src/common/weblink-store.injectable.ts +++ b/src/common/weblinks-store/weblink-store.injectable.ts @@ -3,10 +3,12 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import directoryForUserDataInjectable from "./app-paths/directory-for-user-data/directory-for-user-data.injectable"; -import getConfigurationFileModelInjectable from "./get-configuration-file-model/get-configuration-file-model.injectable"; -import loggerInjectable from "./logger.injectable"; -import storeMigrationVersionInjectable from "./vars/store-migration-version.injectable"; +import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable"; +import storeMigrationsInjectable from "../base-store/migrations.injectable"; +import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable"; +import loggerInjectable from "../logger.injectable"; +import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable"; +import { weblinkStoreMigrationInjectionToken } from "./migration-token"; import { WeblinkStore } from "./weblink-store"; const weblinkStoreInjectable = getInjectable({ @@ -16,6 +18,7 @@ const weblinkStoreInjectable = getInjectable({ getConfigurationFileModel: di.inject(getConfigurationFileModelInjectable), logger: di.inject(loggerInjectable), storeMigrationVersion: di.inject(storeMigrationVersionInjectable), + migrations: di.inject(storeMigrationsInjectable, weblinkStoreMigrationInjectionToken), }), }); diff --git a/src/common/weblink-store.ts b/src/common/weblinks-store/weblink-store.ts similarity index 87% rename from src/common/weblink-store.ts rename to src/common/weblinks-store/weblink-store.ts index a1115581c4..91bf578e84 100644 --- a/src/common/weblink-store.ts +++ b/src/common/weblinks-store/weblink-store.ts @@ -4,11 +4,10 @@ */ import { action, comparer, observable, makeObservable } from "mobx"; -import type { BaseStoreDependencies } from "./base-store/base-store"; -import { BaseStore } from "./base-store/base-store"; -import migrations from "../migrations/weblinks-store"; +import type { BaseStoreDependencies } from "../base-store/base-store"; +import { BaseStore } from "../base-store/base-store"; import * as uuid from "uuid"; -import { toJS } from "./utils"; +import { toJS } from "../utils"; export interface WeblinkData { id: string; @@ -38,7 +37,6 @@ export class WeblinkStore extends BaseStore { syncOptions: { equals: comparer.structural, }, - migrations, }); makeObservable(this); this.load(); diff --git a/src/main/catalog-sources/sync-weblinks.injectable.ts b/src/main/catalog-sources/sync-weblinks.injectable.ts index 836418781d..f75de34a9d 100644 --- a/src/main/catalog-sources/sync-weblinks.injectable.ts +++ b/src/main/catalog-sources/sync-weblinks.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { syncWeblinks } from "./weblinks"; -import weblinkStoreInjectable from "../../common/weblink-store.injectable"; +import weblinkStoreInjectable from "../../common/weblinks-store/weblink-store.injectable"; import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable"; const syncWeblinksInjectable = getInjectable({ diff --git a/src/main/catalog-sources/weblinks.ts b/src/main/catalog-sources/weblinks.ts index 353f5f91bb..084654efc0 100644 --- a/src/main/catalog-sources/weblinks.ts +++ b/src/main/catalog-sources/weblinks.ts @@ -4,7 +4,7 @@ */ import { computed, observable, reaction } from "mobx"; -import type { WeblinkStore } from "../../common/weblink-store"; +import type { WeblinkStore } from "../../common/weblinks-store/weblink-store"; import { WebLink } from "../../common/catalog-entities"; import type { CatalogEntityRegistry } from "../catalog"; import got from "got"; diff --git a/src/main/weblinks-store/links.ts b/src/main/weblinks-store/links.ts new file mode 100644 index 0000000000..ae53b6ec27 --- /dev/null +++ b/src/main/weblinks-store/links.ts @@ -0,0 +1,24 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + + +export const lensWebsiteWeblinkId = "lens-website-link"; +export const lensWebsiteLinkName = "Lens Website"; + +export const lensDocumentationWeblinkId = "lens-documentation-link"; +export const lensDocumentationWeblinkName = "Lens Documentation"; + +export const lensSlackWeblinkId = "lens-slack-link"; +export const lensSlackWeblinkName = "Lens Community Slack"; + +export const lensTwitterWeblinkId = "lens-twitter-link"; +export const lensTwitterWeblinkName = "Lens on Twitter"; + +export const lensBlogWeblinkId = "lens-blog-link"; +export const lensBlogWeblinkName = "Lens Official Blog"; + +export const kubernetesDocumentationWeblinkId = "kubernetes-documentation-link"; +export const kubernetesDocumentationWeblinkName = "Kubernetes Documentation"; + diff --git a/src/main/weblinks-store/migrations/5.1.4.injectable.ts b/src/main/weblinks-store/migrations/5.1.4.injectable.ts new file mode 100644 index 0000000000..fe27b9ae3e --- /dev/null +++ b/src/main/weblinks-store/migrations/5.1.4.injectable.ts @@ -0,0 +1,35 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { docsUrl, slackUrl } from "../../../common/vars"; +import type { WeblinkData } from "../../../common/weblinks-store/weblink-store"; +import { getInjectable } from "@ogre-tools/injectable"; +import { weblinkStoreMigrationInjectionToken } from "../../../common/weblinks-store/migration-token"; +import * as links from "../links"; + +const v514WeblinkStoreMigrationInjectable = getInjectable({ + id: "v5.1.4-weblink-store-migration", + instantiate: () => ({ + version: "5.1.4", + run(store) { + const weblinksRaw = store.get("weblinks"); + const weblinks = (Array.isArray(weblinksRaw) ? weblinksRaw : []) as WeblinkData[]; + + weblinks.push( + { id: "https://k8slens.dev", name: links.lensWebsiteLinkName, url: "https://k8slens.dev" }, + { id: docsUrl, name: links.lensDocumentationWeblinkName, url: docsUrl }, + { id: slackUrl, name: links.lensSlackWeblinkName, url: slackUrl }, + { id: "https://twitter.com/k8slens", name: links.lensTwitterWeblinkName, url: "https://twitter.com/k8slens" }, + { id: "https://medium.com/k8slens", name: links.lensBlogWeblinkName, url: "https://medium.com/k8slens" }, + { id: "https://kubernetes.io/docs/home/", name: links.kubernetesDocumentationWeblinkName, url: "https://kubernetes.io/docs/home/" }, + ); + + store.set("weblinks", weblinks); + }, + }), + injectionToken: weblinkStoreMigrationInjectionToken, +}); + +export default v514WeblinkStoreMigrationInjectable; diff --git a/src/main/weblinks-store/migrations/5.4.5-beta.1.injectable.ts b/src/main/weblinks-store/migrations/5.4.5-beta.1.injectable.ts new file mode 100644 index 0000000000..dbe580bec3 --- /dev/null +++ b/src/main/weblinks-store/migrations/5.4.5-beta.1.injectable.ts @@ -0,0 +1,61 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import type { WeblinkData } from "../../../common/weblinks-store/weblink-store"; +import * as links from "../links"; +import { getInjectable } from "@ogre-tools/injectable"; +import { weblinkStoreMigrationInjectionToken } from "../../../common/weblinks-store/migration-token"; + +const v545Beta1WeblinkStoreMigrationInjectable = getInjectable({ + id: "v5.4.5-beta.1-weblink-store-migration", + instantiate: () => ({ + version: "5.4.5-beta.1 || >=5.5.0-alpha.0", + run(store) { + const weblinksRaw = store.get("weblinks"); + const weblinks = (Array.isArray(weblinksRaw) ? weblinksRaw : []) as WeblinkData[]; + + const lensWebsiteLink = weblinks.find(weblink => weblink.name === links.lensWebsiteLinkName); + + if (lensWebsiteLink) { + lensWebsiteLink.id = links.lensWebsiteWeblinkId; + } + + const lensDocumentationWeblinkLink = weblinks.find(weblink => weblink.name === links.lensDocumentationWeblinkName); + + if (lensDocumentationWeblinkLink) { + lensDocumentationWeblinkLink.id = links.lensDocumentationWeblinkId; + } + + const lensSlackWeblinkLink = weblinks.find(weblink => weblink.name === links.lensSlackWeblinkName); + + if (lensSlackWeblinkLink) { + lensSlackWeblinkLink.id = links.lensSlackWeblinkId; + } + + const lensTwitterWeblinkLink = weblinks.find(weblink => weblink.name === links.lensTwitterWeblinkName); + + if (lensTwitterWeblinkLink) { + lensTwitterWeblinkLink.id = links.lensTwitterWeblinkId; + } + + const lensBlogWeblinkLink = weblinks.find(weblink => weblink.name === links.lensBlogWeblinkName); + + if (lensBlogWeblinkLink) { + lensBlogWeblinkLink.id = links.lensBlogWeblinkId; + } + + const kubernetesDocumentationWeblinkLink = weblinks.find(weblink => weblink.name === links.kubernetesDocumentationWeblinkName); + + if (kubernetesDocumentationWeblinkLink) { + kubernetesDocumentationWeblinkLink.id = links.kubernetesDocumentationWeblinkId; + } + + store.set("weblinks", weblinks); + }, + }), + injectionToken: weblinkStoreMigrationInjectionToken, +}); + +export default v545Beta1WeblinkStoreMigrationInjectable; diff --git a/src/main/weblinks-store/migrations/currentVersion.injectable.ts b/src/main/weblinks-store/migrations/currentVersion.injectable.ts new file mode 100644 index 0000000000..9a23a1a326 --- /dev/null +++ b/src/main/weblinks-store/migrations/currentVersion.injectable.ts @@ -0,0 +1,42 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { docsUrl, slackUrl } from "../../../common/vars"; +import type { WeblinkData } from "../../../common/weblinks-store/weblink-store"; +import { getInjectable } from "@ogre-tools/injectable"; +import { weblinkStoreMigrationInjectionToken } from "../../../common/weblinks-store/migration-token"; +import applicationInformationInjectable from "../../../common/vars/application-information.injectable"; +import { lensDocumentationWeblinkId, lensSlackWeblinkId } from "../links"; + +const currentVersionWeblinkStoreMigrationInjectable = getInjectable({ + id: "current-version-weblink-store-migration", + instantiate: (di) => { + const { version } = di.inject(applicationInformationInjectable); + + return { + version, // Run always after upgrade + run(store) { + const weblinksRaw = store.get("weblinks"); + const weblinks = (Array.isArray(weblinksRaw) ? weblinksRaw : []) as WeblinkData[]; + const slackWeblink = weblinks.find(weblink => weblink.id === lensSlackWeblinkId); + + if (slackWeblink) { + slackWeblink.url = slackUrl; + } + + const docsWeblink = weblinks.find(weblink => weblink.id === lensDocumentationWeblinkId); + + if (docsWeblink) { + docsWeblink.url = docsUrl; + } + + store.set("weblinks", weblinks); + }, + }; + }, + injectionToken: weblinkStoreMigrationInjectionToken, +}); + +export default currentVersionWeblinkStoreMigrationInjectable; diff --git a/src/migrations/weblinks-store/5.1.4.ts b/src/migrations/weblinks-store/5.1.4.ts deleted file mode 100644 index 59c47be8b0..0000000000 --- a/src/migrations/weblinks-store/5.1.4.ts +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import { docsUrl, slackUrl } from "../../common/vars"; -import type { WeblinkData } from "../../common/weblink-store"; -import type { MigrationDeclaration } from "../helpers"; - -export const lensWebsiteLinkName = "Lens Website"; -export const lensDocumentationWeblinkName = "Lens Documentation"; -export const lensSlackWeblinkName = "Lens Community Slack"; -export const lensTwitterWeblinkName = "Lens on Twitter"; -export const lensBlogWeblinkName = "Lens Official Blog"; -export const kubernetesDocumentationWeblinkName = "Kubernetes Documentation"; - -export default { - version: "5.1.4", - run(store) { - const weblinksRaw: any = store.get("weblinks"); - const weblinks = (Array.isArray(weblinksRaw) ? weblinksRaw : []) as WeblinkData[]; - - weblinks.push( - { id: "https://k8slens.dev", name: lensWebsiteLinkName, url: "https://k8slens.dev" }, - { id: docsUrl, name: lensDocumentationWeblinkName, url: docsUrl }, - { id: slackUrl, name: lensSlackWeblinkName, url: slackUrl }, - { id: "https://twitter.com/k8slens", name: lensTwitterWeblinkName, url: "https://twitter.com/k8slens" }, - { id: "https://medium.com/k8slens", name: lensBlogWeblinkName, url: "https://medium.com/k8slens" }, - { id: "https://kubernetes.io/docs/home/", name: kubernetesDocumentationWeblinkName, url: "https://kubernetes.io/docs/home/" }, - ); - - store.set("weblinks", weblinks); - }, -} as MigrationDeclaration; diff --git a/src/migrations/weblinks-store/5.4.5-beta.1.ts b/src/migrations/weblinks-store/5.4.5-beta.1.ts deleted file mode 100644 index 57d6f5c4ba..0000000000 --- a/src/migrations/weblinks-store/5.4.5-beta.1.ts +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import { kubernetesDocumentationWeblinkId, lensBlogWeblinkId, lensDocumentationWeblinkId, lensSlackWeblinkId, lensTwitterWeblinkId, lensWebsiteWeblinkId } from "../../common/vars"; -import type { WeblinkData } from "../../common/weblink-store"; -import type { MigrationDeclaration } from "../helpers"; -import { kubernetesDocumentationWeblinkName, lensBlogWeblinkName, lensDocumentationWeblinkName, lensSlackWeblinkName, lensTwitterWeblinkName, lensWebsiteLinkName } from "./5.1.4"; - -export default { - version: "5.4.5-beta.1 || >=5.5.0-alpha.0", - run(store) { - const weblinksRaw: any = store.get("weblinks"); - const weblinks = (Array.isArray(weblinksRaw) ? weblinksRaw : []) as WeblinkData[]; - - const lensWebsiteLink = weblinks.find(weblink => weblink.name === lensWebsiteLinkName); - - if (lensWebsiteLink) { - lensWebsiteLink.id = lensWebsiteWeblinkId; - } - - const lensDocumentationWeblinkLink = weblinks.find(weblink => weblink.name === lensDocumentationWeblinkName); - - if (lensDocumentationWeblinkLink) { - lensDocumentationWeblinkLink.id = lensDocumentationWeblinkId; - } - - const lensSlackWeblinkLink = weblinks.find(weblink => weblink.name === lensSlackWeblinkName); - - if (lensSlackWeblinkLink) { - lensSlackWeblinkLink.id = lensSlackWeblinkId; - } - - const lensTwitterWeblinkLink = weblinks.find(weblink => weblink.name === lensTwitterWeblinkName); - - if (lensTwitterWeblinkLink) { - lensTwitterWeblinkLink.id = lensTwitterWeblinkId; - } - - const lensBlogWeblinkLink = weblinks.find(weblink => weblink.name === lensBlogWeblinkName); - - if (lensBlogWeblinkLink) { - lensBlogWeblinkLink.id = lensBlogWeblinkId; - } - - const kubernetesDocumentationWeblinkLink = weblinks.find(weblink => weblink.name === kubernetesDocumentationWeblinkName); - - if (kubernetesDocumentationWeblinkLink) { - kubernetesDocumentationWeblinkLink.id = kubernetesDocumentationWeblinkId; - } - - store.set("weblinks", weblinks); - }, -} as MigrationDeclaration; diff --git a/src/migrations/weblinks-store/currentVersion.ts b/src/migrations/weblinks-store/currentVersion.ts deleted file mode 100644 index afa404847b..0000000000 --- a/src/migrations/weblinks-store/currentVersion.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import { docsUrl, lensDocumentationWeblinkId, lensSlackWeblinkId, slackUrl } from "../../common/vars"; -import type { WeblinkData } from "../../common/weblink-store"; -import type { MigrationDeclaration } from "../helpers"; -import packageJson from "../../../package.json"; - -export default { - // TODO: replace with injection once migrations are made as injectables - version: packageJson.version, // Run always after upgrade - run(store) { - const weblinksRaw: any = store.get("weblinks"); - const weblinks = (Array.isArray(weblinksRaw) ? weblinksRaw : []) as WeblinkData[]; - const slackWeblink = weblinks.find(weblink => weblink.id === lensSlackWeblinkId); - - if (slackWeblink) { - slackWeblink.url = slackUrl; - } - - const docsWeblink = weblinks.find(weblink => weblink.id === lensDocumentationWeblinkId); - - if (docsWeblink) { - docsWeblink.url = docsUrl; - } - - store.set("weblinks", weblinks); - }, -} as MigrationDeclaration; diff --git a/src/migrations/weblinks-store/index.ts b/src/migrations/weblinks-store/index.ts deleted file mode 100644 index a6e6ea1eea..0000000000 --- a/src/migrations/weblinks-store/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import { joinMigrations } from "../helpers"; - -import version514 from "./5.1.4"; -import version545Beta1 from "./5.4.5-beta.1"; -import currentVersion from "./currentVersion"; - -export default joinMigrations( - version514, - version545Beta1, - currentVersion, -); diff --git a/src/renderer/bootstrap.tsx b/src/renderer/bootstrap.tsx index 735d349ac7..b28e336736 100644 --- a/src/renderer/bootstrap.tsx +++ b/src/renderer/bootstrap.tsx @@ -19,7 +19,7 @@ import { DefaultProps } from "./mui-base-theme"; import configurePackages from "../common/configure-packages"; import * as initializers from "./initializers"; import logger from "../common/logger"; -import { registerCustomThemes } from "./components/monaco-editor"; +import { registerCustomThemes ../common/weblinks-store/weblink-storenaco-editor"; import { getDi } from "./getDi"; import { DiContextProvider } from "@ogre-tools/injectable-react"; import type { DiContainer } from "@ogre-tools/injectable"; diff --git a/src/renderer/components/catalog-entities/weblink-add-command.tsx b/src/renderer/components/catalog-entities/weblink-add-command.tsx index b6daee6e5b..0209ff93fa 100644 --- a/src/renderer/components/catalog-entities/weblink-add-command.tsx +++ b/src/renderer/components/catalog-entities/weblink-add-command.tsx @@ -7,11 +7,11 @@ import React from "react"; import { observer } from "mobx-react"; import { Input } from "../input"; import { isUrl } from "../input/input_validators"; -import type { WeblinkStore } from "../../../common/weblink-store"; +import type { WeblinkStore } from "../../../common/weblinks-store/weblink-store"; import { computed, makeObservable, observable } from "mobx"; import { withInjectables } from "@ogre-tools/injectable-react"; import commandOverlayInjectable from "../command-palette/command-overlay.injectable"; -import weblinkStoreInjectable from "../../../common/weblink-store.injectable"; +import weblinkStoreInjectable from "../../../common/weblinks-store/weblink-store.injectable"; interface Dependencies { closeCommandOverlay: () => void;