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