Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

fix: DIA-609: Workspaces #269

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/sdk/dm-sdk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @global LSF */
/** @global LSF * /

/**
* @typedef {{
Expand Down Expand Up @@ -191,14 +191,7 @@ export class DataManager {

Object.assign(this.tabControls, config.tabControls ?? {});

if (config.actions) {
config.actions.forEach(([action, callback]) => {
if (!isDefined(action.id)) {
throw new Error("Every action must provide a unique ID");
}
this.actions.set(action.id, { action, callback });
});
}
this.updateActions(config.actions);

this.type = config.type ?? "dm";

Expand Down Expand Up @@ -262,7 +255,10 @@ export class DataManager {
if (!id) throw new Error("Action must provide a unique ID");

this.actions.set(id, { action, callback });
this.store.addActions(action);

const actions = Array.from(this.actions.values()).map(({ action }) => action);

this.store?.setActions(actions);
}

removeAction(id) {
Expand All @@ -280,6 +276,17 @@ export class DataManager {
});
}

updateActions(actions) {
if (!Array.isArray(actions)) return;

actions.forEach(([action, callback]) => {
if (!isDefined(action.id)) {
throw new Error("Every action must provide a unique ID");
}
this.addAction(action, callback);
});
}

registerInstrument(name, initializer) {
if (instruments[name]) {
return console.warn(`Can't override native instrument ${name}`);
Expand Down
17 changes: 11 additions & 6 deletions src/stores/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ export const AppStore = types
self.mode = mode;
},

addActions(...actions) {
self.availableActions.push(...actions);
setActions(actions) {
if (!Array.isArray(actions)) throw new Error("Actions must be an array");
self.availableActions = actions;
},

removeAction(id) {
Expand Down Expand Up @@ -454,7 +455,7 @@ export const AppStore = types
} else if (JSON.stringify(newProject ?? {}) !== JSON.stringify(self.project ?? {})) {
self.project = newProject;
}
if ( isFF(FF_LOPS_E_3) ) {
if (isFF(FF_LOPS_E_3)) {
const itemType = self.SDK.type === 'DE' ? 'dataset' : 'project';

self.SDK.invoke(`${itemType}Updated`, self.project);
Expand All @@ -470,7 +471,11 @@ export const AppStore = types
fetchActions: flow(function* () {
const serverActions = yield self.apiCall("actions");

self.addActions(...(serverActions ?? []));
const actions = (serverActions ?? []).map((action) => {
return [action, undefined];
});

self.SDK.updateActions(actions);
}),

fetchUsers: flow(function* () {
Expand All @@ -492,8 +497,8 @@ export const AppStore = types
];

if (!isLabelStream || (self.project?.show_annotation_history && task)) {
if(self.SDK.type === 'dm') {
requests.push(self.fetchActions());
if (self.SDK.type === 'dm') {
requests.push(self.fetchActions());
}

if (self.SDK.settings?.onlyVirtualTabs && self.project?.show_annotation_history && !task) {
Expand Down