|
1 | 1 | /* eslint-disable camelcase */
|
2 | 2 | import {isActionEnabled} from '@sanity/schema/_internal'
|
| 3 | +import {useTelemetry} from '@sanity/telemetry/react' |
3 | 4 | import {
|
4 | 5 | type ObjectSchemaType,
|
5 | 6 | type Path,
|
@@ -47,6 +48,7 @@ import {usePaneRouter} from '../../components'
|
47 | 48 | import {structureLocaleNamespace} from '../../i18n'
|
48 | 49 | import {type PaneMenuItem} from '../../types'
|
49 | 50 | import {useStructureTool} from '../../useStructureTool'
|
| 51 | +import {DocumentURLCopied} from './__telemetry__' |
50 | 52 | import {
|
51 | 53 | DEFAULT_MENU_ITEM_GROUPS,
|
52 | 54 | EMPTY_PARAMS,
|
@@ -400,13 +402,30 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
|
400 | 402 | [inspectOpen, params, setPaneParams],
|
401 | 403 | )
|
402 | 404 |
|
| 405 | + const telemetry = useTelemetry() |
| 406 | + |
403 | 407 | const handleMenuAction = useCallback(
|
404 | 408 | (item: PaneMenuItem) => {
|
405 | 409 | if (item.action === 'production-preview' && previewUrl) {
|
406 | 410 | window.open(previewUrl)
|
407 | 411 | return true
|
408 | 412 | }
|
409 | 413 |
|
| 414 | + if (item.action === 'copy-document-url' && navigator) { |
| 415 | + telemetry.log(DocumentURLCopied) |
| 416 | + // Chose to copy the user's current URL instead of |
| 417 | + // the document's edit intent link because |
| 418 | + // of bugs when resolving a document that has |
| 419 | + // multiple access paths within Structure |
| 420 | + navigator.clipboard.writeText(window.location.toString()) |
| 421 | + pushToast({ |
| 422 | + id: 'copy-document-url', |
| 423 | + status: 'info', |
| 424 | + title: t('panes.document-operation-results.operation-success_copy-url'), |
| 425 | + }) |
| 426 | + return true |
| 427 | + } |
| 428 | + |
410 | 429 | if (item.action === 'inspect') {
|
411 | 430 | toggleLegacyInspect(true)
|
412 | 431 | return true
|
@@ -434,13 +453,16 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
|
434 | 453 | return false
|
435 | 454 | },
|
436 | 455 | [
|
| 456 | + t, |
437 | 457 | closeInspector,
|
438 | 458 | handleHistoryOpen,
|
439 | 459 | inspectorName,
|
440 | 460 | inspectors,
|
441 | 461 | openInspector,
|
442 | 462 | previewUrl,
|
443 | 463 | toggleLegacyInspect,
|
| 464 | + pushToast, |
| 465 | + telemetry, |
444 | 466 | ],
|
445 | 467 | )
|
446 | 468 |
|
|
0 commit comments