Skip to content

Commit

Permalink
Merge branch 'fix/integrations-grouping' into alpha
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/components/ChatLinks/ChatLinks.tsx
#	src/features/Chat/Thread/actions.ts
  • Loading branch information
olegklimov committed Dec 8, 2024
2 parents 77c97f7 + 63beb3e commit 5edb16c
Show file tree
Hide file tree
Showing 17 changed files with 726 additions and 160 deletions.
2 changes: 1 addition & 1 deletion src/components/ChatLinks/ChatLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const ChatLinks: React.FC = () => {
if (link.action === "summarize-project") {
if ("current_config_file" in link && link.current_config_file) {
dispatch(setIntegrationData({ path: link.current_config_file }));
// set the integration fata
// set the integration data
}
submit(link.text, "PROJECT_SUMMARY");
return;
Expand Down
9 changes: 7 additions & 2 deletions src/components/IntegrationsView/CustomFieldsAndWidgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Switch,
} from "@radix-ui/themes";
import { Markdown } from "../Markdown";
import { useState } from "react";
import { type ChangeEventHandler, useState } from "react";

// Custom Input Field
export const CustomInputField = ({
Expand All @@ -20,6 +20,8 @@ export const CustomInputField = ({
name,
width,
size = "long",
color = "gray",
onChange,
}: {
id?: string;
type?:
Expand All @@ -42,6 +44,8 @@ export const CustomInputField = ({
placeholder?: string;
size?: string;
width?: string;
color?: TextField.RootProps["color"];
onChange?: ChangeEventHandler<HTMLInputElement>;
}) => {
return (
<Box
Expand All @@ -64,9 +68,10 @@ export const CustomInputField = ({
size="2"
value={value}
variant="soft"
color="gray"
color={color}
defaultValue={defaultValue}
placeholder={placeholder}
onChange={onChange}
/>
) : (
<TextArea
Expand Down
9 changes: 8 additions & 1 deletion src/components/IntegrationsView/IntegrationCard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
}

.integrationCardInline {
width: 33%;
width: calc(33% - 7px);
min-height: 140px;
display: flex;
align-items: center;
justify-content: center;
padding: 0.75rem;
.integrationIcon {
max-width: 45px;
}
}

.integrationIcon {
Expand Down
34 changes: 23 additions & 11 deletions src/components/IntegrationsView/IntegrationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@ import { toPascalCase } from "../../utils/toPascalCase";
import styles from "./IntegrationCard.module.css";
import {
IntegrationWithIconRecord,
IntegrationWithIconResponse,
NotConfiguredIntegrationWithIconRecord,
} from "../../services/refact";
import { FC } from "react";
import classNames from "classnames";
import { iconMap } from "./icons/iconMap";

type IntegrationCardProps = {
integration: IntegrationWithIconRecord;
integration:
| IntegrationWithIconRecord
| NotConfiguredIntegrationWithIconRecord;
handleIntegrationShowUp: (
integration: IntegrationWithIconResponse["integrations"][number],
integration:
| IntegrationWithIconRecord
| NotConfiguredIntegrationWithIconRecord,
) => void;
isInline?: boolean;
isNotConfigured?: boolean;
};

const INTEGRATIONS_WITH_TERMINAL_ICON = ["cmdline", "service"];

export const IntegrationCard: FC<IntegrationCardProps> = ({
integration,
handleIntegrationShowUp,
isInline = false,
isNotConfigured = false,
}) => {
const integrationLogo = INTEGRATIONS_WITH_TERMINAL_ICON.includes(
integration.integr_name.split("_")[0],
Expand All @@ -33,11 +37,15 @@ export const IntegrationCard: FC<IntegrationCardProps> = ({
return (
<Card
className={classNames(styles.integrationCard, {
[styles.integrationCardInline]: isInline,
[styles.integrationCardInline]: isNotConfigured,
})}
onClick={() => handleIntegrationShowUp(integration)}
>
<Flex gap="4" direction={isInline ? "column" : "row"} align={"center"}>
<Flex
gap="4"
direction={isNotConfigured ? "column" : "row"}
align={"center"}
>
<img
src={integrationLogo}
className={styles.integrationIcon}
Expand All @@ -46,18 +54,22 @@ export const IntegrationCard: FC<IntegrationCardProps> = ({
<Flex
align="center"
justify="between"
gap={isInline ? "0" : "2"}
width={isInline ? "auto" : "100%"}
gap={isNotConfigured ? "0" : "2"}
width={isNotConfigured ? "auto" : "100%"}
>
<Text size="3" weight="medium">
<Text
size="3"
weight="medium"
align={isNotConfigured ? "center" : "left"}
>
{/* {toPascalCase(
integration.integr_name.startsWith("cmdline")
? integration.integr_name.split("_")[0]
: integration.integr_name,
)} */}
{toPascalCase(integration.integr_name)}
</Text>
{!isInline && (
{!isNotConfigured && (
<Badge
color={
integration.on_your_laptop || integration.when_isolated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.integrationIcon {
max-width: 30px;
object-fit: cover;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { type FormEvent, type FC, useState, ChangeEventHandler } from "react";
import { NotConfiguredIntegrationWithIconRecord } from "../../../services/refact";
import {
Button,
Card,
Flex,
Heading,
RadioGroup,
Text,
} from "@radix-ui/themes";
import { iconMap } from "../icons/iconMap";
import styles from "./IntegrationCmdline.module.css";
import { toPascalCase } from "../../../utils/toPascalCase";
import { formatProjectName } from "../../../utils/formatProjectName";
import { CustomInputField } from "../CustomFieldsAndWidgets";
import { Link } from "../../Link";

const validateSnakeCase = (value: string) => {
const snakeCaseRegex = /^[a-z]+(_[a-z]+)*$/;
return snakeCaseRegex.test(value);
};

type IntegrationCmdlineProps = {
integration: NotConfiguredIntegrationWithIconRecord;
handleSubmit: (event: FormEvent<HTMLFormElement>) => void;
};

const renderIntegrationCmdlineField = ({
path,
label,
shouldBeFormatted,
}: {
path: string;
label?: string;
shouldBeFormatted: boolean;
}) => {
const formattedLabel = shouldBeFormatted
? formatProjectName({
projectPath: path,
isMarkdown: false,
indexOfLastFolder: 4,
})
: label;
return (
<Flex gap="2">
<RadioGroup.Item value={path} /> {formattedLabel}
</Flex>
);
};

const CMDLINE_TOOLS = ["cmdline", "service"];

export const IntegrationCmdline: FC<IntegrationCmdlineProps> = ({
integration,
handleSubmit,
}) => {
const [integrationType, integrationTemplate] =
integration.integr_name.split("_");
const isIntegrationAComamndLine = CMDLINE_TOOLS.includes(integrationType);
const [commandName, setCommandName] = useState("");
const [errorMessage, setErrorMessage] = useState("");

const handleCommandNameChange: ChangeEventHandler<HTMLInputElement> = (
event,
) => {
const value = event.target.value;
setCommandName(value);
if (!validateSnakeCase(value)) {
setErrorMessage("The command name must be in snake case!");
} else {
setErrorMessage("");
}
};

return (
<Flex direction="column" gap="4" width="100%">
<Heading as="h3" size="4">
<Flex align="center" gap="3">
<img
src={
iconMap[isIntegrationAComamndLine ? "cmdline" : integrationType]
}
className={styles.integrationIcon}
/>
{isIntegrationAComamndLine
? "Command Line Tool"
: toPascalCase(integrationType)}
</Flex>
</Heading>
<Text size="2" color="gray">
Please, choose where you want to setup your integration
</Text>
<form onSubmit={handleSubmit} id={`form-${integration.integr_name}`}>
<Flex gap="5" direction="column" width="100%">
<Card>
<RadioGroup.Root
name="integr_config_path"
defaultValue={integration.integr_config_path[0]}
>
{integration.integr_config_path.map((path, index) => {
const shouldPathBeFormatted =
integration.project_path[index] !== "";
return (
<Text as="label" size="2" key={path}>
{renderIntegrationCmdlineField({
path,
label: !shouldPathBeFormatted ? "Global" : path,
shouldBeFormatted: shouldPathBeFormatted,
})}
</Text>
);
})}
</RadioGroup.Root>
</Card>
<Flex direction="column" gap="3">
{integrationTemplate && (
<Flex direction="column" gap="2">
<Text size="2" color="gray">
Please, write a name of your command in the text field below,
make sure that it&apos;s written in{" "}
<Link
href="https://en.wikipedia.org/wiki/Snake_case"
target="_blank"
>
snake case
</Link>
</Text>
<Flex direction="column" gap="1">
<CustomInputField
name="command_name"
placeholder="runserver_py"
value={commandName}
onChange={handleCommandNameChange}
color={errorMessage ? "red" : undefined}
/>
{errorMessage && (
<Text color="red" size="1">
{errorMessage}
</Text>
)}
</Flex>
</Flex>
)}
<Button
type="submit"
variant="surface"
color="green"
disabled={
integrationTemplate ? !!errorMessage || !commandName : false
}
title={
!!errorMessage || !commandName
? "Please, fix all issues with the data"
: "Continue setting up integration"
}
>
Continue with setup
</Button>
</Flex>
</Flex>
</form>
</Flex>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { IntegrationCmdline } from "./IntegrationCmdline";
Loading

0 comments on commit 5edb16c

Please sign in to comment.