From 2f0ee9802f942b95ce4a510a2131773220d46220 Mon Sep 17 00:00:00 2001 From: Rising Odegua Date: Thu, 29 Apr 2021 13:23:28 +0100 Subject: [PATCH] [Component][m]: Add KeyInfo component --- .../portal/src/components/page/KeyInfo.js | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 packages/portal/src/components/page/KeyInfo.js diff --git a/packages/portal/src/components/page/KeyInfo.js b/packages/portal/src/components/page/KeyInfo.js new file mode 100644 index 00000000..a464a99d --- /dev/null +++ b/packages/portal/src/components/page/KeyInfo.js @@ -0,0 +1,94 @@ +import React from 'react'; +import filesize from 'filesize' + +/** + * 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 : + resources.reduce((accumulator, currentValue) => { + return accumulator.size + currentValue.size + }) + } + + return ( + <> +
+

+ {descriptor.title} +

+

Key info

+
+
+

Files

+
+
+

Size

+
+
+

Format

+
+
+

Created

+
+
+

Updated

+
+
+

Licence

+
+
+

Source

+
+
+
+
+

{resources.length}

+
+
+

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

+
+
+

{resources[0].format} zip

+
+
+

{descriptor.created}

+
+
+

{descriptor.updated}

+
+
+

{descriptor.license}

+
+
+

+ + {descriptor.sources[0].title} + +

+
+
+
+ + + ) +} + +export default KeyInfo \ No newline at end of file