Skip to content

Commit 3750669

Browse files
author
Ives van Hoorne
committed
Fix null for tabs
1 parent d66381e commit 3750669

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

packages/app/src/app/store/factories.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,28 @@ export function addTabById(id) {
77
// eslint-disable-next-line
88
return function addTabById({ state, resolve }) {
99
const modules = state.get('editor.currentSandbox.modules');
10-
const shortid = modules.find(module => module.id === resolve.value(id))
11-
.shortid;
10+
const m = modules.find(module => module.id === resolve.value(id));
1211

13-
const newTab = {
14-
type: 'MODULE',
15-
moduleShortid: shortid,
16-
dirty: true,
17-
};
18-
const tabs = state.get('editor.tabs');
12+
if (m) {
13+
const { shortid } = m;
1914

20-
if (tabs.length === 0) {
21-
state.push('editor.tabs', newTab);
22-
} else if (!tabs.some(tab => tab.moduleShortid === shortid)) {
23-
const dirtyTabIndex = tabs.findIndex(tab => tab.dirty);
15+
const newTab = {
16+
type: 'MODULE',
17+
moduleShortid: shortid,
18+
dirty: true,
19+
};
20+
const tabs = state.get('editor.tabs');
2421

25-
if (dirtyTabIndex >= 0) {
26-
state.splice('editor.tabs', dirtyTabIndex, 1, newTab);
27-
} else {
28-
state.splice('editor.tabs', 0, 0, newTab);
22+
if (tabs.length === 0) {
23+
state.push('editor.tabs', newTab);
24+
} else if (!tabs.some(tab => tab.moduleShortid === shortid)) {
25+
const dirtyTabIndex = tabs.findIndex(tab => tab.dirty);
26+
27+
if (dirtyTabIndex >= 0) {
28+
state.splice('editor.tabs', dirtyTabIndex, 1, newTab);
29+
} else {
30+
state.splice('editor.tabs', 0, 0, newTab);
31+
}
2932
}
3033
}
3134
};

0 commit comments

Comments
 (0)