From 73680b39b0aa3badaafad7d1a6793bf880f4e332 Mon Sep 17 00:00:00 2001 From: Frederick Borges Date: Tue, 13 Jul 2021 10:08:13 +0200 Subject: [PATCH] M #5422: Add Comments to client models (#1357) --- src/fireedge/src/client/constants/states.js | 8 ++- src/fireedge/src/client/models/Datastore.js | 33 +++++++++- src/fireedge/src/client/models/Helper.js | 66 ++++++++++++++++++- src/fireedge/src/client/models/Host.js | 24 ++++++- src/fireedge/src/client/models/Image.js | 22 +++++++ src/fireedge/src/client/models/Marketplace.js | 24 ++++++- .../src/client/models/MarketplaceApp.js | 13 ++++ .../src/client/models/ProviderTemplate.js | 10 +++ .../src/client/models/ProvisionTemplate.js | 12 ++++ .../src/client/models/VirtualMachine.js | 4 ++ .../src/client/models/VirtualNetwork.js | 18 +++++ src/fireedge/src/client/models/Zone.js | 8 +++ 12 files changed, 233 insertions(+), 9 deletions(-) diff --git a/src/fireedge/src/client/constants/states.js b/src/fireedge/src/client/constants/states.js index 234d8a4417..532e624a86 100644 --- a/src/fireedge/src/client/constants/states.js +++ b/src/fireedge/src/client/constants/states.js @@ -14,7 +14,13 @@ * limitations under the License. * * ------------------------------------------------------------------------- */ -/** @typedef {{color: string, name: string, meaning: string}} StateInfo */ +/** + * @typedef {object} StateInfo + * @property {string} color - Color. + * @property {string} name - Name. + * @property {string} [meaning] - Meaning. + * @property {string} [shortName] - Short name. + */ export const ACTIVE = 'ACTIVE' export const BOOT = 'BOOT' diff --git a/src/fireedge/src/client/models/Datastore.js b/src/fireedge/src/client/models/Datastore.js index c9fb2a0007..cf222813f6 100644 --- a/src/fireedge/src/client/models/Datastore.js +++ b/src/fireedge/src/client/models/Datastore.js @@ -13,13 +13,42 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -import { prettyBytes } from 'client/utils' -import { DATASTORE_STATES, DATASTORE_TYPES } from 'client/constants' +import { prettyBytes } from 'client/utils' +import { DATASTORE_STATES, DATASTORE_TYPES, StateInfo } from 'client/constants' + +/** + * This gets the Datastore type object. + * + * @param {object} datastore - Datastore. + * @param {number} datastore.TYPE - Datastore type. + * @returns {{ + * name: string, + * shortName: string + * }} - Datastore type object. + */ export const getType = ({ TYPE } = {}) => DATASTORE_TYPES[TYPE] +/** + * This gets the Datastore state object. + * + * @param {object} datastore - Datastore. + * @param {number} datastore.STATE - Datastore state ID. + * @returns {StateInfo} - Datastore state object. + */ export const getState = ({ STATE = 0 } = {}) => DATASTORE_STATES[STATE] +/** + * This gets the Datasore use percentage and the corresponding label. + * + * @param {object} props - Props object. + * @param {number} props.TOTAL_MB - Datastore total space in MB. + * @param {number} props.USED_MB - Datastore used space in MB. + * @returns {{ + * percentOfUsed: number, + * percentLabel: string + * }} - Datastore use percentage and label. + */ export const getCapacityInfo = ({ TOTAL_MB, USED_MB } = {}) => { const percentOfUsed = +USED_MB * 100 / +TOTAL_MB || 0 const usedBytes = prettyBytes(+USED_MB, 'MB') diff --git a/src/fireedge/src/client/models/Helper.js b/src/fireedge/src/client/models/Helper.js index b552125a27..7e54a2c411 100644 --- a/src/fireedge/src/client/models/Helper.js +++ b/src/fireedge/src/client/models/Helper.js @@ -13,19 +13,51 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ + import { DateTime } from 'luxon' +/** + * This converts the boolean value into a string. + * + * @param {boolean} bool - Boolean value. + * @returns {'Yes'|'No'} - If true return 'Yes', in other cases, return 'No'. + */ export const booleanToString = bool => bool ? 'Yes' : 'No' +/** + * This converts the string value into a boolean. + * + * @param {string} str - String value. + * @returns {boolean} - If str is "yes" or 1 then returns true, + * in other cases, return false. + */ export const stringToBoolean = str => String(str).toLowerCase() === 'yes' || +str === 1 +/** + * This converts the time values to string. + * + * @param {number|string} time - Time to convert. + * @returns {string} - Time string. + */ export const timeToString = time => +time ? new Date(+time * 1000).toLocaleString() : '-' +/** + * This function converts the given time into DateTime. + * + * @param {number|string} time - Time to convert + * @returns {DateTime} - Datetime object. + */ export const timeFromMilliseconds = time => DateTime.fromMillis(+time * 1000) +/** + * This function converts the lock level to its string value. + * + * @param {number} level - Level code number. + * @returns {string} - Lock level text. + */ export const levelLockToString = level => ({ 0: 'None', 1: 'Use', @@ -34,6 +66,22 @@ export const levelLockToString = level => ({ 4: 'All' }[level] || '-') +/** + * This function gets the permission string given the + * owner, group and owner permissions strings. + * + * @param {object} permissions - Permissions object. + * @param {('YES'|'NO')} permissions.OWNER_U - Owner use permission. + * @param {('YES'|'NO')} permissions.OWNER_M - Owner manage permission. + * @param {('YES'|'NO')} permissions.OWNER_A - Owner access permission. + * @param {('YES'|'NO')} permissions.GROUP_U - Group use permission. + * @param {('YES'|'NO')} permissions.GROUP_M - Group manage permission. + * @param {('YES'|'NO')} permissions.GROUP_A - Group access permission. + * @param {('YES'|'NO')} permissions.OTHER_U - Other use permission. + * @param {('YES'|'NO')} permissions.OTHER_M - Other manage permission. + * @param {('YES'|'NO')} permissions.OTHER_A - Other access permission. + * @returns {string} - Permissions string. + */ export const permissionsToOctal = permissions => { const { OWNER_U, OWNER_M, OWNER_A, @@ -41,6 +89,16 @@ export const permissionsToOctal = permissions => { OTHER_U, OTHER_M, OTHER_A } = permissions + /** + * This function will return the permission numeric code. + * + * @param {string[]} props - Array with Use, Manage and Access + * permissions. + * @param {('YES'|'NO')} props.0 - Is use permission allowed? + * @param {('YES'|'NO')} props.1 - Is manage permission allowed? + * @param {('YES'|'NO')} props.2 - Is access permission allowed? + * @returns {number} Permission code number. + */ const getCategoryValue = ([u, m, a]) => ( (stringToBoolean(u) ? 4 : 0) + (stringToBoolean(m) ? 2 : 0) + @@ -55,9 +113,11 @@ export const permissionsToOctal = permissions => { } /** - * @param {Object} actions Actions from view yaml - * @param {String} [hypervisor] Resource hypervisor - * @returns {String[]} List of actions available for the resource + * This returns the resource available actions. + * + * @param {object} actions - Actions from view yaml + * @param {string} [hypervisor] - Resource hypervisor + * @returns {string[]} - List of actions available for the resource */ export const getActionsAvailable = (actions = {}, hypervisor = '') => Object.entries(actions) diff --git a/src/fireedge/src/client/models/Host.js b/src/fireedge/src/client/models/Host.js index b0ad4ad602..e39f82fb15 100644 --- a/src/fireedge/src/client/models/Host.js +++ b/src/fireedge/src/client/models/Host.js @@ -13,11 +13,31 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -import { prettyBytes } from 'client/utils' -import { HOST_STATES } from 'client/constants' +import { prettyBytes } from 'client/utils' +import { HOST_STATES, StateInfo } from 'client/constants' + +/** + * This function gets the host state. + * + * @param {object} host - Host. + * @param {number} host.STATE - Host state. + * @returns {StateInfo} - Host state object. + */ export const getState = ({ STATE } = {}) => HOST_STATES[STATE] +/** + * This function get the allocate information. + * + * @param {object} host - Host. + * @param {object} host.HOST_SHARE - Host share object. + * @returns {{ + * percentCpuUsed: number, + * percentCpuLabel: string, + * percentMemUsed: number, + * percentMemLabel: string + * }} - Allocated information object. + */ export const getAllocatedInfo = ({ HOST_SHARE = {} } = {}) => { const { CPU_USAGE, TOTAL_CPU, MEM_USAGE, TOTAL_MEM } = HOST_SHARE diff --git a/src/fireedge/src/client/models/Image.js b/src/fireedge/src/client/models/Image.js index fc86253373..93a68b3d02 100644 --- a/src/fireedge/src/client/models/Image.js +++ b/src/fireedge/src/client/models/Image.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ + import * as STATES from 'client/constants/states' import COLOR from 'client/constants/color' @@ -79,8 +80,29 @@ const DISK_TYPES = [ 'RBD' ] +/** + * This function gets the image type. + * + * @param {object} image - Image. + * @param {number|string} image.TYPE - Type numeric code. + * @returns {string} - Image type. + */ export const getType = ({ TYPE } = {}) => IMAGE_TYPES[+TYPE] +/** + * This function gets the disk type. + * + * @param {object} image - Image. + * @param {number|string} image.DISK_TYPE - Disk type numeric code. + * @returns {string} - Disk type. + */ export const getDiskType = ({ DISK_TYPE } = {}) => DISK_TYPES[+DISK_TYPE] +/** + * This function gets the image state. + * + * @param {object} image - Image. + * @param {number|string} image.STATE - State code. + * @returns {STATES.StateInfo} - Image state information. + */ export const getState = ({ STATE } = {}) => IMAGE_STATES[+STATE] diff --git a/src/fireedge/src/client/models/Marketplace.js b/src/fireedge/src/client/models/Marketplace.js index e0ce1e8393..1ee2b6aad1 100644 --- a/src/fireedge/src/client/models/Marketplace.js +++ b/src/fireedge/src/client/models/Marketplace.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ + import { prettyBytes } from 'client/utils' import * as STATES from 'client/constants/states' import COLOR from 'client/constants/color' @@ -28,13 +29,34 @@ const MARKETPLACE_STATES = [ } ] +/** + * This function gets the marketplace state. + * + * @param {object} marketplace - Marketplace. + * @param {number|string} marketplace.STATE - Marketplace state numeric code. + * @returns {STATES.StateInfo} - Marketplace state information. + */ export const getState = ({ STATE } = {}) => MARKETPLACE_STATES[+STATE] +/** + * This function gets the marketplace capacity information. + * + * @param {object} props - Props object. + * @param {number|string} props.TOTAL_MB - Marketplace total MB available. + * @param {number|string} props.USED_MB - Marketplace used MB. + * @returns {{ + * percentOfUsed: number, + * percentLabel: string + * }} - Marketplace capacity information. + */ export const getCapacityInfo = ({ TOTAL_MB, USED_MB } = {}) => { const percentOfUsed = +USED_MB * 100 / +TOTAL_MB || 0 const usedBytes = prettyBytes(+USED_MB, 'MB') const totalBytes = prettyBytes(+TOTAL_MB, 'MB') const percentLabel = `${usedBytes} / ${totalBytes} (${Math.round(percentOfUsed)}%)` - return { percentOfUsed, percentLabel } + return { + percentOfUsed, + percentLabel + } } diff --git a/src/fireedge/src/client/models/MarketplaceApp.js b/src/fireedge/src/client/models/MarketplaceApp.js index 436273e279..f209b1f786 100644 --- a/src/fireedge/src/client/models/MarketplaceApp.js +++ b/src/fireedge/src/client/models/MarketplaceApp.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ + import * as STATES from 'client/constants/states' import COLOR from 'client/constants/color' @@ -46,6 +47,18 @@ const MARKETPLACE_APP_STATES = [ } ] +/** + * @param {object} marketplaceApp - Marketplace app. + * @param {number|string} marketplaceApp.TYPE - Marketplace app type numeric code. + * @returns {string} - Marketplace app type. + */ export const getType = ({ TYPE = 0 } = {}) => MARKETPLACE_APP_TYPES[+TYPE] +/** + * This function gets the marketplace app state information. + * + * @param {object} marketplaceApp - Marketplace app. + * @param {number|string} marketplaceApp.STATE - Marketplace app state numeric code. + * @returns {STATES.StateInfo} - Marketplace App state information. + */ export const getState = ({ STATE = 0 } = {}) => MARKETPLACE_APP_STATES[+STATE] diff --git a/src/fireedge/src/client/models/ProviderTemplate.js b/src/fireedge/src/client/models/ProviderTemplate.js index e9b4a4e965..43a5c9686e 100644 --- a/src/fireedge/src/client/models/ProviderTemplate.js +++ b/src/fireedge/src/client/models/ProviderTemplate.js @@ -13,6 +13,9 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ + +/* eslint-disable jsdoc/require-jsdoc */ + export const isValidProviderTemplate = ({ name, provider, plain = {}, connection }) => { const { provision_type: provisionType, location_key: locationKey } = plain @@ -29,6 +32,13 @@ export const isValidProviderTemplate = ({ name, provider, plain = {}, connection ) } +/** + * This function gets the provider locations string. + * + * @param {object} props - Props object. + * @param {string|string[]} props.location_key - Location key. + * @returns {string[]} - Provider's location keys. + */ export const getLocationKeys = ({ location_key: locationKey }) => typeof locationKey === 'string' ? locationKey.split(',') : locationKey diff --git a/src/fireedge/src/client/models/ProvisionTemplate.js b/src/fireedge/src/client/models/ProvisionTemplate.js index ba51c8de25..46b2eb40c1 100644 --- a/src/fireedge/src/client/models/ProvisionTemplate.js +++ b/src/fireedge/src/client/models/ProvisionTemplate.js @@ -13,6 +13,18 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ + +/** + * This function indicates if the provision template is valid. + * + * @param {object} props - Props object. + * @param {object} props.defaults - Provision defaults object. + * @param {object} props.hosts - Provision host object. + * @param {string} props.name - Provider name. + * @param {string} props.provider - Provider code name. + * @param {string} props.provision_type - Provision type name. + * @returns {boolean} - Valid provision template. + */ export const isValidProvisionTemplate = ({ defaults, hosts, diff --git a/src/fireedge/src/client/models/VirtualMachine.js b/src/fireedge/src/client/models/VirtualMachine.js index 631a66ab45..3f6da16a4b 100644 --- a/src/fireedge/src/client/models/VirtualMachine.js +++ b/src/fireedge/src/client/models/VirtualMachine.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ + import { STATES, VM_STATES, VM_LCM_STATES, StateInfo } from 'client/constants' /* const EXTERNAL_IP_ATTRS = [ @@ -36,6 +37,9 @@ const NIC_ALIAS_IP_ATTRS = [ ] /** + * This function removes, from the given list, + * the Virtual machines in state DONE. + * * @param {Array} vms - List of virtual machines * @returns {Array} Clean list of vms with done state */ diff --git a/src/fireedge/src/client/models/VirtualNetwork.js b/src/fireedge/src/client/models/VirtualNetwork.js index 4068522765..e47a5e090f 100644 --- a/src/fireedge/src/client/models/VirtualNetwork.js +++ b/src/fireedge/src/client/models/VirtualNetwork.js @@ -13,12 +13,30 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ + +/** + * This function get the total number of leases in the Address Range. + * + * @param {object} virtualNetwork - Virtual network. + * @param {object} virtualNetwork.AR_POOL - Virtual network Address Range Pool. + * @returns {number} - Total leases. + */ export const getTotalLeases = ({ AR_POOL } = {}) => { const addressRanges = [AR_POOL?.AR ?? []].flat() return addressRanges.reduce((total, { SIZE = 0 }) => total + (+SIZE), 0) } +/** + * This function gets the virtual network leases information. + * + * @param {object} virtualNetwork - Virtual network. + * @param {object} virtualNetwork.USED_LEASES - Used network leases. + * @returns {{ + * percentOfUsed: number, + * percentLabel: string + * }} - Leases information. + */ export const getLeasesInfo = ({ USED_LEASES, ...virtualNetwork } = {}) => { const totalLeases = getTotalLeases(virtualNetwork) const percentOfUsed = +USED_LEASES * 100 / +totalLeases || 0 diff --git a/src/fireedge/src/client/models/Zone.js b/src/fireedge/src/client/models/Zone.js index ca2f811717..6674ab2c0e 100644 --- a/src/fireedge/src/client/models/Zone.js +++ b/src/fireedge/src/client/models/Zone.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ + import * as STATES from 'client/constants/states' import COLOR from 'client/constants/color' @@ -27,4 +28,11 @@ const ZONE_STATES = [ } ] +/** + * This function gets the zone state. + * + * @param {object} zone - Zone. + * @param {number|string} zone.STATE - Zone state numeric code. + * @returns {STATES.StateInfo} - Zone state information. + */ export const getState = ({ STATE = 0 } = {}) => ZONE_STATES[+STATE]