feat: utilise un toggle pour les stats multi

wip-related-pages
Sébastien Arod 2024-10-16 14:09:30 +02:00
parent ab251909d0
commit 65213126e1
2 changed files with 10 additions and 3 deletions

View File

@ -1,15 +1,21 @@
import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
import { ValueFormatOptions } from "../../../format/ValueFormatOptions"; import { ValueFormatOptions } from "../../../format/ValueFormatOptions";
import { MultiValueStatDesc } from "../../../statistiques/v2/desc/StatsDesc"; import { MultiValueStatDesc } from "../../../statistiques/v2/desc/StatsDesc";
import { BulletedListItemBlockObjectRequest } from "../blocks/BulletedListItemBlockObjectRequest"; import { BulletedListItemBlockObjectRequest } from "../blocks/BulletedListItemBlockObjectRequest";
import { BulletedListItemChildren } from "../blocks/BulletedListItemChildren"; import { BulletedListItemChildren } from "../blocks/BulletedListItemChildren";
import { createSingleValueStatListItemBlock } from "./createSingleValueStatListItemBlock"; import { createSingleValueStatListItemBlock } from "./createSingleValueStatListItemBlock";
export type ToggleBlockObjectRequest = Extract<
BlockObjectRequest,
{ toggle: object }
>;
export function createMultiValueStatListItemBlock( export function createMultiValueStatListItemBlock(
descriptor: MultiValueStatDesc, descriptor: MultiValueStatDesc,
statValue: Record<string, number> statValue: Record<string, number>
): BulletedListItemBlockObjectRequest { ): ToggleBlockObjectRequest {
return { return {
bulleted_list_item: { toggle: {
rich_text: [ rich_text: [
{ {
text: { text: {

View File

@ -10,6 +10,7 @@ import { BulletedListItemBlockObjectRequest } from "../blocks/BulletedListItemBl
import { BulletedListItemChildren } from "../blocks/BulletedListItemChildren"; import { BulletedListItemChildren } from "../blocks/BulletedListItemChildren";
import { createMultiValueStatListItemBlock } from "./createMultiValueStatListItemBlock"; import { createMultiValueStatListItemBlock } from "./createMultiValueStatListItemBlock";
import { ValueFormatOptions } from "../../../format/ValueFormatOptions"; import { ValueFormatOptions } from "../../../format/ValueFormatOptions";
import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
export function createStatGroupListItemBlock<D extends StatGroupDesc>( export function createStatGroupListItemBlock<D extends StatGroupDesc>(
descriptor: D, descriptor: D,
@ -35,7 +36,7 @@ export function createStatGroupListItemBlock<D extends StatGroupDesc>(
export function createStatGroupChildrenListItemBlock<D extends StatGroupDesc>( export function createStatGroupChildrenListItemBlock<D extends StatGroupDesc>(
descriptor: D, descriptor: D,
stats: StatsType<D> stats: StatsType<D>
): BulletedListItemBlockObjectRequest[] { ): BlockObjectRequest[] {
return Object.keys(descriptor.stats).map((statName) => { return Object.keys(descriptor.stats).map((statName) => {
const childStatDesc = descriptor.stats[statName]; const childStatDesc = descriptor.stats[statName];
const childStatValue = stats[statName]; const childStatValue = stats[statName];