Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from ecmwf-projects/COPDS-1308
Browse files Browse the repository at this point in the history
Copds 1308
  • Loading branch information
pelusanchez authored Oct 20, 2023
2 parents dc23519 + 6978232 commit c683508
Show file tree
Hide file tree
Showing 9 changed files with 17,017 additions and 1,712 deletions.
33 changes: 33 additions & 0 deletions __tests__/components/blocks/HtmlBlock.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import { render, screen } from '@testing-library/react'

import { HtmlBlock } from '../../../src/components'

describe('type html', () => {
it('it renders correctly', () => {
render(
<HtmlBlock
block={{
type: 'html',
id: 'test-id-1',
content:
'<div>This is a raw HTML</div><p>With more HTML</p>',
}}
/>,
)

screen.getByText('This is a raw HTML')
screen.getByText('With more HTML')
})
it('it renders correctly without content', () => {
render(
<HtmlBlock
block={{
type: 'html',
id: 'test-id-1',
content: null as unknown as string,
}}
/>,
)
})
})
8,697 changes: 6,988 additions & 1,709 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@ecmwf-projects/cads-blocks-library",
"description": "CADS Blocks library for webportal",
"private": false,
"version": "1.0.1",
"version": "2.0.0-0",
"repository": {
"type": "git",
"url": "git@github.com:ecmwf-projects/cads-blocks-library.git"
Expand All @@ -23,7 +23,7 @@
"build": "tsc",
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
"lint:fix": "eslint --fix 'src/**/*.{jsx,ts,tsx}'",
"format": "prettier --write src//**/*.{ts,tsx,css} --config ./.prettierrc",
"format": "prettier --write src//**/*.{ts,tsx} --config ./.prettierrc",
"preview": "vite preview",
"prepare": "husky install",
"lint-staged": "npm run lint && npm run format",
Expand All @@ -36,6 +36,7 @@
"devDependencies": {
"@babel/preset-env": "^7.22.9",
"@babel/preset-react": "^7.22.5",
"@ladle/react": "^3.2.2",
"@rollup/plugin-typescript": "^11.1.2",
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^5.17.0",
Expand Down
3 changes: 3 additions & 0 deletions src/components/GenerateBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import {
ButtonBlockInterface,
LayoutSectionBlocksMix,
MarkdownBlockInterface,
HtmlBlockInteface,
} from '../models'
import { HtmlBlock } from './blocks/HtmlBlock'

const generateBlockByType = {
['markdown']: (block: MarkdownBlockInterface, markdownParsingOptions: MarkdownToJSX.Options) => (
<MarkdownBlock block={block} markdownParsingOptions={markdownParsingOptions} />
),
['html']: (block: HtmlBlockInteface) => <HtmlBlock block={block} />,
['table']: (block: TableBlock) => <Table block={block} />,
['thumb-markdown']: (
block: ThumbMarkdownBlock,
Expand Down
17 changes: 17 additions & 0 deletions src/components/blocks/HtmlBlock.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { HtmlBlock } from './HtmlBlock';

export const HtmlBlockStory = () => (<div style={
{
width: '100%',
height: '100%',
}
}>
<HtmlBlock
block={{
'id': 'html',
'type': 'html',
'content': `<div>This is an HTML</div> <b>inside</b> <p>an HTML block</p>`
}}
/>
</div>);
29 changes: 29 additions & 0 deletions src/components/blocks/HtmlBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'

import styled from 'styled-components'

import { HtmlBlockInteface, } from '../../models'

export const HtmlBlock = ({
block,
}: {
block: HtmlBlockInteface
}) => (
<Content data-stylizable="block html-content">
{block?.content && (
<ContentWrapper dangerouslySetInnerHTML={{ __html: block.content }} />
)}
</Content>
)

const Content = styled.div`
display: flex;
margin: 0;
flex-direction: column;
justify-content: flex-start;
`

const ContentWrapper = styled.div`
width: 100%;
height: 100%;
`
1 change: 1 addition & 0 deletions src/components/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from './LinkBlock'
export * from './Markdown'
export * from './Section'
export * from './Table'
export * from './HtmlBlock'
export * from './ThumbMarkdown'
9 changes: 8 additions & 1 deletion src/models/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum LayoutBlockTypes {
'button',
'link',
'markdown',
'html',
'section',
'table',
'thumb-markdown',
Expand All @@ -17,6 +18,10 @@ export interface MarkdownBlockInterface extends GenericBlock {
content: string
}

export interface HtmlBlockInteface extends GenericBlock {
content: string
}

export type TableBlockHeadings = {
id: string
label: string
Expand All @@ -38,7 +43,7 @@ export interface TableBlock extends GenericBlock {
export interface SectionBlock extends GenericBlock {
title: string
open: boolean
blocks: (MarkdownBlockInterface | LinkBlockInterface | ButtonBlockInterface)[]
blocks: (HtmlBlockInteface | MarkdownBlockInterface | LinkBlockInterface | ButtonBlockInterface)[]
}

export type ImageThumb = {
Expand Down Expand Up @@ -79,6 +84,7 @@ export interface ButtonBlockInterface extends GenericBlock {

export type LayoutSectionBlock =
| MarkdownBlockInterface
| HtmlBlockInteface
| TableBlock
| ThumbMarkdownBlock
| LinkBlockInterface
Expand All @@ -88,6 +94,7 @@ export type LayoutSectionBlock =

export type LayoutSectionBlocksMix = MarkdownBlockInterface &
TableBlock &
HtmlBlockInteface &
ThumbMarkdownBlock &
LinkBlockInterface &
SectionBlock &
Expand Down
Loading

0 comments on commit c683508

Please sign in to comment.