@sanity/sdk-react 0.0.0-alpha.27 → 0.0.0-alpha.28
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/dist/_chunks-es/index.js +34 -19
- package/dist/_chunks-es/index.js.map +1 -1
- package/dist/index.d.ts +16 -11
- package/package.json +4 -4
- package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +120 -4
- package/src/hooks/dashboard/useNavigateToStudioDocument.ts +51 -16
- package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.test.tsx +103 -90
- package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.ts +21 -13
package/dist/_chunks-es/index.js
CHANGED
|
@@ -5268,13 +5268,17 @@ function useStudioWorkspacesByProjectIdDataset() {
|
|
|
5268
5268
|
try {
|
|
5269
5269
|
const data = await fetch2("dashboard/v1/bridge/context", void 0, {
|
|
5270
5270
|
signal
|
|
5271
|
-
}), workspaceMap = {};
|
|
5271
|
+
}), workspaceMap = {}, noProjectIdAndDataset = [];
|
|
5272
5272
|
data.context.availableResources.forEach((resource) => {
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5273
|
+
if (resource.type !== "studio")
|
|
5274
|
+
return;
|
|
5275
|
+
if (!resource.projectId || !resource.dataset) {
|
|
5276
|
+
noProjectIdAndDataset.push(resource);
|
|
5277
|
+
return;
|
|
5278
|
+
}
|
|
5279
|
+
const key = `${resource.projectId}:${resource.dataset}`;
|
|
5280
|
+
workspaceMap[key] || (workspaceMap[key] = []), workspaceMap[key].push(resource);
|
|
5281
|
+
}), noProjectIdAndDataset.length > 0 && (workspaceMap["NO_PROJECT_ID:NO_DATASET"] = noProjectIdAndDataset), setWorkspacesByProjectIdAndDataset(workspaceMap), setError(null);
|
|
5278
5282
|
} catch (t42) {
|
|
5279
5283
|
const err = t42;
|
|
5280
5284
|
if (err instanceof Error) {
|
|
@@ -5296,8 +5300,8 @@ function useStudioWorkspacesByProjectIdDataset() {
|
|
|
5296
5300
|
isConnected: t4
|
|
5297
5301
|
}, $[6] = error, $[7] = t4, $[8] = workspacesByProjectIdAndDataset, $[9] = t5) : t5 = $[9], t5;
|
|
5298
5302
|
}
|
|
5299
|
-
function useNavigateToStudioDocument(documentHandle) {
|
|
5300
|
-
const $ = c$3(
|
|
5303
|
+
function useNavigateToStudioDocument(documentHandle, preferredStudioUrl) {
|
|
5304
|
+
const $ = c$3(11), {
|
|
5301
5305
|
workspacesByProjectIdAndDataset,
|
|
5302
5306
|
isConnected: workspacesConnected
|
|
5303
5307
|
} = useStudioWorkspacesByProjectIdDataset(), [status, setStatus] = useState("idle");
|
|
@@ -5311,35 +5315,46 @@ function useNavigateToStudioDocument(documentHandle) {
|
|
|
5311
5315
|
sendMessage
|
|
5312
5316
|
} = useWindowConnection(t0);
|
|
5313
5317
|
let t1;
|
|
5314
|
-
$[1] !== documentHandle || $[2] !==
|
|
5318
|
+
$[1] !== documentHandle || $[2] !== preferredStudioUrl || $[3] !== sendMessage || $[4] !== status || $[5] !== workspacesByProjectIdAndDataset || $[6] !== workspacesConnected ? (t1 = () => {
|
|
5315
5319
|
const {
|
|
5316
5320
|
projectId: projectId2,
|
|
5317
5321
|
dataset: dataset2
|
|
5318
5322
|
} = documentHandle;
|
|
5319
|
-
if (!workspacesConnected || status !== "connected"
|
|
5323
|
+
if (!workspacesConnected || status !== "connected") {
|
|
5324
|
+
console.warn("Not connected to Dashboard");
|
|
5320
5325
|
return;
|
|
5321
|
-
|
|
5322
|
-
if (!
|
|
5323
|
-
console.warn(
|
|
5326
|
+
}
|
|
5327
|
+
if (!projectId2 || !dataset2) {
|
|
5328
|
+
console.warn("Project ID and dataset are required to navigate to a studio document");
|
|
5329
|
+
return;
|
|
5330
|
+
}
|
|
5331
|
+
let workspace;
|
|
5332
|
+
if (preferredStudioUrl)
|
|
5333
|
+
workspace = [...workspacesByProjectIdAndDataset[`${projectId2}:${dataset2}`] || [], ...workspacesByProjectIdAndDataset["NO_PROJECT_ID:NO_DATASET"] || []].find((w2) => w2.url === preferredStudioUrl);
|
|
5334
|
+
else {
|
|
5335
|
+
const workspaces = workspacesByProjectIdAndDataset[`${projectId2}:${dataset2}`];
|
|
5336
|
+
workspaces?.length > 1 && (console.warn("Multiple workspaces found for document and no preferred studio url", documentHandle), console.warn("Using the first one", workspaces[0])), workspace = workspaces?.[0];
|
|
5337
|
+
}
|
|
5338
|
+
if (!workspace) {
|
|
5339
|
+
console.warn(`No workspace found for document with projectId: ${projectId2} and dataset: ${dataset2}${preferredStudioUrl ? ` or with preferred studio url: ${preferredStudioUrl}` : ""}`);
|
|
5324
5340
|
return;
|
|
5325
5341
|
}
|
|
5326
|
-
workspaces.length > 1 && (console.warn("Multiple workspaces found for document", documentHandle), console.warn("Using the first one", workspaces[0]));
|
|
5327
5342
|
const message = {
|
|
5328
5343
|
type: "dashboard/v1/bridge/navigate-to-resource",
|
|
5329
5344
|
data: {
|
|
5330
|
-
resourceId:
|
|
5345
|
+
resourceId: workspace.id,
|
|
5331
5346
|
resourceType: "studio",
|
|
5332
5347
|
path: `/intent/edit/id=${documentHandle.documentId};type=${documentHandle.documentType}`
|
|
5333
5348
|
}
|
|
5334
5349
|
};
|
|
5335
5350
|
sendMessage(message.type, message.data);
|
|
5336
|
-
}, $[1] = documentHandle, $[2] =
|
|
5351
|
+
}, $[1] = documentHandle, $[2] = preferredStudioUrl, $[3] = sendMessage, $[4] = status, $[5] = workspacesByProjectIdAndDataset, $[6] = workspacesConnected, $[7] = t1) : t1 = $[7];
|
|
5337
5352
|
const navigateToStudioDocument = t1, t2 = workspacesConnected && status === "connected";
|
|
5338
5353
|
let t3;
|
|
5339
|
-
return $[
|
|
5354
|
+
return $[8] !== navigateToStudioDocument || $[9] !== t2 ? (t3 = {
|
|
5340
5355
|
navigateToStudioDocument,
|
|
5341
5356
|
isConnected: t2
|
|
5342
|
-
}, $[
|
|
5357
|
+
}, $[8] = navigateToStudioDocument, $[9] = t2, $[10] = t3) : t3 = $[10], t3;
|
|
5343
5358
|
}
|
|
5344
5359
|
const useDatasets = createStateSourceHook({
|
|
5345
5360
|
getState: getDatasetsState,
|
|
@@ -5768,7 +5783,7 @@ function useUsers(options) {
|
|
|
5768
5783
|
loadMore
|
|
5769
5784
|
};
|
|
5770
5785
|
}
|
|
5771
|
-
var version = "0.0.0-alpha.
|
|
5786
|
+
var version = "0.0.0-alpha.28";
|
|
5772
5787
|
function getEnv(key) {
|
|
5773
5788
|
if (typeof import.meta < "u" && import.meta.env)
|
|
5774
5789
|
return import.meta.env[key];
|