Skip to content

Commit

Permalink
fix: typeguard extracted & docker section renders if docker is presen…
Browse files Browse the repository at this point in the history
…t in integr_schema
  • Loading branch information
alashchev17 committed Dec 11, 2024
1 parent 5d13894 commit 1fdf718
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
52 changes: 19 additions & 33 deletions src/components/IntegrationsView/IntegrationForm/IntegrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ import { toPascalCase } from "../../../utils/toPascalCase";
import { debugIntegrations } from "../../../debugConfig";
import { iconMap } from "../icons/iconMap";

// TODO: should be extracted in the future
function jsonHasWhenIsolated(
json: unknown,
): json is Record<string, boolean> & { when_isolated: boolean } {
return (
typeof json === "object" &&
json !== null &&
"when_isolated" in json &&
typeof json.when_isolated === "boolean"
);
}

function areAllFieldsBoolean(json: unknown): json is Record<string, boolean> {
return (
typeof json === "object" &&
Expand Down Expand Up @@ -257,29 +245,27 @@ export const IntegrationForm: FC<IntegrationFormProps> = ({
</Flex>
</Flex>
)}
{integration.data.integr_schema.docker &&
jsonHasWhenIsolated(integration.data.integr_values.available) &&
integration.data.integr_values.available.when_isolated && (
<Flex mt="6" direction="column" align="start" gap="5">
<Flex gap="2" align="center" justify="center" width="100%">
<img
src={iconMap.docker}
className={styles.DockerIcon}
alt={integration.data.integr_name}
/>
<Heading as="h3" align="left">
{toPascalCase(integration.data.integr_name)} Containers
</Heading>
</Flex>
<IntegrationDocker
dockerData={integration.data.integr_schema.docker}
integrationName={integration.data.integr_name}
integrationProject={integration.data.project_path}
integrationPath={integration.data.integr_config_path}
handleSwitchIntegration={handleSwitchIntegration}
{integration.data.integr_schema.docker && (
<Flex mt="6" direction="column" align="start" gap="5">
<Flex gap="2" align="center" justify="center" width="100%">
<img
src={iconMap.docker}
className={styles.DockerIcon}
alt={integration.data.integr_name}
/>
<Heading as="h3" align="left">
{toPascalCase(integration.data.integr_name)} Containers
</Heading>
</Flex>
)}
<IntegrationDocker
dockerData={integration.data.integr_schema.docker}
integrationName={integration.data.integr_name}
integrationProject={integration.data.project_path}
integrationPath={integration.data.integr_config_path}
handleSwitchIntegration={handleSwitchIntegration}
/>
</Flex>
)}
</Flex>
);
};
11 changes: 11 additions & 0 deletions src/services/refact/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,14 @@ function isDockerPorts(json: unknown): json is DockerPorts {
// Since DockerPorts is defined as NonNullable<unknown>, we don't have specific structure to validate. Just checking, that it's not null | undefined
return json !== null && json !== undefined;
}

export function jsonHasWhenIsolated(
json: unknown,
): json is Record<string, boolean> & { when_isolated: boolean } {
return (
typeof json === "object" &&
json !== null &&
"when_isolated" in json &&
typeof json.when_isolated === "boolean"
);
}

0 comments on commit 1fdf718

Please sign in to comment.