Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input/refactor #278

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/apps/console/components/name-id-view.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-nested-ternary */
import { CircleNotch } from '~/console/components/icons';
import { ReactNode, forwardRef, useEffect, useState } from 'react';
import { TextInput } from '~/components/atoms/input';
import { ITextInputBase, TextInput } from '~/components/atoms/input';
import useDebounce from '~/root/lib/client/hooks/use-debounce';
import { NonNullableString } from '~/root/lib/types/common';
import { handleError } from '~/root/lib/utils/common';
Expand Down Expand Up @@ -36,6 +36,7 @@ interface INameIdView {
};
}) => void;
nameErrorLabel: string;
size?: ITextInputBase['size'];
}

export const NameIdView = forwardRef<HTMLInputElement, INameIdView>(
Expand All @@ -53,8 +54,9 @@ export const NameIdView = forwardRef<HTMLInputElement, INameIdView>(
isUpdate,
handleChange,
nameErrorLabel,
size = 'lg',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a constant for the default size value

Using a constant (e.g., DEFAULT_INPUT_SIZE = 'lg') for the default size would make it easier to maintain and update this value across the application in the future.

Suggested change
size = 'lg',
const DEFAULT_INPUT_SIZE = 'lg';
// ... other code ...
size = DEFAULT_INPUT_SIZE,

},
ref
ref,
) => {
const [nameValid, setNameValid] = useState(false);
const [nameLoading, setNameLoading] = useState(true);
Expand Down Expand Up @@ -212,7 +214,7 @@ export const NameIdView = forwardRef<HTMLInputElement, INameIdView>(
}
},
500,
[displayName, name, isUpdate]
[displayName, name, isUpdate],
);

return (
Expand Down Expand Up @@ -242,7 +244,7 @@ export const NameIdView = forwardRef<HTMLInputElement, INameIdView>(
}
}}
placeholder={placeholder}
size="lg"
size={size}
error={
(!nameLoading || !isUpdate) &&
((!nameValid && !!name && !nameLoading) || !!errors)
Expand All @@ -254,5 +256,5 @@ export const NameIdView = forwardRef<HTMLInputElement, INameIdView>(
focusRing
/>
);
}
},
);
2 changes: 1 addition & 1 deletion src/apps/console/components/search-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const SearchBox = ({ InputElement = Toolbar.TextInput }) => {
}
},
300,
[search]
[search],
);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* eslint-disable guard-for-in */
/* eslint-disable react/destructuring-assignment */
import { useEffect, useRef, useState } from 'react';
import { NumberInput, TextInput } from '~/components/atoms/input';
import {
ITextInputBase,
NumberInput,
TextInput,
} from '~/components/atoms/input';
import Popup from '~/components/molecule/popup';
import { IDialogBase } from '~/console/components/types.d';
import { useConsoleApi } from '~/console/server/gql/api-provider';
Expand Down Expand Up @@ -66,8 +70,8 @@ const RenderField = ({
dummyEvent(
`${parseFloat(target.value) * (field.multiplier || 1)}${
field.unit
}`
)
}`,
),
);
}}
suffix={field.displayUnit}
Expand Down Expand Up @@ -106,16 +110,16 @@ const RenderField = ({
dummyEvent(
`${parseFloat(target.value) * (field.multiplier || 1)}${
field.unit
}`
)
}`,
),
);
if (qos) {
onChange(`res.${field.name}.max`)(
dummyEvent(
`${parseFloat(target.value) * (field.multiplier || 1)}${
field.unit
}`
)
}`,
),
);
}
}}
Expand All @@ -134,8 +138,8 @@ const RenderField = ({
dummyEvent(
`${parseFloat(target.value) * (field.multiplier || 1)}${
field.unit
}`
)
}`,
),
);
}}
suffix={field.displayUnit}
Expand Down Expand Up @@ -167,13 +171,15 @@ export const Fill = ({
values,
handleChange,
errors,
size = 'lg',
}: {
selectedService: ISelectedService;
values: { [key: string]: any };
handleChange: (key: string) => (e: { target: { value: any } }) => void;
errors: {
[key: string]: string | undefined;
};
size?: ITextInputBase['size'];
}) => {
const nameRef = useRef<HTMLInputElement>(null);
useEffect(() => {
Expand All @@ -183,6 +189,7 @@ export const Fill = ({
<div className="flex flex-col gap-3xl min-h-[30vh]">
<NameIdView
isUpdate
size={size}
ref={nameRef}
placeholder="Enter managed service name"
label="Name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const ClusterManagedServiceSettingGeneral = () => {
<TextInput
label="Integrated service URL"
value={`${consoleBaseUrl}/${parseName(account)}/${parseName(
managedService
managedService,
)}`}
message="This is your URL namespace within Kloudlite"
disabled
Expand All @@ -166,8 +166,8 @@ const ClusterManagedServiceSettingGeneral = () => {
onClick={() =>
copy(
`${consoleBaseUrl}/${parseName(account)}/${parseName(
managedService
)}`
managedService,
)}`,
)
}
className="outline-none hover:bg-surface-basic-hovered active:bg-surface-basic-active rounded text-text-default"
Expand Down Expand Up @@ -216,6 +216,7 @@ const ClusterManagedServiceSettingGeneral = () => {
errors,
handleChange,
}}
size="md"
/>
</Box>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ const RenderField = ({
label={`${field.label}${field.required ? ' *' : ''}`}
placeholder={field.label}
value={parseFloat(value) / (field.multiplier || 1) || ''}
size="lg"
onChange={({ target }) => {
onChange(`res.${field.name}`)(
dummyEvent(
`${parseFloat(target.value) * (field.multiplier || 1)}${
field.unit
}`
)
}`,
),
);
}}
suffix={field.displayUnit}
Expand All @@ -92,6 +93,7 @@ const RenderField = ({
suffix={field.displayUnit}
error={!!errors[fieldKey]}
message={errors[fieldKey]}
size="lg"
/>
);
}
Expand All @@ -105,6 +107,7 @@ const RenderField = ({
<div className="flex flex-row gap-xl items-end flex-1 ">
<div className="flex-1">
<NumberInput
size="lg"
error={!!errors[`${fieldKey}.min`]}
message={errors[`${fieldKey}.min`]}
placeholder={qos ? field.label : `${field.label} min`}
Expand All @@ -114,16 +117,16 @@ const RenderField = ({
dummyEvent(
`${parseFloat(target.value) * (field.multiplier || 1)}${
field.unit
}`
)
}`,
),
);
if (qos) {
onChange(`res.${field.name}.max`)(
dummyEvent(
`${parseFloat(target.value) * (field.multiplier || 1)}${
field.unit
}`
)
}`,
),
);
}
}}
Expand All @@ -133,6 +136,7 @@ const RenderField = ({
{!qos && (
<div className="flex-1">
<NumberInput
size="lg"
error={!!errors[`${fieldKey}.max`]}
message={errors[`${fieldKey}.max`]}
placeholder={`${field.label} max`}
Expand All @@ -142,8 +146,8 @@ const RenderField = ({
dummyEvent(
`${parseFloat(target.value) * (field.multiplier || 1)}${
field.unit
}`
)
}`,
),
);
}}
suffix={field.displayUnit}
Expand Down Expand Up @@ -383,7 +387,7 @@ const ReviewView = ({
}) => {
const renderFieldView = () => {
const fields = Object.entries(values.res).filter(
([k, _v]) => !['resources'].includes(k)
([k, _v]) => !['resources'].includes(k),
);
if (fields.length > 0) {
return (
Expand Down Expand Up @@ -584,7 +588,7 @@ const ManagedServiceLayout = () => {
'Cluster name is required',
(v) => {
return !(currentStep === 2 && !v);
}
},
),
selectedTemplate: Yup.object({}).required('Template is required.'),
// @ts-ignore
Expand All @@ -604,9 +608,9 @@ const ManagedServiceLayout = () => {
(acc: any, curr: any) => {
return { ...acc, [curr.name]: curr };
},
{}
)
)
{},
),
),
);
}

Expand Down Expand Up @@ -689,7 +693,7 @@ const ManagedServiceLayout = () => {
...flatM(
selectedTemplate?.template?.fields.reduce((acc, curr) => {
return { ...acc, [curr.name]: curr };
}, {})
}, {}),
),
},
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const Root = (props: IDialog) => {
message={errors.format}
value={values.format}
label="Format"
size="lg"
onChange={(_, value) => {
handleChange('format')(dummyEvent(value));
}}
Expand Down
2 changes: 1 addition & 1 deletion src/design-system/components/atoms/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ export const TextInputBase = forwardRef<HTMLInputElement, ITextInputBase>(
'pr-0': component !== 'input',
},
{
'h-[38px]': size === 'md' && component === 'input',
'h-[48px]': size === 'lg' && component === 'input',
'h-[60px]': size === 'xl' && component === 'input',
'h-[32px]': size === 'md' && component === 'input',
},
size === 'xl' ? '!px-2xl' : 'px-lg',
className,
Expand Down
Loading