1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix using default hotbars (#3196)

Signed-off-by: Pavel Ashevskii <pashevskii@mirantis.com>
This commit is contained in:
pashevskii 2021-06-30 15:21:11 +04:00 committed by GitHub
parent aa86e5a41e
commit 52828a4385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ 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: {
@ -94,7 +95,15 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
@action
protected async fromStore(data: Partial<HotbarStoreModel> = {}) {
this.hotbars = data.hotbars;
if (!data.hotbars || !data.hotbars.length) {
this.hotbars = [{
id: uuid.v4(),
name: "Default",
items: this.defaultHotbarInitialItems,
}];
} else {
this.hotbars = data.hotbars;
}
if (data.activeHotbarId) {
if (this.getById(data.activeHotbarId)) {
@ -107,6 +116,16 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
}
}
get defaultHotbarInitialItems() {
const { metadata: { uid, name, source } } = catalogEntity;
const initialItem = { entity: { uid, name, source }};
return [
initialItem,
...Array.from(Array(defaultHotbarCells - 1).fill(null))
];
}
getActive() {
return this.getById(this.activeHotbarId);
}