mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix hotbar migration of workspaces (#3178)
This commit is contained in:
1 parent
b9dfd20a93
commit
51655884c7
39 files changed
+333
-446
No files matched your search
+14
-34
@@ -26,7 +26,6 @@ import * as uuid from "uuid";
|
||||
import isNull from "lodash/isNull";
|
||||
import { toJS } from "./utils";
|
||||
import { CatalogEntity } from "./catalog";
|
||||
import { catalogEntity } from "../main/catalog-sources/general";
|
||||
|
||||
export interface HotbarItem {
|
||||
entity: {
|
||||
@@ -39,16 +38,12 @@ export interface HotbarItem {
|
||||
}
|
||||
}
|
||||
|
||||
export interface Hotbar {
|
||||
id: string;
|
||||
name: string;
|
||||
items: HotbarItem[];
|
||||
}
|
||||
export type Hotbar = Required<HotbarCreateOptions>;
|
||||
|
||||
export interface HotbarCreateOptions {
|
||||
id?: string;
|
||||
name: string;
|
||||
items?: HotbarItem[];
|
||||
items?: (HotbarItem | null)[];
|
||||
}
|
||||
|
||||
export interface HotbarStoreModel {
|
||||
@@ -72,6 +67,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
migrations,
|
||||
});
|
||||
makeObservable(this);
|
||||
this.load();
|
||||
}
|
||||
|
||||
get activeHotbarId() {
|
||||
@@ -92,30 +88,13 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
return this.hotbarIndex(this.activeHotbarId);
|
||||
}
|
||||
|
||||
get defaultHotbarInitialItems() {
|
||||
const { metadata: { uid, name, source } } = catalogEntity;
|
||||
const initialItem = { entity: { uid, name, source }};
|
||||
|
||||
return [
|
||||
initialItem,
|
||||
...Array.from(Array(defaultHotbarCells - 1).fill(null))
|
||||
];
|
||||
}
|
||||
|
||||
get initialItems() {
|
||||
static getInitialItems() {
|
||||
return [...Array.from(Array(defaultHotbarCells).fill(null))];
|
||||
}
|
||||
|
||||
@action protected async fromStore(data: Partial<HotbarStoreModel> = {}) {
|
||||
if (data.hotbars?.length === 0) {
|
||||
this.hotbars = [{
|
||||
id: uuid.v4(),
|
||||
name: "Default",
|
||||
items: this.defaultHotbarInitialItems,
|
||||
}];
|
||||
} else {
|
||||
this.hotbars = data.hotbars;
|
||||
}
|
||||
@action
|
||||
protected async fromStore(data: Partial<HotbarStoreModel> = {}) {
|
||||
this.hotbars = data.hotbars;
|
||||
|
||||
if (data.activeHotbarId) {
|
||||
if (this.getById(data.activeHotbarId)) {
|
||||
@@ -140,18 +119,19 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
return this.hotbars.find((hotbar) => hotbar.id === id);
|
||||
}
|
||||
|
||||
add(data: HotbarCreateOptions) {
|
||||
@action
|
||||
add(data: HotbarCreateOptions, { setActive = false } = {}) {
|
||||
const {
|
||||
id = uuid.v4(),
|
||||
items = this.initialItems,
|
||||
items = HotbarStore.getInitialItems(),
|
||||
name,
|
||||
} = data;
|
||||
|
||||
const hotbar = { id, name, items };
|
||||
this.hotbars.push({ id, name, items });
|
||||
|
||||
this.hotbars.push(hotbar as Hotbar);
|
||||
|
||||
return hotbar as Hotbar;
|
||||
if (setActive) {
|
||||
this._activeHotbarId = id;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
|
||||
Reference in new issue
Block a user