import React from 'react'; import filesize from 'filesize' import PropTypes from 'prop-types'; /** * KeyInfo component receives two arguments. * @param {Object} descriptor A Frictionless datapackage descriptor object with the following fields: * { * title: "Title of the data package", * length: "The number of resources present in the data package" * datasetSize: The combined size of the data package resources * format: The format of resources in the dataset. e.g csv, json, excel * created: The date the dataset was created * updated: The date the dataset was last updated * licence: The licence of the dataset * sources: An array of the data set sources * } * @param {Array} resources A Frictionless datapackage resource array * @returns React Component */ const KeyInfo = ({ descriptor, resources }) => { let datasetSize = 0 if (resources) { datasetSize = resources.length == 1 ? (resources[0].size || 0) : resources.reduce((accumulator, currentValue) => { return (accumulator.size || 0) + (currentValue.size || 0) }) } return ( <>

{descriptor.title}

Key info

Files

Size

Format

Created

Updated

Licence

Source

{resources.length}

{datasetSize && filesize(datasetSize, { bits: true })}

{resources[0]["format"]} zip

{descriptor["created"]}

{descriptor["updated"]}

{descriptor["license"]}

{descriptor["sources"] && descriptor["sources"][0]["title"]}

) } KeyInfo.propTypes = { descriptor: PropTypes.object.isRequired, resources: PropTypes.array.isRequired } export default KeyInfo