mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fixing workspaces adding/editing (#1405)
* Fix creating new workspace Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Show not yet enabled workspaces in list Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Not showing disabled workspaces Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
7489e5ff7b
commit
6fd0bebdd6
@ -38,15 +38,18 @@ describe("workspace store tests", () => {
|
|||||||
expect(() => ws.removeWorkspaceById(WorkspaceStore.defaultId)).toThrowError("Cannot remove");
|
expect(() => ws.removeWorkspaceById(WorkspaceStore.defaultId)).toThrowError("Cannot remove");
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can update default workspace name", () => {
|
it("can update workspace description", () => {
|
||||||
const ws = WorkspaceStore.getInstance<WorkspaceStore>();
|
const ws = WorkspaceStore.getInstance<WorkspaceStore>();
|
||||||
|
|
||||||
ws.addWorkspace(new Workspace({
|
const workspace = ws.addWorkspace(new Workspace({
|
||||||
id: WorkspaceStore.defaultId,
|
id: "foobar",
|
||||||
name: "foobar",
|
name: "foobar",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(ws.currentWorkspace.name).toBe("foobar");
|
workspace.description = "Foobar description";
|
||||||
|
ws.updateWorkspace(workspace);
|
||||||
|
|
||||||
|
expect(ws.getById("foobar").description).toBe("Foobar description");
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can add workspaces", () => {
|
it("can add workspaces", () => {
|
||||||
|
|||||||
@ -153,20 +153,20 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
|||||||
@action
|
@action
|
||||||
addWorkspace(workspace: Workspace) {
|
addWorkspace(workspace: Workspace) {
|
||||||
const { id, name } = workspace;
|
const { id, name } = workspace;
|
||||||
const existingWorkspace = this.getById(id);
|
|
||||||
if (!name.trim() || this.getByName(name.trim())) {
|
if (!name.trim() || this.getByName(name.trim())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (existingWorkspace) {
|
|
||||||
Object.assign(existingWorkspace, workspace);
|
|
||||||
appEventBus.emit({name: "workspace", action: "update"})
|
|
||||||
} else {
|
|
||||||
appEventBus.emit({name: "workspace", action: "add"})
|
|
||||||
}
|
|
||||||
this.workspaces.set(id, workspace);
|
this.workspaces.set(id, workspace);
|
||||||
|
appEventBus.emit({name: "workspace", action: "add"})
|
||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
updateWorkspace(workspace: Workspace) {
|
||||||
|
this.workspaces.set(workspace.id, workspace);
|
||||||
|
appEventBus.emit({name: "workspace", action: "update"});
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
removeWorkspace(workspace: Workspace) {
|
removeWorkspace(workspace: Workspace) {
|
||||||
this.removeWorkspaceById(workspace.id)
|
this.removeWorkspaceById(workspace.id)
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export class Workspaces extends React.Component {
|
|||||||
|
|
||||||
@computed get workspaces(): Workspace[] {
|
@computed get workspaces(): Workspace[] {
|
||||||
const currentWorkspaces: Map<WorkspaceId, Workspace> = new Map()
|
const currentWorkspaces: Map<WorkspaceId, Workspace> = new Map()
|
||||||
workspaceStore.enabledWorkspacesList.forEach((w) => {
|
workspaceStore.workspacesList.forEach((w) => {
|
||||||
currentWorkspaces.set(w.id, w)
|
currentWorkspaces.set(w.id, w)
|
||||||
})
|
})
|
||||||
const allWorkspaces = new Map([
|
const allWorkspaces = new Map([
|
||||||
@ -45,9 +45,13 @@ export class Workspaces extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveWorkspace = (id: WorkspaceId) => {
|
saveWorkspace = (id: WorkspaceId) => {
|
||||||
const draft = toJS(this.editingWorkspaces.get(id));
|
const workspace = new Workspace(this.editingWorkspaces.get(id));
|
||||||
const workspace = workspaceStore.addWorkspace(draft);
|
if (workspaceStore.getById(id)) {
|
||||||
if (workspace) {
|
workspaceStore.updateWorkspace(workspace);
|
||||||
|
this.clearEditing(id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (workspaceStore.addWorkspace(workspace)) {
|
||||||
this.clearEditing(id);
|
this.clearEditing(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,7 +131,7 @@ export class Workspaces extends React.Component {
|
|||||||
validate: value => !workspaceStore.getByName(value.trim())
|
validate: value => !workspaceStore.getByName(value.trim())
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div key={workspaceId} className={className}>
|
<div key={workspaceId} className={cssNames(className)}>
|
||||||
{!isEditing && (
|
{!isEditing && (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<span className="name flex gaps align-center">
|
<span className="name flex gaps align-center">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user