Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] Sport Tables #9166

Merged
merged 22 commits into from
Jun 24, 2021
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
16677f8
Sport table plumbing
ryanmccombe Jun 8, 2021
9f118a4
Added CPS table components
paulcrane-bbc Jun 10, 2021
a4e7be1
Merge branch 'latest' of github.com:bbc/simorgh into sport-table-plum…
paulcrane-bbc Jun 10, 2021
f846631
Merge branch 'latest' into sport-table-plumbing
ryanmccombe Jun 15, 2021
434bc96
Simplified CpsTable. Added checks for paragraph blocks in getInitialData
paulcrane-bbc Jun 14, 2021
d9f5c83
Added prop types
paulcrane-bbc Jun 14, 2021
4c80d9f
Added tests for table converter
paulcrane-bbc Jun 15, 2021
4ec03c7
Added thead and tbody elements. Align heading to left
paulcrane-bbc Jun 15, 2021
461004e
Updated converter tests
paulcrane-bbc Jun 15, 2021
8b6e45e
Added storybook tests
paulcrane-bbc Jun 15, 2021
3e8c850
Added an extra cricket asset
paulcrane-bbc Jun 15, 2021
c02f1e2
Add tests for CpsTable
paulcrane-bbc Jun 15, 2021
1808969
Merge branch 'latest' of github.com:bbc/simorgh into sport-table-plum…
paulcrane-bbc Jun 15, 2021
e5f2967
Merge branch 'latest' into sport-table-plumbing
ryanmccombe Jun 15, 2021
9690993
Merge branch 'sport-table-plumbing' of github.com:bbc/simorgh into sp…
paulcrane-bbc Jun 15, 2021
b10b87c
Are you signed?
ryanmccombe Jun 16, 2021
c312c63
Merge pull request #9185 from bbc/gpg-test
ryanmccombe Jun 16, 2021
27ec8e2
Merge branch 'latest' into sport-table-plumbing
ryanmccombe Jun 22, 2021
936528c
Use colour variables
ryanmccombe Jun 22, 2021
78dbea7
Re-bump bundle sizes
ryanmccombe Jun 22, 2021
3670241
Update snapshots
ryanmccombe Jun 23, 2021
42feb42
Merge branch 'latest' into sport-table-plumbing
ryanmccombe Jun 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplified CpsTable. Added checks for paragraph blocks in getInitialData
  • Loading branch information
paulcrane-bbc committed Jun 15, 2021
commit 434bc96cd26dfb0e0ca18df5643d31b3c0f60c3f
21 changes: 15 additions & 6 deletions src/app/containers/CpsTable/CpsTableCell/index.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering why CpsTable is in the containers directory rather than components; tbh I'm not clear what the distinction is in Simorgh myself? The distinction I've come across tends involve where the react component does data fetching or not. So if the CpsTable had a useEffect to get some data it might be more suitable as a container, if it is just a dumb component hydrated with data via props it is more of a component? I'm unsure if the distinction is that useful in our codebase but just want to try and be consitent where we can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't find the distinction useful - I think the whole "containers and components" pattern was popularised by Dan Abramov in a 6-year-old medium post that went viral: https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0

He has since updated it to say he doesn't consider it a useful pattern - I tend to agree. Particularly in Simorgh, it seems somewhat arbitrary where we put components. Reason I put this one in containers is really just because that's where all the other block renderers are

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ryanmccombe, just wanted to sound this out, I'd be in favour flattening the structure to just components we should bring this up with the wider team. Just thinking about this stuff before we do live pages where we will make a lot more components.

I'd stick with this in containers like you've done for now 👍

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! #4478

import styled from '@emotion/styled';
import { arrayOf, shape } from 'prop-types';
import { arrayOf, shape, string } from 'prop-types';
import { GEL_SPACING } from '@bbc/gel-foundations/spacings';

import Blocks from '../../Blocks';
import CpsText from '../../CpsText';

const StyledTd = styled.td`
border-bottom: 1px solid #dbdbdb;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these colours reference values from https://github.com/bbc/psammead/blob/latest/packages/utilities/psammead-styles/src/colours.js

Just in case we are using colours inconsistent with those agreed by UX?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These colours come from the existing Sport colours here - https://github.com/bbc/gs-sass-tools/blob/master/settings/_sport-colours.scss#L14
Should I open a PR to add these two colours to psammead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's a bit annoying but that's our source of truth for colours, just makes clear what UX etc refer to them as and allows us to change them en masse e.g. for chameleon project.

Feel free to do this in a follow-up PR though

Copy link
Contributor Author

@ryanmccombe ryanmccombe Jun 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry was looking into this earlier and got distracted - I did some comparison and it seems the colour here is different to what is on the sport pages like https://www.bbc.co.uk/sport/cricket/54646061

That page seems to have a border-bottom of #eee rather than #dbdbdb - the hover background colour seems to be slightly different too

Not sure if it's an issue. Either way, none of these exact colours were on our pallette. If we wanted to use the variables we'd need to either add new ones to psammead, or update the components to use one of the existing variables if they're "close enough"

Happy to help with either of these :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good spot! I actually copied these colours from AlephAMP rather than Morph - https://www.bbc.co.uk/sport/amp/cricket/54646061

I'll open a follow up PR to add these to psammead :)

padding-top: 8px;
padding-bottom: 8px;
padding-left: 8px;
padding-top: ${GEL_SPACING};
padding-bottom: ${GEL_SPACING};
padding-left: ${GEL_SPACING};
vertical-align: middle;

${({ isHeaderCell }) => isHeaderCell && 'background: #f7f7f5;'}

& p {
padding-bottom: 0;
}
@@ -21,16 +24,22 @@ const componentsToRender = {
text: CpsText,
};

const CpsTableCell = ({ blocks }) => {
const CpsTableCell = ({ blocks, type }) => {
const isHeaderCell = type === 'tableHeader';
return (
<StyledTd>
<StyledTd as={isHeaderCell ? 'th' : 'td'} isHeaderCell={isHeaderCell}>
<Blocks blocks={blocks} componentsToRender={componentsToRender} />
</StyledTd>
);
};

CpsTableCell.propTypes = {
blocks: arrayOf(shape({})).isRequired,
type: string,
};

CpsTableCell.defaultProps = {
type: 'tableCell',
};

export default CpsTableCell;
37 changes: 0 additions & 37 deletions src/app/containers/CpsTable/CpsTableHeader/index.jsx

This file was deleted.

15 changes: 6 additions & 9 deletions src/app/containers/CpsTable/CpsTableRow/index.jsx
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import { arrayOf, shape } from 'prop-types';

import Blocks from '../../Blocks';
import CpsTableCell from '../CpsTableCell';
import CpsTableHeader from '../CpsTableHeader';

const StyledTr = styled.tr`
&:hover {
@@ -14,16 +13,14 @@ const StyledTr = styled.tr`

const componentsToRender = {
tableCell: CpsTableCell,
tableHeader: CpsTableHeader,
tableHeader: CpsTableCell,
};

const CpsTableRow = ({ blocks }) => {
return (
<StyledTr>
<Blocks blocks={blocks} componentsToRender={componentsToRender} />
</StyledTr>
);
};
const CpsTableRow = ({ blocks }) => (
<StyledTr>
<Blocks blocks={blocks} componentsToRender={componentsToRender} />
</StyledTr>
);

CpsTableRow.propTypes = {
blocks: arrayOf(shape({})).isRequired,
8 changes: 3 additions & 5 deletions src/app/containers/CpsTable/index.jsx
Original file line number Diff line number Diff line change
@@ -25,11 +25,9 @@ const CpsTable = ({ blocks, supportedServices }) => {
if (!supportedServices.includes(service)) return null;

return (
<>
<StyledTable service={service}>
<Blocks blocks={blocks} componentsToRender={componentsToRender} />
</StyledTable>
</>
<StyledTable service={service}>
<Blocks blocks={blocks} componentsToRender={componentsToRender} />
</StyledTable>
);
};

Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import convertParagraph from '../paragraph';

const convertCells = async block => ({
type: block.cellType === 'header' ? 'tableHeader' : 'tableCell',
model: {
blocks: [await convertParagraph(block.content[0])],
},
});
const convertCells = async block => {
const paragraphContentOnly = block.content.filter(
content => content.type === 'paragraph',
);

const paragraphBlocks = await Promise.all(
paragraphContentOnly.map(convertParagraph),
);

return {
type: block.cellType === 'header' ? 'tableHeader' : 'tableCell',
model: {
blocks: paragraphBlocks,
},
};
};

const convertRows = async block => {
const cellBlocks = await Promise.all(block.map(convertCells));