diff --git a/src/components/DocumentView/Mention.tsx b/src/components/DocumentView/Mention.tsx index c3ed8fea9..1b89530d4 100644 --- a/src/components/DocumentView/Mention.tsx +++ b/src/components/DocumentView/Mention.tsx @@ -1,5 +1,6 @@ import { DocumentInlineMention } from '@gitbook/api'; -import NextLink from 'next/link'; + +import { Link } from '@/components/primitives'; import { InlineProps } from './Inline'; @@ -12,12 +13,5 @@ export async function Mention(props: InlineProps) { return null; } - return ( - - {resolved.text} - - ); + return {resolved.text}; } diff --git a/src/components/DocumentView/Table/RecordColumnValue.tsx b/src/components/DocumentView/Table/RecordColumnValue.tsx index e7e729a88..851394633 100644 --- a/src/components/DocumentView/Table/RecordColumnValue.tsx +++ b/src/components/DocumentView/Table/RecordColumnValue.tsx @@ -1,8 +1,11 @@ -import { DocumentBlockTable } from '@gitbook/api'; +import IconStar from '@geist-ui/icons/star'; +import { ContentRef, DocumentBlockTable } from '@gitbook/api'; +import assertNever from 'assert-never'; -import { Checkbox } from '@/components/primitives'; +import { Checkbox, Link } from '@/components/primitives'; import { getNodeFragmentByName } from '@/lib/document'; import { tcls } from '@/lib/tailwind'; +import { filterOutNullable } from '@/lib/typescript'; import { TableRecordKV } from './Table'; import { BlockProps } from '../Block'; @@ -28,25 +31,6 @@ export async function RecordColumnValue( } switch (definition.type) { - /* case 'content-ref': - // @ts-ignore - const target = await resolveContentRef(value, context); - if (!target) { - return {''}; - } - return ( - - {target.text} - - ); */ case 'checkbox': return ( ( /> ); case 'rating': + const rating = value as number; + return ( - - {`${value}`} + + {value ? ( + + {Array.from({ length: rating }).map((_, i) => ( + + ))} + + ) : null} ); case 'number': @@ -85,7 +84,87 @@ export async function RecordColumnValue( blockStyle={['w-full', 'max-w-[unset]']} /> ); + case 'files': + const files = await Promise.all( + (value as string[]).map((fileId) => + context.resolveContentRef({ + kind: 'file', + file: fileId, + }), + ), + ); + + return ( + + {files.filter(filterOutNullable).map((file, index) => ( + + {file.text} + + ))} + + ); + case 'content-ref': { + const resolved = value ? await context.resolveContentRef(value as ContentRef) : null; + return ( + + {resolved ? {resolved.text} : null} + + ); + } + case 'users': { + const resolved = await Promise.all( + (value as string[]).map((userId) => + context.resolveContentRef({ + kind: 'user', + user: userId, + }), + ), + ); + + return ( + + {resolved.filter(filterOutNullable).map((file, index) => ( + + {file.text} + + ))} + + ); + } + case 'select': { + return ( + + + {(value as string[]).map((selectId) => { + const option = definition.options.find( + (option) => option.value === selectId, + ); + + if (!option) { + return null; + } + + return ( + + {option.label} + + ); + })} + + + ); + } default: - return null; + assertNever(definition); } } diff --git a/src/components/DocumentView/Table/ViewGrid.tsx b/src/components/DocumentView/Table/ViewGrid.tsx index ba43dcf21..941cbf1fc 100644 --- a/src/components/DocumentView/Table/ViewGrid.tsx +++ b/src/components/DocumentView/Table/ViewGrid.tsx @@ -143,6 +143,8 @@ export function ViewGrid(props: TableViewProps) { {view.columns.map((column) => { + const columnWidth = view.columnWidths?.[column]; + return ( ) { 'dark:border-l-light/2', 'dark:border-b-light/4', )} + style={columnWidth ? { width: columnWidth } : undefined} > {block.data.definition[column].title} diff --git a/src/components/Search/SearchAskAnswer.tsx b/src/components/Search/SearchAskAnswer.tsx index 0ceae92ad..e0a6bcf10 100644 --- a/src/components/Search/SearchAskAnswer.tsx +++ b/src/components/Search/SearchAskAnswer.tsx @@ -65,13 +65,13 @@ export function SearchAskAnswer(props: { spaceId: string; query: string }) { }); }, ); - }, [spaceId, query, setSearchState]); + }, [spaceId, query, setSearchState, setState]); React.useEffect(() => { return () => { setState(null); }; - }, []); + }, [setState]); return (
+ {props.children} + + ); +} diff --git a/src/components/primitives/index.ts b/src/components/primitives/index.ts index a46f82b52..457af3084 100644 --- a/src/components/primitives/index.ts +++ b/src/components/primitives/index.ts @@ -3,3 +3,4 @@ export * from './Button'; export * from './Loading'; export * from './Card'; export * from './Skeleton'; +export * from './Link';