mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix errors in HotbarStore migrations (#4105)
This commit is contained in:
parent
1872a8da87
commit
cd14097668
@ -27,7 +27,8 @@ import type { MigrationDeclaration } from "../helpers";
|
|||||||
export default {
|
export default {
|
||||||
version: "5.0.0-alpha.2",
|
version: "5.0.0-alpha.2",
|
||||||
run(store) {
|
run(store) {
|
||||||
const hotbars = (store.get("hotbars") || []) as Hotbar[];
|
const rawHotbars = store.get("hotbars");
|
||||||
|
const hotbars: Hotbar[] = Array.isArray(rawHotbars) ? rawHotbars : [];
|
||||||
|
|
||||||
store.set("hotbars", hotbars.map((hotbar) => ({
|
store.set("hotbars", hotbars.map((hotbar) => ({
|
||||||
id: uuid.v4(),
|
id: uuid.v4(),
|
||||||
|
|||||||
@ -46,9 +46,20 @@ interface PartialHotbar {
|
|||||||
export default {
|
export default {
|
||||||
version: "5.0.0-beta.10",
|
version: "5.0.0-beta.10",
|
||||||
run(store) {
|
run(store) {
|
||||||
const hotbars = (store.get("hotbars") as Hotbar[] ?? []).filter(Boolean);
|
const rawHotbars = store.get("hotbars");
|
||||||
|
const hotbars: Hotbar[] = Array.isArray(rawHotbars) ? rawHotbars.filter(h => h && typeof h === "object") : [];
|
||||||
const userDataPath = app.getPath("userData");
|
const userDataPath = app.getPath("userData");
|
||||||
|
|
||||||
|
// Hotbars might be empty, if some of the previous migrations weren't run
|
||||||
|
if (hotbars.length === 0) {
|
||||||
|
const hotbar = getEmptyHotbar("default");
|
||||||
|
const { metadata: { uid, name, source } } = catalogEntity;
|
||||||
|
|
||||||
|
hotbar.items[0] = { entity: { uid, name, source } };
|
||||||
|
|
||||||
|
hotbars.push(hotbar);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const workspaceStoreData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));
|
const workspaceStoreData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));
|
||||||
const { clusters }: ClusterStoreModel = fse.readJSONSync(path.join(userDataPath, "lens-cluster-store.json"));
|
const { clusters }: ClusterStoreModel = fse.readJSONSync(path.join(userDataPath, "lens-cluster-store.json"));
|
||||||
@ -144,12 +155,13 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
store.set("hotbars", hotbars);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// ignore files being missing
|
// ignore files being missing
|
||||||
if (error.code !== "ENOENT") {
|
if (error.code !== "ENOENT") {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
store.set("hotbars", hotbars);
|
||||||
}
|
}
|
||||||
} as MigrationDeclaration;
|
} as MigrationDeclaration;
|
||||||
|
|||||||
@ -26,25 +26,27 @@ import type { MigrationDeclaration } from "../helpers";
|
|||||||
export default {
|
export default {
|
||||||
version: "5.0.0-beta.5",
|
version: "5.0.0-beta.5",
|
||||||
run(store) {
|
run(store) {
|
||||||
const hotbars: Hotbar[] = store.get("hotbars");
|
const rawHotbars = store.get("hotbars");
|
||||||
|
const hotbars: Hotbar[] = Array.isArray(rawHotbars) ? rawHotbars : [];
|
||||||
|
|
||||||
hotbars.forEach((hotbar, hotbarIndex) => {
|
for (const hotbar of hotbars) {
|
||||||
hotbar.items.forEach((item, itemIndex) => {
|
for (let i = 0; i < hotbar.items.length; i += 1) {
|
||||||
|
const item = hotbar.items[i];
|
||||||
const entity = catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item?.entity.uid);
|
const entity = catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item?.entity.uid);
|
||||||
|
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
// Clear disabled item
|
// Clear disabled item
|
||||||
hotbars[hotbarIndex].items[itemIndex] = null;
|
hotbar.items[i] = null;
|
||||||
} else {
|
} else {
|
||||||
// Save additional data
|
// Save additional data
|
||||||
hotbars[hotbarIndex].items[itemIndex].entity = {
|
hotbar.items[i].entity = {
|
||||||
...item.entity,
|
...item.entity,
|
||||||
name: entity.metadata.name,
|
name: entity.metadata.name,
|
||||||
source: entity.metadata.source
|
source: entity.metadata.source
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
store.set("hotbars", hotbars);
|
store.set("hotbars", hotbars);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user