diff --git a/app/src/modules/insights/routes/dashboard.vue b/app/src/modules/insights/routes/dashboard.vue
index b4fd87a620..04d4b25797 100644
--- a/app/src/modules/insights/routes/dashboard.vue
+++ b/app/src/modules/insights/routes/dashboard.vue
@@ -8,13 +8,21 @@
-
-
-
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -50,6 +58,9 @@ import { Panel } from '@/types';
import { nanoid } from 'nanoid';
import { merge } from 'lodash';
import router from '@/router';
+import { omit } from 'lodash';
+import { unexpectedError } from '@/utils/unexpected-error';
+import api from '@/api';
export default defineComponent({
name: 'InsightsDashboard',
@@ -61,11 +72,12 @@ export default defineComponent({
},
panelKey: {
type: String,
- required: true,
+ default: null,
},
},
setup(props) {
const editMode = ref(false);
+ const saving = ref(false);
const insightsStore = useInsightsStore();
const currentDashboard = computed(() =>
@@ -91,7 +103,7 @@ export default defineComponent({
];
});
- return { currentDashboard, editMode, panels, stagePanelEdits, stagedPanels };
+ return { currentDashboard, editMode, panels, stagePanelEdits, stagedPanels, saving, saveChanges };
function stagePanelEdits(edits: Partial) {
if (props.panelKey === '+') {
@@ -126,6 +138,36 @@ export default defineComponent({
router.push(`/insights/${props.primaryKey}`);
}
+
+ async function saveChanges() {
+ if (!currentDashboard.value) return;
+
+ saving.value = true;
+
+ const currentIDs = currentDashboard.value.panels.map((panel) => panel.id);
+
+ const updatedPanels = [
+ ...currentIDs.map((id) => {
+ return stagedPanels.value.find((panel) => panel.id === id) || id;
+ }),
+ ...stagedPanels.value.filter((panel) => '$tempID' in panel).map((panel) => omit(panel, '$tempID')),
+ ];
+
+ try {
+ await api.patch(`/dashboards/${props.primaryKey}`, {
+ panels: updatedPanels,
+ });
+
+ await insightsStore.hydrate();
+
+ stagedPanels.value = [];
+ editMode.value = false;
+ } catch (err) {
+ unexpectedError(err);
+ } finally {
+ saving.value = false;
+ }
+ }
},
});
diff --git a/app/src/modules/insights/routes/panel-configuration.vue b/app/src/modules/insights/routes/panel-configuration.vue
index 08b6645b71..af9ecfa840 100644
--- a/app/src/modules/insights/routes/panel-configuration.vue
+++ b/app/src/modules/insights/routes/panel-configuration.vue
@@ -64,7 +64,7 @@ export default defineComponent({
props: {
panel: {
type: Object as PropType>,
- required: true,
+ default: null,
},
},
setup(props, { emit }) {
@@ -78,6 +78,8 @@ export default defineComponent({
color: undefined,
width: undefined,
height: undefined,
+ position_x: 0,
+ position_y: 0,
...(props.panel || {}),
});