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

fix(core): wrong fetch injected to snapshot downloader #9460

Merged
merged 1 commit into from
Dec 31, 2024
Merged
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 @@ -206,6 +206,7 @@ const Dialog = ({
loading={disabled}
disabled={disabled}
onClick={handleImportToSelectedWorkspace}
data-testid="import-template-to-workspace-btn"
>
{selectedWorkspaceName &&
t['com.affine.import-template.dialog.createDocToWorkspace']({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ export const Component = () => {
const [searchParams] = useSearchParams();
const { jumpToIndex } = useNavigateHelper();
useEffect(() => {
globalDialogService.open('import-template', {
const id = globalDialogService.open('import-template', {
templateName: searchParams.get('name') ?? '',
templateMode: (searchParams.get('mode') as DocMode) ?? 'page',
snapshotUrl: searchParams.get('snapshotUrl') ?? '',
});

return () => {
globalDialogService.close(id);
};
}, [globalDialogService, jumpToIndex, searchParams]);
// no ui for this route, just open the dialog
return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/core/src/modules/import-template/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Framework } from '@toeverything/infra';

import { FetchService } from '../cloud';
import { RawFetchProvider } from '../cloud';
import { WorkspacesService } from '../workspace';
import { ImportTemplateDialog } from './entities/dialog';
import { TemplateDownloader } from './entities/downloader';
Expand All @@ -16,6 +16,6 @@ export function configureImportTemplateModule(framework: Framework) {
.entity(ImportTemplateDialog)
.service(TemplateDownloaderService)
.entity(TemplateDownloader, [TemplateDownloaderStore])
.store(TemplateDownloaderStore, [FetchService])
.store(TemplateDownloaderStore, [RawFetchProvider])
.service(ImportTemplateService, [WorkspacesService]);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Store } from '@toeverything/infra';

import type { FetchService } from '../../cloud';
import type { RawFetchProvider } from '../../cloud';

export class TemplateDownloaderStore extends Store {
constructor(private readonly fetchService: FetchService) {
constructor(private readonly fetchProvider: RawFetchProvider) {
super();
}

async download(snapshotUrl: string) {
const response = await this.fetchService.fetch(snapshotUrl, {
const response = await this.fetchProvider.fetch(snapshotUrl, {
priority: 'high',
} as any);
const arrayBuffer = await response.arrayBuffer();
Expand Down
33 changes: 33 additions & 0 deletions tests/affine-cloud/e2e/template.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test } from '@affine-test/kit/playwright';
import { createRandomUser, loginUser } from '@affine-test/kit/utils/cloud';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';

test.beforeEach(async ({ page }) => {
const user = await createRandomUser();
await loginUser(page, user);
});

test('import from template should work', async ({ page }) => {
await page.goto('https://affine.pro/templates', { waitUntil: 'load' });

await page.click('.template-list > a:first-child');
const importLink = page.getByText('Use this template');

const href = await importLink.evaluate((el: HTMLElement) => {
const a = el.closest('a');
if (!a) {
throw new Error('Import link not found');
}
return a.href;
});

const url = new URL(href);

await page.goto(url.pathname + url.search);

const btn = page.getByTestId('import-template-to-workspace-btn');

await btn.isVisible();
btn.click();
await waitForEditorLoad(page);
});
Loading