refactor: update routing in dashboard components to include environment context; add new service pages for MongoDB, MySQL, PostgreSQL, Redis, and MariaDB

This commit is contained in:
Mauricio Siu
2025-09-01 20:12:14 -06:00
parent d57a0cf439
commit ecf7ae924f
12 changed files with 42 additions and 36 deletions
@@ -69,7 +69,7 @@ export const ShowGeneralApplication = ({ applicationId }: Props) => {
toast.success("Application deployed successfully"); toast.success("Application deployed successfully");
refetch(); refetch();
router.push( router.push(
`/dashboard/project/${data?.projectId}/services/application/${applicationId}?tab=deployments`, `/dashboard/project/${data?.environment.projectId}/environment/${data?.environmentId}/services/application/${applicationId}?tab=deployments`,
); );
}) })
.catch(() => { .catch(() => {
@@ -47,7 +47,7 @@ export const ComposeActions = ({ composeId }: Props) => {
toast.success("Compose deployed successfully"); toast.success("Compose deployed successfully");
refetch(); refetch();
router.push( router.push(
`/dashboard/project/${data?.project.projectId}/services/compose/${composeId}?tab=deployments`, `/dashboard/project/${data?.environment.projectId}/environment/${data?.environmentId}/services/compose/${composeId}?tab=deployments`,
); );
}) })
.catch(() => { .catch(() => {
@@ -87,7 +87,7 @@ export const SearchCommand = () => {
key={application.id} key={application.id}
onSelect={() => { onSelect={() => {
router.push( router.push(
`/dashboard/project/${project.projectId}/services/${application.type}/${application.id}`, `/dashboard/project/${project.projectId}/environment/${application.environmentId}/services/${application.type}/${application.id}`,
); );
setOpen(false); setOpen(false);
}} }}
@@ -1251,7 +1251,7 @@ const EnvironmentPage = (
key={service.id} key={service.id}
onClick={() => { onClick={() => {
router.push( router.push(
`/dashboard/project/${projectId}/services/${service.type}/${service.id}`, `/dashboard/project/${projectId}/environment/${environmentId}/services/${service.type}/${service.id}`,
); );
}} }}
className="flex flex-col group relative cursor-pointer bg-transparent transition-colors hover:bg-border" className="flex flex-col group relative cursor-pointer bg-transparent transition-colors hover:bg-border"
@@ -71,7 +71,7 @@ const Service = (
const [_toggleMonitoring, _setToggleMonitoring] = useState(false); const [_toggleMonitoring, _setToggleMonitoring] = useState(false);
const { applicationId, activeTab } = props; const { applicationId, activeTab } = props;
const router = useRouter(); const router = useRouter();
const { projectId } = router.query; const { projectId, environmentId } = router.query;
const [tab, setTab] = useState<TabState>(activeTab); const [tab, setTab] = useState<TabState>(activeTab);
useEffect(() => { useEffect(() => {
@@ -97,18 +97,18 @@ const Service = (
list={[ list={[
{ name: "Projects", href: "/dashboard/projects" }, { name: "Projects", href: "/dashboard/projects" },
{ {
name: data?.project?.name || "", name: data?.environment.project.name || "",
href: `/dashboard/project/${projectId}`, href: `/dashboard/project/${projectId}`,
}, },
{ {
name: data?.name || "", name: data?.name || "",
href: `/dashboard/project/${projectId}/services/application/${applicationId}`, href: `/dashboard/project/${projectId}/environment/${environmentId}/services/application/${applicationId}`,
}, },
]} ]}
/> />
<Head> <Head>
<title> <title>
Application: {data?.name} - {data?.project.name} | Dokploy Application: {data?.name} - {data?.environment.project.name} | Dokploy
</title> </title>
</Head> </Head>
<div className="w-full"> <div className="w-full">
@@ -215,7 +215,7 @@ const Service = (
className="w-full" className="w-full"
onValueChange={(e) => { onValueChange={(e) => {
setTab(e as TabState); setTab(e as TabState);
const newPath = `/dashboard/project/${projectId}/services/application/${applicationId}?tab=${e}`; const newPath = `/dashboard/project/${projectId}/environment/${environmentId}/services/application/${applicationId}?tab=${e}`;
router.push(newPath); router.push(newPath);
}} }}
> >
@@ -379,6 +379,7 @@ export async function getServerSideProps(
ctx: GetServerSidePropsContext<{ ctx: GetServerSidePropsContext<{
applicationId: string; applicationId: string;
activeTab: TabState; activeTab: TabState;
environmentId: string;
}>, }>,
) { ) {
const { query, params, req, res } = ctx; const { query, params, req, res } = ctx;
@@ -420,6 +421,7 @@ export async function getServerSideProps(
trpcState: helpers.dehydrate(), trpcState: helpers.dehydrate(),
applicationId: params?.applicationId, applicationId: params?.applicationId,
activeTab: (activeTab || "general") as TabState, activeTab: (activeTab || "general") as TabState,
environmentId: params?.environmentId,
}, },
}; };
} catch { } catch {
@@ -67,7 +67,7 @@ const Service = (
const [_toggleMonitoring, _setToggleMonitoring] = useState(false); const [_toggleMonitoring, _setToggleMonitoring] = useState(false);
const { composeId, activeTab } = props; const { composeId, activeTab } = props;
const router = useRouter(); const router = useRouter();
const { projectId } = router.query; const { projectId, environmentId } = router.query;
const [tab, setTab] = useState<TabState>(activeTab); const [tab, setTab] = useState<TabState>(activeTab);
useEffect(() => { useEffect(() => {
@@ -88,18 +88,18 @@ const Service = (
list={[ list={[
{ name: "Projects", href: "/dashboard/projects" }, { name: "Projects", href: "/dashboard/projects" },
{ {
name: data?.project?.name || "", name: data?.environment?.project?.name || "",
href: `/dashboard/project/${projectId}`, href: `/dashboard/project/${projectId}`,
}, },
{ {
name: data?.name || "", name: data?.name || "",
href: `/dashboard/project/${projectId}/services/compose/${composeId}`, href: `/dashboard/project/${projectId}/environment/${environmentId}/services/compose/${composeId}`,
}, },
]} ]}
/> />
<Head> <Head>
<title> <title>
Compose: {data?.name} - {data?.project.name} | Dokploy Compose: {data?.name} - {data?.environment?.project?.name} | Dokploy
</title> </title>
</Head> </Head>
<div className="w-full"> <div className="w-full">
@@ -208,7 +208,7 @@ const Service = (
className="w-full" className="w-full"
onValueChange={(e) => { onValueChange={(e) => {
setTab(e as TabState); setTab(e as TabState);
const newPath = `/dashboard/project/${projectId}/services/compose/${composeId}?tab=${e}`; const newPath = `/dashboard/project/${projectId}/environment/${environmentId}/services/compose/${composeId}?tab=${e}`;
router.push(newPath); router.push(newPath);
}} }}
> >
@@ -375,6 +375,7 @@ export async function getServerSideProps(
ctx: GetServerSidePropsContext<{ ctx: GetServerSidePropsContext<{
composeId: string; composeId: string;
activeTab: TabState; activeTab: TabState;
environmentId: string;
}>, }>,
) { ) {
const { query, params, req, res } = ctx; const { query, params, req, res } = ctx;
@@ -414,6 +415,7 @@ export async function getServerSideProps(
trpcState: helpers.dehydrate(), trpcState: helpers.dehydrate(),
composeId: params?.composeId, composeId: params?.composeId,
activeTab: (activeTab || "general") as TabState, activeTab: (activeTab || "general") as TabState,
environmentId: params?.environmentId,
}, },
}; };
} catch { } catch {
@@ -55,7 +55,7 @@ const Mariadb = (
const { mariadbId, activeTab } = props; const { mariadbId, activeTab } = props;
const router = useRouter(); const router = useRouter();
const { projectId } = router.query; const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab); const [tab, setSab] = useState<TabState>(activeTab);
const { data } = api.mariadb.one.useQuery({ mariadbId }); const { data } = api.mariadb.one.useQuery({ mariadbId });
const { data: auth } = api.user.get.useQuery(); const { data: auth } = api.user.get.useQuery();
@@ -74,7 +74,7 @@ const Mariadb = (
}, },
{ {
name: data?.name || "", name: data?.name || "",
href: `/dashboard/project/${projectId}/services/mariadb/${mariadbId}`, href: `/dashboard/project/${projectId}/environment/${environmentId}/services/mariadb/${mariadbId}`,
}, },
]} ]}
/> />
@@ -179,7 +179,7 @@ const Mariadb = (
className="w-full" className="w-full"
onValueChange={(e) => { onValueChange={(e) => {
setSab(e as TabState); setSab(e as TabState);
const newPath = `/dashboard/project/${projectId}/services/mariadb/${mariadbId}?tab=${e}`; const newPath = `/dashboard/project/${projectId}/environment/${environmentId}/services/mariadb/${mariadbId}?tab=${e}`;
router.push(newPath, undefined, { shallow: true }); router.push(newPath, undefined, { shallow: true });
}} }}
@@ -300,7 +300,7 @@ Mariadb.getLayout = (page: ReactElement) => {
}; };
export async function getServerSideProps( export async function getServerSideProps(
ctx: GetServerSidePropsContext<{ mariadbId: string; activeTab: TabState }>, ctx: GetServerSidePropsContext<{ mariadbId: string; activeTab: TabState; environmentId: string }>,
) { ) {
const { query, params, req, res } = ctx; const { query, params, req, res } = ctx;
const activeTab = query.tab; const activeTab = query.tab;
@@ -338,6 +338,7 @@ export async function getServerSideProps(
trpcState: helpers.dehydrate(), trpcState: helpers.dehydrate(),
mariadbId: params?.mariadbId, mariadbId: params?.mariadbId,
activeTab: (activeTab || "general") as TabState, activeTab: (activeTab || "general") as TabState,
environmentId: params?.environmentId,
}, },
}; };
} catch { } catch {
@@ -54,7 +54,7 @@ const Mongo = (
const [_toggleMonitoring, _setToggleMonitoring] = useState(false); const [_toggleMonitoring, _setToggleMonitoring] = useState(false);
const { mongoId, activeTab } = props; const { mongoId, activeTab } = props;
const router = useRouter(); const router = useRouter();
const { projectId } = router.query; const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab); const [tab, setSab] = useState<TabState>(activeTab);
const { data } = api.mongo.one.useQuery({ mongoId }); const { data } = api.mongo.one.useQuery({ mongoId });
@@ -74,7 +74,7 @@ const Mongo = (
}, },
{ {
name: data?.name || "", name: data?.name || "",
href: `/dashboard/project/${projectId}/services/mongo/${mongoId}`, href: `/dashboard/project/${projectId}/environment/${environmentId}/services/mongo/${mongoId}`,
}, },
]} ]}
/> />
@@ -180,7 +180,7 @@ const Mongo = (
className="w-full" className="w-full"
onValueChange={(e) => { onValueChange={(e) => {
setSab(e as TabState); setSab(e as TabState);
const newPath = `/dashboard/project/${projectId}/services/mongo/${mongoId}?tab=${e}`; const newPath = `/dashboard/project/${projectId}/environment/${environmentId}/services/mongo/${mongoId}?tab=${e}`;
router.push(newPath, undefined, { shallow: true }); router.push(newPath, undefined, { shallow: true });
}} }}
@@ -302,7 +302,7 @@ Mongo.getLayout = (page: ReactElement) => {
}; };
export async function getServerSideProps( export async function getServerSideProps(
ctx: GetServerSidePropsContext<{ mongoId: string; activeTab: TabState }>, ctx: GetServerSidePropsContext<{ mongoId: string; activeTab: TabState; environmentId: string }>,
) { ) {
const { query, params, req, res } = ctx; const { query, params, req, res } = ctx;
const activeTab = query.tab; const activeTab = query.tab;
@@ -340,6 +340,7 @@ export async function getServerSideProps(
trpcState: helpers.dehydrate(), trpcState: helpers.dehydrate(),
mongoId: params?.mongoId, mongoId: params?.mongoId,
activeTab: (activeTab || "general") as TabState, activeTab: (activeTab || "general") as TabState,
environmentId: params?.environmentId,
}, },
}; };
} catch { } catch {
@@ -54,7 +54,7 @@ const MySql = (
const [_toggleMonitoring, _setToggleMonitoring] = useState(false); const [_toggleMonitoring, _setToggleMonitoring] = useState(false);
const { mysqlId, activeTab } = props; const { mysqlId, activeTab } = props;
const router = useRouter(); const router = useRouter();
const { projectId } = router.query; const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab); const [tab, setSab] = useState<TabState>(activeTab);
const { data } = api.mysql.one.useQuery({ mysqlId }); const { data } = api.mysql.one.useQuery({ mysqlId });
const { data: auth } = api.user.get.useQuery(); const { data: auth } = api.user.get.useQuery();
@@ -73,7 +73,7 @@ const MySql = (
}, },
{ {
name: data?.name || "", name: data?.name || "",
href: `/dashboard/project/${projectId}/services/mysql/${mysqlId}`, href: `/dashboard/project/${projectId}/environment/${environmentId}/services/mysql/${mysqlId}`,
}, },
]} ]}
/> />
@@ -180,7 +180,7 @@ const MySql = (
className="w-full" className="w-full"
onValueChange={(e) => { onValueChange={(e) => {
setSab(e as TabState); setSab(e as TabState);
const newPath = `/dashboard/project/${projectId}/services/mysql/${mysqlId}?tab=${e}`; const newPath = `/dashboard/project/${projectId}/environment/${environmentId}/services/mysql/${mysqlId}?tab=${e}`;
router.push(newPath, undefined, { shallow: true }); router.push(newPath, undefined, { shallow: true });
}} }}
@@ -286,7 +286,7 @@ MySql.getLayout = (page: ReactElement) => {
}; };
export async function getServerSideProps( export async function getServerSideProps(
ctx: GetServerSidePropsContext<{ mysqlId: string; activeTab: TabState }>, ctx: GetServerSidePropsContext<{ mysqlId: string; activeTab: TabState; environmentId: string }>,
) { ) {
const { query, params, req, res } = ctx; const { query, params, req, res } = ctx;
const activeTab = query.tab; const activeTab = query.tab;
@@ -54,7 +54,7 @@ const Postgresql = (
const [_toggleMonitoring, _setToggleMonitoring] = useState(false); const [_toggleMonitoring, _setToggleMonitoring] = useState(false);
const { postgresId, activeTab } = props; const { postgresId, activeTab } = props;
const router = useRouter(); const router = useRouter();
const { projectId } = router.query; const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab); const [tab, setSab] = useState<TabState>(activeTab);
const { data } = api.postgres.one.useQuery({ postgresId }); const { data } = api.postgres.one.useQuery({ postgresId });
const { data: auth } = api.user.get.useQuery(); const { data: auth } = api.user.get.useQuery();
@@ -73,7 +73,7 @@ const Postgresql = (
}, },
{ {
name: data?.name || "", name: data?.name || "",
href: `/dashboard/project/${projectId}/services/postgres/${postgresId}`, href: `/dashboard/project/${projectId}/environment/${environmentId}/services/postgres/${postgresId}`,
}, },
]} ]}
/> />
@@ -179,7 +179,7 @@ const Postgresql = (
className="w-full" className="w-full"
onValueChange={(e) => { onValueChange={(e) => {
setSab(e as TabState); setSab(e as TabState);
const newPath = `/dashboard/project/${projectId}/services/postgres/${postgresId}?tab=${e}`; const newPath = `/dashboard/project/${projectId}/environment/${environmentId}/services/postgres/${postgresId}?tab=${e}`;
router.push(newPath, undefined, { shallow: true }); router.push(newPath, undefined, { shallow: true });
}} }}
@@ -284,7 +284,7 @@ Postgresql.getLayout = (page: ReactElement) => {
}; };
export async function getServerSideProps( export async function getServerSideProps(
ctx: GetServerSidePropsContext<{ postgresId: string; activeTab: TabState }>, ctx: GetServerSidePropsContext<{ postgresId: string; activeTab: TabState; environmentId: string }>,
) { ) {
const { query, params, req, res } = ctx; const { query, params, req, res } = ctx;
const activeTab = query.tab; const activeTab = query.tab;
@@ -53,7 +53,7 @@ const Redis = (
const [_toggleMonitoring, _setToggleMonitoring] = useState(false); const [_toggleMonitoring, _setToggleMonitoring] = useState(false);
const { redisId, activeTab } = props; const { redisId, activeTab } = props;
const router = useRouter(); const router = useRouter();
const { projectId } = router.query; const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab); const [tab, setSab] = useState<TabState>(activeTab);
const { data } = api.redis.one.useQuery({ redisId }); const { data } = api.redis.one.useQuery({ redisId });
@@ -73,7 +73,7 @@ const Redis = (
}, },
{ {
name: data?.name || "", name: data?.name || "",
href: `/dashboard/project/${projectId}/services/redis/${redisId}`, href: `/dashboard/project/${projectId}/environment/${environmentId}/services/redis/${redisId}`,
}, },
]} ]}
/> />
@@ -179,7 +179,7 @@ const Redis = (
className="w-full" className="w-full"
onValueChange={(e) => { onValueChange={(e) => {
setSab(e as TabState); setSab(e as TabState);
const newPath = `/dashboard/project/${projectId}/services/redis/${redisId}?tab=${e}`; const newPath = `/dashboard/project/${projectId}/environment/${environmentId}/services/redis/${redisId}?tab=${e}`;
router.push(newPath, undefined, { shallow: true }); router.push(newPath, undefined, { shallow: true });
}} }}
@@ -291,7 +291,7 @@ Redis.getLayout = (page: ReactElement) => {
}; };
export async function getServerSideProps( export async function getServerSideProps(
ctx: GetServerSidePropsContext<{ redisId: string; activeTab: TabState }>, ctx: GetServerSidePropsContext<{ redisId: string; activeTab: TabState; environmentId: string }>,
) { ) {
const { query, params, req, res } = ctx; const { query, params, req, res } = ctx;
const activeTab = query.tab; const activeTab = query.tab;
+2 -2
View File
@@ -185,7 +185,7 @@ export const deployApplication = async ({
}) => { }) => {
const application = await findApplicationById(applicationId); const application = await findApplicationById(applicationId);
const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; const buildLink = `${await getDokployUrl()}/dashboard/project/${application.environment.projectId}/environment/${application.environmentId}/services/application/${application.applicationId}?tab=deployments`;
const deployment = await createDeployment({ const deployment = await createDeployment({
applicationId: applicationId, applicationId: applicationId,
title: titleLog, title: titleLog,
@@ -312,7 +312,7 @@ export const deployRemoteApplication = async ({
}) => { }) => {
const application = await findApplicationById(applicationId); const application = await findApplicationById(applicationId);
const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; const buildLink = `${await getDokployUrl()}/dashboard/project/${application.environment.projectId}/environment/${application.environmentId}/services/application/${application.applicationId}?tab=deployments`;
const deployment = await createDeployment({ const deployment = await createDeployment({
applicationId: applicationId, applicationId: applicationId,
title: titleLog, title: titleLog,