mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
Desktop: Fixes #4926: Fixed issue with empty panels being created by plugins
This commit is contained in:
parent
deaa731983
commit
0b46880a00
@ -578,6 +578,9 @@ packages/app-desktop/gui/ResizableLayout/utils/persist.test.js.map
|
|||||||
packages/app-desktop/gui/ResizableLayout/utils/removeItem.d.ts
|
packages/app-desktop/gui/ResizableLayout/utils/removeItem.d.ts
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/removeItem.js
|
packages/app-desktop/gui/ResizableLayout/utils/removeItem.js
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/removeItem.js.map
|
packages/app-desktop/gui/ResizableLayout/utils/removeItem.js.map
|
||||||
|
packages/app-desktop/gui/ResizableLayout/utils/removeKeylessItems.d.ts
|
||||||
|
packages/app-desktop/gui/ResizableLayout/utils/removeKeylessItems.js
|
||||||
|
packages/app-desktop/gui/ResizableLayout/utils/removeKeylessItems.js.map
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.d.ts
|
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.d.ts
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.js
|
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.js
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.js.map
|
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.js.map
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -564,6 +564,9 @@ packages/app-desktop/gui/ResizableLayout/utils/persist.test.js.map
|
|||||||
packages/app-desktop/gui/ResizableLayout/utils/removeItem.d.ts
|
packages/app-desktop/gui/ResizableLayout/utils/removeItem.d.ts
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/removeItem.js
|
packages/app-desktop/gui/ResizableLayout/utils/removeItem.js
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/removeItem.js.map
|
packages/app-desktop/gui/ResizableLayout/utils/removeItem.js.map
|
||||||
|
packages/app-desktop/gui/ResizableLayout/utils/removeKeylessItems.d.ts
|
||||||
|
packages/app-desktop/gui/ResizableLayout/utils/removeKeylessItems.js
|
||||||
|
packages/app-desktop/gui/ResizableLayout/utils/removeKeylessItems.js.map
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.d.ts
|
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.d.ts
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.js
|
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.js
|
||||||
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.js.map
|
packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.js.map
|
||||||
|
@ -34,6 +34,7 @@ import ShareFolderDialog from '../ShareFolderDialog/ShareFolderDialog';
|
|||||||
import { ShareInvitation } from '@joplin/lib/services/share/reducer';
|
import { ShareInvitation } from '@joplin/lib/services/share/reducer';
|
||||||
import ShareService from '@joplin/lib/services/share/ShareService';
|
import ShareService from '@joplin/lib/services/share/ShareService';
|
||||||
import { reg } from '@joplin/lib/registry';
|
import { reg } from '@joplin/lib/registry';
|
||||||
|
import removeKeylessItems from '../ResizableLayout/utils/removeKeylessItems';
|
||||||
|
|
||||||
const { connect } = require('react-redux');
|
const { connect } = require('react-redux');
|
||||||
const { PromptDialog } = require('../PromptDialog.min.js');
|
const { PromptDialog } = require('../PromptDialog.min.js');
|
||||||
@ -234,6 +235,14 @@ class MainScreenComponent extends React.Component<Props, State> {
|
|||||||
try {
|
try {
|
||||||
output = loadLayout(Object.keys(userLayout).length ? userLayout : null, defaultLayout, rootLayoutSize);
|
output = loadLayout(Object.keys(userLayout).length ? userLayout : null, defaultLayout, rootLayoutSize);
|
||||||
|
|
||||||
|
// For unclear reasons, layout items sometimes end up witout a key.
|
||||||
|
// In that case, we can't do anything with them, so remove them
|
||||||
|
// here. It could be due to the deprecated plugin API, which allowed
|
||||||
|
// creating panel without a key, although in this case it should
|
||||||
|
// have been set automatically.
|
||||||
|
// https://github.com/laurent22/joplin/issues/4926
|
||||||
|
output = removeKeylessItems(output);
|
||||||
|
|
||||||
if (!findItemByKey(output, 'sideBar') || !findItemByKey(output, 'noteList') || !findItemByKey(output, 'editor')) {
|
if (!findItemByKey(output, 'sideBar') || !findItemByKey(output, 'noteList') || !findItemByKey(output, 'editor')) {
|
||||||
throw new Error('"sideBar", "noteList" and "editor" must be present in the layout');
|
throw new Error('"sideBar", "noteList" and "editor" must be present in the layout');
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
import produce from 'immer';
|
||||||
|
import iterateItems from './iterateItems';
|
||||||
|
import { LayoutItem } from './types';
|
||||||
|
import validateLayout from './validateLayout';
|
||||||
|
|
||||||
|
interface ItemToRemove {
|
||||||
|
parent: LayoutItem;
|
||||||
|
index: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function(layout: LayoutItem): LayoutItem {
|
||||||
|
const itemsToRemove: ItemToRemove[] = [];
|
||||||
|
|
||||||
|
const output = produce(layout, (layoutDraft: LayoutItem) => {
|
||||||
|
iterateItems(layoutDraft, (itemIndex: number, item: LayoutItem, parent: LayoutItem) => {
|
||||||
|
if (!item.key) itemsToRemove.push({ parent, index: itemIndex });
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
itemsToRemove.sort((a: ItemToRemove, b: ItemToRemove) => {
|
||||||
|
return a.index > b.index ? -1 : +1;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const item of itemsToRemove) {
|
||||||
|
item.parent.children.splice(item.index, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return output !== layout ? validateLayout(output) : layout;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user