Skip to content

Commit

Permalink
add support for multitasking
Browse files Browse the repository at this point in the history
  • Loading branch information
zainadr committed Oct 29, 2024
1 parent f3efcd6 commit 7da91d8
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 12 deletions.
14 changes: 14 additions & 0 deletions Frontend/tools/BaseTab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class BaseTab {
constructor() {
// Default value for AllowMultipleTabs
this.allowMultipleTabs = "notAllow";
}
}

class IconItem {
constructor(name) {
this.name = name;
}
}

module.exports = BaseTab;
1 change: 1 addition & 0 deletions Frontend/tools/Internal/InternalFinalJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class InternalFinalJson {
this.product = null;
this.assets = [];
this.extension = devParameters;
this.tabs = [];
}
}
module.exports = InternalFinalJson;
43 changes: 43 additions & 0 deletions Frontend/tools/Internal/InternalTab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const BaseTab = require('./../BaseTab');
class InternalTab extends BaseTab {
constructor({
displayName,
displayNamePlural,
name,
artifactType,
icon,
getTabId,
onInit,
canDeactivate,
onDeactivate,
canDestroy,
onDestroy,
onDelete,
maxInstanceCount
} = {}) {
super();
this.displayName = displayName;
this.displayNamePlural = displayNamePlural;
this.name = name;
this.artifactType = artifactType;
this.icon = icon;
this.getTabId = getTabId;
this.onInit = onInit;
this.canDeactivate = canDeactivate;
this.onDeactivate = onDeactivate;
this.canDestroy = canDestroy;
this.onDestroy = onDestroy;
this.onDelete = onDelete;
this.maxInstanceCount = maxInstanceCount;
}
}

// Handler class
class Handler {
constructor({ action, extensionName, iframeType} = {}) {
this.action = action;
this.extensionName = extensionName;
this.iframeType = iframeType;
}
}
module.exports = InternalTab;
3 changes: 2 additions & 1 deletion Frontend/tools/JsonProcessorHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class JsonProcessorHelper {

processItemJson(jsonContent) {
const publicItemSchema = Object.assign(new PublicItem, JSON.parse(jsonContent));
const internalItemSchema = PublicToInternalTransformer.toInternal(publicItemSchema, this.workloadName, this.productName);
const {internalItemSchema, tab} = PublicToInternalTransformer.toInternal(publicItemSchema, this.workloadName, this.productName);
this.internalFinalJson.artifacts.push(internalItemSchema);
this.internalFinalJson.tabs.push(tab);
}

async processAssetEntriesAsync(folderPath) {
Expand Down
6 changes: 3 additions & 3 deletions Frontend/tools/Public/PublicItem.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const BaseItem = require('./../BaseItem');

class PublicItem extends BaseItem {
constructor(name, displayName, displayNamePlural, editor, icon, activeIcon, contextMenuItems,
quickActionItems, supportedInMonitoringHub, itemJobActionConfig, itemSettings, itemJobTypes) {
super(name, displayName, displayNamePlural, editor, icon, activeIcon, contextMenuItems, quickActionItems, supportedInMonitoringHub);
constructor(name, displayName, displayNamePlural, editor, icon, activeIcon, contextMenuItems, quickActionItems, supportedInMonitoringHub, supportedInDatahubL1, itemJobActionConfig, itemSettings, editorTab, itemJobTypes) {
super(name, displayName, displayNamePlural, editor, icon, activeIcon, contextMenuItems, quickActionItems, supportedInMonitoringHub, supportedInDatahubL1);
this.itemJobActionConfig = itemJobActionConfig;
this.itemSettings = itemSettings;
this.editorTab = editorTab;
this.itemJobTypes = itemJobTypes;
}
}
Expand Down
83 changes: 83 additions & 0 deletions Frontend/tools/Public/PublicTab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const BaseTab = require('../BaseTab');
class PublicTab extends BaseTab {
constructor(
params = {}
) {
super();
this.onInit = params.onInit;
this.canDeactivate = params.canDeactivate;
this.onDeactivate = params.onDeactivate;
this.canDestroy = params.canDestroy;
this.onDestroy = params.onDestroy;
this.onDelete = params.onDelete;
this.maxInstanceCount = params.maxInstanceCount || 1;
}

get onInit() {
return this._onInit || PublicTab.getDefaultAction('onInit');
}

set onInit(value) {
this._onInit = value;
}

get canDeactivate() {
return this._canDeactivate || PublicTab.getDefaultAction('canDeactivate');
}

set canDeactivate(value) {
this._canDeactivate = value;
}

get onDeactivate() {
return this._onDeactivate || PublicTab.getDefaultAction('onDeactivate');
}

set onDeactivate(value) {
this._onDeactivate = value;
}

get canDestroy() {
return this._canDestroy || PublicTab.getDefaultAction('canDestroy');
}

set canDestroy(value) {
this._canDestroy = value;
}

get onDestroy() {
return this._onDestroy || PublicTab.getDefaultAction('onDestroy');
}

set onDestroy(value) {
this._onDestroy = value;
}

get onDelete() {
return this._onDelete || PublicTab.getDefaultAction('onDelete');
}

set onDelete(value) {
this._onDelete = value;
}

static getDefaultAction(actionKey) {
const defaultActions = ExtensibilityConstants.Validation.MultiTaskingDefaultActions;
return defaultActions[actionKey] || null;
}
}

class ExtensibilityConstants {
static Validation = {
MultiTaskingDefaultActions: {
onInit: "multitasking.default-on-init",
canDeactivate: "multitasking.default-can-deactivate",
onDeactivate: "multitasking.default-on-deactivate",
canDestroy: "multitasking.default-can-destroy",
onDestroy: "multitasking.default-on-destroy",
onDelete: "multitasking.default-on-delete"
}
};
}

module.exports = PublicTab;
47 changes: 39 additions & 8 deletions Frontend/tools/PublicToInternalTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const PublicProduct = require('./Public/PublicProduct');
const PublicItem = require('./Public/PublicItem');
const InternalProduct = require('./Internal/InternalProduct');
const InternalItem = require('./Internal/InternalItem');
const PublicTab = require('./Public/PublicTab');
const InternalTab = require('./Internal/InternalTab');

class PublicToInternalTransformer {
static toInternal(publicSchema, workloadName, productName = "") {
Expand Down Expand Up @@ -35,25 +37,54 @@ class PublicToInternalTransformer {
}


static ItemToInternal(publicSchema, workloadName, productName) {
static ItemToInternal(publicSchema, workloadName, productName, prefix) {
const itemName = `${workloadName}.${publicSchema.name}`;
const internalItemSchema = new InternalItem(
itemName,
[`${workloadName}.${productName}`],
publicSchema.displayName,
publicSchema.displayNamePlural,
prefix + publicSchema.displayName,
prefix + publicSchema.displayNamePlural,
{ ...publicSchema.editor, extension: workloadName },
{ ...publicSchema.icon, name: `${workloadName}/${publicSchema.icon.name}` },
{ ...publicSchema.activeIcon, name: `${workloadName}/${publicSchema.activeIcon.name}` },
publicSchema.contextMenuItems?.map(mi => this.MenuItemToInternal(mi, workloadName)),
publicSchema.quickActionItems?.map(mi => this.MenuItemToInternal(mi, workloadName)),
publicSchema.contextMenuItems?.map(mi => this.MenuItemToInternal(mi, workloadName, prefix)),
publicSchema.quickActionItems?.map(mi => this.MenuItemToInternal(mi, workloadName,prefix)),
publicSchema.supportedInMonitoringHub,
this.JobActionConfigToInternal(publicSchema.itemJobActionConfig, workloadName),
this.ItemSettingsToInternal(publicSchema.itemSettings, itemName),
publicSchema.supportedInDatahubL1,
this.JobActionConfigToInternal(publicSchema.itemJobActionConfig, workloadName, prefix),
this.ItemSettingsToInternal(publicSchema.itemSettings, itemName, prefix),
publicSchema.itemJobTypes
);

return internalItemSchema;
publicSchema.editorTab = new PublicTab(publicSchema.editorTab) ?? new PublicTab();
const tab = this.ToInternal(publicSchema, workloadName);

return {internalItemSchema,tab};
}

static ToInternal(publicItem, workloadName) {
return new InternalTab({
name: publicItem.Name,
displayName: `${publicItem.displayName}`,
displayNamePlural: `${publicItem.displayNamePlural}`,
artifactType: `${workloadName}.${publicItem.name}`,
icon: { name: `${workloadName}/${publicItem.icon.name}` },
onInit: this.CreateTabActionObj(publicItem.editorTab, workloadName, 'onInit'),
onDeactivate: this.CreateTabActionObj(publicItem.editorTab, workloadName, 'onDeactivate'),
canDeactivate: this.CreateTabActionObj(publicItem.editorTab, workloadName, 'canDeactivate'),
canDestroy: this.CreateTabActionObj(publicItem.editorTab, workloadName, 'canDestroy'),
onDestroy: this.CreateTabActionObj(publicItem.editorTab, workloadName, 'onDestroy'),
onDelete: this.CreateTabActionObj(publicItem.editorTab, workloadName, 'onDelete'),
maxInstanceCount: publicItem.editorTab.maxInstanceCount
});
}

static CreateTabActionObj(editorTab, workloadName, actionName) {
const action = editorTab[actionName];
return {
action,
...(action !== PublicTab.getDefaultAction(actionName) && { extensionName: workloadName, iframeType: "page" })
};
}

static MenuItemToInternal(publicSchema, workloadName) {
Expand Down

0 comments on commit 7da91d8

Please sign in to comment.