& {
+ mode?: DocMode;
+ docRef: AttachmentPeekViewInfo['docRef'];
+};
+
export const AttachmentPeekViewControls = ({
docRef,
className,
...rest
-}: DocPeekViewControlsProps) => {
+}: AttachmentPeekViewControls) => {
+ const { docId, blockIds: [blockId] = [], filetype: type } = docRef;
const peekView = useService(PeekViewService).peekView;
const workbench = useService(WorkbenchService).workbench;
const t = useI18n();
+
const controls = useMemo(() => {
- return [
+ const controls = [
{
icon: ,
nameKey: 'close',
name: t['com.affine.peek-view-controls.close'](),
onClick: () => peekView.close(),
},
+ ];
+ if (!type) return controls;
+
+ return [
+ ...controls,
// TODO(@fundon): needs to be implemented on mobile
BUILD_CONFIG.isDesktopEdition && {
icon: ,
name: t['com.affine.peek-view-controls.open-attachment'](),
nameKey: 'open',
onClick: () => {
- const { docId, blockIds: [blockId] = [] } = docRef;
- if (docId && blockId) {
- workbench.openAttachment(docId, blockId);
- }
+ workbench.openAttachment(docId, blockId);
peekView.close(false);
+
+ track.$.attachment.$.openAttachmentInFullscreen({ type });
},
},
{
@@ -188,11 +204,10 @@ export const AttachmentPeekViewControls = ({
nameKey: 'new-tab',
name: t['com.affine.peek-view-controls.open-attachment-in-new-tab'](),
onClick: () => {
- const { docId, blockIds: [blockId] = [] } = docRef;
- if (docId && blockId) {
- workbench.openAttachment(docId, blockId, { at: 'new-tab' });
- }
+ workbench.openAttachment(docId, blockId, { at: 'new-tab' });
peekView.close(false);
+
+ track.$.attachment.$.openAttachmentInNewTab({ type });
},
},
BUILD_CONFIG.isElectron && {
@@ -202,15 +217,21 @@ export const AttachmentPeekViewControls = ({
'com.affine.peek-view-controls.open-attachment-in-split-view'
](),
onClick: () => {
- const { docId, blockIds: [blockId] = [] } = docRef;
- if (docId && blockId) {
- workbench.openAttachment(docId, blockId, { at: 'beside' });
- }
+ workbench.openAttachment(docId, blockId, { at: 'beside' });
peekView.close(false);
+
+ track.$.attachment.$.openAttachmentInSplitView({ type });
},
},
].filter((opt): opt is ControlButtonProps => Boolean(opt));
- }, [t, peekView, workbench, docRef]);
+ }, [t, peekView, workbench, docId, blockId, type]);
+
+ useEffect(() => {
+ if (type === undefined) return;
+
+ track.$.attachment.$.openAttachmentInPeekView({ type });
+ }, [type]);
+
return (
{controls.map(option => (
diff --git a/packages/frontend/track/src/events.ts b/packages/frontend/track/src/events.ts
index 638d540067a12..8d2554622aaab 100644
--- a/packages/frontend/track/src/events.ts
+++ b/packages/frontend/track/src/events.ts
@@ -116,6 +116,15 @@ type PaymentEvents =
| 'confirmResumingSubscription';
// END SECTION
+// SECTION: attachment
+type AttachmentEvents =
+ | 'openAttachmentInFullscreen'
+ | 'openAttachmentInNewTab'
+ | 'openAttachmentInPeekView'
+ | 'openAttachmentInSplitView'
+ | 'openPDFRendererFail';
+// END SECTION
+
type UserEvents =
| GeneralEvents
| AppEvents
@@ -130,7 +139,8 @@ type UserEvents =
| AuthEvents
| AccountEvents
| PaymentEvents
- | DNDEvents;
+ | DNDEvents
+ | AttachmentEvents;
interface PageDivision {
[page: string]: {
[segment: string]: {
@@ -284,6 +294,15 @@ const PageEvents = {
importModal: ['open'],
snapshot: ['import', 'export'],
},
+ attachment: {
+ $: [
+ 'openAttachmentInFullscreen',
+ 'openAttachmentInNewTab',
+ 'openAttachmentInPeekView',
+ 'openAttachmentInSplitView',
+ 'openPDFRendererFail',
+ ],
+ },
},
doc: {
editor: {
@@ -353,6 +372,10 @@ type PaymentEventArgs = {
recurring: string;
};
+type AttachmentEventArgs = {
+ type: string; // file type
+};
+
type TabActionControlType =
| 'click'
| 'dnd'
@@ -435,6 +458,10 @@ export type EventArgs = {
linkDoc: { type: string; journal: boolean };
drop: { type: string };
dragStart: { type: string };
+ openAttachmentInFullscreen: AttachmentEventArgs;
+ openAttachmentInNewTab: AttachmentEventArgs;
+ openAttachmentInPeekView: AttachmentEventArgs;
+ openAttachmentInSplitView: AttachmentEventArgs;
};
// for type checking