@jskit-ai/workspaces-web 0.2.8 → 0.2.10
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/fixtures/workspaces-components/index.html +2 -0
- package/fixtures/workspaces-components/main.js +90 -0
- package/fixtures/workspaces-components/vite.config.mjs +9 -0
- package/package.json +8 -8
- package/patterns/workspace-surfaces/example/src/composables/useWorkspaceNotFoundState.js +2 -2
- package/src/client/account-settings/accountSettingsInvitesRuntime.js +25 -7
- package/src/client/account-settings/useAccountSettingsInvitesSectionRuntime.js +11 -54
- package/src/client/browser.js +54 -0
- package/src/client/components/MembersAdminClientElement.vue +41 -111
- package/src/client/components/WorkspaceMembersClientElement.vue +17 -701
- package/src/client/components/WorkspaceSelector.vue +4 -18
- package/src/client/components/WorkspacesClientElement.vue +21 -392
- package/src/client/composables/useWorkspaceMembersActions.js +309 -0
- package/src/client/composables/useWorkspaceMembersPage.js +401 -0
- package/src/client/composables/useWorkspaceRouteContext.js +8 -3
- package/src/client/composables/useWorkspaceSurfaceId.js +15 -17
- package/src/client/composables/useWorkspacesLanding.js +386 -0
- package/src/client/lib/bootstrap.js +4 -9
- package/src/client/lib/lastWorkspace.js +7 -19
- package/src/client/lib/pendingInvites.js +53 -0
- package/src/client/lib/profileSurfaceMenuLinks.js +6 -5
- package/src/client/lib/surfaceAccessPolicy.js +18 -32
- package/src/client/lib/theme.js +8 -69
- package/src/client/lib/workspaceLinkResolver.js +9 -2
- package/src/client/lib/workspaceMembersPayloads.js +98 -0
- package/src/client/lib/workspaceSurfacePaths.js +3 -8
- package/src/client/providers/WorkspacesWebClientProvider.js +23 -22
- package/src/client/runtime/bootstrapPlacementRouteGuards.js +44 -41
- package/src/client/runtime/bootstrapPlacementRuntime.js +49 -76
- package/src/client/runtime/bootstrapPlacementRuntimeHelpers.js +6 -12
- package/src/client/support/realtimeWorkspace.js +6 -2
- package/src/client/support/runtimeNormalization.js +1 -8
- package/src/client/support/workspaceScopeSupport.js +10 -7
- package/src/client/types.js +168 -0
- package/test/bootstrapPlacementRuntime.test.js +25 -1
- package/test/pendingInvites.test.js +34 -0
- package/test/settingsPlacementContract.test.js +7 -3
- package/test/workspaceMembersPayloads.test.js +52 -0
- package/test/workspacesComponents.browser.test.js +285 -0
|
@@ -2,16 +2,21 @@ import { computed } from "vue";
|
|
|
2
2
|
import { useSurfaceRouteContext } from "@jskit-ai/shell-web/client/navigation/useSurfaceRouteContext";
|
|
3
3
|
import { readWorkspaceRouteScope } from "../support/workspaceScopeSupport.js";
|
|
4
4
|
|
|
5
|
+
/** The surface route context, with the workspace the route names. */
|
|
5
6
|
function useWorkspaceRouteContext() {
|
|
6
7
|
const routeContext = useSurfaceRouteContext();
|
|
7
8
|
const workspaceSlugFromRoute = computed(() => {
|
|
8
9
|
return readWorkspaceRouteScope(routeContext).workspaceSlug;
|
|
9
10
|
});
|
|
10
11
|
|
|
11
|
-
return
|
|
12
|
-
|
|
12
|
+
return {
|
|
13
|
+
route: routeContext.route,
|
|
14
|
+
routePath: routeContext.routePath,
|
|
15
|
+
placementContext: routeContext.placementContext,
|
|
16
|
+
mergePlacementContext: routeContext.mergePlacementContext,
|
|
17
|
+
currentSurfaceId: routeContext.currentSurfaceId,
|
|
13
18
|
workspaceSlugFromRoute
|
|
14
|
-
}
|
|
19
|
+
};
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export { useWorkspaceRouteContext };
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import { computed
|
|
1
|
+
import { computed } from "vue";
|
|
2
2
|
import { resolveSurfaceIdFromPlacementPathname } from "@jskit-ai/shell-web/client/placement";
|
|
3
|
+
import { pagePathname } from "../browser.js";
|
|
3
4
|
import {
|
|
4
5
|
resolveSurfaceSwitchTargetsFromPlacementContext,
|
|
5
6
|
surfaceRequiresWorkspaceFromPlacementContext
|
|
6
7
|
} from "../lib/workspaceSurfaceContext.js";
|
|
7
8
|
|
|
8
|
-
function resolveCurrentPathname(route
|
|
9
|
-
|
|
10
|
-
if (routePath) {
|
|
11
|
-
return routePath;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (typeof window === "object" && window?.location?.pathname) {
|
|
15
|
-
return String(window.location.pathname);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return "/";
|
|
9
|
+
function resolveCurrentPathname(route) {
|
|
10
|
+
return String(route.path || "").trim() || pagePathname() || "/";
|
|
19
11
|
}
|
|
20
12
|
|
|
21
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The surface on the route, and the surface a workspace opens on from there.
|
|
15
|
+
* @param {object} options
|
|
16
|
+
* @param {import("vue-router").RouteLocationNormalizedLoaded} options.route
|
|
17
|
+
* @param {import("vue").Ref<import("../types.js").WorkspacePlacementContext>} options.placementContext
|
|
18
|
+
*/
|
|
19
|
+
function useWorkspaceSurfaceId({ route, placementContext }) {
|
|
22
20
|
const currentSurfaceId = computed(() =>
|
|
23
|
-
resolveSurfaceIdFromPlacementPathname(
|
|
21
|
+
resolveSurfaceIdFromPlacementPathname(placementContext.value, resolveCurrentPathname(route))
|
|
24
22
|
);
|
|
25
23
|
|
|
26
24
|
const workspaceSurfaceId = computed(() => {
|
|
27
|
-
const contextValue =
|
|
25
|
+
const contextValue = placementContext.value;
|
|
28
26
|
const surfaceId = String(currentSurfaceId.value || "").trim().toLowerCase();
|
|
29
27
|
if (surfaceId && surfaceRequiresWorkspaceFromPlacementContext(contextValue, surfaceId)) {
|
|
30
28
|
return surfaceId;
|
|
@@ -34,10 +32,10 @@ function useWorkspaceSurfaceId({ route = null, placementContext = null } = {}) {
|
|
|
34
32
|
return String(targets.workspaceSurfaceId || "").trim().toLowerCase();
|
|
35
33
|
});
|
|
36
34
|
|
|
37
|
-
return
|
|
35
|
+
return {
|
|
38
36
|
currentSurfaceId,
|
|
39
37
|
workspaceSurfaceId
|
|
40
|
-
}
|
|
38
|
+
};
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
export { useWorkspaceSurfaceId };
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { computed, reactive, ref, watch } from "vue";
|
|
2
|
+
import { useRoute, useRouter } from "vue-router";
|
|
3
|
+
import {
|
|
4
|
+
useWebPlacementContext,
|
|
5
|
+
resolveSurfaceNavigationTargetFromPlacementContext
|
|
6
|
+
} from "@jskit-ai/shell-web/client/placement";
|
|
7
|
+
import { useShellWebErrorRuntime } from "@jskit-ai/shell-web/client/error";
|
|
8
|
+
import { ROUTE_VISIBILITY_PUBLIC } from "@jskit-ai/kernel/shared/support/visibility";
|
|
9
|
+
import {
|
|
10
|
+
WORKSPACES_TRANSPORT,
|
|
11
|
+
WORKSPACE_INVITE_REDEEM_TRANSPORT
|
|
12
|
+
} from "@jskit-ai/workspaces-core/shared/jsonApiTransports";
|
|
13
|
+
import { useCommand } from "@jskit-ai/http-web/client/composables/useCommand";
|
|
14
|
+
import { useView } from "@jskit-ai/http-web/client/composables/useView";
|
|
15
|
+
import { usePaths } from "@jskit-ai/shell-web/client/navigation/usePaths";
|
|
16
|
+
import { useRealtimeQueryInvalidation } from "@jskit-ai/http-web/client/composables/useRealtimeQueryInvalidation";
|
|
17
|
+
import { assignPageLocation } from "../browser.js";
|
|
18
|
+
import { useJskitText } from "../i18n.js";
|
|
19
|
+
import { normalizeWorkspaceList } from "../lib/bootstrap.js";
|
|
20
|
+
import { readLastWorkspaceSlug, resolveWorkspaceLandingSlug } from "../lib/lastWorkspace.js";
|
|
21
|
+
import { readPendingInvites } from "../lib/pendingInvites.js";
|
|
22
|
+
import { useWorkspaceSurfaceId } from "./useWorkspaceSurfaceId.js";
|
|
23
|
+
|
|
24
|
+
const OWNERSHIP_PUBLIC = ROUTE_VISIBILITY_PUBLIC;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The Your workspaces page: what the person can open, join or create, and the opening of the last-used or only
|
|
28
|
+
* workspace as soon as that is known.
|
|
29
|
+
*/
|
|
30
|
+
function useWorkspacesLanding() {
|
|
31
|
+
const { t, errorMessage } = useJskitText();
|
|
32
|
+
const route = useRoute();
|
|
33
|
+
const router = useRouter();
|
|
34
|
+
const { context: placementContext } = useWebPlacementContext();
|
|
35
|
+
const paths = usePaths();
|
|
36
|
+
const errorRuntime = useShellWebErrorRuntime();
|
|
37
|
+
|
|
38
|
+
const selectingWorkspaceSlug = ref("");
|
|
39
|
+
const bootstrapModel = reactive({
|
|
40
|
+
sessionAuthenticated: false,
|
|
41
|
+
userId: "",
|
|
42
|
+
tenancyMode: "none",
|
|
43
|
+
workspaceAllowSelfCreate: false,
|
|
44
|
+
workspaceInvitesEnabled: false,
|
|
45
|
+
workspaces: [],
|
|
46
|
+
pendingInvites: []
|
|
47
|
+
});
|
|
48
|
+
const inviteAction = ref({
|
|
49
|
+
token: "",
|
|
50
|
+
decision: ""
|
|
51
|
+
});
|
|
52
|
+
const createWorkspaceModel = reactive({
|
|
53
|
+
name: "",
|
|
54
|
+
slug: ""
|
|
55
|
+
});
|
|
56
|
+
const redeemInviteModel = reactive({
|
|
57
|
+
token: "",
|
|
58
|
+
decision: ""
|
|
59
|
+
});
|
|
60
|
+
const bootstrapQueryKey = Object.freeze(["workspaces-web", "bootstrap", "__none__"]);
|
|
61
|
+
|
|
62
|
+
const bootstrapView = useView({
|
|
63
|
+
ownershipFilter: OWNERSHIP_PUBLIC,
|
|
64
|
+
apiSuffix: "/bootstrap",
|
|
65
|
+
queryKeyFactory: () => bootstrapQueryKey,
|
|
66
|
+
realtime: {
|
|
67
|
+
event: "workspace.settings.changed"
|
|
68
|
+
},
|
|
69
|
+
fallbackLoadError: t("jskit.workspaces.workspacesView.loadFailed"),
|
|
70
|
+
model: bootstrapModel,
|
|
71
|
+
mapLoadedToModel: (model, payload) => {
|
|
72
|
+
model.sessionAuthenticated = Boolean(payload?.session?.authenticated);
|
|
73
|
+
model.userId = String(payload?.session?.userId || "");
|
|
74
|
+
model.tenancyMode = String(payload?.tenancy?.mode || "").trim().toLowerCase() || "none";
|
|
75
|
+
model.workspaceAllowSelfCreate = payload?.tenancy?.workspace?.allowSelfCreate === true;
|
|
76
|
+
model.workspaceInvitesEnabled = payload?.app?.features?.workspaceInvites === true;
|
|
77
|
+
model.workspaces = normalizeWorkspaceList(payload?.workspaces);
|
|
78
|
+
model.pendingInvites = readPendingInvites(payload, model.workspaceInvitesEnabled);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const redeemInviteCommand = useCommand({
|
|
83
|
+
ownershipFilter: OWNERSHIP_PUBLIC,
|
|
84
|
+
apiSuffix: "/workspace/invitations/redeem",
|
|
85
|
+
writeMethod: "POST",
|
|
86
|
+
transport: WORKSPACE_INVITE_REDEEM_TRANSPORT,
|
|
87
|
+
fallbackRunError: t("jskit.workspaces.common.respondToInvitationFailed"),
|
|
88
|
+
suppressSuccessMessage: true,
|
|
89
|
+
model: redeemInviteModel,
|
|
90
|
+
buildRawPayload: (model) => ({
|
|
91
|
+
token: String(model.token || "").trim(),
|
|
92
|
+
decision: String(model.decision || "").trim().toLowerCase()
|
|
93
|
+
}),
|
|
94
|
+
messages: {
|
|
95
|
+
error: t("jskit.workspaces.common.respondToInvitationFailed")
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const createWorkspaceCommand = useCommand({
|
|
100
|
+
ownershipFilter: OWNERSHIP_PUBLIC,
|
|
101
|
+
apiSuffix: "/workspaces",
|
|
102
|
+
writeMethod: "POST",
|
|
103
|
+
transport: WORKSPACES_TRANSPORT,
|
|
104
|
+
fallbackRunError: t("jskit.workspaces.workspacesView.createFailed"),
|
|
105
|
+
suppressSuccessMessage: true,
|
|
106
|
+
model: createWorkspaceModel,
|
|
107
|
+
buildRawPayload: (model) => {
|
|
108
|
+
const payload = {
|
|
109
|
+
name: String(model.name || "").trim()
|
|
110
|
+
};
|
|
111
|
+
const slug = String(model.slug || "").trim().toLowerCase();
|
|
112
|
+
if (slug) {
|
|
113
|
+
payload.slug = slug;
|
|
114
|
+
}
|
|
115
|
+
return payload;
|
|
116
|
+
},
|
|
117
|
+
messages: {
|
|
118
|
+
error: t("jskit.workspaces.workspacesView.createFailed")
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
useRealtimeQueryInvalidation({
|
|
123
|
+
event: "workspaces.changed",
|
|
124
|
+
queryKey: bootstrapQueryKey
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
useRealtimeQueryInvalidation({
|
|
128
|
+
event: "workspace.invitations.pending.changed",
|
|
129
|
+
queryKey: bootstrapQueryKey
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const workspaceItems = computed(() => {
|
|
133
|
+
return Array.isArray(bootstrapModel.workspaces) ? bootstrapModel.workspaces : [];
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const pendingInvites = computed(() => {
|
|
137
|
+
return Array.isArray(bootstrapModel.pendingInvites) ? bootstrapModel.pendingInvites : [];
|
|
138
|
+
});
|
|
139
|
+
const workspaceInvitesEnabled = computed(() => bootstrapModel.workspaceInvitesEnabled === true);
|
|
140
|
+
|
|
141
|
+
const isBootstrapping = computed(() => Boolean(bootstrapView.isLoading));
|
|
142
|
+
const isRefreshingBootstrap = computed(() => Boolean(bootstrapView.isRefetching));
|
|
143
|
+
const bootstrapLoadError = computed(() => String(bootstrapView.loadError || "").trim());
|
|
144
|
+
const canCreateWorkspace = computed(() => bootstrapModel.workspaceAllowSelfCreate === true);
|
|
145
|
+
const isCreatingWorkspace = computed(() => Boolean(createWorkspaceCommand.isRunning));
|
|
146
|
+
|
|
147
|
+
function reportFeedback({
|
|
148
|
+
message,
|
|
149
|
+
severity = "error",
|
|
150
|
+
channel = "",
|
|
151
|
+
dedupeKey = ""
|
|
152
|
+
}) {
|
|
153
|
+
const normalizedMessage = String(message || "").trim();
|
|
154
|
+
if (!normalizedMessage) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
errorRuntime.report({
|
|
159
|
+
source: "workspaces-web.workspaces-view",
|
|
160
|
+
message: normalizedMessage,
|
|
161
|
+
intent: "action-feedback",
|
|
162
|
+
severity,
|
|
163
|
+
channel,
|
|
164
|
+
dedupeKey: dedupeKey || `workspaces-web.workspaces-view:${severity}:${normalizedMessage}`,
|
|
165
|
+
dedupeWindowMs: 3000
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const { workspaceSurfaceId } = useWorkspaceSurfaceId({
|
|
170
|
+
route,
|
|
171
|
+
placementContext
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
function workspaceHomePath(workspaceSlug) {
|
|
175
|
+
const normalizedSlug = String(workspaceSlug || "").trim();
|
|
176
|
+
if (!normalizedSlug || !workspaceSurfaceId.value) {
|
|
177
|
+
return "";
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return paths.page("/", {
|
|
181
|
+
surface: workspaceSurfaceId.value,
|
|
182
|
+
params: {
|
|
183
|
+
workspaceSlug: normalizedSlug
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function resolveLandingSlug() {
|
|
189
|
+
return resolveWorkspaceLandingSlug({
|
|
190
|
+
workspaces: workspaceItems.value,
|
|
191
|
+
pendingInvites: pendingInvites.value,
|
|
192
|
+
lastWorkspaceSlug: readLastWorkspaceSlug(bootstrapModel.userId)
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function openWorkspace(workspaceSlug) {
|
|
197
|
+
const normalizedSlug = String(workspaceSlug || "").trim();
|
|
198
|
+
if (!normalizedSlug) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const targetPath = workspaceHomePath(normalizedSlug);
|
|
203
|
+
if (!targetPath) {
|
|
204
|
+
reportFeedback({
|
|
205
|
+
message: t("jskit.workspaces.common.surfaceNotConfigured"),
|
|
206
|
+
severity: "error",
|
|
207
|
+
dedupeKey: "workspaces-web.workspaces-view:workspace-surface-missing"
|
|
208
|
+
});
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
selectingWorkspaceSlug.value = normalizedSlug;
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
const navigationTarget = resolveSurfaceNavigationTargetFromPlacementContext(placementContext.value, {
|
|
216
|
+
path: targetPath,
|
|
217
|
+
surfaceId: workspaceSurfaceId.value
|
|
218
|
+
});
|
|
219
|
+
if (navigationTarget.sameOrigin) {
|
|
220
|
+
await router.push(navigationTarget.href);
|
|
221
|
+
} else if (assignPageLocation(navigationTarget.href)) {
|
|
222
|
+
return;
|
|
223
|
+
} else {
|
|
224
|
+
throw new Error(t("jskit.workspaces.workspacesView.navigationUnavailable"));
|
|
225
|
+
}
|
|
226
|
+
} catch (error) {
|
|
227
|
+
reportFeedback({
|
|
228
|
+
message: errorMessage(error, t("jskit.workspaces.common.openWorkspaceFailed")),
|
|
229
|
+
severity: "error",
|
|
230
|
+
dedupeKey: `workspaces-web.workspaces-view:open-workspace:${normalizedSlug}`
|
|
231
|
+
});
|
|
232
|
+
} finally {
|
|
233
|
+
selectingWorkspaceSlug.value = "";
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function respondToInvite(invite, decision) {
|
|
238
|
+
if (!workspaceInvitesEnabled.value) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const token = String(invite?.token || "").trim();
|
|
243
|
+
const normalizedDecision = String(decision || "").trim().toLowerCase();
|
|
244
|
+
if (!token || (normalizedDecision !== "accept" && normalizedDecision !== "refuse")) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
inviteAction.value = {
|
|
249
|
+
token,
|
|
250
|
+
decision: normalizedDecision
|
|
251
|
+
};
|
|
252
|
+
redeemInviteModel.token = token;
|
|
253
|
+
redeemInviteModel.decision = normalizedDecision;
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
await redeemInviteCommand.run();
|
|
257
|
+
|
|
258
|
+
bootstrapModel.pendingInvites = pendingInvites.value.filter((entry) => entry.token !== token);
|
|
259
|
+
await bootstrapView.refresh();
|
|
260
|
+
|
|
261
|
+
if (normalizedDecision === "accept") {
|
|
262
|
+
const nextWorkspaceSlug = String(invite?.workspaceSlug || "").trim();
|
|
263
|
+
if (nextWorkspaceSlug) {
|
|
264
|
+
await openWorkspace(nextWorkspaceSlug);
|
|
265
|
+
}
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
reportFeedback({
|
|
270
|
+
message: t("jskit.workspaces.common.invitationRefused"),
|
|
271
|
+
severity: "success",
|
|
272
|
+
dedupeKey: `workspaces-web.workspaces-view:invite-refused:${token}`
|
|
273
|
+
});
|
|
274
|
+
} catch (error) {
|
|
275
|
+
reportFeedback({
|
|
276
|
+
message: errorMessage(error, t(normalizedDecision === "accept" ? "jskit.workspaces.workspacesView.acceptFailed" : "jskit.workspaces.workspacesView.refuseFailed")),
|
|
277
|
+
severity: "error",
|
|
278
|
+
dedupeKey: `workspaces-web.workspaces-view:invite-${normalizedDecision}:${token}`
|
|
279
|
+
});
|
|
280
|
+
} finally {
|
|
281
|
+
inviteAction.value = {
|
|
282
|
+
token: "",
|
|
283
|
+
decision: ""
|
|
284
|
+
};
|
|
285
|
+
redeemInviteModel.token = "";
|
|
286
|
+
redeemInviteModel.decision = "";
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function acceptInvite(invite) {
|
|
291
|
+
return respondToInvite(invite, "accept");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function refuseInvite(invite) {
|
|
295
|
+
return respondToInvite(invite, "refuse");
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async function createWorkspace() {
|
|
299
|
+
if (!canCreateWorkspace.value) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const name = String(createWorkspaceModel.name || "").trim();
|
|
304
|
+
if (!name) {
|
|
305
|
+
reportFeedback({
|
|
306
|
+
message: t("jskit.workspaces.workspacesView.nameRequired"),
|
|
307
|
+
severity: "error",
|
|
308
|
+
dedupeKey: "workspaces-web.workspaces-view:create-workspace-name-required"
|
|
309
|
+
});
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
const createdWorkspace = await createWorkspaceCommand.run();
|
|
315
|
+
await bootstrapView.refresh();
|
|
316
|
+
const createdSlug = String(createdWorkspace?.slug || "").trim();
|
|
317
|
+
const autoOpenHandledByWatcher = Boolean(resolveLandingSlug());
|
|
318
|
+
if (createdSlug && !autoOpenHandledByWatcher) {
|
|
319
|
+
await openWorkspace(createdSlug);
|
|
320
|
+
}
|
|
321
|
+
createWorkspaceModel.name = "";
|
|
322
|
+
createWorkspaceModel.slug = "";
|
|
323
|
+
} catch (error) {
|
|
324
|
+
reportFeedback({
|
|
325
|
+
message: errorMessage(error, t("jskit.workspaces.workspacesView.createFailed")),
|
|
326
|
+
severity: "error",
|
|
327
|
+
dedupeKey: "workspaces-web.workspaces-view:create-workspace-error"
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async function refreshBootstrap() {
|
|
333
|
+
return bootstrapView.refresh();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
watch(
|
|
337
|
+
() => bootstrapView.resource.data.value,
|
|
338
|
+
async (payload) => {
|
|
339
|
+
if (!payload) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (!bootstrapModel.sessionAuthenticated) {
|
|
344
|
+
const loginTarget = resolveSurfaceNavigationTargetFromPlacementContext(placementContext.value, {
|
|
345
|
+
path: "/auth/login",
|
|
346
|
+
surfaceId: "auth"
|
|
347
|
+
});
|
|
348
|
+
if (loginTarget.sameOrigin) {
|
|
349
|
+
await router.replace(loginTarget.href);
|
|
350
|
+
} else {
|
|
351
|
+
assignPageLocation(loginTarget.href);
|
|
352
|
+
}
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const landingSlug = resolveLandingSlug();
|
|
357
|
+
if (landingSlug) {
|
|
358
|
+
await openWorkspace(landingSlug);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
immediate: true
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
selectingWorkspaceSlug,
|
|
368
|
+
inviteAction,
|
|
369
|
+
createWorkspaceModel,
|
|
370
|
+
workspaceItems,
|
|
371
|
+
pendingInvites,
|
|
372
|
+
workspaceInvitesEnabled,
|
|
373
|
+
isBootstrapping,
|
|
374
|
+
isRefreshingBootstrap,
|
|
375
|
+
bootstrapLoadError,
|
|
376
|
+
canCreateWorkspace,
|
|
377
|
+
isCreatingWorkspace,
|
|
378
|
+
openWorkspace,
|
|
379
|
+
acceptInvite,
|
|
380
|
+
refuseInvite,
|
|
381
|
+
createWorkspace,
|
|
382
|
+
refreshBootstrap
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export { useWorkspacesLanding };
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { normalizeLowerText, normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
|
-
import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
|
|
1
|
+
import { normalizeLowerText, normalizeRecordId, normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
3
2
|
import { BOOTSTRAP_PATH } from "@jskit-ai/kernel/shared/surface/paths";
|
|
4
3
|
|
|
5
|
-
function normalizeWorkspaceSlug(value = "") {
|
|
6
|
-
return normalizeLowerText(value);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
4
|
function normalizeWorkspaceEntry(entry = null) {
|
|
10
5
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
11
6
|
return null;
|
|
12
7
|
}
|
|
13
8
|
|
|
14
9
|
const id = normalizeRecordId(entry.id, { fallback: "" });
|
|
15
|
-
const slug =
|
|
10
|
+
const slug = normalizeLowerText(entry.slug);
|
|
16
11
|
const name = normalizeText(entry.name);
|
|
17
12
|
if (!id || !slug || !name) {
|
|
18
13
|
return null;
|
|
@@ -38,7 +33,7 @@ function normalizeWorkspaceList(entries = []) {
|
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
function findWorkspaceBySlug(entries = [], workspaceSlug = "") {
|
|
41
|
-
const normalizedWorkspaceSlug =
|
|
36
|
+
const normalizedWorkspaceSlug = normalizeLowerText(workspaceSlug);
|
|
42
37
|
if (!normalizedWorkspaceSlug) {
|
|
43
38
|
return null;
|
|
44
39
|
}
|
|
@@ -47,7 +42,7 @@ function findWorkspaceBySlug(entries = [], workspaceSlug = "") {
|
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
function buildBootstrapApiPath(workspaceSlug = "") {
|
|
50
|
-
const normalizedWorkspaceSlug =
|
|
45
|
+
const normalizedWorkspaceSlug = normalizeLowerText(workspaceSlug);
|
|
51
46
|
if (!normalizedWorkspaceSlug) {
|
|
52
47
|
return BOOTSTRAP_PATH;
|
|
53
48
|
}
|
|
@@ -1,48 +1,36 @@
|
|
|
1
1
|
import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
|
+
import { pageLocalStorage } from "../browser.js";
|
|
2
3
|
import { findWorkspaceBySlug } from "./bootstrap.js";
|
|
3
4
|
|
|
4
5
|
const LAST_WORKSPACE_STORAGE_KEY_PREFIX = "jskit.workspaces-web.last-workspace.";
|
|
5
6
|
|
|
6
|
-
function resolveStorage(storage) {
|
|
7
|
-
if (storage !== undefined) {
|
|
8
|
-
return storage;
|
|
9
|
-
}
|
|
10
|
-
try {
|
|
11
|
-
return typeof window === "object" ? window?.localStorage || null : null;
|
|
12
|
-
} catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
7
|
function lastWorkspaceStorageKey(userId) {
|
|
18
8
|
const normalizedUserId = normalizeRecordId(userId, { fallback: "" });
|
|
19
9
|
return normalizedUserId ? `${LAST_WORKSPACE_STORAGE_KEY_PREFIX}${normalizedUserId}` : "";
|
|
20
10
|
}
|
|
21
11
|
|
|
22
|
-
function readLastWorkspaceSlug(userId, { storage } = {}) {
|
|
12
|
+
function readLastWorkspaceSlug(userId, { storage = pageLocalStorage() } = {}) {
|
|
23
13
|
const key = lastWorkspaceStorageKey(userId);
|
|
24
|
-
|
|
25
|
-
if (!key || !resolvedStorage || typeof resolvedStorage.getItem !== "function") {
|
|
14
|
+
if (!key || !storage) {
|
|
26
15
|
return "";
|
|
27
16
|
}
|
|
28
17
|
|
|
29
18
|
try {
|
|
30
|
-
return String(
|
|
19
|
+
return String(storage.getItem(key) || "").trim();
|
|
31
20
|
} catch {
|
|
32
21
|
return "";
|
|
33
22
|
}
|
|
34
23
|
}
|
|
35
24
|
|
|
36
|
-
function writeLastWorkspaceSlug(userId, workspaceSlug, { storage } = {}) {
|
|
25
|
+
function writeLastWorkspaceSlug(userId, workspaceSlug, { storage = pageLocalStorage() } = {}) {
|
|
37
26
|
const key = lastWorkspaceStorageKey(userId);
|
|
38
27
|
const normalizedWorkspaceSlug = String(workspaceSlug || "").trim();
|
|
39
|
-
|
|
40
|
-
if (!key || !normalizedWorkspaceSlug || !resolvedStorage || typeof resolvedStorage.setItem !== "function") {
|
|
28
|
+
if (!key || !normalizedWorkspaceSlug || !storage) {
|
|
41
29
|
return;
|
|
42
30
|
}
|
|
43
31
|
|
|
44
32
|
try {
|
|
45
|
-
|
|
33
|
+
storage.setItem(key, normalizedWorkspaceSlug);
|
|
46
34
|
} catch {
|
|
47
35
|
// Ignore localStorage write failures in unsupported or locked-down environments.
|
|
48
36
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A pending invitation as the bootstrap payload lists it, or null when it lacks what the person needs to answer it.
|
|
5
|
+
* @param {unknown} entry
|
|
6
|
+
* @returns {import("../types.js").PendingInvite | null}
|
|
7
|
+
*/
|
|
8
|
+
function normalizePendingInvite(entry) {
|
|
9
|
+
if (!entry || typeof entry !== "object") {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const id = normalizeRecordId(entry.id, { fallback: null });
|
|
14
|
+
const workspaceId = normalizeRecordId(entry.workspaceId, { fallback: null });
|
|
15
|
+
if (!id || !workspaceId) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const workspaceSlug = String(entry.workspaceSlug || "").trim();
|
|
20
|
+
const token = String(entry.token || "").trim();
|
|
21
|
+
if (!workspaceSlug || !token) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
id,
|
|
27
|
+
token,
|
|
28
|
+
workspaceId,
|
|
29
|
+
workspaceSlug,
|
|
30
|
+
workspaceName: String(entry.workspaceName || workspaceSlug).trim() || workspaceSlug,
|
|
31
|
+
workspaceAvatarUrl: String(entry.workspaceAvatarUrl || "").trim(),
|
|
32
|
+
roleSid: String(entry.roleSid || "member").trim().toLowerCase() || "member",
|
|
33
|
+
roleLabel: typeof entry.roleLabel === "string" ? entry.roleLabel.trim() : "",
|
|
34
|
+
status: String(entry.status || "pending").trim().toLowerCase() || "pending",
|
|
35
|
+
expiresAt: String(entry.expiresAt || "").trim()
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The invitations a bootstrap payload offers: none when the application has them switched off.
|
|
41
|
+
* @param {object} payload
|
|
42
|
+
* @param {boolean} invitesEnabled
|
|
43
|
+
* @returns {import("../types.js").PendingInvite[]}
|
|
44
|
+
*/
|
|
45
|
+
function readPendingInvites(payload, invitesEnabled) {
|
|
46
|
+
if (!invitesEnabled) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
const entries = Array.isArray(payload?.pendingInvites) ? payload.pendingInvites : [];
|
|
50
|
+
return entries.map(normalizePendingInvite).filter(Boolean);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { readPendingInvites };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveSurfaceIdFromPlacementPathname
|
|
3
3
|
} from "@jskit-ai/shell-web/client/placement";
|
|
4
|
+
import { pagePathname } from "../browser.js";
|
|
4
5
|
import { useJskitText } from "../i18n.js";
|
|
5
6
|
import { resolveWorkspaceShellLinkPath } from "./workspaceLinkResolver.js";
|
|
6
7
|
import { resolveSurfaceSwitchTargetsFromPlacementContext } from "./workspaceSurfaceContext.js";
|
|
@@ -39,11 +40,11 @@ function resolveCurrentWorkspaceSlug(contextValue, surfaceId) {
|
|
|
39
40
|
return workspaceSlugFromContext;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
const pathname = pagePathname();
|
|
44
|
+
if (!pathname) {
|
|
43
45
|
return "";
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
const pathname = String(window.location.pathname || "").trim();
|
|
47
48
|
const currentSurfaceId =
|
|
48
49
|
resolveWorkspaceSurfaceIdFromPlacementPathname(context, pathname) ||
|
|
49
50
|
resolveSurfaceIdFromPlacementPathname(context, pathname) ||
|
|
@@ -81,7 +82,7 @@ function resolveSurfaceSwitchLinkLabel(surfaceDefinition = null, surfaceId = "")
|
|
|
81
82
|
return t("jskit.workspaces.menu.goToSurface", { surface: label.toLowerCase() });
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
function resolveSurfaceSwitchLinks({ context, surface }
|
|
85
|
+
function resolveSurfaceSwitchLinks({ context, surface }) {
|
|
85
86
|
const source = context && typeof context === "object" ? context : {};
|
|
86
87
|
const targets = resolveSurfaceSwitchTargetsFromPlacementContext(source, surface);
|
|
87
88
|
const currentSurfaceId = String(targets.currentSurfaceId || "").trim().toLowerCase();
|
|
@@ -137,7 +138,7 @@ function resolveSurfaceSwitchLinks({ context, surface } = {}) {
|
|
|
137
138
|
return links;
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
function resolvePrimarySurfaceSwitchLink({ context, surface }
|
|
141
|
+
function resolvePrimarySurfaceSwitchLink({ context, surface }) {
|
|
141
142
|
const links = resolveSurfaceSwitchLinks({
|
|
142
143
|
context,
|
|
143
144
|
surface
|
|
@@ -145,7 +146,7 @@ function resolvePrimarySurfaceSwitchLink({ context, surface } = {}) {
|
|
|
145
146
|
return links[0] || null;
|
|
146
147
|
}
|
|
147
148
|
|
|
148
|
-
function resolveProfileSurfaceMenuLinks({ context, surface }
|
|
149
|
+
function resolveProfileSurfaceMenuLinks({ context, surface }) {
|
|
149
150
|
const source = context && typeof context === "object" ? context : {};
|
|
150
151
|
const authenticated = Boolean(source?.auth?.authenticated);
|
|
151
152
|
if (!authenticated) {
|