feat: optimize import export event tracker (#8652)
This commit is contained in:
@@ -2,6 +2,7 @@ import { Button, IconButton, Modal } from '@affine/component';
|
|||||||
import { UrlService } from '@affine/core/modules/url';
|
import { UrlService } from '@affine/core/modules/url';
|
||||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
|
import track from '@affine/track';
|
||||||
import {
|
import {
|
||||||
MarkdownTransformer,
|
MarkdownTransformer,
|
||||||
NotionHtmlTransformer,
|
NotionHtmlTransformer,
|
||||||
@@ -294,19 +295,35 @@ export const ImportModal = ({ ...modalProps }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setStatus('importing');
|
setStatus('importing');
|
||||||
|
track.$.importModal.$.import({
|
||||||
|
type,
|
||||||
|
status: 'importing',
|
||||||
|
});
|
||||||
|
|
||||||
const pageIds = await importConfig.importFunction(docCollection, file);
|
const pageIds = await importConfig.importFunction(docCollection, file);
|
||||||
|
|
||||||
setPageIds(pageIds);
|
setPageIds(pageIds);
|
||||||
setStatus('success');
|
setStatus('success');
|
||||||
|
track.$.importModal.$.import({
|
||||||
|
type,
|
||||||
|
status: 'success',
|
||||||
|
result: {
|
||||||
|
docCount: pageIds.length,
|
||||||
|
},
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setImportError(
|
setImportError(
|
||||||
error instanceof Error ? error.message : 'Unknown error occurred'
|
error instanceof Error ? error.message : 'Unknown error occurred'
|
||||||
);
|
);
|
||||||
setStatus('error');
|
setStatus('error');
|
||||||
|
track.$.importModal.$.import({
|
||||||
|
type,
|
||||||
|
status: 'failed',
|
||||||
|
error: importError || undefined,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[docCollection, t]
|
[docCollection, t, importError]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleComplete = useCallback(() => {
|
const handleComplete = useCallback(() => {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hoo
|
|||||||
import { useSystemOnline } from '@affine/core/components/hooks/use-system-online';
|
import { useSystemOnline } from '@affine/core/components/hooks/use-system-online';
|
||||||
import { DesktopApiService } from '@affine/core/modules/desktop-api/service';
|
import { DesktopApiService } from '@affine/core/modules/desktop-api/service';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
|
import track from '@affine/track';
|
||||||
import {
|
import {
|
||||||
useService,
|
useService,
|
||||||
type Workspace,
|
type Workspace,
|
||||||
@@ -33,6 +34,9 @@ export const DesktopExportPanel = ({
|
|||||||
}
|
}
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
try {
|
try {
|
||||||
|
track.$.settingsPanel.workspace.export({
|
||||||
|
type: 'workspace',
|
||||||
|
});
|
||||||
if (isOnline) {
|
if (isOnline) {
|
||||||
await workspace.engine.waitForDocSynced();
|
await workspace.engine.waitForDocSynced();
|
||||||
await workspace.engine.blob.sync();
|
await workspace.engine.blob.sync();
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ export const PageHeaderMenuButton = ({
|
|||||||
}, [duplicate, pageId]);
|
}, [duplicate, pageId]);
|
||||||
|
|
||||||
const handleOpenImportModal = useCallback(() => {
|
const handleOpenImportModal = useCallback(() => {
|
||||||
track.$.header.docOptions.import();
|
track.$.header.importModal.open();
|
||||||
setOpenImportModalAtom(true);
|
setOpenImportModalAtom(true);
|
||||||
}, [setOpenImportModalAtom]);
|
}, [setOpenImportModalAtom]);
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,11 @@ export const Snapshot = ({ className }: SnapshotProps) => {
|
|||||||
const file = await openFileOrFiles({ acceptType: 'Zip' });
|
const file = await openFileOrFiles({ acceptType: 'Zip' });
|
||||||
if (!file) return null;
|
if (!file) return null;
|
||||||
|
|
||||||
|
track.$.header.snapshot.import({
|
||||||
|
type: 'snapshot',
|
||||||
|
status: 'importing',
|
||||||
|
});
|
||||||
|
|
||||||
const importedDocs = (
|
const importedDocs = (
|
||||||
await ZipTransformer.importDocs(docCollection, file)
|
await ZipTransformer.importDocs(docCollection, file)
|
||||||
).filter(doc => doc !== undefined);
|
).filter(doc => doc !== undefined);
|
||||||
@@ -122,6 +127,13 @@ export const Snapshot = ({ className }: SnapshotProps) => {
|
|||||||
title: 'Imported Snapshot Successfully',
|
title: 'Imported Snapshot Successfully',
|
||||||
message: `Imported ${importedDocs.length} doc(s)`,
|
message: `Imported ${importedDocs.length} doc(s)`,
|
||||||
});
|
});
|
||||||
|
track.$.header.snapshot.import({
|
||||||
|
type: 'snapshot',
|
||||||
|
status: 'success',
|
||||||
|
result: {
|
||||||
|
docCount: importedDocs.length,
|
||||||
|
},
|
||||||
|
});
|
||||||
return importedDocs;
|
return importedDocs;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error importing snapshot:', error);
|
console.error('Error importing snapshot:', error);
|
||||||
@@ -129,6 +141,11 @@ export const Snapshot = ({ className }: SnapshotProps) => {
|
|||||||
title: 'Import Snapshot Failed',
|
title: 'Import Snapshot Failed',
|
||||||
message: 'Failed to import snapshot. Please try again.',
|
message: 'Failed to import snapshot. Please try again.',
|
||||||
});
|
});
|
||||||
|
track.$.header.snapshot.import({
|
||||||
|
type: 'snapshot',
|
||||||
|
status: 'failed',
|
||||||
|
error: error instanceof Error ? error.message : undefined,
|
||||||
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, [docCollection]);
|
}, [docCollection]);
|
||||||
@@ -165,6 +182,9 @@ export const Snapshot = ({ className }: SnapshotProps) => {
|
|||||||
case 'import':
|
case 'import':
|
||||||
return handleImportSnapshot();
|
return handleImportSnapshot();
|
||||||
case 'export':
|
case 'export':
|
||||||
|
track.$.header.snapshot.export({
|
||||||
|
type: 'snapshot',
|
||||||
|
});
|
||||||
return exportHandler('snapshot');
|
return exportHandler('snapshot');
|
||||||
case 'disable':
|
case 'disable':
|
||||||
return disableSnapshotActionOption();
|
return disableSnapshotActionOption();
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ export const RootAppSidebar = (): ReactElement => {
|
|||||||
}, [setOpenSettingModalAtom]);
|
}, [setOpenSettingModalAtom]);
|
||||||
|
|
||||||
const onOpenImportModal = useCallback(() => {
|
const onOpenImportModal = useCallback(() => {
|
||||||
|
track.$.navigationPanel.importModal.open();
|
||||||
setOpenImportModalAtom(true);
|
setOpenImportModalAtom(true);
|
||||||
}, [setOpenImportModalAtom]);
|
}, [setOpenImportModalAtom]);
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
"fr": 73,
|
"fr": 73,
|
||||||
"hi": 2,
|
"hi": 2,
|
||||||
"it": 1,
|
"it": 1,
|
||||||
"ja": 97,
|
"ja": 98,
|
||||||
"ko": 86,
|
"ko": 87,
|
||||||
"pl": 0,
|
"pl": 0,
|
||||||
"pt-BR": 94,
|
"pt-BR": 94,
|
||||||
"ru": 80,
|
"ru": 80,
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ type UserEvents =
|
|||||||
| AuthEvents
|
| AuthEvents
|
||||||
| AccountEvents
|
| AccountEvents
|
||||||
| PaymentEvents;
|
| PaymentEvents;
|
||||||
|
|
||||||
interface PageDivision {
|
interface PageDivision {
|
||||||
[page: string]: {
|
[page: string]: {
|
||||||
[segment: string]: {
|
[segment: string]: {
|
||||||
@@ -152,7 +151,7 @@ const PageEvents = {
|
|||||||
},
|
},
|
||||||
settingsPanel: {
|
settingsPanel: {
|
||||||
menu: ['openSettings'],
|
menu: ['openSettings'],
|
||||||
workspace: ['viewPlans'],
|
workspace: ['viewPlans', 'export'],
|
||||||
profileAndBadge: ['viewPlans'],
|
profileAndBadge: ['viewPlans'],
|
||||||
accountUsage: ['viewPlans'],
|
accountUsage: ['viewPlans'],
|
||||||
accountSettings: ['uploadAvatar', 'removeAvatar', 'updateUserName'],
|
accountSettings: ['uploadAvatar', 'removeAvatar', 'updateUserName'],
|
||||||
@@ -214,7 +213,8 @@ const PageEvents = {
|
|||||||
'openChangelog',
|
'openChangelog',
|
||||||
'dismissChangelog',
|
'dismissChangelog',
|
||||||
],
|
],
|
||||||
others: ['navigate', 'import'],
|
others: ['navigate'],
|
||||||
|
importModal: ['open'],
|
||||||
workspaceList: [
|
workspaceList: [
|
||||||
'open',
|
'open',
|
||||||
'signIn',
|
'signIn',
|
||||||
@@ -231,6 +231,9 @@ const PageEvents = {
|
|||||||
docHistory: {
|
docHistory: {
|
||||||
$: ['open', 'close', 'switchPageMode', 'viewPlans'],
|
$: ['open', 'close', 'switchPageMode', 'viewPlans'],
|
||||||
},
|
},
|
||||||
|
importModal: {
|
||||||
|
$: ['open', 'import'],
|
||||||
|
},
|
||||||
paywall: {
|
paywall: {
|
||||||
storage: ['viewPlans'],
|
storage: ['viewPlans'],
|
||||||
aiAction: ['viewPlans'],
|
aiAction: ['viewPlans'],
|
||||||
@@ -259,6 +262,8 @@ const PageEvents = {
|
|||||||
],
|
],
|
||||||
history: ['open'],
|
history: ['open'],
|
||||||
pageInfo: ['open'],
|
pageInfo: ['open'],
|
||||||
|
importModal: ['open'],
|
||||||
|
snapshot: ['import', 'export'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
doc: {
|
doc: {
|
||||||
@@ -354,6 +359,16 @@ type AuthArgs = {
|
|||||||
provider?: string;
|
provider?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ImportStatus = 'importing' | 'failed' | 'success';
|
||||||
|
type ImportArgs = {
|
||||||
|
type: string;
|
||||||
|
status?: ImportStatus;
|
||||||
|
error?: string;
|
||||||
|
result?: {
|
||||||
|
docCount: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export type EventArgs = {
|
export type EventArgs = {
|
||||||
createWorkspace: { flavour: string };
|
createWorkspace: { flavour: string };
|
||||||
signIn: AuthArgs;
|
signIn: AuthArgs;
|
||||||
@@ -393,6 +408,7 @@ export type EventArgs = {
|
|||||||
copyShareLink: {
|
copyShareLink: {
|
||||||
type: 'default' | 'doc' | 'whiteboard' | 'block' | 'element';
|
type: 'default' | 'doc' | 'whiteboard' | 'block' | 'element';
|
||||||
};
|
};
|
||||||
|
import: ImportArgs;
|
||||||
export: { type: string };
|
export: { type: string };
|
||||||
copyBlockToLink: {
|
copyBlockToLink: {
|
||||||
type: string;
|
type: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user