Skip to content

Commit 52820d9

Browse files
committed
fix(web): Correct handling of empty fields in Docker Compose API request
1 parent baf4635 commit 52820d9

2 files changed

Lines changed: 46 additions & 30 deletions

File tree

web/src/pages/docker-compose/docker-compose.tsx

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
INetworkConfig,
1313
TDockerCompose,
1414
} from './docker-compose.type';
15+
import type { DockerCompose } from './docker-compose.type';
1516
import { cn } from '@/lib/utils';
1617
import ServiceNetworkFields from './components/service-network-fields';
1718
import ServiceDependsOnFields from './components/service-depends-on-fields';
@@ -200,36 +201,31 @@ const DockerCompose: FC = () => {
200201
);
201202

202203
const services = refactoredService.map((item) => {
203-
if (item.ports?.some((port) => !port.value)) {
204-
item.ports = null;
205-
}
206-
if (item.volumes?.some((volume) => !volume.value)) {
207-
item.volumes = null;
208-
}
209-
if (item.networks?.some((network) => !network.value)) {
210-
item.networks = null;
211-
}
212-
if (item.depends_on?.some((depend_on) => !depend_on.value)) {
213-
item.depends_on = null;
214-
}
215-
if (
216-
item.environment &&
217-
!Object.entries(item.environment).some(
218-
([k, v]) => k !== '' || v !== '',
219-
)
220-
) {
221-
item.environment = null;
222-
}
223-
if (
224-
item.build?.args &&
225-
!Object.entries(item.build?.args).some(
226-
([k, v]) => k !== '' || v !== '',
227-
)
228-
) {
229-
item.build.args = null;
230-
}
231-
232-
return item;
204+
const bodyService = {
205+
name: item.name,
206+
build: item.build?.context ? item.build : null,
207+
command: item.command ? item.command : null,
208+
image: item.image ? item.image : null,
209+
container_name: item.container_name ? item.container_name : null,
210+
depends_on: item.depends_on?.some((item) => item.value) ? [''] : null,
211+
ports: item.ports?.some((item) => item.value)
212+
? item.ports.map((port) => port.value)
213+
: null,
214+
volumes: item.volumes?.some((item) => item.value)
215+
? item.volumes.map((volume) => volume.value)
216+
: null,
217+
networks: item.networks?.some((item) => item.value)
218+
? item.networks.map((network) => network.value)
219+
: null,
220+
environment:
221+
item.environment &&
222+
Object.entries(item.environment).some(
223+
([k, v]) => k !== '' || v !== '',
224+
)
225+
? item.environment
226+
: null,
227+
};
228+
return bodyService;
233229
});
234230

235231
const requestBody: DockerComposeBody = {

web/src/pages/docker-compose/docker-compose.type.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,26 @@ export const DockerComposeSchema = zod.object({
145145

146146
export type TDockerCompose = zod.infer<typeof DockerComposeSchema>;
147147

148+
export type DockerCompose = {
149+
version: string;
150+
services: {
151+
[key: string]: {
152+
build: IBuildConfig | null;
153+
image: string | null;
154+
environment: {
155+
[key: string]: string;
156+
} | null;
157+
container_name: string | null;
158+
ports: string[] | null;
159+
command: string | null;
160+
volumes: string[] | null;
161+
networks: string[] | null;
162+
depends_on: string[] | null;
163+
};
164+
}[];
165+
networks: INetworkConfig;
166+
};
167+
148168
type AppNetwork = {
149169
network_name: string;
150170
driver: {

0 commit comments

Comments
 (0)