mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
1 parent
437731b67f
commit
786af2a96b
4 files changed
+24
-8
No files matched your search
@@ -17,4 +17,11 @@ describe("HotbarStore", () => {
|
||||
expect(hotbarStore.hotbars.length).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("add", () => {
|
||||
it("adds a hotbar", () => {
|
||||
hotbarStore.add({ name: "hottest" });
|
||||
expect(hotbarStore.hotbars.length).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { action, comparer, observable, toJS } from "mobx";
|
||||
import { BaseStore } from "./base-store";
|
||||
import migrations from "../migrations/hotbar-store";
|
||||
import uuid from "uuid";
|
||||
import * as uuid from "uuid";
|
||||
|
||||
export interface HotbarItem {
|
||||
entity: {
|
||||
@@ -18,6 +18,12 @@ export interface Hotbar {
|
||||
items: HotbarItem[];
|
||||
}
|
||||
|
||||
export interface HotbarCreateOptions {
|
||||
id?: string;
|
||||
name: string;
|
||||
items?: HotbarItem[];
|
||||
}
|
||||
|
||||
export interface HotbarStoreModel {
|
||||
hotbars: Hotbar[];
|
||||
activeHotbarId: string;
|
||||
@@ -86,18 +92,21 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
return this.hotbars.find((hotbar) => hotbar.id === id);
|
||||
}
|
||||
|
||||
add(hotbar: Partial<Hotbar>) {
|
||||
hotbar.id = uuid.v4();
|
||||
add(data: HotbarCreateOptions) {
|
||||
const {
|
||||
id = uuid.v4(),
|
||||
items = [],
|
||||
name,
|
||||
} = data;
|
||||
|
||||
if (!hotbar.items) {
|
||||
hotbar.items = [];
|
||||
}
|
||||
const hotbar = { id, name, items };
|
||||
|
||||
this.hotbars.push(hotbar as Hotbar);
|
||||
|
||||
return hotbar as Hotbar;
|
||||
}
|
||||
|
||||
@action
|
||||
remove(hotbar: Hotbar) {
|
||||
this.hotbars = this.hotbars.filter((h) => h !== hotbar);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Cleans up a store that had the state related data stored
|
||||
import { Hotbar } from "../../common/hotbar-store";
|
||||
import { migration } from "../migration-wrapper";
|
||||
import uuid from "uuid";
|
||||
import * as uuid from "uuid";
|
||||
|
||||
export default migration({
|
||||
version: "5.0.0-alpha.2",
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Input, InputValidator } from "../input";
|
||||
|
||||
const uniqueHotbarName: InputValidator = {
|
||||
condition: ({ required }) => required,
|
||||
message: () => `Hotbar with this name already exists`,
|
||||
message: () => "Hotbar with this name already exists",
|
||||
validate: value => !hotbarStore.getByName(value),
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user