From 8f062e16711dfe24f1fa697050b3b89b14cd16c8 Mon Sep 17 00:00:00 2001 From: Cody Olsen Date: Thu, 7 Dec 2023 16:00:18 +0100 Subject: [PATCH] fix(stega): add `mode=presentation` to edit intent links --- README.md | 2 +- src/csm/createEditUrl.ts | 7 +- src/csm/types.ts | 3 +- test/csm/createEditUrl.test.ts | 6 +- test/csm/resolveEditUrl.test.ts | 6 +- .../stegaEncodeSourceMap.test.ts.snap | 72 +++++++++---------- test/stega/client.test.ts | 6 +- 7 files changed, 54 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 9c4375fc..9d8a5ac0 100644 --- a/README.md +++ b/README.md @@ -771,7 +771,7 @@ resolveEditUrl({ // or an array of segments resultPath: ['pictures', 0, 'alt'], }) -// ^? 'https://your-project-name.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=author;path=pictures[_key=="cee5fbb69da2"].alt' +// ^? 'https://your-project-name.sanity.studio/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=author;path=pictures[_key=="cee5fbb69da2"].alt' ``` ### Listening to queries diff --git a/src/csm/createEditUrl.ts b/src/csm/createEditUrl.ts index 5d33ad30..ca887680 100644 --- a/src/csm/createEditUrl.ts +++ b/src/csm/createEditUrl.ts @@ -55,7 +55,12 @@ export function createEditUrl(options: CreateEditUrlOptions): `${StudioBaseUrl}$ if (workspace) { segments.push(workspace) } - const routerParams = [`id=${id}`, `type=${type}`, `path=${encodeURIComponent(stringifiedPath)}`] + const routerParams = [ + 'mode=presentation', + `id=${id}`, + `type=${type}`, + `path=${encodeURIComponent(stringifiedPath)}`, + ] if (tool) { routerParams.push(`tool=${tool}`) } diff --git a/src/csm/types.ts b/src/csm/types.ts index 85d29d0a..f308fca8 100644 --- a/src/csm/types.ts +++ b/src/csm/types.ts @@ -58,7 +58,8 @@ export type ResolveStudioUrl = (sourceDocument: ContentSourceMapDocuments[number export type StudioPathLike = Path | string /** @alpha */ -export type EditIntentUrl = `/intent/edit/id=${string};type=${string};path=${string}` +export type EditIntentUrl = + `/intent/edit/mode=presentation;id=${string};type=${string};path=${string}` /** @internal */ export interface CreateEditUrlOptions { diff --git a/test/csm/createEditUrl.test.ts b/test/csm/createEditUrl.test.ts index e329f0fa..7664c19c 100644 --- a/test/csm/createEditUrl.test.ts +++ b/test/csm/createEditUrl.test.ts @@ -14,19 +14,19 @@ const cases = [ context: {baseUrl, workspace, tool, id, type}, path: parseJsonPath("$['foo'][?(@._key=='section-1')][0]['baz'][?(@._key=='section-2')]"), expected: - 'https://test.sanity.studio/staging/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0].baz[_key=="section-2"];tool=content?baseUrl=https://test.sanity.studio&id=homepage&type=page&path=foo[_key=="section-1"][0].baz[_key=="section-2"]&workspace=staging&tool=content', + 'https://test.sanity.studio/staging/intent/edit/mode=presentation;id=homepage;type=page;path=foo[_key=="section-1"][0].baz[_key=="section-2"];tool=content?baseUrl=https://test.sanity.studio&id=homepage&type=page&path=foo[_key=="section-1"][0].baz[_key=="section-2"]&workspace=staging&tool=content', }, { context: {baseUrl: '/', id, type}, path: parseJsonPath("$['foo'][?(@._key=='section-1')][0]"), expected: - '/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0]?baseUrl=/&id=homepage&type=page&path=foo[_key=="section-1"][0]', + '/intent/edit/mode=presentation;id=homepage;type=page;path=foo[_key=="section-1"][0]?baseUrl=/&id=homepage&type=page&path=foo[_key=="section-1"][0]', }, { context: {baseUrl: '/', workspace, tool, id, type}, path: parseJsonPath("$['foo'][?(@._key=='section-1')][0]"), expected: - '/staging/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0];tool=content?baseUrl=/&id=homepage&type=page&path=foo[_key=="section-1"][0]&workspace=staging&tool=content', + '/staging/intent/edit/mode=presentation;id=homepage;type=page;path=foo[_key=="section-1"][0];tool=content?baseUrl=/&id=homepage&type=page&path=foo[_key=="section-1"][0]&workspace=staging&tool=content', }, ] diff --git a/test/csm/resolveEditUrl.test.ts b/test/csm/resolveEditUrl.test.ts index 8fb90a0d..e647930c 100644 --- a/test/csm/resolveEditUrl.test.ts +++ b/test/csm/resolveEditUrl.test.ts @@ -501,19 +501,19 @@ const cases = [ path: 'products[0].title', studioUrl: 'https://test.sanity.studio', expected: - 'https://test.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=title?baseUrl=https://test.sanity.studio&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=title', + 'https://test.sanity.studio/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=title?baseUrl=https://test.sanity.studio&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=title', }, { path: 'products[0].media.alt', studioUrl: '/', expected: - '/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=media[_key=="cee5fbb69da2"].alt?baseUrl=/&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=media[_key=="cee5fbb69da2"].alt', + '/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=media[_key=="cee5fbb69da2"].alt?baseUrl=/&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=media[_key=="cee5fbb69da2"].alt', }, { path: 'products[0].description[0].children[0].text', studioUrl: '/', expected: - '/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=description[0].children[0].text?baseUrl=/&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=description[0].children[0].text', + '/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=description[0].children[0].text?baseUrl=/&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=description[0].children[0].text', }, ] diff --git a/test/stega/__snapshots__/stegaEncodeSourceMap.test.ts.snap b/test/stega/__snapshots__/stegaEncodeSourceMap.test.ts.snap index bb14904b..c2c35006 100644 --- a/test/stega/__snapshots__/stegaEncodeSourceMap.test.ts.snap +++ b/test/stega/__snapshots__/stegaEncodeSourceMap.test.ts.snap @@ -2,24 +2,24 @@ exports[`resolveEditUrl '/' > decode all 1`] = ` [ - "/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=description[_key=="d8fa6d59e49b"].children[_key=="6a057cf2fb310"].text", - "/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=media[_key=="cee5fbb69da2"].alt", - "/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=title", - "/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=title", - "/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="60b5ed16f4cc"].children[_key=="0ebc1c5b37350"].text", - "/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="5d457324f980"].children[_key=="ad7206c98f29"].text", - "/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="782db3651957"].children[_key=="cbd1965e0d78"].text", - "/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=media[_key=="55659c72ec46"].alt", - "/intent/edit/id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=title", - "/intent/edit/id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="94e937616df1"].children[_key=="d53c7c4c3314"].text", - "/intent/edit/id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="65f554bf0220"].children[_key=="633d1506e24f"].text", - "/intent/edit/id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="7c6bbc4dc6c9"].children[_key=="4f27de6e55d8"].text", - "/intent/edit/id=c9de5527-ebd9-4f90-8c30-a26e3439ca2d;type=product;path=title", - "/intent/edit/id=c9de5527-ebd9-4f90-8c30-a26e3439ca2d;type=product;path=description[_key=="85cce8f03c3c"].children[_key=="1689e57dff090"].text", - "/intent/edit/id=e1bf9f1f-efdb-4105-8c26-6b64f897e9c1;type=product;path=description[_key=="b61f8576b42b"].children[_key=="625afd80ca530"].text", - "/intent/edit/id=e1bf9f1f-efdb-4105-8c26-6b64f897e9c1;type=product;path=title", - "/intent/edit/id=siteSettings;type=siteSettings;path=title", - "/intent/edit/id=siteSettings;type=siteSettings;path=copyrightText", + "/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=description[_key=="d8fa6d59e49b"].children[_key=="6a057cf2fb310"].text", + "/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=media[_key=="cee5fbb69da2"].alt", + "/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=title", + "/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=title", + "/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="60b5ed16f4cc"].children[_key=="0ebc1c5b37350"].text", + "/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="5d457324f980"].children[_key=="ad7206c98f29"].text", + "/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="782db3651957"].children[_key=="cbd1965e0d78"].text", + "/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=media[_key=="55659c72ec46"].alt", + "/intent/edit/mode=presentation;id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=title", + "/intent/edit/mode=presentation;id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="94e937616df1"].children[_key=="d53c7c4c3314"].text", + "/intent/edit/mode=presentation;id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="65f554bf0220"].children[_key=="633d1506e24f"].text", + "/intent/edit/mode=presentation;id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="7c6bbc4dc6c9"].children[_key=="4f27de6e55d8"].text", + "/intent/edit/mode=presentation;id=c9de5527-ebd9-4f90-8c30-a26e3439ca2d;type=product;path=title", + "/intent/edit/mode=presentation;id=c9de5527-ebd9-4f90-8c30-a26e3439ca2d;type=product;path=description[_key=="85cce8f03c3c"].children[_key=="1689e57dff090"].text", + "/intent/edit/mode=presentation;id=e1bf9f1f-efdb-4105-8c26-6b64f897e9c1;type=product;path=description[_key=="b61f8576b42b"].children[_key=="625afd80ca530"].text", + "/intent/edit/mode=presentation;id=e1bf9f1f-efdb-4105-8c26-6b64f897e9c1;type=product;path=title", + "/intent/edit/mode=presentation;id=siteSettings;type=siteSettings;path=title", + "/intent/edit/mode=presentation;id=siteSettings;type=siteSettings;path=copyrightText", ] `; @@ -155,24 +155,24 @@ exports[`resolveEditUrl '/' > logger.table 1`] = ` exports[`resolveEditUrl 'https://test.sanity.studio' > decode all 1`] = ` [ - "https://test.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=description[_key=="d8fa6d59e49b"].children[_key=="6a057cf2fb310"].text", - "https://test.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=media[_key=="cee5fbb69da2"].alt", - "https://test.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=title", - "https://test.sanity.studio/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=title", - "https://test.sanity.studio/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="60b5ed16f4cc"].children[_key=="0ebc1c5b37350"].text", - "https://test.sanity.studio/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="5d457324f980"].children[_key=="ad7206c98f29"].text", - "https://test.sanity.studio/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="782db3651957"].children[_key=="cbd1965e0d78"].text", - "https://test.sanity.studio/intent/edit/id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=media[_key=="55659c72ec46"].alt", - "https://test.sanity.studio/intent/edit/id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=title", - "https://test.sanity.studio/intent/edit/id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="94e937616df1"].children[_key=="d53c7c4c3314"].text", - "https://test.sanity.studio/intent/edit/id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="65f554bf0220"].children[_key=="633d1506e24f"].text", - "https://test.sanity.studio/intent/edit/id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="7c6bbc4dc6c9"].children[_key=="4f27de6e55d8"].text", - "https://test.sanity.studio/intent/edit/id=c9de5527-ebd9-4f90-8c30-a26e3439ca2d;type=product;path=title", - "https://test.sanity.studio/intent/edit/id=c9de5527-ebd9-4f90-8c30-a26e3439ca2d;type=product;path=description[_key=="85cce8f03c3c"].children[_key=="1689e57dff090"].text", - "https://test.sanity.studio/intent/edit/id=e1bf9f1f-efdb-4105-8c26-6b64f897e9c1;type=product;path=description[_key=="b61f8576b42b"].children[_key=="625afd80ca530"].text", - "https://test.sanity.studio/intent/edit/id=e1bf9f1f-efdb-4105-8c26-6b64f897e9c1;type=product;path=title", - "https://test.sanity.studio/intent/edit/id=siteSettings;type=siteSettings;path=title", - "https://test.sanity.studio/intent/edit/id=siteSettings;type=siteSettings;path=copyrightText", + "https://test.sanity.studio/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=description[_key=="d8fa6d59e49b"].children[_key=="6a057cf2fb310"].text", + "https://test.sanity.studio/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=media[_key=="cee5fbb69da2"].alt", + "https://test.sanity.studio/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=title", + "https://test.sanity.studio/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=title", + "https://test.sanity.studio/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="60b5ed16f4cc"].children[_key=="0ebc1c5b37350"].text", + "https://test.sanity.studio/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="5d457324f980"].children[_key=="ad7206c98f29"].text", + "https://test.sanity.studio/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=description[_key=="782db3651957"].children[_key=="cbd1965e0d78"].text", + "https://test.sanity.studio/intent/edit/mode=presentation;id=807cc05c-8c4c-443a-a9c1-198fd3fd7b16;type=product;path=media[_key=="55659c72ec46"].alt", + "https://test.sanity.studio/intent/edit/mode=presentation;id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=title", + "https://test.sanity.studio/intent/edit/mode=presentation;id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="94e937616df1"].children[_key=="d53c7c4c3314"].text", + "https://test.sanity.studio/intent/edit/mode=presentation;id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="65f554bf0220"].children[_key=="633d1506e24f"].text", + "https://test.sanity.studio/intent/edit/mode=presentation;id=a643da0c-2cc6-439e-92b7-9f31c822ee05;type=product;path=description[_key=="7c6bbc4dc6c9"].children[_key=="4f27de6e55d8"].text", + "https://test.sanity.studio/intent/edit/mode=presentation;id=c9de5527-ebd9-4f90-8c30-a26e3439ca2d;type=product;path=title", + "https://test.sanity.studio/intent/edit/mode=presentation;id=c9de5527-ebd9-4f90-8c30-a26e3439ca2d;type=product;path=description[_key=="85cce8f03c3c"].children[_key=="1689e57dff090"].text", + "https://test.sanity.studio/intent/edit/mode=presentation;id=e1bf9f1f-efdb-4105-8c26-6b64f897e9c1;type=product;path=description[_key=="b61f8576b42b"].children[_key=="625afd80ca530"].text", + "https://test.sanity.studio/intent/edit/mode=presentation;id=e1bf9f1f-efdb-4105-8c26-6b64f897e9c1;type=product;path=title", + "https://test.sanity.studio/intent/edit/mode=presentation;id=siteSettings;type=siteSettings;path=title", + "https://test.sanity.studio/intent/edit/mode=presentation;id=siteSettings;type=siteSettings;path=copyrightText", ] `; diff --git a/test/stega/client.test.ts b/test/stega/client.test.ts index 4d30d23f..33d8df97 100644 --- a/test/stega/client.test.ts +++ b/test/stega/client.test.ts @@ -145,18 +145,18 @@ describe('@sanity/client/stega', async () => { expect(vercelStegaSplit(res[0].title).cleaned).toBe(result[0].title) expect(vercelStegaDecode(res[0].title)).toMatchInlineSnapshot(` { - "href": "/studio/intent/edit/id=njgNkngskjg;type=beer;path=title?baseUrl=%2Fstudio&id=njgNkngskjg&type=beer&path=title", + "href": "/studio/intent/edit/mode=presentation;id=njgNkngskjg;type=beer;path=title?baseUrl=%2Fstudio&id=njgNkngskjg&type=beer&path=title", "origin": "sanity.io", } `) expect(vercelStegaDecodeAll(JSON.stringify(res))).toMatchInlineSnapshot(` [ { - "href": "/studio/intent/edit/id=njgNkngskjg;type=beer;path=title?baseUrl=%2Fstudio&id=njgNkngskjg&type=beer&path=title", + "href": "/studio/intent/edit/mode=presentation;id=njgNkngskjg;type=beer;path=title?baseUrl=%2Fstudio&id=njgNkngskjg&type=beer&path=title", "origin": "sanity.io", }, { - "href": "/studio/intent/edit/id=njgNkngskjg;type=beer;path=country?baseUrl=%2Fstudio&id=njgNkngskjg&type=beer&path=country", + "href": "/studio/intent/edit/mode=presentation;id=njgNkngskjg;type=beer;path=country?baseUrl=%2Fstudio&id=njgNkngskjg&type=beer&path=country", "origin": "sanity.io", }, ]