mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
fix(core): add toDocSearchParams for better typeschecking doc search params (#11383)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { toURLSearchParams } from '@affine/core/modules/navigation';
|
||||
import { toDocSearchParams } from '@affine/core/modules/navigation';
|
||||
import type { IndexerSyncState } from '@affine/nbstore';
|
||||
import type { ReferenceParams } from '@blocksuite/affine/model';
|
||||
import { fromPromise, LiveData, Service } from '@toeverything/infra';
|
||||
@@ -193,7 +193,7 @@ export class DocsSearchService extends Service {
|
||||
docId: doc.id,
|
||||
params: isEmpty(params)
|
||||
? undefined
|
||||
: toURLSearchParams(params),
|
||||
: toDocSearchParams(params),
|
||||
};
|
||||
})
|
||||
.filter(ref => !!ref);
|
||||
|
||||
@@ -2,6 +2,7 @@ export { Navigator } from './entities/navigator';
|
||||
export {
|
||||
resolveLinkToDoc,
|
||||
resolveRouteLinkMeta,
|
||||
toDocSearchParams,
|
||||
toURLSearchParams,
|
||||
} from './utils';
|
||||
export { NavigationButtons } from './view/navigation-buttons';
|
||||
|
||||
@@ -189,3 +189,12 @@ export function toURLSearchParams(
|
||||
.map(([k, v]) => [k, Array.isArray(v) ? v.join(',') : v])
|
||||
);
|
||||
}
|
||||
|
||||
// a type safe version of toURLSearchParams for doc search params
|
||||
export function toDocSearchParams(
|
||||
params?: ReferenceParams & {
|
||||
refreshKey?: string;
|
||||
}
|
||||
) {
|
||||
return toURLSearchParams(params);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
import { ServerService } from '../../cloud';
|
||||
import { WorkspaceDialogService } from '../../dialogs';
|
||||
import { DocsService } from '../../doc/services/docs';
|
||||
import { toURLSearchParams } from '../../navigation';
|
||||
import { toDocSearchParams } from '../../navigation';
|
||||
import { WorkbenchService } from '../../workbench';
|
||||
import type {
|
||||
AttachmentPeekViewInfo,
|
||||
@@ -153,7 +153,7 @@ export const DocPeekViewControls = ({
|
||||
name: t['com.affine.peek-view-controls.copy-link'](),
|
||||
onClick: async () => {
|
||||
const preferredMode = docsService.list.getPrimaryMode(docRef.docId);
|
||||
const search = toURLSearchParams({
|
||||
const search = toDocSearchParams({
|
||||
mode: docRef.mode || preferredMode,
|
||||
blockIds: docRef.blockIds,
|
||||
elementIds: docRef.elementIds,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { toURLSearchParams } from '@affine/core/modules/navigation/utils';
|
||||
import { toDocSearchParams } from '@affine/core/modules/navigation/utils';
|
||||
import { Unreachable } from '@affine/env/constant';
|
||||
import type { ReferenceParams } from '@blocksuite/affine/model';
|
||||
import { Entity, LiveData } from '@toeverything/infra';
|
||||
@@ -156,10 +156,11 @@ export class Workbench extends Entity {
|
||||
openDoc(
|
||||
id:
|
||||
| string
|
||||
| ({ docId: string } & (
|
||||
| ReferenceParams
|
||||
| Record<string, string | undefined>
|
||||
)),
|
||||
| ({
|
||||
docId: string;
|
||||
refreshKey?: string;
|
||||
fromTab?: string;
|
||||
} & ReferenceParams),
|
||||
options?: WorkbenchOpenOptions
|
||||
) {
|
||||
const isString = typeof id === 'string';
|
||||
@@ -167,7 +168,7 @@ export class Workbench extends Entity {
|
||||
|
||||
let query = '';
|
||||
if (!isString) {
|
||||
const search = toURLSearchParams(omit(id, ['docId']));
|
||||
const search = toDocSearchParams(omit(id, ['docId']));
|
||||
if (search?.size) {
|
||||
query = `?${search.toString()}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user