diff --git a/src/fireedge/src/client/components/Cards/EmptyCard.js b/src/fireedge/src/client/components/Cards/EmptyCard.js index b4238307a1..18019862fe 100644 --- a/src/fireedge/src/client/components/Cards/EmptyCard.js +++ b/src/fireedge/src/client/components/Cards/EmptyCard.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { memo } from 'react' import PropTypes from 'prop-types' import { Card, CardHeader, Fade, makeStyles } from '@material-ui/core' @@ -15,14 +15,14 @@ const useStyles = makeStyles(theme => ({ } })) -const EmptyCard = React.memo(({ name }) => { +const EmptyCard = memo(({ name }) => { const classes = useStyles() return ( diff --git a/src/fireedge/src/client/components/List/ListCards.js b/src/fireedge/src/client/components/List/ListCards.js index 66d1194e67..c505f3b112 100644 --- a/src/fireedge/src/client/components/List/ListCards.js +++ b/src/fireedge/src/client/components/List/ListCards.js @@ -9,6 +9,7 @@ import { Grid } from '@material-ui/core' import AddIcon from '@material-ui/icons/Add' +import { EmptyCard } from 'client/components/Cards' const gridValues = [false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] @@ -27,7 +28,9 @@ const ListCards = memo(({ handleCreate, ButtonCreateComponent, CardComponent, - cardsProps + cardsProps, + EmptyComponent, + displayEmpty }) => { const classes = useStyles() @@ -53,11 +56,19 @@ const ListCards = memo(({ [handleCreate, classes] )} {Array.isArray(list) && - list?.map((value, index) => ( - - - - ))} + list.length > 0 ? ( + list?.map((value, index) => ( + + + + )) + ) : ( + (displayEmpty || EmptyComponent) && ( + + {EmptyComponent ?? } + + ) + )} ) }) @@ -84,7 +95,11 @@ ListCards.propTypes = { PropTypes.object, PropTypes.element ]), - cardsProps: PropTypes.func + cardsProps: PropTypes.func, + EmptyComponent: PropTypes.oneOfType([ + PropTypes.element + ]), + displayEmpty: PropTypes.bool } ListCards.defaultProps = { @@ -93,7 +108,9 @@ ListCards.defaultProps = { handleCreate: undefined, ButtonCreateComponent: undefined, CardComponent: null, - cardsProps: () => undefined + cardsProps: () => undefined, + EmptyComponent: undefined, + displayEmpty: false } ListCards.displayName = 'ListCards' diff --git a/src/fireedge/src/client/containers/ApplicationsInstances/index.js b/src/fireedge/src/client/containers/ApplicationsInstances/index.js index b553f853df..badd7068fe 100644 --- a/src/fireedge/src/client/containers/ApplicationsInstances/index.js +++ b/src/fireedge/src/client/containers/ApplicationsInstances/index.js @@ -9,7 +9,7 @@ import useFetch from 'client/hooks/useFetch' import ListCards from 'client/components/List/ListCards' import DialogInfo from 'client/containers/ApplicationsInstances/DialogInfo' -import { ApplicationCard } from 'client/components/Cards' +import { ApplicationCard, EmptyCard } from 'client/components/Cards' import { Tr } from 'client/components/HOC' function ApplicationsInstances () { @@ -39,6 +39,7 @@ function ApplicationsInstances () { } CardComponent={ApplicationCard} cardsProps={({ value }) => ({ handleShow: () => setShowDialog(value) diff --git a/src/fireedge/src/client/containers/ApplicationsTemplates/Form/Create/Steps/Clusters/index.js b/src/fireedge/src/client/containers/ApplicationsTemplates/Form/Create/Steps/Clusters/index.js index ae7e100245..06cb7778e8 100644 --- a/src/fireedge/src/client/containers/ApplicationsTemplates/Form/Create/Steps/Clusters/index.js +++ b/src/fireedge/src/client/containers/ApplicationsTemplates/Form/Create/Steps/Clusters/index.js @@ -4,7 +4,7 @@ import useOpennebula from 'client/hooks/useOpennebula' import useListForm from 'client/hooks/useListForm' import ListCards from 'client/components/List/ListCards' -import { ClusterCard } from 'client/components/Cards' +import { ClusterCard, EmptyCard } from 'client/components/Cards' import { STEP_FORM_SCHEMA } from './schema' @@ -28,16 +28,13 @@ const Clusters = () => ({ return ( } CardComponent={ClusterCard} - cardsProps={({ value }) => { - const { ID } = value - - return { - isSelected: data?.some(selected => selected === ID), - handleSelect: () => handleSelect(ID), - handleUnselect: () => handleUnselect(ID) - } - }} + cardsProps={({ value: { ID } }) => ({ + isSelected: data?.some(selected => selected === ID), + handleSelect: () => handleSelect(ID), + handleUnselect: () => handleUnselect(ID) + })} /> ) }, [])