Make Draftail document rendering logic sturdier

pull/4136/head
Thibaud Colas 2018-01-17 10:56:33 +02:00
rodzic 233f2f60a7
commit 03c7f662d2
1 zmienionych plików z 7 dodań i 2 usunięć

Wyświetl plik

@ -7,16 +7,21 @@ import TooltipEntity from '../decorators/TooltipEntity';
const documentIcon = <Icon name="doc-full" />;
const getFilename = (path) => {
const splitPath = path.split('/');
return splitPath[splitPath.length - 1];
};
const Document = props => {
const { entityKey, contentState } = props;
const { url } = contentState.getEntity(entityKey).getData();
const filename = url.split('/')[3];
return (
<TooltipEntity
{...props}
icon={documentIcon}
label={filename}
label={getFilename(url)}
url={url}
/>
);