mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix hotbar migration of workspaces
- Don't use the cluster.id field as it was previously a uuidV4, and newer clusterIds are md5's of path:name Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
7058193295
commit
ef837e1503
@ -23,7 +23,7 @@ import path from "path";
|
|||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import type { ClusterModel } from "../../common/cluster-store";
|
import type { ClusterModel } from "../../common/cluster-store";
|
||||||
import { MigrationDeclaration, migrationLog } from "../helpers";
|
import type { MigrationDeclaration } from "../helpers";
|
||||||
|
|
||||||
interface Pre500WorkspaceStoreModel {
|
interface Pre500WorkspaceStoreModel {
|
||||||
workspaces: {
|
workspaces: {
|
||||||
@ -36,7 +36,7 @@ export default {
|
|||||||
version: "5.0.0-beta.10",
|
version: "5.0.0-beta.10",
|
||||||
run(store) {
|
run(store) {
|
||||||
const userDataPath = app.getPath("userData");
|
const userDataPath = app.getPath("userData");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const workspaceData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));
|
const workspaceData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));
|
||||||
const workspaces = new Map<string, string>(); // mapping from WorkspaceId to name
|
const workspaces = new Map<string, string>(); // mapping from WorkspaceId to name
|
||||||
@ -45,8 +45,6 @@ export default {
|
|||||||
workspaces.set(id, name);
|
workspaces.set(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
migrationLog("workspaces", JSON.stringify([...workspaces.entries()]));
|
|
||||||
|
|
||||||
const clusters: ClusterModel[] = store.get("clusters");
|
const clusters: ClusterModel[] = store.get("clusters");
|
||||||
|
|
||||||
for (const cluster of clusters) {
|
for (const cluster of clusters) {
|
||||||
@ -58,8 +56,6 @@ export default {
|
|||||||
|
|
||||||
store.set("clusters", clusters);
|
store.set("clusters", clusters);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
migrationLog("error", error.path);
|
|
||||||
|
|
||||||
if (!(error.code === "ENOENT" && error.path.endsWith("lens-workspace-store.json"))) {
|
if (!(error.code === "ENOENT" && error.path.endsWith("lens-workspace-store.json"))) {
|
||||||
// ignore lens-workspace-store.json being missing
|
// ignore lens-workspace-store.json being missing
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@ -21,33 +21,18 @@
|
|||||||
|
|
||||||
// Cleans up a store that had the state related data stored
|
// Cleans up a store that had the state related data stored
|
||||||
import type { Hotbar } from "../../common/hotbar-store";
|
import type { Hotbar } from "../../common/hotbar-store";
|
||||||
import { ClusterStore } from "../../common/cluster-store";
|
|
||||||
import * as uuid from "uuid";
|
import * as uuid from "uuid";
|
||||||
import type { MigrationDeclaration } from "../helpers";
|
import type { MigrationDeclaration } from "../helpers";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
version: "5.0.0-alpha.0",
|
version: "5.0.0-alpha.0",
|
||||||
run(store) {
|
run(store) {
|
||||||
const hotbars: Hotbar[] = [];
|
const hotbar: Hotbar = {
|
||||||
|
id: uuid.v4(),
|
||||||
|
name: "default",
|
||||||
|
items: [...Array.from(Array(12).fill(null))],
|
||||||
|
};
|
||||||
|
|
||||||
ClusterStore.getInstance().clustersList.forEach((cluster: any) => {
|
store.set("hotbars", [hotbar]);
|
||||||
const name = cluster.workspace;
|
|
||||||
|
|
||||||
if (!name) return;
|
|
||||||
|
|
||||||
let hotbar = hotbars.find((h) => h.name === name);
|
|
||||||
|
|
||||||
if (!hotbar) {
|
|
||||||
hotbar = { id: uuid.v4(), name, items: [] };
|
|
||||||
hotbars.push(hotbar);
|
|
||||||
}
|
|
||||||
|
|
||||||
hotbar.items.push({
|
|
||||||
entity: { uid: cluster.id },
|
|
||||||
params: {}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
store.set("hotbars", hotbars);
|
|
||||||
}
|
}
|
||||||
} as MigrationDeclaration;
|
} as MigrationDeclaration;
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { createHash } from "crypto";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
@ -59,7 +60,7 @@ export default {
|
|||||||
if (workspaceHotbar?.items.length < defaultHotbarCells) {
|
if (workspaceHotbar?.items.length < defaultHotbarCells) {
|
||||||
workspaceHotbar.items.push({
|
workspaceHotbar.items.push({
|
||||||
entity: {
|
entity: {
|
||||||
uid: cluster.id,
|
uid: createHash("md5").update(`${cluster.kubeConfigPath}:${cluster.contextName}`).digest("hex"),
|
||||||
name: cluster.preferences.clusterName || cluster.contextName,
|
name: cluster.preferences.clusterName || cluster.contextName,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import { CatalogEntityDrawerMenu } from "./catalog-entity-drawer-menu";
|
|||||||
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
||||||
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
||||||
import type { CatalogEntityItem } from "./catalog-entity.store";
|
import type { CatalogEntityItem } from "./catalog-entity.store";
|
||||||
|
import { isDevelopment } from "../../../common/vars";
|
||||||
|
|
||||||
interface Props<T extends CatalogEntity> {
|
interface Props<T extends CatalogEntity> {
|
||||||
item: CatalogEntityItem<T> | null | undefined;
|
item: CatalogEntityItem<T> | null | undefined;
|
||||||
@ -91,6 +92,11 @@ export class CatalogEntityDetails<T extends CatalogEntity> extends Component<Pro
|
|||||||
<DrawerItem name="Labels">
|
<DrawerItem name="Labels">
|
||||||
{...item.getLabelBadges(this.props.hideDetails)}
|
{...item.getLabelBadges(this.props.hideDetails)}
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
|
{isDevelopment && (
|
||||||
|
<DrawerItem name="Id">
|
||||||
|
{item.getId()}
|
||||||
|
</DrawerItem>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user