From 5469e6ec80d531311d3ec9592d16c88399786b9f Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Sun, 22 Nov 2020 23:45:27 +0100 Subject: [PATCH] Add displayCard function to utils --- src/index.js | 2 +- src/utils/displayCard.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/utils/displayCard.js diff --git a/src/index.js b/src/index.js index 417aac3..651fdf9 100644 --- a/src/index.js +++ b/src/index.js @@ -39,7 +39,6 @@ export { Modal, ModalBody, ModalFooter, ModalHeader } from "./bootstrap/Modal"; // Common export { RebootButton } from "./common/RebootButton"; export { WiFiSettings } from "./common/WiFiSettings/WiFiSettings"; - // Form export { ForisForm } from "./form/components/ForisForm"; export { @@ -70,6 +69,7 @@ export { export { ErrorMessage } from "./utils/ErrorMessage"; export { useClickOutside } from "./utils/hooks"; export { toLocaleDateString } from "./utils/datetime"; +export { displayCard } from "./utils/displayCard"; // Foris URL export { ForisURLs, REFORIS_URL_PREFIX } from "./utils/forisUrls"; diff --git a/src/utils/displayCard.js b/src/utils/displayCard.js new file mode 100644 index 0000000..8fd5662 --- /dev/null +++ b/src/utils/displayCard.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2020 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * + * This is free software, licensed under the GNU General Public License v3. + * See /LICENSE for more information. + */ + +export function displayCard({ package_lists: packages }, cardName) { + const enabledPackagesNames = []; + packages + .filter((item) => item.enabled) + .map((item) => { + enabledPackagesNames.push(item.name); + item.options + .filter((option) => option.enabled) + .map((option) => { + enabledPackagesNames.push(option.name); + return null; + }); + return null; + }); + return enabledPackagesNames.includes(cardName); +}