mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import { useFormik } from 'formik';
|
|
import { ChangeEvent, KeyboardEvent } from 'react';
|
|
import { object, number } from 'yup';
|
|
|
|
import { Button } from '@@/buttons';
|
|
import { Input } from '@@/form-components/Input';
|
|
|
|
interface Values {
|
|
page: number | '';
|
|
}
|
|
|
|
interface Props {
|
|
onChange(page: number): void;
|
|
totalPages: number;
|
|
}
|
|
|
|
export function PageInput({ onChange, totalPages }: Props) {
|
|
const { handleSubmit, setFieldValue, values, isValid } = useFormik<Values>({
|
|
initialValues: { page: '' },
|
|
onSubmit: async ({ page }) => page && onChange(page),
|
|
validateOnMount: true,
|
|
validationSchema: () =>
|
|
object({ page: number().required().max(totalPages).min(1) }),
|
|
});
|
|
|
|
return (
|
|
<form className="mx-3" onSubmit={handleSubmit}>
|
|
<label className="small m-0 mr-2 font-normal" htmlFor="go-to-page-input">
|
|
Go to page
|
|
</label>
|
|
<Input
|
|
id="go-to-page-input"
|
|
className="!w-32"
|
|
type="number"
|
|
value={values.page}
|
|
max={totalPages}
|
|
min={1}
|
|
step={1}
|
|
onChange={handleChange}
|
|
onKeyPress={preventNotNumber}
|
|
data-cy="pagination-go-to-page-input"
|
|
/>
|
|
<Button
|
|
type="submit"
|
|
disabled={!isValid}
|
|
data-cy="pagination-go-to-page-button"
|
|
>
|
|
Go
|
|
</Button>
|
|
</form>
|
|
);
|
|
|
|
function preventNotNumber(e: KeyboardEvent<HTMLInputElement>) {
|
|
if (e.key.match(/^\D$/)) {
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
|
|
function handleChange(e: ChangeEvent<HTMLInputElement>) {
|
|
const value = parseInt(e.target.value, 10);
|
|
setFieldValue('page', Number.isNaN(value) ? '' : value);
|
|
}
|
|
}
|