@datagrok/sequence-translator 1.5.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/sequence-translator",
3
3
  "friendlyName": "Sequence Translator",
4
- "version": "1.5.1",
4
+ "version": "1.5.2",
5
5
  "author": {
6
6
  "name": "Leonid Stolbov",
7
7
  "email": "lstolbov@datagrok.ai"
@@ -31,7 +31,9 @@ export class RuleInputs extends ActiveFiles {
31
31
  const editIcon = ui.icons.edit(async () => {
32
32
  const rulesManager = await RulesManager.getInstance(available);
33
33
  //await rulesManager.show();
34
- grok.shell.addView(await rulesManager.getView());
34
+ // close the dialogs, its easier if we just close it from active dialogs with filtering
35
+ DG.Dialog.getOpenDialogs()?.filter((d) => d.root.contains(editIcon)).forEach((d) => d.close());
36
+ await rulesManager.getAndAddView();
35
37
  }, 'Edit rules');
36
38
 
37
39
  res.addOptions(editIcon);
@@ -11,14 +11,15 @@ export class RulesManager {
11
11
  linkRuleDataFrame: DG.DataFrame;
12
12
  synthRuleDataFrame: DG.DataFrame;
13
13
  fileName: string;
14
- v: DG.View | null = null;
14
+ private v: DG.ViewBase | null = null;
15
15
 
16
16
  homoDimerInput: DG.InputBase;
17
17
  heteroDimerInput: DG.InputBase;
18
18
 
19
19
  currentTab = '';
20
20
 
21
- private static instance: RulesManager;
21
+ // every rule set will have its editor instance
22
+ private static instances: Record<string, RulesManager> = {};
22
23
 
23
24
  protected constructor(rules: Rules, fileName: string) {
24
25
  this.rules = rules;
@@ -34,22 +35,43 @@ export class RulesManager {
34
35
  );
35
36
  }
36
37
 
37
- async getView(): Promise<DG.ViewBase> {
38
+ async getAndAddView(): Promise<DG.ViewBase> {
39
+ if (this.v) {
40
+ try {
41
+ //find active view; name is unique due to file names in name
42
+ const activeView = Array.from(grok.shell.views).find((v) => v.name === this.v!.name);
43
+ if (!activeView) {
44
+ this.v.detach();
45
+ this.v.close();
46
+ throw new Error('View is closed, making it null in catch statement');
47
+ }
48
+ // switch to existing view
49
+ grok.shell.v = activeView;
50
+ } catch (_) {
51
+ //here we only come if some error is caused due to double detaching, so no handling needed
52
+ this.v = null;
53
+ }
54
+ }
55
+
38
56
  if (!this.v) {
39
57
  this.v = DG.View.create();
40
- this.v.name = 'Manage Polytool Rules';
58
+ this.v.name = `Manage Polytool Rules - ${this.fileName}`;
41
59
  this.v.append(await this.getForm());
60
+ this.v = grok.shell.addView(this.v);
61
+ grok.shell.v = this.v!; // just in any case, to make sure it switches
62
+ return this.v;
42
63
  }
43
64
 
44
65
  return this.v;
45
66
  }
46
67
 
47
68
  public static async getInstance(name: string): Promise<RulesManager> {
48
- if (!this.instance) {
69
+ // every rull will have its own instance
70
+ if (!this.instances[name]) {
49
71
  const rules = await getRules([name]);
50
- this.instance = new RulesManager(rules, name);
72
+ this.instances[name] = new RulesManager(rules, name);
51
73
  }
52
- return this.instance;
74
+ return this.instances[name]!;
53
75
  }
54
76
 
55
77
  save(): void {