@platforma-sdk/ui-vue 1.86.5 → 1.88.0

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.
Files changed (143) hide show
  1. package/.turbo/turbo-build.log +36 -13
  2. package/.turbo/turbo-formatter$colon$check.log +1 -1
  3. package/.turbo/turbo-linter$colon$check.log +1 -1
  4. package/CHANGELOG.md +38 -0
  5. package/dist/columnLinkViews.d.ts +97 -0
  6. package/dist/columnLinkViews.d.ts.map +1 -0
  7. package/dist/columnLinkViews.js +208 -0
  8. package/dist/columnLinkViews.js.map +1 -0
  9. package/dist/columnLinkViews.test.d.ts +2 -0
  10. package/dist/columnLinkViews.test.d.ts.map +1 -0
  11. package/dist/columnLinks.d.ts +5 -0
  12. package/dist/columnLinks.d.ts.map +1 -0
  13. package/dist/columnLinks.js +5 -0
  14. package/dist/columnLinks.js.map +1 -0
  15. package/dist/components/PlAnnotations/components/PlAnnotations.vue2.js.map +1 -1
  16. package/dist/components/PlBlockDependencies/PlBlockDependencies.js +7 -0
  17. package/dist/components/PlBlockDependencies/PlBlockDependencies.js.map +1 -0
  18. package/dist/components/PlBlockDependencies/PlBlockDependencies.jsdomtest.d.ts +2 -0
  19. package/dist/components/PlBlockDependencies/PlBlockDependencies.jsdomtest.d.ts.map +1 -0
  20. package/dist/components/PlBlockDependencies/PlBlockDependencies.style.css +1 -0
  21. package/dist/components/PlBlockDependencies/PlBlockDependencies.style.js +13 -0
  22. package/dist/components/PlBlockDependencies/PlBlockDependencies.style.js.map +1 -0
  23. package/dist/components/PlBlockDependencies/PlBlockDependencies.vue.d.ts +4 -0
  24. package/dist/components/PlBlockDependencies/PlBlockDependencies.vue.d.ts.map +1 -0
  25. package/dist/components/PlBlockDependencies/PlBlockDependencies.vue2.js +79 -0
  26. package/dist/components/PlBlockDependencies/PlBlockDependencies.vue2.js.map +1 -0
  27. package/dist/components/PlBlockDependencies/fold.d.ts +25 -0
  28. package/dist/components/PlBlockDependencies/fold.d.ts.map +1 -0
  29. package/dist/components/PlBlockDependencies/fold.js +55 -0
  30. package/dist/components/PlBlockDependencies/fold.js.map +1 -0
  31. package/dist/components/PlBlockDependencies/index.d.ts +2 -0
  32. package/dist/components/PlBlockDependencies/index.d.ts.map +1 -0
  33. package/dist/components/PlBlockDependencies/index.js +1 -0
  34. package/dist/components/PlBlockName/PlBlockName.js +7 -0
  35. package/dist/components/PlBlockName/PlBlockName.js.map +1 -0
  36. package/dist/components/PlBlockName/PlBlockName.jsdomtest.d.ts +2 -0
  37. package/dist/components/PlBlockName/PlBlockName.jsdomtest.d.ts.map +1 -0
  38. package/dist/components/PlBlockName/PlBlockName.style.css +1 -0
  39. package/dist/components/PlBlockName/PlBlockName.style.js +5 -0
  40. package/dist/components/PlBlockName/PlBlockName.style.js.map +1 -0
  41. package/dist/components/PlBlockName/PlBlockName.vue.d.ts +14 -0
  42. package/dist/components/PlBlockName/PlBlockName.vue.d.ts.map +1 -0
  43. package/dist/components/PlBlockName/PlBlockName.vue2.js +33 -0
  44. package/dist/components/PlBlockName/PlBlockName.vue2.js.map +1 -0
  45. package/dist/components/PlBlockName/index.d.ts +2 -0
  46. package/dist/components/PlBlockName/index.d.ts.map +1 -0
  47. package/dist/components/PlBlockName/index.js +1 -0
  48. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.js +6 -0
  49. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.js.map +1 -0
  50. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.jsdomtest.d.ts +2 -0
  51. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.jsdomtest.d.ts.map +1 -0
  52. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.vue.d.ts +26 -0
  53. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.vue.d.ts.map +1 -0
  54. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.vue2.js +37 -0
  55. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.vue2.js.map +1 -0
  56. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.js +6 -0
  57. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.js.map +1 -0
  58. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue.d.ts +26 -0
  59. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue.d.ts.map +1 -0
  60. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue2.js +37 -0
  61. package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue2.js.map +1 -0
  62. package/dist/components/PlColumnValueDropdown/index.d.ts +5 -0
  63. package/dist/components/PlColumnValueDropdown/index.d.ts.map +1 -0
  64. package/dist/components/PlColumnValueDropdown/index.js +4 -0
  65. package/dist/components/PlColumnValueDropdown/settings.d.ts +34 -0
  66. package/dist/components/PlColumnValueDropdown/settings.d.ts.map +1 -0
  67. package/dist/components/PlColumnValueDropdown/settings.js +25 -0
  68. package/dist/components/PlColumnValueDropdown/settings.js.map +1 -0
  69. package/dist/components/PlColumnValueDropdown/settings.test.d.ts +2 -0
  70. package/dist/components/PlColumnValueDropdown/settings.test.d.ts.map +1 -0
  71. package/dist/components/PlColumnValueDropdown/useColumnValueOptions.d.ts +20 -0
  72. package/dist/components/PlColumnValueDropdown/useColumnValueOptions.d.ts.map +1 -0
  73. package/dist/components/PlColumnValueDropdown/useColumnValueOptions.js +45 -0
  74. package/dist/components/PlColumnValueDropdown/useColumnValueOptions.js.map +1 -0
  75. package/dist/components/PlColumnValueDropdown/useColumnValueOptions.test.d.ts +2 -0
  76. package/dist/components/PlColumnValueDropdown/useColumnValueOptions.test.d.ts.map +1 -0
  77. package/dist/components/PlDatasetSelector/PlDatasetSelector.js.map +1 -1
  78. package/dist/components/PlDatasetSelector/PlDatasetSelector.vue.d.ts.map +1 -1
  79. package/dist/components/PlDatasetSelector/PlDatasetSelector.vue2.js +49 -35
  80. package/dist/components/PlDatasetSelector/PlDatasetSelector.vue2.js.map +1 -1
  81. package/dist/components/PlDatasetSelector/__tests__/missingValueHint.jsdomtest.d.ts +2 -0
  82. package/dist/components/PlDatasetSelector/__tests__/missingValueHint.jsdomtest.d.ts.map +1 -0
  83. package/dist/components/ValuePickers/ValuePickers.jsdomtest.d.ts +2 -0
  84. package/dist/components/ValuePickers/ValuePickers.jsdomtest.d.ts.map +1 -0
  85. package/dist/components/ValuePickers/columnLinksMissingValue.d.ts +25 -0
  86. package/dist/components/ValuePickers/columnLinksMissingValue.d.ts.map +1 -0
  87. package/dist/components/ValuePickers/columnLinksMissingValue.js +35 -0
  88. package/dist/components/ValuePickers/columnLinksMissingValue.js.map +1 -0
  89. package/dist/components/ValuePickers/columnLinksMissingValue.jsdomtest.d.ts +2 -0
  90. package/dist/components/ValuePickers/columnLinksMissingValue.jsdomtest.d.ts.map +1 -0
  91. package/dist/components/ValuePickers/index.d.ts +276 -0
  92. package/dist/components/ValuePickers/index.d.ts.map +1 -0
  93. package/dist/components/ValuePickers/index.js +22 -0
  94. package/dist/components/ValuePickers/index.js.map +1 -0
  95. package/dist/composition/useOpenBlock.d.ts +12 -0
  96. package/dist/composition/useOpenBlock.d.ts.map +1 -0
  97. package/dist/composition/useOpenBlock.js +20 -0
  98. package/dist/composition/useOpenBlock.js.map +1 -0
  99. package/dist/composition/useOpenBlock.test.d.ts +2 -0
  100. package/dist/composition/useOpenBlock.test.d.ts.map +1 -0
  101. package/dist/defineApp.d.ts +2 -0
  102. package/dist/defineApp.d.ts.map +1 -1
  103. package/dist/defineApp.js +30 -29
  104. package/dist/defineApp.js.map +1 -1
  105. package/dist/index.js +48 -40
  106. package/dist/index.js.map +1 -1
  107. package/dist/internal/createAppV3.d.ts +3 -1
  108. package/dist/internal/createAppV3.d.ts.map +1 -1
  109. package/dist/internal/createAppV3.js +2 -1
  110. package/dist/internal/createAppV3.js.map +1 -1
  111. package/dist/lib.d.ts +5 -0
  112. package/dist/lib.d.ts.map +1 -1
  113. package/dist/lib.js +49 -38
  114. package/package.json +6 -6
  115. package/src/columnLinkViews.test.ts +540 -0
  116. package/src/columnLinkViews.ts +368 -0
  117. package/src/columnLinks.ts +6 -0
  118. package/src/components/PlBlockDependencies/PlBlockDependencies.jsdomtest.ts +101 -0
  119. package/src/components/PlBlockDependencies/PlBlockDependencies.vue +132 -0
  120. package/src/components/PlBlockDependencies/fold.ts +85 -0
  121. package/src/components/PlBlockDependencies/index.ts +1 -0
  122. package/src/components/PlBlockName/PlBlockName.jsdomtest.ts +52 -0
  123. package/src/components/PlBlockName/PlBlockName.vue +56 -0
  124. package/src/components/PlBlockName/index.ts +1 -0
  125. package/src/components/PlColumnValueDropdown/PlColumnValueDropdown.jsdomtest.ts +144 -0
  126. package/src/components/PlColumnValueDropdown/PlColumnValueDropdown.vue +50 -0
  127. package/src/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue +50 -0
  128. package/src/components/PlColumnValueDropdown/index.ts +4 -0
  129. package/src/components/PlColumnValueDropdown/settings.test.ts +86 -0
  130. package/src/components/PlColumnValueDropdown/settings.ts +59 -0
  131. package/src/components/PlColumnValueDropdown/useColumnValueOptions.test.ts +114 -0
  132. package/src/components/PlColumnValueDropdown/useColumnValueOptions.ts +77 -0
  133. package/src/components/PlDatasetSelector/PlDatasetSelector.vue +36 -1
  134. package/src/components/PlDatasetSelector/__tests__/missingValueHint.jsdomtest.ts +81 -0
  135. package/src/components/ValuePickers/ValuePickers.jsdomtest.ts +77 -0
  136. package/src/components/ValuePickers/columnLinksMissingValue.jsdomtest.ts +82 -0
  137. package/src/components/ValuePickers/columnLinksMissingValue.ts +56 -0
  138. package/src/components/ValuePickers/index.ts +66 -0
  139. package/src/composition/useOpenBlock.test.ts +49 -0
  140. package/src/composition/useOpenBlock.ts +41 -0
  141. package/src/defineApp.ts +8 -8
  142. package/src/internal/createAppV3.ts +6 -1
  143. package/src/lib.ts +14 -0
@@ -0,0 +1,77 @@
1
+ import type { ColumnValueOption } from "@platforma-sdk/model";
2
+ import { readColumnValueOptions } from "@platforma-sdk/model";
3
+ import type { ComputedRef } from "vue";
4
+ import { computed, shallowRef, watch } from "vue";
5
+ import type { PlColumnValueSettings } from "./settings";
6
+
7
+ /** The options of a value picker, read as its settings say. */
8
+ export type ColumnValueOptions = {
9
+ /**
10
+ * The options as a picker takes them: `undefined`, shown as loading, until they are read; none
11
+ * once the column is gone or cannot be read, so that its picks stay picked and are shown as not
12
+ * available.
13
+ */
14
+ readonly options: ComputedRef<ColumnValueOption[] | undefined>;
15
+ /** Why the column offers no options: it is gone, or its values cannot be read. */
16
+ readonly error: ComputedRef<string | undefined>;
17
+ };
18
+
19
+ /**
20
+ * Reads the options of a value picker through the frame its `settings` hold. A read made for
21
+ * earlier settings is dropped. Called from `setup`.
22
+ */
23
+ export function useColumnValueOptions(settings: () => PlColumnValueSettings): ColumnValueOptions {
24
+ const state = shallowRef<ReadState>(LOADING);
25
+ let request = 0;
26
+
27
+ watch(
28
+ settings,
29
+ (current) => {
30
+ const own = ++request;
31
+ switch (current.type) {
32
+ case "none":
33
+ case "pending":
34
+ state.value = LOADING;
35
+ return;
36
+ case "absent":
37
+ state.value = { type: "failed", message: ABSENT_MESSAGE };
38
+ return;
39
+ case "present":
40
+ state.value = LOADING;
41
+ readColumnValueOptions(current.model).then(
42
+ (options) => {
43
+ if (own === request) state.value = { type: "read", options };
44
+ },
45
+ (error: unknown) => {
46
+ if (own === request) state.value = { type: "failed", message: messageOf(error) };
47
+ },
48
+ );
49
+ }
50
+ },
51
+ { immediate: true },
52
+ );
53
+
54
+ return {
55
+ options: computed(() => {
56
+ const value = state.value;
57
+ if (value.type === "loading") return undefined;
58
+ return value.type === "read" ? value.options : [];
59
+ }),
60
+ error: computed(() => (state.value.type === "failed" ? state.value.message : undefined)),
61
+ };
62
+ }
63
+
64
+ // Internals
65
+
66
+ type ReadState =
67
+ | { readonly type: "loading" }
68
+ | { readonly type: "read"; readonly options: ColumnValueOption[] }
69
+ | { readonly type: "failed"; readonly message: string };
70
+
71
+ const LOADING: ReadState = { type: "loading" };
72
+
73
+ const ABSENT_MESSAGE = "The picked column is not available";
74
+
75
+ function messageOf(error: unknown): string {
76
+ return error instanceof Error ? error.message : String(error);
77
+ }
@@ -17,12 +17,19 @@ import type {
17
17
  DatasetOption,
18
18
  DatasetSelection,
19
19
  LabeledEnrichmentRefs,
20
+ PObjectId,
20
21
  PlRef,
21
22
  } from "@platforma-sdk/model";
22
- import { createDatasetSelection, createPrimaryRef, plRefsEqual } from "@platforma-sdk/model";
23
+ import {
24
+ createDatasetSelection,
25
+ createGlobalPObjectId,
26
+ createPrimaryRef,
27
+ plRefsEqual,
28
+ } from "@platforma-sdk/model";
23
29
  import type { ListOption } from "@milaboratories/uikit";
24
30
  import { PlDropdown } from "@milaboratories/uikit";
25
31
  import { computed } from "vue";
32
+ import { useColumnLinksMissingValue } from "../ValuePickers/columnLinksMissingValue";
26
33
 
27
34
  const slots = defineSlots<{
28
35
  tooltip?: () => unknown;
@@ -115,6 +122,32 @@ const dropdownOptions = computed<ListOption<Selection>[] | undefined>(() => {
115
122
  return out;
116
123
  });
117
124
 
125
+ const columnLinks = useColumnLinksMissingValue();
126
+
127
+ /**
128
+ * The column a selection the options lack is shown and explained by: the dataset first, as the
129
+ * filter of a missing dataset is missing with it, then the filter; `undefined` when the column
130
+ * links tell nothing about either.
131
+ */
132
+ function explainedColumn(): PObjectId | undefined {
133
+ const primary = model.value?.primary;
134
+ if (columnLinks === undefined || primary === undefined) return undefined;
135
+ const refs = primary.filter === undefined ? [primary.column] : [primary.column, primary.filter];
136
+ return refs
137
+ .map((ref) => createGlobalPObjectId(ref.blockId, ref.name))
138
+ .find((column) => columnLinks.tooltip(column) !== undefined);
139
+ }
140
+
141
+ const missingValueLabel = () => {
142
+ const column = explainedColumn();
143
+ return column === undefined ? undefined : columnLinks?.label(column);
144
+ };
145
+
146
+ const missingValueTooltip = () => {
147
+ const column = explainedColumn();
148
+ return column === undefined ? undefined : columnLinks?.tooltip(column);
149
+ };
150
+
118
151
  function onChange(selection: Selection | undefined) {
119
152
  if (selection === undefined) {
120
153
  model.value = undefined;
@@ -140,6 +173,8 @@ function onChange(selection: Selection | undefined) {
140
173
  :clearable="clearable"
141
174
  :required="required"
142
175
  :disabled="disabled"
176
+ :missing-value-label="missingValueLabel"
177
+ :missing-value-tooltip="missingValueTooltip"
143
178
  @update:model-value="onChange"
144
179
  >
145
180
  <template v-if="slots.tooltip" #tooltip>
@@ -0,0 +1,81 @@
1
+ import {
2
+ createDatasetSelection,
3
+ createGlobalPObjectId,
4
+ createPlRef,
5
+ createPrimaryRef,
6
+ type BlockColumnLinks,
7
+ type DatasetOption,
8
+ } from "@platforma-sdk/model";
9
+ import { flushPromises, mount } from "@vue/test-utils";
10
+ import { describe, expect, test, vi } from "vitest";
11
+ import { computed } from "vue";
12
+
13
+ // uikit reads the theme from localStorage on import, which this jsdom setup lacks.
14
+ vi.hoisted(() => {
15
+ const store = new Map<string, string>();
16
+ vi.stubGlobal("localStorage", {
17
+ getItem: (key: string) => store.get(key) ?? null,
18
+ setItem: (key: string, value: string) => store.set(key, value),
19
+ removeItem: (key: string) => store.delete(key),
20
+ });
21
+ });
22
+
23
+ vi.mock("../../../composition/useOpenBlock", () => ({ useOpenBlock: () => undefined }));
24
+
25
+ const { default: PlDatasetSelector } = await import("../PlDatasetSelector.vue");
26
+ const { columnLinksKey } = await import("../../../columnLinks");
27
+
28
+ const abundance = createPlRef("mixcr", "clonotypes.abundance", true);
29
+ const filter = createPlRef("labeling", "labels.top");
30
+
31
+ const options: DatasetOption[] = [
32
+ { primary: { label: "Other", ref: createPlRef("mixcr", "clonotypes.other", true) } },
33
+ ];
34
+
35
+ function links(producerBlockId: string, output: string): BlockColumnLinks {
36
+ return {
37
+ blockId: "enrichment",
38
+ dependencies: [
39
+ {
40
+ producer: { blockId: producerBlockId, name: output },
41
+ holderBlockId: "enrichment",
42
+ ref: createGlobalPObjectId(producerBlockId, output),
43
+ values: null,
44
+ columnLabel: "Abundance",
45
+ check: { type: "unavailable" },
46
+ },
47
+ ],
48
+ dependents: [],
49
+ labels: { mixcr: "MiXCR Clonotyping", labeling: "Repertoire Labeling" },
50
+ };
51
+ }
52
+
53
+ function mountSelector(columnLinks: BlockColumnLinks) {
54
+ return mount(PlDatasetSelector, {
55
+ props: {
56
+ modelValue: createDatasetSelection(createPrimaryRef(abundance, filter)),
57
+ options,
58
+ },
59
+ global: { provide: { [columnLinksKey]: computed(() => columnLinks) } },
60
+ });
61
+ }
62
+
63
+ describe("PlDatasetSelector missing value hint", () => {
64
+ test("explains a missing dataset by the block that was to provide it", async () => {
65
+ const wrapper = mountSelector(links("mixcr", "clonotypes.abundance"));
66
+ await flushPromises();
67
+ expect(wrapper.find("[data-testid='pl-dropdown-value-hint']").exists()).toBe(true);
68
+ });
69
+
70
+ test("explains a missing filter of a dataset that is there", async () => {
71
+ const wrapper = mountSelector(links("labeling", "labels.top"));
72
+ await flushPromises();
73
+ expect(wrapper.find("[data-testid='pl-dropdown-value-hint']").exists()).toBe(true);
74
+ });
75
+
76
+ test("gives no hint when the links tell nothing about the selection", async () => {
77
+ const wrapper = mountSelector(links("other", "out"));
78
+ await flushPromises();
79
+ expect(wrapper.find("[data-testid='pl-dropdown-value-hint']").exists()).toBe(false);
80
+ });
81
+ });
@@ -0,0 +1,77 @@
1
+ import {
2
+ createColumnValueId,
3
+ createGlobalPObjectId,
4
+ type BlockColumnLinks,
5
+ } from "@platforma-sdk/model";
6
+ import { mount } from "@vue/test-utils";
7
+ import { describe, expect, test, vi } from "vitest";
8
+ import { computed } from "vue";
9
+
10
+ // uikit reads the theme from localStorage on import, which this jsdom setup lacks.
11
+ vi.hoisted(() => {
12
+ const store = new Map<string, string>();
13
+ vi.stubGlobal("localStorage", {
14
+ getItem: (key: string) => store.get(key) ?? null,
15
+ setItem: (key: string, value: string) => store.set(key, value),
16
+ removeItem: (key: string) => store.delete(key),
17
+ });
18
+ });
19
+
20
+ vi.mock("../../composition/useOpenBlock", () => ({ useOpenBlock: () => undefined }));
21
+
22
+ const { PlValueLabel } = await import("./index");
23
+ const { columnLinksKey } = await import("../../columnLinks");
24
+
25
+ const PATH = createGlobalPObjectId("samples", "metadata.path");
26
+ const ty1 = createColumnValueId({ column: PATH, value: "Ty1" });
27
+
28
+ const links: BlockColumnLinks = {
29
+ blockId: "enrichment",
30
+ dependencies: [
31
+ {
32
+ producer: { blockId: "samples", name: "metadata.path" },
33
+ holderBlockId: "enrichment",
34
+ ref: PATH,
35
+ values: ["Ty1"],
36
+ columnLabel: "Path",
37
+ check: { type: "notRun" },
38
+ },
39
+ ],
40
+ dependents: [],
41
+ labels: { samples: "Samples" },
42
+ };
43
+
44
+ describe("value pickers", () => {
45
+ test("show a missing value without a hint outside a block", () => {
46
+ const wrapper = mount(PlValueLabel, { props: { value: ty1, options: [] } });
47
+ expect(wrapper.text()).toBe("Ty1 — not available");
48
+ expect(wrapper.find("[data-testid='pl-tooltip']").exists()).toBe(false);
49
+ });
50
+
51
+ test("explain a missing value by the column links the app provides", () => {
52
+ const wrapper = mount(PlValueLabel, {
53
+ props: { value: ty1, options: [] },
54
+ global: { provide: { [columnLinksKey]: computed(() => links) } },
55
+ });
56
+ expect(wrapper.find("[data-testid='pl-tooltip']").exists()).toBe(true);
57
+ });
58
+
59
+ test("show a missing value without a hint while the app gives no column links", () => {
60
+ const wrapper = mount(PlValueLabel, {
61
+ props: { value: ty1, options: [] },
62
+ global: { provide: { [columnLinksKey]: computed(() => undefined) } },
63
+ });
64
+ expect(wrapper.find("[data-testid='pl-tooltip']").exists()).toBe(false);
65
+ });
66
+
67
+ test("keep the tooltip the caller gives", () => {
68
+ const wrapper = mount(PlValueLabel, {
69
+ props: {
70
+ value: ty1,
71
+ options: [],
72
+ missingValueTooltip: "Gone",
73
+ },
74
+ });
75
+ expect(wrapper.find("[data-testid='pl-tooltip']").exists()).toBe(true);
76
+ });
77
+ });
@@ -0,0 +1,82 @@
1
+ import {
2
+ createColumnValueId,
3
+ createGlobalPObjectId,
4
+ type BlockColumnLinks,
5
+ type ColumnLink,
6
+ } from "@platforma-sdk/model";
7
+ import { mount } from "@vue/test-utils";
8
+ import { describe, expect, test, vi } from "vitest";
9
+ import { columnLinksMissingValue } from "./columnLinksMissingValue";
10
+
11
+ vi.mock("../../composition/useOpenBlock", () => ({ useOpenBlock: () => async () => {} }));
12
+
13
+ const PATH = createGlobalPObjectId("samples", "metadata.path");
14
+ const ty1 = createColumnValueId({ column: PATH, value: "Ty1" });
15
+
16
+ const OTHER = createGlobalPObjectId("mixcr", "abundance");
17
+
18
+ const links: Pick<BlockColumnLinks, "dependencies" | "labels"> = {
19
+ dependencies: [
20
+ {
21
+ producer: { blockId: "samples", name: "metadata.path" },
22
+ holderBlockId: "enrichment",
23
+ ref: PATH,
24
+ values: ["Ty1"],
25
+ columnLabel: "Path",
26
+ check: { type: "unavailable" },
27
+ },
28
+ ],
29
+ labels: { samples: "Samples" },
30
+ };
31
+
32
+ describe("columnLinksMissingValue", () => {
33
+ test("links the block that does not provide the column", () => {
34
+ const missing = columnLinksMissingValue(() => links);
35
+ const tooltip = missing.tooltip(ty1);
36
+ if (tooltip === undefined) throw new Error("expected a tooltip");
37
+ const wrapper = mount(tooltip);
38
+
39
+ expect(missing.label(ty1)).toBe("Ty1 — not available");
40
+
41
+ expect(wrapper.text()).toBe("Samples does not provide “Path”.");
42
+ expect(wrapper.get("button").attributes("title")).toBe("Open Samples");
43
+ });
44
+
45
+ test("says a block that has not been run does not provide the column", () => {
46
+ const tooltip = columnLinksMissingValue(() => ({
47
+ ...links,
48
+ dependencies: links.dependencies.map((link): ColumnLink => ({
49
+ ...link,
50
+ check: { type: "notRun" },
51
+ })),
52
+ })).tooltip(ty1);
53
+ if (tooltip === undefined) throw new Error("expected a tooltip");
54
+
55
+ expect(mount(tooltip).text()).toBe("Samples does not provide “Path”.");
56
+ });
57
+
58
+ test("says a provided column waits for the other inputs of the block", () => {
59
+ const missing = columnLinksMissingValue(() => ({
60
+ ...links,
61
+ dependencies: [
62
+ ...links.dependencies.map((link): ColumnLink => ({ ...link, check: { type: "ok" } })),
63
+ ...links.dependencies.map((link): ColumnLink => ({
64
+ ...link,
65
+ ref: OTHER,
66
+ check: { type: "notRun" },
67
+ })),
68
+ ],
69
+ }));
70
+ const tooltip = missing.tooltip(ty1);
71
+ if (tooltip === undefined) throw new Error("expected a tooltip");
72
+
73
+ expect(missing.label(ty1)).toBe("Ty1");
74
+ expect(mount(tooltip).text()).toBe("Waiting for the other inputs of this block.");
75
+ });
76
+
77
+ test("tells nothing while the dependencies are not known", () => {
78
+ const missing = columnLinksMissingValue(() => undefined);
79
+ expect(missing.label(ty1)).toBeUndefined();
80
+ expect(missing.tooltip(ty1)).toBeUndefined();
81
+ });
82
+ });
@@ -0,0 +1,56 @@
1
+ import type { BlockColumnLinks } from "@platforma-sdk/model";
2
+ import type { FunctionalComponent } from "vue";
3
+ import { h, inject } from "vue";
4
+ import { columnLinksKey } from "../../columnLinks";
5
+ import { blockName, describeMissingValue } from "../../columnLinkViews";
6
+ import { PlBlockName } from "../PlBlockName";
7
+
8
+ /**
9
+ * How a picker shows a selected column or column value missing from its options, by the column
10
+ * links of the block: the text in its place and the tooltip over it, `undefined` where the links
11
+ * tell nothing about the value.
12
+ */
13
+ export type ColumnLinksMissingValue = {
14
+ label: (value: unknown) => string | undefined;
15
+ tooltip: (value: unknown) => FunctionalComponent | undefined;
16
+ };
17
+
18
+ /**
19
+ * How the pickers of the block show a missing value, by the column links the app computes for
20
+ * it; `undefined` outside a block. Called from `setup`.
21
+ */
22
+ export function useColumnLinksMissingValue(): ColumnLinksMissingValue | undefined {
23
+ const links = inject(columnLinksKey, undefined);
24
+ if (links === undefined) return undefined;
25
+ return columnLinksMissingValue(() => links.value);
26
+ }
27
+
28
+ /**
29
+ * How a picker shows a missing value by the column links `readLinks` gives. The text is
30
+ * the picked value or the label of the column selected as a whole: alone while it waits for the
31
+ * other inputs of the block, marked as not available otherwise. The tooltip names the block meant
32
+ * to provide it, as a link to that block, and what went wrong; or that it waits for the other
33
+ * inputs.
34
+ */
35
+ export function columnLinksMissingValue(
36
+ readLinks: () => Pick<BlockColumnLinks, "dependencies" | "labels"> | undefined,
37
+ ): ColumnLinksMissingValue {
38
+ const causeOf = (value: unknown) => {
39
+ const links = readLinks();
40
+ return links === undefined ? undefined : describeMissingValue(links.dependencies, value);
41
+ };
42
+ return {
43
+ label: (value) => {
44
+ const cause = causeOf(value);
45
+ if (cause === undefined || cause.name === null) return undefined;
46
+ return cause.type === "waiting" ? cause.name : `${cause.name} — not available`;
47
+ },
48
+ tooltip: (value) => {
49
+ const cause = causeOf(value);
50
+ if (cause === undefined) return undefined;
51
+ if (cause.type === "waiting") return () => cause.text;
52
+ const name = blockName(readLinks()?.labels ?? {}, cause.blockId);
53
+ return () => h("span", [h(PlBlockName, { blockId: cause.blockId, name }), ` ${cause.text}`]);
54
+ },
55
+ };
56
+ }
@@ -0,0 +1,66 @@
1
+ import {
2
+ PlDropdown as UikitPlDropdown,
3
+ PlDropdownMulti as UikitPlDropdownMulti,
4
+ PlDropdownMultiRef as UikitPlDropdownMultiRef,
5
+ PlDropdownRef as UikitPlDropdownRef,
6
+ PlValueLabel as UikitPlValueLabel,
7
+ } from "@milaboratories/uikit";
8
+ import type { Component } from "vue";
9
+ import { defineComponent, h } from "vue";
10
+ import { useColumnLinksMissingValue } from "./columnLinksMissingValue";
11
+
12
+ /**
13
+ * The uikit `PlDropdown` whose missing column or column value tells, in a tooltip, which block was to
14
+ * provide it and what went wrong, when the app computes column links.
15
+ */
16
+ export const PlDropdown = withColumnLinksMissingValue("PlDropdown", UikitPlDropdown);
17
+
18
+ /**
19
+ * The uikit `PlDropdownMulti` whose missing columns and column values tell, in a tooltip, which block was to
20
+ * provide them and what went wrong, when the app computes column links.
21
+ */
22
+ export const PlDropdownMulti = withColumnLinksMissingValue("PlDropdownMulti", UikitPlDropdownMulti);
23
+
24
+ /**
25
+ * The uikit `PlDropdownRef` whose missing column tells, in a tooltip, which block was to provide
26
+ * it and what went wrong, when the app computes column links.
27
+ */
28
+ export const PlDropdownRef = withColumnLinksMissingValue("PlDropdownRef", UikitPlDropdownRef);
29
+
30
+ /**
31
+ * The uikit `PlDropdownMultiRef` whose missing columns tell, in a tooltip, which block was to
32
+ * provide them and what went wrong, when the app computes column links.
33
+ */
34
+ export const PlDropdownMultiRef = withColumnLinksMissingValue(
35
+ "PlDropdownMultiRef",
36
+ UikitPlDropdownMultiRef,
37
+ );
38
+
39
+ /**
40
+ * The uikit `PlValueLabel` whose missing column or column value tells, in a tooltip, which block was to
41
+ * provide it and what went wrong, when the app computes column links.
42
+ */
43
+ export const PlValueLabel = withColumnLinksMissingValue("PlValueLabel", UikitPlValueLabel);
44
+
45
+ // Internals
46
+
47
+ /**
48
+ * `component` showing a missing value by the column links of the block, as `missingValueLabel`
49
+ * and `missingValueTooltip`, unless the caller gives its own.
50
+ */
51
+ function withColumnLinksMissingValue<C extends Component>(name: string, component: C): C {
52
+ const wrapper = defineComponent({
53
+ name,
54
+ inheritAttrs: false,
55
+ setup(_, { attrs, slots }) {
56
+ const missing = useColumnLinksMissingValue();
57
+ return () =>
58
+ h(
59
+ component,
60
+ { missingValueLabel: missing?.label, missingValueTooltip: missing?.tooltip, ...attrs },
61
+ slots,
62
+ );
63
+ },
64
+ });
65
+ return wrapper as C;
66
+ }
@@ -0,0 +1,49 @@
1
+ import type { ResultOrError } from "@platforma-sdk/model";
2
+ import { describe, expect, test, vi } from "vitest";
3
+ import { hostOpenBlock } from "./useOpenBlock";
4
+
5
+ describe("hostOpenBlock", () => {
6
+ test("is absent without a host", () => {
7
+ expect(hostOpenBlock(undefined)).toBeUndefined();
8
+ });
9
+
10
+ test("is absent on hosts of earlier API versions", () => {
11
+ expect(hostOpenBlock({ apiVersion: undefined })).toBeUndefined();
12
+ expect(hostOpenBlock({ apiVersion: 2 })).toBeUndefined();
13
+ });
14
+
15
+ test("is absent on a host that cannot open blocks", () => {
16
+ expect(hostOpenBlock({ apiVersion: 3 })).toBeUndefined();
17
+ });
18
+
19
+ test("asks the host to open the block", async () => {
20
+ const openBlock = vi.fn(async (_blockId: string): Promise<ResultOrError<void>> => ({
21
+ value: undefined,
22
+ }));
23
+ const open = definedOpenBlock(hostOpenBlock({ apiVersion: 3, openBlock }));
24
+
25
+ await open("b1");
26
+
27
+ expect(openBlock).toHaveBeenCalledWith("b1");
28
+ });
29
+
30
+ test("rejects when the host cannot open the block", async () => {
31
+ const open = definedOpenBlock(
32
+ hostOpenBlock({
33
+ apiVersion: 3,
34
+ openBlock: async () => ({ error: new Error("no block b1") }),
35
+ }),
36
+ );
37
+
38
+ await expect(open("b1")).rejects.toThrow("no block b1");
39
+ });
40
+ });
41
+
42
+ // Internals
43
+
44
+ function definedOpenBlock(
45
+ open: undefined | ((blockId: string) => Promise<void>),
46
+ ): (blockId: string) => Promise<void> {
47
+ if (open === undefined) throw new Error("The host is expected to open blocks");
48
+ return open;
49
+ }
@@ -0,0 +1,41 @@
1
+ import {
2
+ getRawPlatformaInstance,
3
+ unwrapResult,
4
+ type PlatformaV1,
5
+ type PlatformaV2,
6
+ type PlatformaV3,
7
+ } from "@platforma-sdk/model";
8
+
9
+ /**
10
+ * Opens another block of the same project in the app, by block id. `undefined` when the app
11
+ * cannot open blocks on a block's request — app versions released before it could, and pages
12
+ * running outside the app — so a way to open a block is offered only when this is defined.
13
+ */
14
+ export function useOpenBlock(): undefined | ((blockId: string) => Promise<void>) {
15
+ return hostOpenBlock(findHost());
16
+ }
17
+
18
+ /** The part of the host API that opens blocks. */
19
+ export type OpenBlockHost =
20
+ | Pick<PlatformaV3, "apiVersion" | "openBlock">
21
+ | Pick<PlatformaV1 | PlatformaV2, "apiVersion">;
22
+
23
+ /** Opening a block through `host`; `undefined` when there is no host or it cannot open blocks. */
24
+ export function hostOpenBlock(
25
+ host: undefined | OpenBlockHost,
26
+ ): undefined | ((blockId: string) => Promise<void>) {
27
+ if (host === undefined || host.apiVersion !== 3) return undefined;
28
+ const openBlock = host.openBlock?.bind(host);
29
+ if (openBlock === undefined) return undefined;
30
+ return async (blockId) => unwrapResult(await openBlock(blockId));
31
+ }
32
+
33
+ // Internals
34
+
35
+ function findHost(): undefined | OpenBlockHost {
36
+ try {
37
+ return getRawPlatformaInstance();
38
+ } catch {
39
+ return undefined;
40
+ }
41
+ }
package/src/defineApp.ts CHANGED
@@ -12,11 +12,13 @@ import {
12
12
  } from "@platforma-sdk/model";
13
13
  import type { App as VueApp, Component, Reactive } from "vue";
14
14
  import { inject, markRaw, reactive } from "vue";
15
+ import { columnLinksKey } from "./columnLinks";
15
16
  import { createAppV3, type BaseAppV3 } from "./internal/createAppV3";
16
17
  import type { AppSettings, ExtendSettings, Routes } from "./types";
17
18
 
18
19
  const pluginKey = Symbol("sdk-vue");
19
20
  export const pluginDataKey = Symbol("plugin-data-access");
21
+ export { columnLinksKey };
20
22
 
21
23
  export function useSdkPlugin(): SdkPlugin {
22
24
  return inject(pluginKey)!;
@@ -59,14 +61,11 @@ export function defineAppV3<
59
61
  await platforma.loadBlockState().then((stateOrError) => {
60
62
  const state = unwrapResult(stateOrError);
61
63
  plugin.loaded = true;
62
- const { app: baseApp, pluginAccess } = createAppV3<
63
- Data,
64
- Args,
65
- Outputs,
66
- Href,
67
- Plugins,
68
- UiServices
69
- >(state, platforma, settings);
64
+ const {
65
+ app: baseApp,
66
+ pluginAccess,
67
+ columnLinks,
68
+ } = createAppV3<Data, Args, Outputs, Href, Plugins, UiServices>(state, platforma, settings);
70
69
 
71
70
  if (!vueAppInstance) {
72
71
  throw new Error(
@@ -74,6 +73,7 @@ export function defineAppV3<
74
73
  );
75
74
  }
76
75
  vueAppInstance.provide(pluginDataKey, pluginAccess);
76
+ vueAppInstance.provide(columnLinksKey, columnLinks);
77
77
 
78
78
  const localState = extendApp(baseApp);
79
79
 
@@ -2,6 +2,7 @@ import { deepClone, delay, uniqueId } from "@milaboratories/helpers";
2
2
  import type { Mutable } from "@milaboratories/helpers";
3
3
  import type {
4
4
  NavigationState,
5
+ BlockColumnLinks,
5
6
  BlockOutputsBase,
6
7
  BlockStateV3,
7
8
  PlatformaV3,
@@ -122,10 +123,12 @@ export function createAppV3<
122
123
  outputs: Partial<Readonly<Outputs>>;
123
124
  blockStorage: unknown;
124
125
  navigationState: NavigationState<Href>;
126
+ columnLinks: BlockColumnLinks | undefined;
125
127
  }>(state.value) as Ref<{
126
128
  outputs: Partial<Readonly<Outputs>>;
127
129
  blockStorage: unknown;
128
130
  navigationState: NavigationState<Href>;
131
+ columnLinks: BlockColumnLinks | undefined;
129
132
  }>;
130
133
 
131
134
  const updateData = async (value: Data) => {
@@ -442,7 +445,9 @@ export function createAppV3<
442
445
  globalThis.__block_app__ = app;
443
446
  }
444
447
 
445
- return { app, pluginAccess };
448
+ const columnLinks = computed(() => snapshot.value.columnLinks);
449
+
450
+ return { app, pluginAccess, columnLinks };
446
451
  }
447
452
 
448
453
  export type BaseAppV3<