fix: workaround Notion API limit on richtext length
parent
fb1fec7001
commit
27cc008813
|
@ -1,7 +1,7 @@
|
|||
import { formatValue } from "../../../format/formatValue";
|
||||
import { ValueFormatOptions } from "../../../format/ValueFormatOptions";
|
||||
import { StatsData } from "../../../statistiques/v2/desc/StatsDesc";
|
||||
import { isNumber } from "lodash";
|
||||
import { chunk, isNumber } from "lodash";
|
||||
import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
|
||||
|
||||
export function createSingleValueStatListItemBlock(
|
||||
|
@ -9,9 +9,9 @@ export function createSingleValueStatListItemBlock(
|
|||
formatOptions: ValueFormatOptions,
|
||||
data: StatsData
|
||||
): BlockObjectRequest {
|
||||
if (isNumber(data) ) {
|
||||
if (isNumber(data)) {
|
||||
return bulletedListNumberData(label, data, formatOptions);
|
||||
} else if (data.relatedPageIds.length === 0 ) {
|
||||
} else if (data.relatedPageIds.length === 0) {
|
||||
return bulletedListNumberData(label, data.value, formatOptions);
|
||||
} else {
|
||||
return {
|
||||
|
@ -32,19 +32,27 @@ export function createSingleValueStatListItemBlock(
|
|||
content: "Liens: ",
|
||||
},
|
||||
},
|
||||
...data.relatedPageIds.map((pageId) =>
|
||||
createPageMentionRichTextElement(pageId)
|
||||
),
|
||||
],
|
||||
},
|
||||
},
|
||||
...chunk(data.relatedPageIds, 100).map((pageIdsChunk) => ({
|
||||
paragraph: {
|
||||
rich_text: pageIdsChunk.map((pageId) =>
|
||||
createPageMentionRichTextElement(pageId)
|
||||
),
|
||||
},
|
||||
})),
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function bulletedListNumberData(label: string, data: number, formatOptions: ValueFormatOptions): BlockObjectRequest {
|
||||
function bulletedListNumberData(
|
||||
label: string,
|
||||
data: number,
|
||||
formatOptions: ValueFormatOptions
|
||||
): BlockObjectRequest {
|
||||
return {
|
||||
bulleted_list_item: {
|
||||
rich_text: [
|
||||
|
|
Loading…
Reference in New Issue