Skip to content

Commit

Permalink
feat(blocks): add event tracking for linked doc
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Dec 6, 2024
1 parent d123c1d commit c1a45ef
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class ReferencePopup extends WithDisposable(LitElement) {
this.abortController.abort();
}

private _viewToggleMenu() {
private _viewSelector() {
// synced doc entry controlled by awareness flag
const isSyncedDocEnabled = this.doc.awarenessStore.getFlag(
'enable_synced_doc_block'
Expand Down Expand Up @@ -389,7 +389,7 @@ export class ReferencePopup extends WithDisposable(LitElement) {
</editor-icon-button>
`,

this._viewToggleMenu(),
this._viewSelector(),

html`
<editor-menu-button
Expand Down
5 changes: 3 additions & 2 deletions packages/affine/components/src/toolbar/menu-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export class EditorMenuButton extends WithDisposable(LitElement) {
this._trigger,
this._content,
({ display }) => {
this._trigger.showTooltip = display === 'hidden';
const opened = display === 'show';
this._trigger.showTooltip = !opened;

this.dispatchEvent(
new CustomEvent('toggle', {
detail: display,
detail: opened,
bubbles: false,
cancelable: false,
composed: true,
Expand Down
14 changes: 14 additions & 0 deletions packages/affine/shared/src/services/telemetry-service/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { TelemetryEvent } from './types.js';

export type LinkEventType =
| 'CopiedLink'
| 'OpenedAliasPopup'
| 'SavedAlias'
| 'ResetedAlias'
| 'OpenedViewSelector'
| 'SelectedView'
| 'OpenedCaptionEditor'
| 'OpenedCardStyleSelector'
| 'SelectedCardStyle';

export type LinkToolbarEvents = Record<LinkEventType, TelemetryEvent>;
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { createIdentifier } from '@blocksuite/global/di';

import type { OutDatabaseAllEvents } from './database.js';
import type { LinkToolbarEvents } from './link.js';
import type {
DocCreatedEvent,
ElementCreationEvent,
TelemetryEvent,
} from './types.js';

export type TelemetryEventMap = OutDatabaseAllEvents & {
DocCreated: DocCreatedEvent;
LinkedDocCreated: TelemetryEvent;
SplitNote: TelemetryEvent;
CanvasElementAdded: ElementCreationEvent;
};
export type TelemetryEventMap = OutDatabaseAllEvents &
LinkToolbarEvents & {
DocCreated: DocCreatedEvent;
LinkedDocCreated: TelemetryEvent;
SplitNote: TelemetryEvent;
CanvasElementAdded: ElementCreationEvent;
};

export interface TelemetryService {
track<T extends keyof TelemetryEventMap>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
EmbedLinkedDocModel,
EmbedSyncedDocModel,
} from '@blocksuite/affine-model';
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
import { FONT_SM, FONT_XS } from '@blocksuite/affine-shared/styles';
import { unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme';
import {
Expand Down Expand Up @@ -150,52 +151,81 @@ export class EmbedCardEditModal extends SignalWatcher(
};

private _onReset = () => {
const blockComponent = this._blockComponent;

if (!blockComponent) {
this.remove();
return;
}

const std = blockComponent.std;

this.model.doc.updateBlock(this.model, { title: null, description: null });

const blockComponent = this._blockComponent;
if (
this.isEmbedLinkedDocModel &&
blockComponent instanceof EmbedLinkedDocBlockComponent
) {
const std = blockComponent.std;

blockComponent.refreshData();

notifyLinkedDocClearedAliases(std);
}
blockComponent?.requestUpdate();
blockComponent.requestUpdate();

std.getOptional(TelemetryProvider)?.track('ResetedAlias', {
control: 'reset',
segment: 'toolbar',
page: 'doc editor',
module: 'embed card edit modal',
type: `${this.viewType} view`,
category: isInternalEmbedModel(this.model) ? 'linked doc' : 'link',
});

this.remove();
};

private _onSave = () => {
const blockComponent = this._blockComponent;

if (!blockComponent) {
this.remove();
return;
}

const title = this.title$.value.trim();
if (title.length === 0) {
toast(this.host, 'Title can not be empty');
return;
}

const std = blockComponent.std;

const description = this.description$.value.trim();

const props: AliasInfo = { title };
if (description) props.description = description;

const blockComponent = this._blockComponent;

if (
this.isEmbedSyncedDocModel &&
blockComponent instanceof EmbedSyncedDocBlockComponent
) {
const std = blockComponent.std;

blockComponent.convertToCard(props);

notifyLinkedDocSwitchedToCard(std);
} else {
this.model.doc.updateBlock(this.model, props);
blockComponent?.requestUpdate();
blockComponent.requestUpdate();
}

std.getOptional(TelemetryProvider)?.track('SavedAlias', {
control: 'save',
segment: 'toolbar',
page: 'doc editor',
module: 'embed card edit modal',
type: `${this.viewType} view`,
category: isInternalEmbedModel(this.model) ? 'linked doc' : 'link',
});

this.remove();
};

Expand Down Expand Up @@ -380,18 +410,23 @@ export class EmbedCardEditModal extends SignalWatcher(

@query('.input.title')
accessor titleInput!: HTMLInputElement;

@property({ attribute: false })
accessor viewType!: string;
}

export function toggleEmbedCardEditModal(
host: EditorHost,
embedCardModel: LinkableEmbedModel,
viewType: string,
originalDocInfo?: AliasInfo
) {
document.body.querySelector('embed-card-edit-modal')?.remove();

const embedCardEditModal = new EmbedCardEditModal();
embedCardEditModal.model = embedCardModel;
embedCardEditModal.host = host;
embedCardEditModal.viewType = viewType;
embedCardEditModal.originalDocInfo = originalDocInfo;
document.body.append(embedCardEditModal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export class EdgelessColorPickerButton extends WithDisposable(LitElement) {

override firstUpdated() {
this.disposables.addFromEvent(this.menuButton, 'toggle', (e: Event) => {
const newState = (e as CustomEvent).detail;
if (newState === 'hidden' && this.tabType !== 'normal') {
const opened = (e as CustomEvent<boolean>).detail;
if (!opened && this.tabType !== 'normal') {
this.tabType = 'normal';
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,12 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) {
const originalDocInfo = this._originalDocInfo;
toggleEmbedCardEditModal(this.std.host, model, originalDocInfo);
toggleEmbedCardEditModal(
this.std.host,
model,
this._viewType,
originalDocInfo
);
}}
>
${EditIcon}
Expand Down
Loading

0 comments on commit c1a45ef

Please sign in to comment.