mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-18 01:45:17 +00:00
refactor: streamline service extraction logic in add-permissions component
- Updated type definitions for Environment and Project to improve clarity and maintainability. - Refactored the extractServices function to use optional chaining and nullish coalescing for safer data handling. - Enhanced type safety by casting the mapped services to the Services type.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import type { findEnvironmentById } from "@dokploy/server/index";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
@@ -27,12 +26,10 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { api } from "@/utils/api";
|
import { api, type RouterOutputs } from "@/utils/api";
|
||||||
|
|
||||||
type Environment = Omit<
|
type Project = RouterOutputs["project"]["all"][number];
|
||||||
Awaited<ReturnType<typeof findEnvironmentById>>,
|
type Environment = Project["environments"][number];
|
||||||
"project"
|
|
||||||
>;
|
|
||||||
|
|
||||||
export type Services = {
|
export type Services = {
|
||||||
appName: string;
|
appName: string;
|
||||||
@@ -53,17 +50,16 @@ export type Services = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const extractServices = (data: Environment | undefined) => {
|
export const extractServices = (data: Environment | undefined) => {
|
||||||
const applications: Services[] =
|
const applications: Services[] = (data?.applications?.map((item) => ({
|
||||||
data?.applications.map((item) => ({
|
appName: item.appName,
|
||||||
appName: item.appName,
|
name: item.name,
|
||||||
name: item.name,
|
type: "application",
|
||||||
type: "application",
|
id: item.applicationId,
|
||||||
id: item.applicationId,
|
createdAt: item.createdAt,
|
||||||
createdAt: item.createdAt,
|
status: item.applicationStatus,
|
||||||
status: item.applicationStatus,
|
description: item.description,
|
||||||
description: item.description,
|
serverId: item.serverId,
|
||||||
serverId: item.serverId,
|
})) ?? []) as Services[];
|
||||||
})) || [];
|
|
||||||
|
|
||||||
const mariadb: Services[] =
|
const mariadb: Services[] =
|
||||||
data?.mariadb.map((item) => ({
|
data?.mariadb.map((item) => ({
|
||||||
@@ -125,17 +121,16 @@ export const extractServices = (data: Environment | undefined) => {
|
|||||||
serverId: item.serverId,
|
serverId: item.serverId,
|
||||||
})) || [];
|
})) || [];
|
||||||
|
|
||||||
const compose: Services[] =
|
const compose: Services[] = (data?.compose?.map((item) => ({
|
||||||
data?.compose.map((item) => ({
|
appName: item.appName,
|
||||||
appName: item.appName,
|
name: item.name,
|
||||||
name: item.name,
|
type: "compose",
|
||||||
type: "compose",
|
id: item.composeId,
|
||||||
id: item.composeId,
|
createdAt: item.createdAt,
|
||||||
createdAt: item.createdAt,
|
status: item.composeStatus,
|
||||||
status: item.composeStatus,
|
description: item.description,
|
||||||
description: item.description,
|
serverId: item.serverId,
|
||||||
serverId: item.serverId,
|
})) ?? []) as Services[];
|
||||||
})) || [];
|
|
||||||
|
|
||||||
applications.push(
|
applications.push(
|
||||||
...mysql,
|
...mysql,
|
||||||
|
|||||||
Reference in New Issue
Block a user