Skip to content

Commit 5c9dfda

Browse files
authored
feat: EditTileModal saving state (#577)
noticed that there's no instant feedback when adding/editing a tile
1 parent fedb2d6 commit 5c9dfda

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

packages/app/src/DBDashboardPage.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,13 @@ const EditTileModal = ({
322322
chart,
323323
onClose,
324324
onSave,
325+
isSaving,
325326
dateRange,
326327
}: {
327328
chart: Tile | undefined;
328329
onClose: () => void;
329330
dateRange: [Date, Date];
331+
isSaving?: boolean;
330332
onSave: (chart: Tile) => void;
331333
}) => {
332334
return (
@@ -343,6 +345,7 @@ const EditTileModal = ({
343345
chartConfig={chart.config}
344346
setChartConfig={config => {}}
345347
dateRange={dateRange}
348+
isSaving={isSaving}
346349
onSave={config => {
347350
onSave({
348351
...chart,
@@ -665,6 +668,8 @@ function DBDashboardPage({ presetConfig }: { presetConfig?: Dashboard }) {
665668
);
666669
}, [createDashboard, router]);
667670

671+
const [isSaving, setIsSaving] = useState(false);
672+
668673
return (
669674
<Box p="sm">
670675
<Head>
@@ -673,12 +678,18 @@ function DBDashboardPage({ presetConfig }: { presetConfig?: Dashboard }) {
673678
<OnboardingModal />
674679
<EditTileModal
675680
chart={editedTile}
676-
onClose={() => setEditedTile(undefined)}
681+
onClose={() => {
682+
if (!isSaving) {
683+
setEditedTile(undefined);
684+
}
685+
}}
677686
dateRange={searchedTimeRange}
687+
isSaving={isSaving}
678688
onSave={newChart => {
679689
if (dashboard == null) {
680690
return;
681691
}
692+
setIsSaving(true);
682693
setDashboard(
683694
produce(dashboard, draft => {
684695
const chartIndex = draft.tiles.findIndex(
@@ -693,6 +704,10 @@ function DBDashboardPage({ presetConfig }: { presetConfig?: Dashboard }) {
693704
}),
694705
() => {
695706
setEditedTile(undefined);
707+
setIsSaving(false);
708+
},
709+
() => {
710+
setIsSaving(false);
696711
},
697712
);
698713
}}

packages/app/src/components/DBEditTimeChartForm.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import DBTableChart from '@/components/DBTableChart';
3535
import { DBTimeChart } from '@/components/DBTimeChart';
3636
import { SQLInlineEditorControlled } from '@/components/SQLInlineEditor';
3737
import { TimePicker } from '@/components/TimePicker';
38+
import { useUpdateDashboard } from '@/dashboard';
3839
import { GranularityPickerControlled } from '@/GranularityPicker';
3940
import SearchInputV2 from '@/SearchInputV2';
4041
import { getFirstTimestampValueExpression, useSource } from '@/source';
@@ -213,6 +214,7 @@ export default function EditTimeChartForm({
213214
chartConfig,
214215
displayedTimeInputValue,
215216
dateRange,
217+
isSaving,
216218
onTimeRangeSearch,
217219
setChartConfig,
218220
setDisplayedTimeInputValue,
@@ -223,6 +225,7 @@ export default function EditTimeChartForm({
223225
chartConfig: SavedChartConfig;
224226
displayedTimeInputValue?: string;
225227
dateRange: [Date, Date];
228+
isSaving?: boolean;
226229
onTimeRangeSearch?: (value: string) => void;
227230
setChartConfig: (chartConfig: SavedChartConfig) => void;
228231
setDisplayedTimeInputValue?: (value: string) => void;
@@ -587,6 +590,7 @@ export default function EditTimeChartForm({
587590
<Flex gap="sm">
588591
{onSave != null && (
589592
<Button
593+
loading={isSaving}
590594
variant="outline"
591595
onClick={() => {
592596
handleSubmit(v => {
@@ -598,7 +602,12 @@ export default function EditTimeChartForm({
598602
</Button>
599603
)}
600604
{onClose != null && (
601-
<Button variant="subtle" color="dark.2" onClick={onClose}>
605+
<Button
606+
variant="subtle"
607+
color="dark.2"
608+
onClick={onClose}
609+
disabled={isSaving}
610+
>
602611
Cancel
603612
</Button>
604613
)}

packages/app/src/dashboard.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ export function useDashboard({
118118
}, [isLocalDashboard, localDashboard, defaultDashboard, remoteDashboard]);
119119

120120
const setDashboard = useCallback(
121-
(newDashboard: Dashboard, onSuccess?: VoidFunction) => {
121+
(
122+
newDashboard: Dashboard,
123+
onSuccess?: VoidFunction,
124+
onError?: VoidFunction,
125+
) => {
122126
if (isLocalDashboard) {
123127
setLocalDashboard(newDashboard);
124128
onSuccess?.();
@@ -134,6 +138,7 @@ export function useDashboard({
134138
message: e.message.slice(0, 100),
135139
autoClose: 5000,
136140
});
141+
onError?.();
137142
},
138143
});
139144
}

0 commit comments

Comments
 (0)