1
0
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:
Sebastian Malton 2021-06-24 09:22:38 -04:00
parent 7058193295
commit ef837e1503
4 changed files with 16 additions and 28 deletions

View File

@ -23,7 +23,7 @@ import path from "path";
import { app } from "electron";
import fse from "fs-extra";
import type { ClusterModel } from "../../common/cluster-store";
import { MigrationDeclaration, migrationLog } from "../helpers";
import type { MigrationDeclaration } from "../helpers";
interface Pre500WorkspaceStoreModel {
workspaces: {
@ -36,7 +36,7 @@ export default {
version: "5.0.0-beta.10",
run(store) {
const userDataPath = app.getPath("userData");
try {
const workspaceData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));
const workspaces = new Map<string, string>(); // mapping from WorkspaceId to name
@ -45,8 +45,6 @@ export default {
workspaces.set(id, name);
}
migrationLog("workspaces", JSON.stringify([...workspaces.entries()]));
const clusters: ClusterModel[] = store.get("clusters");
for (const cluster of clusters) {
@ -58,8 +56,6 @@ export default {
store.set("clusters", clusters);
} catch (error) {
migrationLog("error", error.path);
if (!(error.code === "ENOENT" && error.path.endsWith("lens-workspace-store.json"))) {
// ignore lens-workspace-store.json being missing
throw error;

View File

@ -21,33 +21,18 @@
// Cleans up a store that had the state related data stored
import type { Hotbar } from "../../common/hotbar-store";
import { ClusterStore } from "../../common/cluster-store";
import * as uuid from "uuid";
import type { MigrationDeclaration } from "../helpers";
export default {
version: "5.0.0-alpha.0",
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) => {
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);
store.set("hotbars", [hotbar]);
}
} as MigrationDeclaration;

View File

@ -19,6 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { createHash } from "crypto";
import { app } from "electron";
import fse from "fs-extra";
import path from "path";
@ -59,7 +60,7 @@ export default {
if (workspaceHotbar?.items.length < defaultHotbarCells) {
workspaceHotbar.items.push({
entity: {
uid: cluster.id,
uid: createHash("md5").update(`${cluster.kubeConfigPath}:${cluster.contextName}`).digest("hex"),
name: cluster.preferences.clusterName || cluster.contextName,
}
});

View File

@ -30,6 +30,7 @@ import { CatalogEntityDrawerMenu } from "./catalog-entity-drawer-menu";
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
import { HotbarIcon } from "../hotbar/hotbar-icon";
import type { CatalogEntityItem } from "./catalog-entity.store";
import { isDevelopment } from "../../../common/vars";
interface Props<T extends CatalogEntity> {
item: CatalogEntityItem<T> | null | undefined;
@ -91,6 +92,11 @@ export class CatalogEntityDetails<T extends CatalogEntity> extends Component<Pro
<DrawerItem name="Labels">
{...item.getLabelBadges(this.props.hideDetails)}
</DrawerItem>
{isDevelopment && (
<DrawerItem name="Id">
{item.getId()}
</DrawerItem>
)}
</div>
</div>
)}