mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 22:37:04 +08:00
fix(core): database backlink row visibility (#11706)
fix AF-2507 do not show the db backlink row if - the row does not have any properties (excluding `title` column) - the target doc is a template page
This commit is contained in:
@@ -6,11 +6,12 @@ import {
|
|||||||
} from '@affine/component';
|
} from '@affine/component';
|
||||||
import { AffinePageReference } from '@affine/core/components/affine/reference-link';
|
import { AffinePageReference } from '@affine/core/components/affine/reference-link';
|
||||||
import { DocService } from '@affine/core/modules/doc';
|
import { DocService } from '@affine/core/modules/doc';
|
||||||
|
import { TemplateDocService } from '@affine/core/modules/template-doc';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import type { DatabaseBlockDataSource } from '@blocksuite/affine/blocks/database';
|
import type { DatabaseBlockDataSource } from '@blocksuite/affine/blocks/database';
|
||||||
import { DatabaseTableViewIcon, PageIcon } from '@blocksuite/icons/rc';
|
import { DatabaseTableViewIcon, PageIcon } from '@blocksuite/icons/rc';
|
||||||
import { LiveData, useLiveData, useService } from '@toeverything/infra';
|
import { LiveData, useLiveData, useService } from '@toeverything/infra';
|
||||||
import { Fragment, useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import type { Observable } from 'rxjs';
|
import type { Observable } from 'rxjs';
|
||||||
|
|
||||||
import { DocDatabaseBacklinksService } from '../../services/doc-database-backlinks';
|
import { DocDatabaseBacklinksService } from '../../services/doc-database-backlinks';
|
||||||
@@ -96,13 +97,24 @@ const DatabaseBacklinkRow = ({
|
|||||||
useMemo(() => LiveData.from(row$, undefined), [row$])
|
useMemo(() => LiveData.from(row$, undefined), [row$])
|
||||||
);
|
);
|
||||||
const sortedCells = useMemo(() => {
|
const sortedCells = useMemo(() => {
|
||||||
return row?.cells.toSorted((a, b) => {
|
return row?.cells
|
||||||
return (a.property.name$.value ?? '').localeCompare(
|
.filter(cell => cell.property.id !== 'title')
|
||||||
b.property.name$.value ?? ''
|
.toSorted((a, b) => {
|
||||||
);
|
return (a.property.name$.value ?? '').localeCompare(
|
||||||
});
|
b.property.name$.value ?? ''
|
||||||
|
);
|
||||||
|
});
|
||||||
}, [row?.cells]);
|
}, [row?.cells]);
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
|
const templateDocService = useService(TemplateDocService);
|
||||||
|
|
||||||
|
const isTemplateDoc = useLiveData(
|
||||||
|
useMemo(
|
||||||
|
() =>
|
||||||
|
row?.docId ? templateDocService.list.isTemplate$(row.docId) : undefined,
|
||||||
|
[row?.docId, templateDocService.list]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
const pageRefParams = useMemo(() => {
|
const pageRefParams = useMemo(() => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
@@ -112,52 +124,55 @@ const DatabaseBacklinkRow = ({
|
|||||||
return params;
|
return params;
|
||||||
}, [row]);
|
}, [row]);
|
||||||
|
|
||||||
if (!row || !sortedCells) {
|
if (!row || !sortedCells || sortedCells.length === 0 || isTemplateDoc) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PropertyCollapsibleSection
|
<>
|
||||||
title={
|
<PropertyCollapsibleSection
|
||||||
<span className={styles.databaseNameWrapper}>
|
title={
|
||||||
<span className={styles.databaseName}>
|
<span className={styles.databaseNameWrapper}>
|
||||||
{row.databaseName || t['unnamed']()}
|
<span className={styles.databaseName}>
|
||||||
|
{row.databaseName || t['unnamed']()}
|
||||||
|
</span>
|
||||||
|
{t['properties']()}
|
||||||
</span>
|
</span>
|
||||||
{t['properties']()}
|
}
|
||||||
</span>
|
defaultCollapsed={!defaultOpen}
|
||||||
}
|
icon={<DatabaseTableViewIcon />}
|
||||||
defaultCollapsed={!defaultOpen}
|
suffix={
|
||||||
icon={<DatabaseTableViewIcon />}
|
<AffinePageReference
|
||||||
suffix={
|
className={
|
||||||
<AffinePageReference
|
BUILD_CONFIG.isMobileEdition
|
||||||
className={
|
? styles.mobileDocRefLink
|
||||||
BUILD_CONFIG.isMobileEdition
|
: styles.docRefLink
|
||||||
? styles.mobileDocRefLink
|
}
|
||||||
: styles.docRefLink
|
pageId={row.docId}
|
||||||
}
|
params={pageRefParams}
|
||||||
pageId={row.docId}
|
Icon={PageIcon}
|
||||||
params={pageRefParams}
|
/>
|
||||||
Icon={PageIcon}
|
}
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<PropertyCollapsibleContent
|
|
||||||
className={styles.cellList}
|
|
||||||
collapsible={false}
|
|
||||||
>
|
>
|
||||||
{sortedCells.map(cell => {
|
<PropertyCollapsibleContent
|
||||||
return (
|
className={styles.cellList}
|
||||||
<DatabaseBacklinkCell
|
collapsible={false}
|
||||||
key={cell.id}
|
>
|
||||||
cell={cell}
|
{sortedCells.map(cell => {
|
||||||
dataSource={row.dataSource}
|
return (
|
||||||
rowId={row.id}
|
<DatabaseBacklinkCell
|
||||||
onChange={value => onChange?.(row, cell, value)}
|
key={cell.id}
|
||||||
/>
|
cell={cell}
|
||||||
);
|
dataSource={row.dataSource}
|
||||||
})}
|
rowId={row.id}
|
||||||
</PropertyCollapsibleContent>
|
onChange={value => onChange?.(row, cell, value)}
|
||||||
</PropertyCollapsibleSection>
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</PropertyCollapsibleContent>
|
||||||
|
</PropertyCollapsibleSection>
|
||||||
|
<Divider size="thinner" className={styles.divider} />
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -196,21 +211,19 @@ export const DocDatabaseBacklinkInfo = ({
|
|||||||
return (
|
return (
|
||||||
<div className={styles.root}>
|
<div className={styles.root}>
|
||||||
{rows.map(({ docId, databaseBlockId, rowId, row$ }) => (
|
{rows.map(({ docId, databaseBlockId, rowId, row$ }) => (
|
||||||
<Fragment key={`${docId}-${rowId}`}>
|
<DatabaseBacklinkRow
|
||||||
<DatabaseBacklinkRow
|
key={`${docId}-${rowId}`}
|
||||||
defaultOpen={
|
defaultOpen={
|
||||||
defaultOpen?.some(
|
defaultOpen?.some(
|
||||||
backlink =>
|
backlink =>
|
||||||
backlink.databaseBlockId === databaseBlockId &&
|
backlink.databaseBlockId === databaseBlockId &&
|
||||||
backlink.rowId === rowId &&
|
backlink.rowId === rowId &&
|
||||||
backlink.docId === docId
|
backlink.docId === docId
|
||||||
) ?? false
|
) ?? false
|
||||||
}
|
}
|
||||||
row$={row$}
|
row$={row$}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
<Divider size="thinner" className={styles.divider} />
|
|
||||||
</Fragment>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user