Skip to content

Commit

Permalink
fix(stega): add mode=presentation to edit intent links
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Dec 7, 2023
1 parent a6841d5 commit 8f062e1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/csm/createEditUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand Down
3 changes: 2 additions & 1 deletion src/csm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions test/csm/createEditUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
]

Expand Down
6 changes: 3 additions & 3 deletions test/csm/resolveEditUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
]

Expand Down
72 changes: 36 additions & 36 deletions test/stega/__snapshots__/stegaEncodeSourceMap.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
`;

Expand Down Expand Up @@ -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",
]
`;

Expand Down
6 changes: 3 additions & 3 deletions test/stega/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
]
Expand Down

0 comments on commit 8f062e1

Please sign in to comment.