@treely/strapi-slices 3.0.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treely/strapi-slices",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "license": "MIT",
5
5
  "author": "Tree.ly GmbH",
6
6
  "description": "@treely/strapi-slices is a open source library maintained by Tree.ly.",
@@ -92,7 +92,6 @@ export const SliceRenderer = ({
92
92
  <TextWithCard
93
93
  key={`${slice.__component}-${slice.id}`}
94
94
  slice={slice}
95
- projects={projects}
96
95
  />
97
96
  );
98
97
  case 'sections.logo-grid-with-text':
@@ -195,6 +194,7 @@ export const SliceRenderer = ({
195
194
  return (
196
195
  <ProjectsGrid
197
196
  key={`${slice.__component}-${slice.id}`}
197
+ slice={slice}
198
198
  projects={projects}
199
199
  />
200
200
  );
@@ -15,6 +15,7 @@ export const SECTIONS_WITH_BLOG_POSTS = [
15
15
  ];
16
16
  export const SECTIONS_WITH_CUSTOMER_STORIES = ['sections.customer-stories'];
17
17
  export const SECTIONS_WITH_PROJECTS = [
18
+ 'sections.projects-grid',
18
19
  'sections.projects-map',
19
20
  'sections.project-facts',
20
21
  ];
@@ -1,10 +1,20 @@
1
- import IStrapi from './IStrapi';
2
1
  import IStrapiData from './IStrapiData';
2
+ import StrapiImage from './StrapiImage';
3
3
  import StrapiProject from './StrapiProject';
4
4
 
5
5
  interface StrapiProjectCard {
6
6
  id: number;
7
- project: IStrapi<IStrapiData<StrapiProject>>;
7
+ title: string;
8
+ facts: {
9
+ id: number;
10
+ text: string;
11
+ }[];
12
+ footerTitle: string;
13
+ footerSubTitle: string;
14
+ image: StrapiImage;
15
+ project?: {
16
+ data?: IStrapiData<StrapiProject>;
17
+ };
8
18
  }
9
19
 
10
20
  export default StrapiProjectCard;
@@ -5,8 +5,12 @@ import { ProjectsGridProps } from './ProjectsGrid';
5
5
  import fpmProjectMock from '../../test/integrationMocks/fpmProjectMock';
6
6
  import { strapiMediaMock } from '../../test/strapiMocks/strapiMedia';
7
7
  import CreditsAvailableState from '../../models/CreditsAvailableState';
8
+ import { strapiProjectMock } from '../../test/strapiMocks/strapiProject';
8
9
 
9
10
  const defaultProps: ProjectsGridProps = {
11
+ slice: {
12
+ projects: { data: [strapiProjectMock] },
13
+ },
10
14
  projects: [
11
15
  {
12
16
  ...fpmProjectMock,
@@ -4,8 +4,12 @@ import Link from 'next/link';
4
4
  import { MEDIUM_TRANSITION_DURATION } from '../../constants/animations';
5
5
  import PortfolioProject from '../../models/PortfolioProject';
6
6
  import PortfolioProjectCard from '../../components/portfolio/PortfolioProjectCard';
7
+ import { IStrapi, IStrapiData, StrapiProject } from '../..';
7
8
 
8
9
  export interface ProjectsGridProps {
10
+ slice: {
11
+ projects: IStrapi<IStrapiData<StrapiProject>[]>;
12
+ };
9
13
  projects: PortfolioProject[];
10
14
  }
11
15
 
@@ -21,9 +25,15 @@ const ConditionalWrapper = ({
21
25
 
22
26
  export const ProjectsGrid: React.FC<ProjectsGridProps> = ({
23
27
  projects,
28
+ slice,
24
29
  }: ProjectsGridProps) => {
25
30
  const filteredProjects = projects.filter(
26
- (p) => p.thumbnail && p.slug && p.isPublic
31
+ (fpmProject) =>
32
+ fpmProject.thumbnail &&
33
+ slice.projects.data.some(
34
+ (strapiProject) =>
35
+ strapiProject.attributes.fpmProjectId === fpmProject.id
36
+ )
27
37
  );
28
38
 
29
39
  return (
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
2
  import { StoryFn, Meta } from '@storybook/react';
3
3
 
4
- import portfolioProjectMock from '../../test/integrationMocks/portfolioProjectMock';
5
- import { strapiProjectMock } from '../../test/strapiMocks/strapiProject';
4
+ import { storybookStrapiCoverMock } from '../../test/storybookMocks/storybookStrapiMedia';
6
5
  import TextWithCard from '.';
7
6
 
8
7
  export default {
@@ -22,9 +21,21 @@ const listItems = [
22
21
  const button = { id: 1, text: 'Button', url: 'https://tree.ly' };
23
22
  const card = {
24
23
  id: 1,
25
- project: { data: strapiProjectMock },
24
+ image: {
25
+ id: 1,
26
+ alt: 'Image alt text',
27
+ img: { data: storybookStrapiCoverMock },
28
+ },
29
+ title: 'Card title',
30
+ facts: [
31
+ { id: 1, text: 'Fact 1' },
32
+ { id: 2, text: 'Fact 2' },
33
+ { id: 3, text: 'Fact 3' },
34
+ { id: 4, text: 'Fact 4' },
35
+ ],
36
+ footerTitle: 'Footer title',
37
+ footerSubTitle: 'Footer sub title',
26
38
  };
27
- const projects = [{ ...portfolioProjectMock, slug: 'slug' }];
28
39
 
29
40
  export const Minimal = Template.bind({});
30
41
  Minimal.args = {
@@ -32,7 +43,6 @@ Minimal.args = {
32
43
  title: 'Title',
33
44
  cardPosition: 'left',
34
45
  },
35
- projects,
36
46
  };
37
47
 
38
48
  export const WithTagline = Template.bind({});
@@ -42,7 +52,6 @@ WithTagline.args = {
42
52
  title: 'Title',
43
53
  cardPosition: 'left',
44
54
  },
45
- projects,
46
55
  };
47
56
 
48
57
  export const WithTaglineAndText = Template.bind({});
@@ -53,7 +62,6 @@ WithTaglineAndText.args = {
53
62
  text: 'Text',
54
63
  cardPosition: 'left',
55
64
  },
56
- projects,
57
65
  };
58
66
 
59
67
  export const WithList = Template.bind({});
@@ -65,7 +73,6 @@ WithList.args = {
65
73
  listItems,
66
74
  cardPosition: 'left',
67
75
  },
68
- projects,
69
76
  };
70
77
 
71
78
  export const WithButton = Template.bind({});
@@ -78,7 +85,6 @@ WithButton.args = {
78
85
  button,
79
86
  cardPosition: 'left',
80
87
  },
81
- projects,
82
88
  };
83
89
 
84
90
  export const WithCard = Template.bind({});
@@ -92,7 +98,6 @@ WithCard.args = {
92
98
  card,
93
99
  cardPosition: 'left',
94
100
  },
95
- projects,
96
101
  };
97
102
 
98
103
  export const WithCardOnRight = Template.bind({});
@@ -106,5 +111,4 @@ WithCardOnRight.args = {
106
111
  card,
107
112
  cardPosition: 'right',
108
113
  },
109
- projects,
110
114
  };
@@ -3,9 +3,6 @@ import { render, screen } from '../../test/testUtils';
3
3
  import { strapiProjectCardMock } from '../../test/strapiMocks/strapiProjectCard';
4
4
  import TextWithCard from '.';
5
5
  import { TextWithCardProps } from './TextWithCard';
6
- import fpmProjectMock from '../../test/integrationMocks/fpmProjectMock';
7
- import { strapiMediaMock } from '../../test/strapiMocks/strapiMedia';
8
- import CreditsAvailableState from '../../models/CreditsAvailableState';
9
6
 
10
7
  const defaultProps: TextWithCardProps = {
11
8
  slice: {
@@ -14,16 +11,6 @@ const defaultProps: TextWithCardProps = {
14
11
  text: 'Text',
15
12
  cardPosition: 'left',
16
13
  },
17
- projects: [
18
- {
19
- ...fpmProjectMock,
20
- slug: 'slug',
21
- isPublic: true,
22
- thumbnail: { img: { data: strapiMediaMock }, alt: 'Alt Text', id: 1 },
23
- footerSubTitle: 'certified-123',
24
- creditsAvailable: CreditsAvailableState.YES,
25
- },
26
- ],
27
14
  };
28
15
 
29
16
  const setup = (props = {}) => {
@@ -74,15 +61,17 @@ describe('The TextWithCard component', () => {
74
61
  it('displays no card if there is no card in the slice', () => {
75
62
  setup();
76
63
 
77
- expect(screen.queryByText(fpmProjectMock.title)).not.toBeInTheDocument();
64
+ expect(
65
+ screen.queryByText(strapiProjectCardMock.title)
66
+ ).not.toBeInTheDocument();
78
67
  });
79
68
 
80
- it('displays the card if a project has been selected', () => {
69
+ it('displays a card if there is a card in the slice', () => {
81
70
  setup({
82
71
  slice: { ...defaultProps.slice, card: strapiProjectCardMock },
83
72
  });
84
73
 
85
- expect(screen.getByText(fpmProjectMock.title)).toBeInTheDocument();
74
+ expect(screen.getByText(strapiProjectCardMock.title)).toBeInTheDocument();
86
75
  });
87
76
 
88
77
  const cardPositions = ['left', 'right'];
@@ -4,16 +4,17 @@ import {
4
4
  DefaultSectionHeader,
5
5
  Grid,
6
6
  GridItem,
7
+ ProjectCard,
7
8
  Spacer,
8
9
  BoemlyList,
9
10
  Wrapper,
10
11
  } from 'boemly';
12
+ import Image from 'next/image';
11
13
  import { ArrowRight } from '@phosphor-icons/react';
14
+ import strapiMediaUrl from '../../utils/strapiMediaUrl';
12
15
  import StrapiLink from '../../models/strapi/StrapiLink';
13
16
  import StrapiProjectCard from '../../models/strapi/StrapiProjectCard';
14
17
  import StrapiLinkButton from '../../components/StrapiLinkButton';
15
- import PortfolioProject from '../../models/PortfolioProject';
16
- import PortfolioProjectCard from '../../components/portfolio/PortfolioProjectCard';
17
18
 
18
19
  interface TextWithCardSlice {
19
20
  tagline?: string;
@@ -29,17 +30,11 @@ interface TextWithCardSlice {
29
30
  }
30
31
  export interface TextWithCardProps {
31
32
  slice: TextWithCardSlice;
32
- projects: PortfolioProject[];
33
33
  }
34
34
 
35
35
  export const TextWithCard: React.FC<TextWithCardProps> = ({
36
36
  slice,
37
- projects,
38
37
  }: TextWithCardProps) => {
39
- const fpmData = projects.find(
40
- (project) => project.slug === slice.card?.project?.data.attributes.slug
41
- );
42
-
43
38
  const card = (
44
39
  <GridItem
45
40
  colSpan={[4, null, null, null, 2]}
@@ -47,8 +42,21 @@ export const TextWithCard: React.FC<TextWithCardProps> = ({
47
42
  position="relative"
48
43
  data-testid={`card-position-${slice.cardPosition}`}
49
44
  >
50
- {slice.card && fpmData && (
51
- <PortfolioProjectCard project={{ ...slice.card, ...fpmData }} />
45
+ {slice.card && (
46
+ <ProjectCard
47
+ facts={slice.card.facts}
48
+ footerSubTitle={slice.card.footerSubTitle}
49
+ footerTitle={slice.card.footerTitle}
50
+ title={slice.card.title}
51
+ image={
52
+ <Image
53
+ src={strapiMediaUrl(slice.card.image.img, 'medium')}
54
+ alt={slice.card.image.alt}
55
+ fill
56
+ style={{ objectFit: slice.card.image.objectFit || 'cover' }}
57
+ />
58
+ }
59
+ />
52
60
  )}
53
61
  </GridItem>
54
62
  );
@@ -1,7 +1,20 @@
1
1
  import StrapiProjectCard from '../../models/strapi/StrapiProjectCard';
2
+ import { strapiMediaMock } from './strapiMedia';
2
3
  import { strapiProjectMock } from './strapiProject';
3
4
 
4
5
  export const strapiProjectCardMock: StrapiProjectCard = {
5
6
  id: 1,
7
+ title: 'My forest',
8
+ facts: [
9
+ { id: 1, text: 'text1' },
10
+ { id: 2, text: 'text2' },
11
+ ],
12
+ footerTitle: 'Footer title',
13
+ footerSubTitle: 'Footer sub title',
14
+ image: {
15
+ id: 1,
16
+ alt: 'Alt text',
17
+ img: { data: strapiMediaMock },
18
+ },
6
19
  project: { data: strapiProjectMock },
7
20
  };