superdesk/superdesk-client-core

View on GitHub
scripts/apps/authoring-react/fields/linked-items/preview.tsx

Summary

Maintainability
B
6 hrs
Test Coverage
import React from 'react';
import {IPreviewComponentProps, ILinkedItemsValueOperational, ILinkedItemsConfig} from 'superdesk-api';
import {ArticleItemConcise} from 'core/ui/components/article-item-concise';
import {WithArticles} from 'core/with-articles';

type IProps = IPreviewComponentProps<ILinkedItemsValueOperational, ILinkedItemsConfig>;

export class Preview extends React.PureComponent<IProps> {
    render() {
        if (this.props.value == null || this.props.value.length < 1) {
            return null;
        }

        return (
            <WithArticles ids={this.props.value.map(({id}) => id)}>
                {
                    (articles) => (
                        <div>
                            {
                                articles.map((article, i) => (
                                    <ArticleItemConcise
                                        key={i}
                                        article={article}
                                    />
                                ))
                            }
                        </div>
                    )
                }
            </WithArticles>
        );
    }
}