Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): events for backlinks #9228

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { toURLSearchParams } from '@affine/core/modules/navigation';
import { WorkbenchLink } from '@affine/core/modules/workbench';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import type { JobMiddleware } from '@blocksuite/affine/store';
import { ToggleExpandIcon } from '@blocksuite/icons/rc';
import * as Collapsible from '@radix-ui/react-collapsible';
Expand Down Expand Up @@ -93,8 +94,16 @@ const CollapsibleSection = ({
docId,
linkDocId
);

const handleToggle = useCallback(() => {
setOpen(!open);
track.doc.biDirectionalLinksPanel.$.toggle({
type: open ? 'collapse' : 'expand',
});
}, [open, setOpen]);

return (
<Collapsible.Root open={open} onOpenChange={setOpen}>
<Collapsible.Root open={open} onOpenChange={handleToggle}>
<Collapsible.Trigger className={styles.link}>
{title}
{length ? (
Expand Down Expand Up @@ -197,6 +206,9 @@ export const BiDirectionalLinkPanel = () => {

const handleClickShow = useCallback(() => {
setShow(!show);
track.doc.biDirectionalLinksPanel.$.toggle({
type: show ? 'collapse' : 'expand',
});
}, [show, setShow]);

const textRendererOptions = useMemo(() => {
Expand Down Expand Up @@ -243,7 +255,14 @@ export const BiDirectionalLinkPanel = () => {
{backlinkGroups.map(linkGroup => (
<CollapsibleSection
key={linkGroup.docId}
title={<AffinePageReference pageId={linkGroup.docId} />}
title={
<AffinePageReference
pageId={linkGroup.docId}
onClick={() => {
track.doc.biDirectionalLinksPanel.backlinkTitle.navigate();
}}
/>
}
length={linkGroup.links.length}
docId={docService.doc.id}
linkDocId={linkGroup.docId}
Expand Down Expand Up @@ -289,6 +308,9 @@ export const BiDirectionalLinkPanel = () => {
to={to}
key={link.blockId}
className={styles.linkPreview}
onClick={() => {
track.doc.biDirectionalLinksPanel.backlinkPreview.navigate();
}}
>
{edgelessLink ? (
<>
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/track/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ const PageEvents = {
sidepanel: {
property: ['addProperty'],
},
biDirectionalLinksPanel: {
$: ['toggle'],
backlinkTitle: ['toggle', 'navigate'],
backlinkPreview: ['navigate'],
},
},
edgeless: {},
workspace: {
Expand Down
Loading