ui: improve activeTab selection from fragment and state

handle invalid fragments for tabs, as well as not rendered tabpanels

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-11-10 14:16:16 +01:00 committed by Thomas Lamprecht
parent a86e703661
commit 240b2ffb9b
2 changed files with 25 additions and 2 deletions

View File

@ -186,8 +186,13 @@ Ext.define('PBS.datastore.DataStores', {
applyState: function(state) { applyState: function(state) {
let me = this; let me = this;
if (state.tab !== undefined) { if (state.tab !== undefined && me.rendered) {
me.setActiveTab(state.tab); me.setActiveTab(state.tab);
} else if (state.tab) {
// if we are not rendered yet, defer setting the activetab
setTimeout(function() {
me.setActiveTab(state.tab);
}, 10);
} }
}, },
@ -228,4 +233,13 @@ Ext.define('PBS.datastore.DataStores', {
aclPath: '/datastore', aclPath: '/datastore',
}, },
], ],
initComponent: function() {
let me = this;
// remove invalid activeTab settings
if (me.activeTab && !me.items.some((item) => item.itemId === me.activeTab)) {
delete me.activeTab;
}
me.callParent();
},
}); });

View File

@ -17,8 +17,13 @@ Ext.define('PBS.DataStorePanel', {
applyState: function(state) { applyState: function(state) {
let me = this; let me = this;
if (state.tab !== undefined) { if (state.tab !== undefined && me.rendered) {
me.setActiveTab(state.tab); me.setActiveTab(state.tab);
} else if (state.tab) {
// if we are not rendered yet, defer setting the activetab
setTimeout(function() {
me.setActiveTab(state.tab);
}, 10);
} }
}, },
@ -101,6 +106,10 @@ Ext.define('PBS.DataStorePanel', {
initComponent: function() { initComponent: function() {
let me = this; let me = this;
me.title = `${gettext("Datastore")}: ${me.datastore}`; me.title = `${gettext("Datastore")}: ${me.datastore}`;
// remove invalid activeTab settings
if (me.activeTab && !me.items.some((item) => item.itemId === me.activeTab)) {
delete me.activeTab;
}
me.callParent(); me.callParent();
}, },
}); });