mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
fix(core): should open a new tab with parameters (#8118)
Closes [AF-1343](https://linear.app/affine-design/issue/AF-1343/点击-center-peek-右侧的按钮时,应该携带参数)
This commit is contained in:
@@ -59,8 +59,9 @@ export const ControlButton = ({
|
||||
|
||||
type DocPeekViewControlsProps = HTMLAttributes<HTMLDivElement> & {
|
||||
docId: string;
|
||||
blockId?: string;
|
||||
mode?: DocMode;
|
||||
blockIds?: string[];
|
||||
elementIds?: string[];
|
||||
};
|
||||
|
||||
export const DefaultPeekViewControls = ({
|
||||
@@ -90,8 +91,9 @@ export const DefaultPeekViewControls = ({
|
||||
|
||||
export const DocPeekViewControls = ({
|
||||
docId,
|
||||
blockId,
|
||||
mode,
|
||||
blockIds,
|
||||
elementIds,
|
||||
className,
|
||||
...rest
|
||||
}: DocPeekViewControlsProps) => {
|
||||
@@ -111,8 +113,7 @@ export const DocPeekViewControls = ({
|
||||
name: t['com.affine.peek-view-controls.open-doc'](),
|
||||
nameKey: 'open',
|
||||
onClick: () => {
|
||||
// TODO(@Peng): for frame blocks, we should mimic "view in edgeless" button behavior
|
||||
workbench.openDoc({ docId, mode, blockId });
|
||||
workbench.openDoc({ docId, mode, blockIds, elementIds });
|
||||
peekView.close('none');
|
||||
},
|
||||
},
|
||||
@@ -121,7 +122,10 @@ export const DocPeekViewControls = ({
|
||||
nameKey: 'new-tab',
|
||||
name: t['com.affine.peek-view-controls.open-doc-in-new-tab'](),
|
||||
onClick: () => {
|
||||
workbench.openDoc({ docId, mode }, { at: 'new-tab' });
|
||||
workbench.openDoc(
|
||||
{ docId, mode, blockIds, elementIds },
|
||||
{ at: 'new-tab' }
|
||||
);
|
||||
peekView.close('none');
|
||||
},
|
||||
},
|
||||
@@ -135,7 +139,7 @@ export const DocPeekViewControls = ({
|
||||
},
|
||||
},
|
||||
].filter((opt): opt is ControlButtonProps => Boolean(opt));
|
||||
}, [blockId, docId, mode, peekView, t, workbench]);
|
||||
}, [docId, mode, blockIds, elementIds, peekView, t, workbench]);
|
||||
return (
|
||||
<div {...rest} className={clsx(styles.root, className)}>
|
||||
{controls.map(option => (
|
||||
|
||||
@@ -53,7 +53,8 @@ const renderControls = ({ info }: ActivePeekView) => {
|
||||
<DocPeekViewControls
|
||||
mode={info.mode}
|
||||
docId={info.docId}
|
||||
blockId={info.docId}
|
||||
blockIds={info.blockIds}
|
||||
elementIds={info.elementIds}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,10 +54,14 @@ export class CMDKQuickSearchService extends Service {
|
||||
result.source === 'docs' &&
|
||||
track.$.cmdk.results.searchResultsDocs();
|
||||
|
||||
this.workbenchService.workbench.openDoc({
|
||||
const options: { docId: string; blockIds?: string[] } = {
|
||||
docId: doc.docId,
|
||||
blockId: doc.blockId,
|
||||
});
|
||||
};
|
||||
if (doc.blockId) {
|
||||
options.blockIds = [doc.blockId];
|
||||
}
|
||||
|
||||
this.workbenchService.workbench.openDoc(options);
|
||||
} else if (result.source === 'collections') {
|
||||
this.workbenchService.workbench.openCollection(
|
||||
result.payload.collectionId
|
||||
|
||||
@@ -122,18 +122,27 @@ export class Workbench extends Entity {
|
||||
}
|
||||
|
||||
openDoc(
|
||||
id: string | { docId: string; blockId?: string; mode?: DocMode },
|
||||
id:
|
||||
| string
|
||||
| {
|
||||
docId: string;
|
||||
mode?: DocMode;
|
||||
blockIds?: string[];
|
||||
elementIds?: string[];
|
||||
},
|
||||
options?: WorkbenchOpenOptions
|
||||
) {
|
||||
const docId = typeof id === 'string' ? id : id.docId;
|
||||
const blockId = typeof id === 'string' ? undefined : id.blockId;
|
||||
const mode = typeof id === 'string' ? undefined : id.mode;
|
||||
const isString = typeof id === 'string';
|
||||
const docId = isString ? id : id.docId;
|
||||
|
||||
let query = '';
|
||||
if (mode || blockId) {
|
||||
if (!isString) {
|
||||
const { mode, blockIds, elementIds } = id;
|
||||
const search = new URLSearchParams();
|
||||
if (mode) search.set('mode', mode);
|
||||
if (blockId) search.set('blockIds', blockId);
|
||||
query = `?${search.toString()}`;
|
||||
if (blockIds?.length) search.set('blockIds', blockIds.join(','));
|
||||
if (elementIds?.length) search.set('elementIds', elementIds.join(','));
|
||||
if (search.size > 0) query = `?${search.toString()}`;
|
||||
}
|
||||
|
||||
this.open(`/${docId}${query}`, options);
|
||||
|
||||
Reference in New Issue
Block a user