Skip to content

Commit b39686a

Browse files
committed
fixed databases for new databases
1 parent cfbfcc1 commit b39686a

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ export class NotionAPI {
125125
collectionId,
126126
collectionViewId
127127
}))
128+
} else if (block && (block as any).view_ids) {
129+
return (block as any).view_ids.map((collectionViewId) => {
130+
if (recordMap.collection_view[collectionViewId]) {
131+
const viewBlock =
132+
recordMap.collection_view[collectionViewId].value
133+
const collectionId = viewBlock.format?.collection_pointer?.id
134+
if (collectionId) {
135+
return {
136+
collectionId,
137+
collectionViewId
138+
}
139+
}
140+
}
141+
return null
142+
})
128143
} else {
129144
return []
130145
}
@@ -421,6 +436,16 @@ export class NotionAPI {
421436
}
422437
}
423438

439+
//TODO: started working on the filters. This doens't seem to quite work yet.
440+
// let filters = collectionView.format?.property_filters.map(filterObj => {
441+
// console.log('map filter', filterObj)
442+
// //get the inner filter
443+
// return {
444+
// filter: filterObj.filter.filter,
445+
// property: filterObj.filter.property
446+
// }
447+
// })
448+
424449
const reducerLabel = isBoardType ? 'board_columns' : `${type}_groups`
425450
loader = {
426451
type: 'reducer',
@@ -439,6 +464,11 @@ export class NotionAPI {
439464
...collectionView?.query2,
440465
searchQuery,
441466
userTimeZone
467+
//TODO: add filters here
468+
// filter: {
469+
// filters: filters,
470+
// operator: 'and'
471+
// }
442472
}
443473
}
444474

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {
2+
CollectionViewBlock,
3+
CollectionViewPageBlock,
4+
ExtendedRecordMap
5+
} from 'notion-types'
6+
7+
export function getBlockCollectionPointerId(
8+
recordMap: ExtendedRecordMap,
9+
block: CollectionViewBlock | CollectionViewPageBlock
10+
): string | null {
11+
const collectionViewId = (block as any).view_ids[0]
12+
if (recordMap.collection_view[collectionViewId]) {
13+
const viewBlock = recordMap.collection_view[collectionViewId].value
14+
const collectionId = viewBlock.format?.collection_pointer?.id
15+
return collectionId
16+
}
17+
return null
18+
}

packages/notion-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ export * from './normalize-title'
2121
export * from './merge-record-maps'
2222
export * from './format-date'
2323
export * from './format-notion-date-time'
24+
export * from './get-block-collection-pointer-id'

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import * as types from 'notion-types'
33
import {
44
getBlockCollectionId,
5+
getBlockCollectionPointerId,
56
getBlockParentPage,
67
getTextContent
78
} from 'notion-utils'
@@ -83,7 +84,8 @@ const CollectionViewBlock: React.FC<{
8384
}> = ({ block, className }) => {
8485
const { recordMap, showCollectionViewDropdown } = useNotionContext()
8586
const { view_ids: viewIds } = block
86-
const collectionId = getBlockCollectionId(block)
87+
const collectionId =
88+
getBlockCollectionId(block) ?? getBlockCollectionPointerId(recordMap, block)
8789

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

0 commit comments

Comments
 (0)