Skip to content

Commit

Permalink
chore(electron): split view tracking events
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Jan 26, 2025
1 parent 6370f45 commit d1bf650
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { RecentDocsService } from '@affine/core/modules/quicksearch';
import { ViewService } from '@affine/core/modules/workbench';
import { WorkspaceService } from '@affine/core/modules/workspace';
import { isNewTabTrigger } from '@affine/core/utils';
import track from '@affine/track';
import { RefNodeSlotsProvider } from '@blocksuite/affine/blocks';
import {
type Disposable,
Expand Down Expand Up @@ -190,6 +191,15 @@ const DetailPageImpl = memo(function DetailPageImpl() {
event && isNewTabTrigger(event)
? 'open-in-new-tab'
: 'open-in-active-view';

if (openMode === 'open-in-new-view') {
track.doc.editor.toolbar.openInSplitView();
} else if (openMode === 'open-in-center-peek') {
track.doc.editor.toolbar.openInPeekView();
} else if (openMode === 'open-in-new-tab') {
track.doc.editor.toolbar.openInNewTab();
}

if (openMode !== 'open-in-center-peek') {
const at = (() => {
if (openMode === 'open-in-active-view') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@affine/component';
import type { AffineDNDData } from '@affine/core/types/dnd';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import {
CloseIcon,
ExpandFullIcon,
Expand Down Expand Up @@ -183,6 +184,10 @@ export const SplitViewPanel = memo(function SplitViewPanel({
}
setDraggingView(null);
setDraggingOverView(null);
track.$.splitViewIndicator.$.splitViewAction({
control: 'indicator',
action: 'move',
});
},
onDragStart() {
setDraggingView({
Expand Down Expand Up @@ -292,18 +297,33 @@ const SplitViewMenu = ({

const viewIndex = views.findIndex(v => v === view);

const handleClose = useCallback(
() => workbench.close(view),
[view, workbench]
);
const handleClose = useCallback(() => {
workbench.close(view);
track.$.splitViewIndicator.$.splitViewAction({
control: 'menu',
action: 'close',
});
}, [view, workbench]);
const handleMoveLeft = useCallback(() => {
onMove(viewIndex, viewIndex - 1);
track.$.splitViewIndicator.$.splitViewAction({
control: 'menu',
action: 'move',
});
}, [onMove, viewIndex]);
const handleMoveRight = useCallback(() => {
onMove(viewIndex, viewIndex + 1);
track.$.splitViewIndicator.$.splitViewAction({
control: 'menu',
action: 'move',
});
}, [onMove, viewIndex]);
const handleCloseOthers = useCallback(() => {
workbench.closeOthers(view);
track.$.splitViewIndicator.$.splitViewAction({
control: 'menu',
action: 'closeOthers',
});
}, [view, workbench]);

const CloseItem =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useDndMonitor } from '@affine/component';
import { useAppSettingHelper } from '@affine/core/components/hooks/affine/use-app-setting-helper';
import type { AffineDNDData } from '@affine/core/types/dnd';
import track from '@affine/track';
import { useService } from '@toeverything/infra';
import clsx from 'clsx';
import { useSetAtom } from 'jotai';
Expand Down Expand Up @@ -121,7 +122,10 @@ export const SplitView = ({
const entity = data.source.data.entity;
const from = data.source.data.from;

if (dropTarget?.at === 'workbench:resize-handle') {
if (
dropTarget?.at === 'workbench:resize-handle' &&
entity?.type !== 'custom-property'
) {
const { edge, viewId } = dropTarget;
const index = views.findIndex(v => v.id === viewId);
const at = (() => {
Expand All @@ -148,6 +152,10 @@ export const SplitView = ({

if (to) {
workbench.createView(at, to);
track.$.splitViewIndicator.$.openInSplitView({
type: entity?.type,
route: to,
});
}
}
},
Expand Down
21 changes: 19 additions & 2 deletions packages/frontend/track/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ type AppEvents =
type NavigationEvents =
| 'openInNewTab'
| 'openInSplitView'
| 'openInPeekView'
| 'switchTab'
| 'switchSplitView'
| 'tabAction'
| 'splitViewAction'
| 'navigate'
| 'goBack'
| 'goForward'
Expand Down Expand Up @@ -314,6 +316,9 @@ const PageEvents = {
newDoc: ['quickStart'],
template: ['openTemplateListMenu', 'quickStart'],
},
splitViewIndicator: {
$: ['splitViewAction', 'openInSplitView', 'openInPeekView'],
},
},
doc: {
editor: {
Expand All @@ -322,7 +327,12 @@ const PageEvents = {
quickSearch: ['createDoc'],
formatToolbar: ['bold'],
pageRef: ['navigate'],
toolbar: ['copyBlockToLink'],
toolbar: [
'copyBlockToLink',
'openInSplitView',
'openInNewTab',
'openInPeekView',
],
aiActions: ['requestSignIn'],
pageBlockHeader: ['openDocInfo'],
starterBar: ['quickStart', 'openTemplateListMenu'],
Expand Down Expand Up @@ -412,6 +422,9 @@ type TabActionType =
| 'switchTab'
| 'separateTabs';

type SplitViewActionControlType = 'menu' | 'indicator';
type SplitViewActionType = 'open' | 'close' | 'move' | 'closeOthers';

type AuthArgs = {
method: 'password' | 'magic-link' | 'oauth';
provider?: string;
Expand Down Expand Up @@ -452,12 +465,16 @@ export type EventArgs = {
deleteOrganizeItem: OrganizeItemArgs;
orderOrganizeItem: OrganizeItemArgs;
openInNewTab: { type: OrganizeItemType };
openInSplitView: { type: OrganizeItemType };
openInSplitView: { type: OrganizeItemType; route?: string };
tabAction: {
type?: OrganizeItemType;
control: TabActionControlType;
action: TabActionType;
};
splitViewAction: {
control: SplitViewActionControlType;
action: SplitViewActionType;
};
toggleFavorite: OrganizeItemArgs & { on: boolean };
toggle: { type: 'collapse' | 'expand' };
createDoc: { mode?: 'edgeless' | 'page' };
Expand Down

0 comments on commit d1bf650

Please sign in to comment.