kopia lustrzana https://github.com/bugout-dev/moonstream
init update dashboard name
rodzic
a5d3226496
commit
bb1cec351f
|
@ -8,6 +8,9 @@ import {
|
||||||
Text,
|
Text,
|
||||||
Spacer,
|
Spacer,
|
||||||
IconButton,
|
IconButton,
|
||||||
|
Editable,
|
||||||
|
EditableInput,
|
||||||
|
EditablePreview,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import Scrollable from "../../src/components/Scrollable";
|
import Scrollable from "../../src/components/Scrollable";
|
||||||
import RangeSelector from "../../src/components/RangeSelector";
|
import RangeSelector from "../../src/components/RangeSelector";
|
||||||
|
@ -94,8 +97,12 @@ const Analytics = () => {
|
||||||
const [timeRange, setTimeRange] = useState(timeMap[MINUTE_KEY]);
|
const [timeRange, setTimeRange] = useState(timeMap[MINUTE_KEY]);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { dashboardId } = router.params;
|
const { dashboardId } = router.params;
|
||||||
const { dashboardCache, dashboardLinksCache, deleteDashboard } =
|
const {
|
||||||
useDashboard(dashboardId);
|
dashboardCache,
|
||||||
|
dashboardLinksCache,
|
||||||
|
deleteDashboard,
|
||||||
|
updateDashboard,
|
||||||
|
} = useDashboard(dashboardId);
|
||||||
|
|
||||||
const { subscriptionsCache } = useSubscriptions();
|
const { subscriptionsCache } = useSubscriptions();
|
||||||
|
|
||||||
|
@ -145,6 +152,12 @@ const Analytics = () => {
|
||||||
// }
|
// }
|
||||||
// }, [nodesReady, windowSize]);
|
// }, [nodesReady, windowSize]);
|
||||||
|
|
||||||
|
const updateCallback = ({ name }) => {
|
||||||
|
const dashboard = { ...dashboardCache.data.data.resource_data };
|
||||||
|
dashboard.name = name;
|
||||||
|
updateDashboard.mutate({ id: dashboardCache.data.data.id, dashboard });
|
||||||
|
};
|
||||||
|
|
||||||
if (
|
if (
|
||||||
dashboardCache.isLoading ||
|
dashboardCache.isLoading ||
|
||||||
dashboardLinksCache.isLoading ||
|
dashboardLinksCache.isLoading ||
|
||||||
|
@ -166,16 +179,28 @@ const Analytics = () => {
|
||||||
minH="100vh"
|
minH="100vh"
|
||||||
>
|
>
|
||||||
<Stack direction={["column", "row", null]} w="100%" placeItems="center">
|
<Stack direction={["column", "row", null]} w="100%" placeItems="center">
|
||||||
<Heading as="h1" py={2} fontSize={["md", "xl"]}>
|
<Editable
|
||||||
{dashboardCache.data.data.resource_data.name}
|
as={Heading}
|
||||||
<IconButton
|
colorScheme="blue"
|
||||||
icon={<BiTrash />}
|
placeholder="enter note here"
|
||||||
variant="ghost"
|
defaultValue={dashboardCache.data.data.resource_data.name}
|
||||||
colorScheme="red"
|
onSubmit={(nextValue) =>
|
||||||
size="sm"
|
updateCallback({
|
||||||
onClick={() => toggleAlert(() => deleteDashboard.mutate())}
|
name: nextValue,
|
||||||
/>
|
})
|
||||||
</Heading>
|
}
|
||||||
|
>
|
||||||
|
<EditablePreview maxW="40rem" _placeholder={{ color: "black" }} />
|
||||||
|
<EditableInput maxW="40rem" />
|
||||||
|
</Editable>
|
||||||
|
<Heading as="h1" py={2} fontSize={["md", "xl"]}></Heading>
|
||||||
|
<IconButton
|
||||||
|
icon={<BiTrash />}
|
||||||
|
variant="ghost"
|
||||||
|
colorScheme="red"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => toggleAlert(() => deleteDashboard.mutate())}
|
||||||
|
/>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<RangeSelector
|
<RangeSelector
|
||||||
initialRange={MINUTE_KEY}
|
initialRange={MINUTE_KEY}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Editable,
|
Editable,
|
||||||
EditableInput,
|
EditableInput,
|
||||||
Image,
|
|
||||||
EditablePreview,
|
EditablePreview,
|
||||||
|
Image,
|
||||||
Button,
|
Button,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { CheckIcon, DeleteIcon } from "@chakra-ui/icons";
|
import { CheckIcon, DeleteIcon } from "@chakra-ui/icons";
|
||||||
|
|
|
@ -34,6 +34,18 @@ const useDashboard = (dashboardId) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const updateDashboard = useMutation(DashboardService.updateDashboard, {
|
||||||
|
onSuccess: () => {
|
||||||
|
toast("Updated new dashboard", "success");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast(error.error, "error", "Fail");
|
||||||
|
},
|
||||||
|
onSettled: () => {
|
||||||
|
dashboardsListCache.refetch();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const deleteDashboard = useMutation(
|
const deleteDashboard = useMutation(
|
||||||
() => DashboardService.deleteDashboard(dashboardId),
|
() => DashboardService.deleteDashboard(dashboardId),
|
||||||
{
|
{
|
||||||
|
@ -80,6 +92,7 @@ const useDashboard = (dashboardId) => {
|
||||||
dashboardCache,
|
dashboardCache,
|
||||||
deleteDashboard,
|
deleteDashboard,
|
||||||
dashboardLinksCache,
|
dashboardLinksCache,
|
||||||
|
updateDashboard,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { identify } from "mixpanel-browser";
|
||||||
import { http } from "../utils";
|
import { http } from "../utils";
|
||||||
|
|
||||||
const API_URL = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL;
|
const API_URL = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL;
|
||||||
|
@ -10,6 +11,18 @@ export const createDashboard = (data) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateDashboard = ({ dashboard, id }) => {
|
||||||
|
return http({
|
||||||
|
method: "PUT",
|
||||||
|
url: `${API_URL}/dashboards/${id}`,
|
||||||
|
data: {
|
||||||
|
...dashboard,
|
||||||
|
dashboard_id: id,
|
||||||
|
subscriptions: dashboard.dashboard_subscriptions,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const getDashboardsList = () => {
|
export const getDashboardsList = () => {
|
||||||
return http({
|
return http({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
|
Ładowanie…
Reference in New Issue