Skip to content

Commit

Permalink
Use vertex-components for TextFields and SelectFields
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Guidée <[email protected]>
  • Loading branch information
quentinguidee committed Oct 27, 2023
1 parent 91e5b6a commit 378570e
Show file tree
Hide file tree
Showing 20 changed files with 555 additions and 983 deletions.
914 changes: 425 additions & 489 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@testing-library/user-event": "^13.5.0",
"@types/byte-size": "^8.1.0",
"@types/uuid": "^9.0.1",
"@vertex-center/components": "^0.2.0",
"@vertex-center/components": "^0.3.1",
"axios": "^1.3.4",
"byte-size": "^8.1.1",
"immer": "^10.0.3",
Expand Down Expand Up @@ -58,16 +58,16 @@
"devDependencies": {
"@types/jest": "^29.4.0",
"@types/node": "^18.14.1",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/react": "^18.2.33",
"@types/react-dom": "^18.2.14",
"@types/react-syntax-highlighter": "^15.5.6",
"@vitejs/plugin-react": "^3.1.0",
"classnames": "^2.3.2",
"csstype": "^3.1.1",
"cypress": "^13.3.0",
"sass": "^1.58.3",
"start-server-and-test": "^2.0.1",
"typescript": "^5.0.3",
"typescript": "^5.2.2",
"vite": "^4.2.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Select, { SelectOption, SelectValue } from "./Select";
import { Container, ContainerQuery } from "../../models/container";
import { api } from "../../backend/api/backend";
import Progress from "../Progress";
import ServiceLogo from "../ServiceLogo/ServiceLogo";
import { SelectField, SelectOption } from "@vertex-center/components";
import { Container, ContainerQuery } from "../../../../models/container";
import { api } from "../../../../backend/api/backend";
import Progress from "../../../../components/Progress";
import ServiceLogo from "../../../../components/ServiceLogo/ServiceLogo";
import { useQuery } from "@tanstack/react-query";
import { APIError } from "../Error/APIError";
import { APIError } from "../../../../components/Error/APIError";
import { Fragment } from "react";

type Props = {
container?: Container;
Expand Down Expand Up @@ -36,24 +37,24 @@ export default function ContainerSelect(props: Readonly<Props>) {
};

const value = (
<SelectValue>
<Fragment>
{container && <ServiceLogo service={container?.service} />}
{container?.display_name ??
container?.service?.name ??
"Select an container"}
</SelectValue>
</Fragment>
);

return (
// @ts-ignore
<Select onChange={onContainerChange} value={value}>
<SelectField onChange={onContainerChange} value={value}>
<SelectOption value="">None</SelectOption>
{Object.entries(containers ?? [])?.map(([, container]) => (
<SelectOption key={container.uuid} value={container.uuid}>
<ServiceLogo service={container?.service} />
{container?.display_name ?? container?.service?.name}
</SelectOption>
))}
</Select>
</SelectField>
);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import PortInput from "../Input/PortInput";
import Input from "../Input/Input";
import { Vertical } from "../Layouts/Layouts";
import TimezoneInput from "../Input/TimezoneInput";
import { EnvVariable } from "../../models/service";
import { TextField } from "@vertex-center/components";
import TimezoneField from "../../../../components/TimezoneField/TimezoneField";
import { EnvVariable } from "../../../../models/service";

type Props = {
id: string;
env: EnvVariable;
value: any;
onChange: (value: any) => void;
disabled?: boolean;
};

export default function EnvVariableInput(props: Readonly<Props>) {
const { env, value, onChange, disabled } = props;
const { id, env, value, onChange, disabled } = props;

const inputProps = {
id,
value,
label: env.display_name,
name: env.name,
Expand All @@ -25,18 +25,16 @@ export default function EnvVariableInput(props: Readonly<Props>) {
};

let input: any;
if (env.type === "port") {
input = <PortInput {...inputProps} />;
} else if (env.type === "timezone") {
if (env.type === "timezone") {
input = (
<TimezoneInput
<TimezoneField
{...inputProps}
onChange={(value: any) => onChange(value)}
/>
);
} else {
input = <Input {...inputProps} />;
input = <TextField {...inputProps} />;
}

return <Vertical gap={6}>{input}</Vertical>;
return input;
}
17 changes: 4 additions & 13 deletions src/apps/Containers/components/SelectTags/SelectTags.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import Select, {
SelectOption,
SelectValue,
} from "../../../../components/Input/Select";
import { SelectField, SelectOption } from "@vertex-center/components";
import { useContainersTags } from "../../hooks/useContainers";

type Props = {
Expand All @@ -17,10 +14,6 @@ export default function SelectTags(props: Readonly<Props>) {

const count = selected?.length;

let value = (
<SelectValue>Tags{count !== 0 ? ` (${count})` : undefined}</SelectValue>
);

const onChange = (value: any) => {
let updated: any[];
if (selected.includes(value)) {
Expand All @@ -32,23 +25,21 @@ export default function SelectTags(props: Readonly<Props>) {
};

return (
// @ts-ignore
<Select
<SelectField
multiple
value={value}
value={`Tags${count !== 0 ? ` (${count})` : ""}`}
onChange={onChange}
disabled={isLoading || isError || !tags || tags.length === 0}
>
{tags?.map((tag) => (
<SelectOption
multiple
key={tag}
value={tag}
selected={selected.includes(tag)}
>
{tag}
</SelectOption>
))}
</Select>
</SelectField>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ import {
} from "../../../../components/KeyValueInfo/KeyValueInfo";
import useContainer from "../../hooks/useContainer";
import { useParams } from "react-router-dom";
import ContainerSelect from "../../../../components/Input/ContainerSelect";
import ContainerSelect from "../../components/ContainerSelect/ContainerSelect";
import { ChangeEvent, Fragment, useEffect, useState } from "react";
import { Container } from "../../../../models/container";
import Progress from "../../../../components/Progress";
import { Button, MaterialIcon } from "@vertex-center/components";
import { Button, MaterialIcon, TextField } from "@vertex-center/components";
import { api } from "../../../../backend/api/backend";
import { DatabaseEnvironment } from "../../../../models/service";
import { APIError } from "../../../../components/Error/APIError";
import { ProgressOverlay } from "../../../../components/Progress/Progress";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import Spacer from "../../../../components/Spacer/Spacer";
import Input from "../../../../components/Input/Input";

type DatabaseProps = {
container?: Container;
Expand Down Expand Up @@ -163,7 +162,7 @@ export default function ContainerDetailsDatabase() {
onChange={onChange}
/>
{databases?.[dbID]?.container_id && (
<Input
<TextField
label="Database name"
onChange={(e: any) =>
onChangeDbName(e, dbID)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState } from "react";
import { Title } from "../../../../components/Text/Text";

import styles from "./ContainerDocker.module.sass";
import { useParams } from "react-router-dom";
import { Horizontal, Vertical } from "../../../../components/Layouts/Layouts";
Expand Down
3 changes: 2 additions & 1 deletion src/apps/Containers/pages/ContainerEnv/ContainerEnv.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fragment, useEffect, useState } from "react";
import { Title } from "../../../../components/Text/Text";
import { useParams } from "react-router-dom";
import EnvVariableInput from "../../../../components/EnvVariableInput/EnvVariableInput";
import EnvVariableInput from "../../components/EnvVariableInput/EnvVariableInput";
import { Button, MaterialIcon } from "@vertex-center/components";
import { Horizontal } from "../../../../components/Layouts/Layouts";
import useContainer from "../../hooks/useContainer";
Expand Down Expand Up @@ -76,6 +76,7 @@ export default function ContainerEnv() {
<Title className={styles.title}>Environment</Title>
{env?.map((env, i) => (
<EnvVariableInput
id={env.env.name}
key={env.env.name}
env={env.env}
value={env.value}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@use "../../../../styles/colors"
@use "../../../../styles/dimensions"

.title, .toggle, .saved
Expand All @@ -14,9 +15,3 @@

& > :first-child
flex-grow: 1

.versionOption
padding-left: 10px

.versionValue
margin-left: -10px
32 changes: 15 additions & 17 deletions src/apps/Containers/pages/ContainerSettings/ContainerSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { Fragment, useEffect, useState } from "react";
import { Text, Title } from "../../../../components/Text/Text";
import { Horizontal } from "../../../../components/Layouts/Layouts";
import Spacer from "../../../../components/Spacer/Spacer";
import { Button, MaterialIcon } from "@vertex-center/components";
import {
Button,
MaterialIcon,
SelectField,
SelectOption,
TextField,
} from "@vertex-center/components";
import { useParams } from "react-router-dom";
import useContainer from "../../hooks/useContainer";
import ToggleButton from "../../../../components/ToggleButton/ToggleButton";
import Input from "../../../../components/Input/Input";

import styles from "./ContainerSettings.module.sass";
import { api } from "../../../../backend/api/backend";
import { APIError } from "../../../../components/Error/APIError";
import Select, {
SelectOption,
SelectValue,
} from "../../../../components/Input/Select";
import VersionTag from "../../../../components/VersionTag/VersionTag";
import classNames from "classnames";
import { ProgressOverlay } from "../../../../components/Progress/Progress";
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function ContainerSettings() {
};

const versionValue = (
<SelectValue
<div
className={classNames({
[styles.versionValue]: version !== "latest",
})}
Expand All @@ -93,7 +93,7 @@ export default function ContainerSettings() {
) : (
<VersionTag>{version}</VersionTag>
)}
</SelectValue>
</div>
);

return (
Expand All @@ -115,7 +115,8 @@ export default function ContainerSettings() {
disabled={isLoadingContainer}
/>
</Horizontal>
<Input
<TextField
id="container-name"
label="Container name"
description="The custom name of your choice for this service"
value={displayName}
Expand All @@ -126,7 +127,8 @@ export default function ContainerSettings() {
disabled={isLoadingContainer}
/>
<div className={styles.versionSelect}>
<Select
<SelectField
id="container-version"
label="Version"
onChange={onVersionChange}
disabled={isLoadingContainer || versionsLoading}
Expand All @@ -143,16 +145,12 @@ export default function ContainerSettings() {
return null;
}
return (
<SelectOption
key={v}
value={v}
className={styles.versionOption}
>
<SelectOption key={v} value={v}>
<VersionTag>{v}</VersionTag>
</SelectOption>
);
})}
</Select>
</SelectField>
<Button
rightIcon={<MaterialIcon icon="refresh" />}
onClick={() => reloadVersions(false)}
Expand Down
Loading

0 comments on commit 378570e

Please sign in to comment.