InseeFr / Lunatic

Library of questionnaire components
https://inseefr.github.io/Lunatic/
MIT License
20 stars 22 forks source link

Improve type related to page and pager #876

Closed ddecrulle closed 6 months ago

ddecrulle commented 9 months ago

Improve type related to page and pager

There are a few things to improve concerning types related to page and pager.

pageTag

Actual type

pageTag: string

Proposed type

type PageNumber = number;
type SubPageNumber = number;
type IterationNumber = number;

type PageTag = `${PageNumber}` | `${PageNumber}.${SubPageNumber}#${IterationNumber}`;

pageTag: PageTag

pager

Actual type

pager: {
        lastReachedPage?: string;
        maxPage: string;
        nbSubPages?: number;
        page: string;
        subPage?: number;
        // Iteration index (starting at 0)
        iteration?: number;
        nbIterations?: number;
        shallowIteration?: number;
        linksIterations?: number[];
    };

Proposed type

type Pager = {
        lastReachedPage?: PageTag;
        maxPage: number; //Or PageTag if it's possible but i dont think
        nbSubPages?: number;
        page: number;
        subPage?: number;
        // Iteration index (starting at 0)
        iteration?: number;
        nbIterations?: number;
        shallowIteration?: number;
        linksIterations?: number[];
    };
pager: Pager

goToPage

Actual type

goToPage: (page: {
        page: string;
        iteration?: number;
        nbIterations?: number;
        subPage?: number;
    }) => void;

Proposed type

goToPage: (params: Pick<Pager,"page","iteration","nbIterations","subPage">| {page: PageTag}) => void;

Priority