diff --git a/src/components/DashboardEditor/DashboardEditor.jsx b/src/components/DashboardEditor/DashboardEditor.jsx
index 86f6da5e15..d4db383267 100644
--- a/src/components/DashboardEditor/DashboardEditor.jsx
+++ b/src/components/DashboardEditor/DashboardEditor.jsx
@@ -3,13 +3,16 @@ import PropTypes from 'prop-types';
import uuid from 'uuid';
import { settings } from '../../constants/Settings';
-import { CARD_SIZES } from '../../constants/LayoutConstants';
-import { Button, CodeSnippet, CardEditor } from '../../index';
+import { CARD_SIZES, CARD_ACTIONS } from '../../constants/LayoutConstants';
+import { DashboardGrid, Card, CardEditor } from '../../index';
const { iotPrefix } = settings;
const defaultProps = {
- initialValue: [],
+ initialValue: {
+ cards: [],
+ layouts: {},
+ },
renderHeader: null,
};
@@ -24,54 +27,74 @@ const DashboardEditor = ({ initialValue, renderHeader }) => {
const baseClassName = `${iotPrefix}--dashboard-editor`;
// show the gallery if no card is being edited
- const [dashboardCards, setDashboardCards] = useState(initialValue);
+ const [dashboardData, setDashboardData] = useState(initialValue);
const [selectedCardId, setSelectedCardId] = useState();
- const addCard = data => setDashboardCards([...dashboardCards, data]);
- const removeCard = id => setDashboardCards(dashboardCards.filter(i => i.id !== id));
+ const addCard = data => {
+ setDashboardData({
+ ...dashboardData,
+ cards: [...dashboardData.cards, data],
+ });
+ setSelectedCardId(data.id);
+ };
+ const removeCard = id =>
+ setDashboardData({
+ ...dashboardData,
+ cards: dashboardData.cards.filter(i => i.id !== id),
+ });
return (
{renderHeader && renderHeader()}
-
Dashboard Template preview
-
- As you add and edit cards, the content underneath here will be updated in real-time. We
- will replace this with the actual Dashboard component.
-
-
- {dashboardCards.map(i => (
-
-
- {JSON.stringify(i, null, 4)}
-
-
-
-
-
- ))}
+
{JSON.stringify(i, null, 4)}
+
+ ))}
+
+
{JSON.stringify(dashboardData, null, 4)}
i.id === selectedCardId)}
+ value={dashboardData.cards.find(i => i.id === selectedCardId)}
onShowGallery={() => setSelectedCardId(null)}
// NOTE: won't support changes to card ID
onChange={cardData =>
- setDashboardCards(dashboardCards.map(i => (i.id === cardData.id ? cardData : i)))
+ setDashboardData({
+ ...dashboardData,
+ cards: dashboardData.cards.map(i => (i.id === cardData.id ? cardData : i)),
+ })
}
onAddCard={type =>
addCard({
id: uuid.v4(),
- title: 'New card',
+ title: `New ${type} card`,
size: CARD_SIZES.SMALL,
type,
})
diff --git a/src/components/DashboardEditor/_dashboard-editor.scss b/src/components/DashboardEditor/_dashboard-editor.scss
index b49ae5d2af..90940eb689 100644
--- a/src/components/DashboardEditor/_dashboard-editor.scss
+++ b/src/components/DashboardEditor/_dashboard-editor.scss
@@ -4,6 +4,7 @@
&--content {
flex: 1;
flex-direction: column;
+ padding-right: $spacing-05;
}
&--preview {
flex: 1;