Skip to content

Commit

Permalink
make breakpoints optional and deal with undefined state
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Nov 18, 2023
1 parent 49c6acb commit e8fef20
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const PageScreenshotParameterSchema = z.object({
* @example
* [ 320, 768, 1280 ]
*/
breakpoints: z.array(z.number()),
breakpoints: z.array(z.number()).optional(),

/**
* Define a custom viewport for the page
Expand Down Expand Up @@ -118,7 +118,7 @@ const LadleShotsSchema = z.object({
* @example
* [ 320, 768, 1280 ]
*/
breakpoints: z.array(z.number()).default([]).optional(),
breakpoints: z.array(z.number()).optional(),
});

const HistoireShotsSchema = z.object({
Expand Down Expand Up @@ -254,7 +254,7 @@ const BaseConfigSchema = z.object({
* @example
* [ 320, 768, 1280 ]
*/
breakpoints: z.array(z.number()).default([]),
breakpoints: z.array(z.number()).optional(),

/**
* Number of concurrent shots to take
Expand Down
2 changes: 1 addition & 1 deletion src/crawler/ladleScreenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const generateLadleShotItems = (
mask: mask ?? [],
};

if (!breakpoints || breakpoints.length === 0) {
if (breakpoints.length === 0) {
return [shotItem];
}

Expand Down
2 changes: 1 addition & 1 deletion src/crawler/pageScreenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const generatePageShotItems = (
mask: [...(mask ?? []), ...(page.mask ?? [])],
};

if (!breakpoints || breakpoints.length === 0) {
if (breakpoints.length === 0) {
return [baseShotItem];
}

Expand Down
5 changes: 3 additions & 2 deletions src/crawler/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,16 @@ export const generateStorybookShotItems = (
mask: [...(mask ?? []), ...(story.parameters?.lostpixel?.mask ?? [])],
};

const storyLevelBreakpoints = story.parameters?.lostpixel?.breakpoints;
const storyLevelBreakpoints =
story.parameters?.lostpixel?.breakpoints ?? [];

const breakpoints = selectBreakpoints(
config.breakpoints,
modeBreakpoints,
storyLevelBreakpoints,
);

if (!breakpoints || breakpoints.length === 0) {
if (breakpoints.length === 0) {
return [baseShotItem];
}

Expand Down
4 changes: 2 additions & 2 deletions src/shots/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const selectBreakpoints = (
topLevelBreakpoints?: number[],
modeBreakpoints?: number[],
shotBreakpoints?: number[],
): number[] | undefined => {
) => {
if (shotBreakpoints && shotBreakpoints.length > 0) {
return shotBreakpoints;
}
Expand All @@ -144,7 +144,7 @@ export const selectBreakpoints = (
return modeBreakpoints;
}

return topLevelBreakpoints;
return topLevelBreakpoints ?? [];
};

export const generateSizeLabel = (breakpoint: number): string => {
Expand Down

0 comments on commit e8fef20

Please sign in to comment.