Skip to content

Commit 2936435

Browse files
Merge pull request #265 from NotionX/fix-new-databases
2 parents 03dbb8a + 3dd720e commit 2936435

File tree

6 files changed

+49
-14
lines changed

6 files changed

+49
-14
lines changed

packages/notion-client/src/notion-api.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class NotionAPI {
118118
block &&
119119
(block.type === 'collection_view' ||
120120
block.type === 'collection_view_page') &&
121-
getBlockCollectionId(block)
121+
getBlockCollectionId(block, recordMap)
122122

123123
if (collectionId) {
124124
return block.view_ids?.map((collectionViewId) => ({
@@ -421,6 +421,16 @@ export class NotionAPI {
421421
}
422422
}
423423

424+
//TODO: started working on the filters. This doens't seem to quite work yet.
425+
// let filters = collectionView.format?.property_filters.map(filterObj => {
426+
// console.log('map filter', filterObj)
427+
// //get the inner filter
428+
// return {
429+
// filter: filterObj.filter.filter,
430+
// property: filterObj.filter.property
431+
// }
432+
// })
433+
424434
const reducerLabel = isBoardType ? 'board_columns' : `${type}_groups`
425435
loader = {
426436
type: 'reducer',
@@ -439,6 +449,11 @@ export class NotionAPI {
439449
...collectionView?.query2,
440450
searchQuery,
441451
userTimeZone
452+
//TODO: add filters here
453+
// filter: {
454+
// filters: filters,
455+
// operator: 'and'
456+
// }
442457
}
443458
}
444459

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
import { Block } from 'notion-types'
1+
import { Block, ExtendedRecordMap } from 'notion-types'
22

3-
export function getBlockCollectionId(block: Block): string | null {
4-
return (
3+
export function getBlockCollectionId(
4+
block: Block,
5+
recordMap: ExtendedRecordMap
6+
): string | null {
7+
const collectionId =
58
(block as any).collection_id ||
6-
(block as any).format?.collection_pointer?.id ||
7-
null
8-
)
9+
(block as any).format?.collection_pointer?.id
10+
11+
if (collectionId) {
12+
return collectionId
13+
}
14+
15+
const collectionViewId = (block as any)?.view_ids?.[0]
16+
if (collectionViewId) {
17+
const collectionView = recordMap.collection_view?.[collectionViewId]?.value
18+
if (collectionView) {
19+
const collectionId = collectionView.format?.collection_pointer?.id
20+
return collectionId
21+
}
22+
}
23+
24+
return null
925
}

packages/notion-utils/src/get-block-icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function getBlockIcon(block: Block, recordMap: ExtendedRecordMap) {
1010
block.type === 'collection_view_page' ||
1111
block.type === 'collection_view'
1212
) {
13-
const collectionId = getBlockCollectionId(block)
13+
const collectionId = getBlockCollectionId(block, recordMap)
1414
if (collectionId) {
1515
const collection = recordMap.collection[collectionId]?.value
1616

packages/notion-utils/src/get-block-title.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ export function getBlockTitle(block: Block, recordMap: ExtendedRecordMap) {
1111
block.type === 'collection_view_page' ||
1212
block.type === 'collection_view'
1313
) {
14-
const collection = recordMap.collection[getBlockCollectionId(block)]?.value
14+
const collectionId = getBlockCollectionId(block, recordMap)
1515

16-
if (collection) {
17-
return getTextContent(collection.name)
16+
if (collectionId) {
17+
const collection = recordMap.collection[collectionId]?.value
18+
19+
if (collection) {
20+
return getTextContent(collection.name)
21+
}
1822
}
1923
}
2024

packages/react-notion-x/src/block.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const Block: React.FC<BlockProps> = (props) => {
120120
? block.properties
121121
: {
122122
title:
123-
recordMap.collection[getBlockCollectionId(block)]?.value
124-
?.name
123+
recordMap.collection[getBlockCollectionId(block, recordMap)]
124+
?.value?.name
125125
}
126126

127127
const coverPosition = (1 - (page_cover_position || 0.5)) * 100

packages/react-notion-x/src/third-party/collection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const CollectionViewBlock: React.FC<{
8383
}> = ({ block, className }) => {
8484
const { recordMap, showCollectionViewDropdown } = useNotionContext()
8585
const { view_ids: viewIds } = block
86-
const collectionId = getBlockCollectionId(block)
86+
const collectionId = getBlockCollectionId(block, recordMap)
8787

8888
const [isMounted, setIsMounted] = React.useState(false)
8989
React.useEffect(() => {

0 commit comments

Comments
 (0)