@knime/hub-features 1.4.0 → 1.5.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @knime/hub-features
2
2
 
3
+ ## 1.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 3f6c9c5: Fix VersionItem content width
8
+
9
+ ## 1.5.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 75dffab: Add useVersionsApi composable
14
+
3
15
  ## 1.4.0
4
16
 
5
17
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knime/hub-features",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "Vue components & composables for shared hub features",
5
5
  "homepage": "https://knime.github.io/webapps-common/",
6
6
  "license": "GPL 3 and Additional Permissions according to Sec. 7 (SEE the file LICENSE)",
@@ -18,7 +18,7 @@ import type {
18
18
 
19
19
  type ManageVersionsProps = {
20
20
  hasUnversionedChanges: boolean;
21
- unversionedSavepoint?: ItemSavepoint & WithAvatar & WithLabels;
21
+ unversionedSavepoint?: (ItemSavepoint & WithAvatar & WithLabels) | null;
22
22
  currentVersion: NamedItemVersion["version"] | null;
23
23
  versionHistory: Array<NamedItemVersion & WithAvatar & WithLabels>;
24
24
  loading: boolean;
@@ -92,11 +92,11 @@ const onLabelLeave = () => {
92
92
 
93
93
  <template>
94
94
  <div>
95
- <Tooltip ref="tooltip" :text="tooltipText">
96
- <div
97
- :class="['version-item-container', isSelected && 'selected']"
98
- @click="toggleVersionSelection"
99
- >
95
+ <div
96
+ :class="['version-item-container', isSelected && 'selected']"
97
+ @click="toggleVersionSelection"
98
+ >
99
+ <Tooltip ref="tooltip" class="tooltip" :text="tooltipText">
100
100
  <div class="left">
101
101
  <h6>
102
102
  {{ version.title }}
@@ -136,8 +136,8 @@ const onLabelLeave = () => {
136
136
  </nav>
137
137
  </div>
138
138
  </div>
139
- </div>
140
- </Tooltip>
139
+ </Tooltip>
140
+ </div>
141
141
  </div>
142
142
  </template>
143
143
 
@@ -146,13 +146,18 @@ const onLabelLeave = () => {
146
146
  position: relative;
147
147
  background-color: var(--knime-white);
148
148
  display: flex;
149
- justify-content: space-between;
150
149
  align-items: center;
151
150
  align-items: stretch;
152
151
  padding: 10px;
153
152
  gap: 15px;
154
153
  transition: background-color 0.25s ease;
155
154
 
155
+ & .tooltip {
156
+ display: flex;
157
+ justify-content: space-between;
158
+ width: 100%;
159
+ }
160
+
156
161
  & p {
157
162
  font-size: 11px;
158
163
  line-height: 1.5;
@@ -4,3 +4,4 @@ import ManageVersions from "./ManageVersions.vue";
4
4
  export { CreateVersionForm, ManageVersions };
5
5
  export type * from "./types";
6
6
  export * from "./constants";
7
+ export * from "./useVersionsApi";
@@ -0,0 +1,175 @@
1
+ /* global RequestInit */
2
+ import { merge } from "lodash-es";
3
+
4
+ import type { HubAvatarData } from "@knime/hub-features";
5
+ import { VERSION_DEFAULT_LIMIT } from "@knime/hub-features/versions";
6
+ import type {
7
+ AssignedLabel,
8
+ ItemSavepoint,
9
+ NamedItemVersion,
10
+ WithAvatar,
11
+ WithLabels,
12
+ } from "@knime/hub-features/versions";
13
+
14
+ type UseVersionsApiOptions = {
15
+ baseUrl?: string;
16
+ };
17
+
18
+ export const useVersionsApi = ({ baseUrl }: UseVersionsApiOptions) => {
19
+ const doHubRequest = (path: string, requestOptions: RequestInit = {}) => {
20
+ const res = `${baseUrl}${path}`;
21
+ consola.trace(`useVersionsApi::fetching '${res}'`, requestOptions);
22
+
23
+ const defaults = {
24
+ method: "GET",
25
+ };
26
+ return fetch(res, {
27
+ ...defaults,
28
+ ...requestOptions,
29
+ });
30
+ };
31
+
32
+ const doHubRequestJson = async (
33
+ path: string,
34
+ requestOptions: RequestInit = {},
35
+ ) => {
36
+ merge(requestOptions, {
37
+ headers: { "Content-Type": "application/json" as const },
38
+ });
39
+ const response = await doHubRequest(path, requestOptions);
40
+ return response.json();
41
+ };
42
+
43
+ const fetchVersions = ({
44
+ itemId,
45
+ loadAll,
46
+ }: {
47
+ itemId: string;
48
+ loadAll: boolean;
49
+ }) => {
50
+ let path = `/repository/${itemId}/versions`;
51
+
52
+ if (loadAll) {
53
+ path += "?limit=-1";
54
+ }
55
+
56
+ return doHubRequestJson(path) as Promise<{
57
+ totalCount: number;
58
+ versions: Array<NamedItemVersion>;
59
+ }>;
60
+ };
61
+
62
+ const fetchResourceLabels = ({
63
+ resourceType,
64
+ resourceId,
65
+ }: {
66
+ resourceType: "savepoint";
67
+ resourceId: string;
68
+ }) => {
69
+ return doHubRequestJson(
70
+ `/validation/validation/resources/${resourceType}/${resourceId}/labels`,
71
+ {},
72
+ ).catch(() => ({ assignedLabels: [] })) as Promise<{
73
+ assignedLabels: Array<AssignedLabel>;
74
+ }>;
75
+ };
76
+
77
+ const deleteVersion = ({
78
+ projectItemId,
79
+ version,
80
+ }: {
81
+ projectItemId: string;
82
+ version: NamedItemVersion["version"];
83
+ }) => {
84
+ return doHubRequest(`/repository/${projectItemId}/versions/${version}`, {
85
+ method: "DELETE",
86
+ });
87
+ };
88
+
89
+ const createVersion = ({
90
+ projectItemId,
91
+ title,
92
+ description,
93
+ }: {
94
+ projectItemId: string;
95
+ title: string;
96
+ description: string;
97
+ }): Promise<NamedItemVersion> => {
98
+ return doHubRequestJson(`/repository/${projectItemId}/versions`, {
99
+ method: "POST",
100
+ body: JSON.stringify({
101
+ title,
102
+ description,
103
+ }),
104
+ });
105
+ };
106
+
107
+ const getAvatar = async ({
108
+ accountName,
109
+ }: {
110
+ accountName: string;
111
+ }): Promise<HubAvatarData> => {
112
+ const accountInfo = await doHubRequestJson(
113
+ `/accounts/name/${accountName}`,
114
+ {
115
+ headers: {
116
+ Prefer: "representation=minimal",
117
+ },
118
+ },
119
+ );
120
+
121
+ return {
122
+ kind: accountInfo.type === "TEAM" ? "group" : "account",
123
+ name: accountInfo.name,
124
+ image: {
125
+ url: accountInfo.avatarUrl,
126
+ altText: `${accountInfo.realName ?? accountInfo.name} profile image`,
127
+ },
128
+ } satisfies HubAvatarData;
129
+ };
130
+
131
+ const loadSavepointMetadata = async (
132
+ savepoint: ItemSavepoint,
133
+ ): Promise<WithAvatar & WithLabels> => {
134
+ return {
135
+ avatar: await getAvatar({
136
+ accountName: savepoint.version?.author ?? savepoint.author,
137
+ }),
138
+ labels: savepoint.itemVersionId
139
+ ? await fetchResourceLabels({
140
+ resourceType: "savepoint",
141
+ resourceId: savepoint.itemVersionId,
142
+ }).then((response) => response.assignedLabels)
143
+ : [],
144
+ };
145
+ };
146
+
147
+ const fetchItemSavepoints = ({
148
+ itemId,
149
+ limit,
150
+ }: {
151
+ itemId: string;
152
+ limit?: number;
153
+ }) => {
154
+ return doHubRequestJson(
155
+ `/repository/${itemId}/savepoints?limit=${
156
+ limit ?? VERSION_DEFAULT_LIMIT
157
+ }`,
158
+ ) as Promise<{
159
+ totalCount: number;
160
+ savepoints: Array<ItemSavepoint>;
161
+ }>;
162
+ };
163
+
164
+ return {
165
+ fetchVersions,
166
+ fetchResourceLabels,
167
+ fetchItemSavepoints,
168
+ loadSavepointMetadata,
169
+ deleteVersion,
170
+ createVersion,
171
+ getAvatar,
172
+ };
173
+ };
174
+
175
+ export type VersionsAPI = ReturnType<typeof useVersionsApi>;
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./rfcErrors";
2
2
  export * from "./useFileUpload";
3
3
  export * from "./useDownloadArtifact";
4
+ export * from "./components/avatars";