Add prev/next navigation buttons to edit pages
Some checks failed
CI / style (push) Has been cancelled
CI / build-client (push) Has been cancelled
CI / build-amd64 (push) Has been cancelled
CI / build-tester (push) Has been cancelled
CI / test (cockroachdb) (push) Has been cancelled
CI / test (mariadb) (push) Has been cancelled
CI / test (postgres) (push) Has been cancelled
CI / test (sqlite) (push) Has been cancelled
CI / build-arm64 (push) Has been cancelled
CI / build-armv7 (push) Has been cancelled
CI / publish-images (push) Has been cancelled
CI / publish-release (push) Has been cancelled
Some checks failed
CI / style (push) Has been cancelled
CI / build-client (push) Has been cancelled
CI / build-amd64 (push) Has been cancelled
CI / build-tester (push) Has been cancelled
CI / test (cockroachdb) (push) Has been cancelled
CI / test (mariadb) (push) Has been cancelled
CI / test (postgres) (push) Has been cancelled
CI / test (sqlite) (push) Has been cancelled
CI / build-arm64 (push) Has been cancelled
CI / build-armv7 (push) Has been cancelled
CI / publish-images (push) Has been cancelled
CI / publish-release (push) Has been cancelled
- Filament, spool, and vendor edit pages now have Prev/Next buttons - Navigate between items without returning to the list - Buttons are disabled at the beginning/end of the list Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,10 @@
|
|||||||
"unArchive": "Unarchive",
|
"unArchive": "Unarchive",
|
||||||
"hideArchived": "Hide Archived",
|
"hideArchived": "Hide Archived",
|
||||||
"showArchived": "Show Archived",
|
"showArchived": "Show Archived",
|
||||||
|
"prev": "Prev",
|
||||||
|
"next": "Next",
|
||||||
|
"yes": "Yes",
|
||||||
|
"no": "No",
|
||||||
"notAccessTitle": "You don't have permission to access",
|
"notAccessTitle": "You don't have permission to access",
|
||||||
"hideColumns": "Hide Columns",
|
"hideColumns": "Hide Columns",
|
||||||
"clearFilters": "Clear Filters"
|
"clearFilters": "Clear Filters"
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import { LeftOutlined, RightOutlined } from "@ant-design/icons";
|
||||||
import { Edit, useForm, useSelect } from "@refinedev/antd";
|
import { Edit, useForm, useSelect } from "@refinedev/antd";
|
||||||
import { HttpError, IResourceComponentsProps, useTranslate } from "@refinedev/core";
|
import { HttpError, IResourceComponentsProps, useList, useTranslate } from "@refinedev/core";
|
||||||
import { Alert, ColorPicker, DatePicker, Form, Input, InputNumber, message, Radio, Select, Space, Typography } from "antd";
|
import { Alert, Button, ColorPicker, DatePicker, Form, Input, InputNumber, message, Radio, Select, Space, Typography } from "antd";
|
||||||
import TextArea from "antd/es/input/TextArea";
|
import TextArea from "antd/es/input/TextArea";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
||||||
import { MultiColorPicker } from "../../components/multiColorPicker";
|
import { MultiColorPicker } from "../../components/multiColorPicker";
|
||||||
import { formatNumberOnUserInput, numberParser, numberParserAllowEmpty } from "../../utils/parsing";
|
import { formatNumberOnUserInput, numberParser, numberParserAllowEmpty } from "../../utils/parsing";
|
||||||
@@ -21,13 +23,21 @@ the form's onFinish method. Form.Item's normalize should do this, but it doesn't
|
|||||||
|
|
||||||
export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
|
const navigate = useNavigate();
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
const [hasChanged, setHasChanged] = useState(false);
|
const [hasChanged, setHasChanged] = useState(false);
|
||||||
const extraFields = useGetFields(EntityType.filament);
|
const extraFields = useGetFields(EntityType.filament);
|
||||||
const currency = useCurrency();
|
const currency = useCurrency();
|
||||||
const [colorType, setColorType] = useState<"single" | "multi">("single");
|
const [colorType, setColorType] = useState<"single" | "multi">("single");
|
||||||
|
|
||||||
const { formProps, saveButtonProps } = useForm<IFilament, HttpError, IFilament, IFilament>({
|
// Get all filament IDs for prev/next navigation
|
||||||
|
const { data: allFilaments } = useList<IFilament>({
|
||||||
|
resource: "filament",
|
||||||
|
pagination: { mode: "off" },
|
||||||
|
sorters: [{ field: "id", order: "asc" }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const { formProps, saveButtonProps, id } = useForm<IFilament, HttpError, IFilament, IFilament>({
|
||||||
liveMode: "manual",
|
liveMode: "manual",
|
||||||
onLiveEvent() {
|
onLiveEvent() {
|
||||||
// Warn the user if the filament has been updated since the form was opened
|
// Warn the user if the filament has been updated since the form was opened
|
||||||
@@ -36,6 +46,17 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Calculate prev/next IDs for navigation
|
||||||
|
const { prevId, nextId } = useMemo(() => {
|
||||||
|
if (!allFilaments?.data || !id) return { prevId: null, nextId: null };
|
||||||
|
const ids = allFilaments.data.map((f) => f.id);
|
||||||
|
const currentIndex = ids.indexOf(Number(id));
|
||||||
|
return {
|
||||||
|
prevId: currentIndex > 0 ? ids[currentIndex - 1] : null,
|
||||||
|
nextId: currentIndex < ids.length - 1 ? ids[currentIndex + 1] : null,
|
||||||
|
};
|
||||||
|
}, [allFilaments?.data, id]);
|
||||||
|
|
||||||
// Get vendor selection options
|
// Get vendor selection options
|
||||||
const { selectProps } = useSelect<IVendor>({
|
const { selectProps } = useSelect<IVendor>({
|
||||||
resource: "vendor",
|
resource: "vendor",
|
||||||
@@ -76,7 +97,28 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Edit saveButtonProps={saveButtonProps}>
|
<Edit
|
||||||
|
saveButtonProps={saveButtonProps}
|
||||||
|
headerButtons={({ defaultButtons }) => (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
icon={<LeftOutlined />}
|
||||||
|
disabled={!prevId}
|
||||||
|
onClick={() => prevId && navigate(`/filament/edit/${prevId}`)}
|
||||||
|
>
|
||||||
|
{t("buttons.prev")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
icon={<RightOutlined />}
|
||||||
|
disabled={!nextId}
|
||||||
|
onClick={() => nextId && navigate(`/filament/edit/${nextId}`)}
|
||||||
|
>
|
||||||
|
{t("buttons.next")}
|
||||||
|
</Button>
|
||||||
|
{defaultButtons}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
<Form {...formProps} layout="vertical">
|
<Form {...formProps} layout="vertical">
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { LeftOutlined, RightOutlined } from "@ant-design/icons";
|
||||||
import { Edit, useForm } from "@refinedev/antd";
|
import { Edit, useForm } from "@refinedev/antd";
|
||||||
import { HttpError, IResourceComponentsProps, useTranslate } from "@refinedev/core";
|
import { HttpError, IResourceComponentsProps, useList, useTranslate } from "@refinedev/core";
|
||||||
import { Alert, DatePicker, Divider, Form, Input, InputNumber, Radio, Select, Typography } from "antd";
|
import { Alert, Button, DatePicker, Divider, Form, Input, InputNumber, Radio, Select, Typography } from "antd";
|
||||||
import TextArea from "antd/es/input/TextArea";
|
import TextArea from "antd/es/input/TextArea";
|
||||||
import { message } from "antd/lib";
|
import { message } from "antd/lib";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
@@ -37,7 +38,14 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
|
|||||||
const [searchParams, _] = useSearchParams();
|
const [searchParams, _] = useSearchParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { form, formProps, saveButtonProps } = useForm<ISpool, HttpError, ISpoolRequest, ISpool>({
|
// Get all spool IDs for prev/next navigation
|
||||||
|
const { data: allSpools } = useList<ISpool>({
|
||||||
|
resource: "spool",
|
||||||
|
pagination: { mode: "off" },
|
||||||
|
sorters: [{ field: "id", order: "asc" }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const { form, formProps, saveButtonProps, id } = useForm<ISpool, HttpError, ISpoolRequest, ISpool>({
|
||||||
liveMode: "manual",
|
liveMode: "manual",
|
||||||
onLiveEvent() {
|
onLiveEvent() {
|
||||||
// Warn the user if the spool has been updated since the form was opened
|
// Warn the user if the spool has been updated since the form was opened
|
||||||
@@ -60,6 +68,17 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
|
|||||||
const initialWeightValue = Form.useWatch("initial_weight", form);
|
const initialWeightValue = Form.useWatch("initial_weight", form);
|
||||||
const spoolWeightValue = Form.useWatch("spool_weight", form);
|
const spoolWeightValue = Form.useWatch("spool_weight", form);
|
||||||
|
|
||||||
|
// Calculate prev/next IDs for navigation
|
||||||
|
const { prevId, nextId } = useMemo(() => {
|
||||||
|
if (!allSpools?.data || !id) return { prevId: null, nextId: null };
|
||||||
|
const ids = allSpools.data.map((s) => s.id);
|
||||||
|
const currentIndex = ids.indexOf(Number(id));
|
||||||
|
return {
|
||||||
|
prevId: currentIndex > 0 ? ids[currentIndex - 1] : null,
|
||||||
|
nextId: currentIndex < ids.length - 1 ? ids[currentIndex + 1] : null,
|
||||||
|
};
|
||||||
|
}, [allSpools?.data, id]);
|
||||||
|
|
||||||
// Add the filament_id field to the form
|
// Add the filament_id field to the form
|
||||||
if (formProps.initialValues) {
|
if (formProps.initialValues) {
|
||||||
formProps.initialValues["filament_id"] = formProps.initialValues["filament"].id;
|
formProps.initialValues["filament_id"] = formProps.initialValues["filament"].id;
|
||||||
@@ -231,7 +250,28 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
|
|||||||
}, [initialUsedWeight]);
|
}, [initialUsedWeight]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Edit saveButtonProps={saveButtonProps}>
|
<Edit
|
||||||
|
saveButtonProps={saveButtonProps}
|
||||||
|
headerButtons={({ defaultButtons }) => (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
icon={<LeftOutlined />}
|
||||||
|
disabled={!prevId}
|
||||||
|
onClick={() => prevId && navigate(`/spool/edit/${prevId}`)}
|
||||||
|
>
|
||||||
|
{t("buttons.prev")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
icon={<RightOutlined />}
|
||||||
|
disabled={!nextId}
|
||||||
|
onClick={() => nextId && navigate(`/spool/edit/${nextId}`)}
|
||||||
|
>
|
||||||
|
{t("buttons.next")}
|
||||||
|
</Button>
|
||||||
|
{defaultButtons}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
<Form {...formProps} layout="vertical">
|
<Form {...formProps} layout="vertical">
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
52
client/src/pages/vendors/edit.tsx
vendored
52
client/src/pages/vendors/edit.tsx
vendored
@@ -1,9 +1,11 @@
|
|||||||
|
import { LeftOutlined, RightOutlined } from "@ant-design/icons";
|
||||||
import { Edit, useForm } from "@refinedev/antd";
|
import { Edit, useForm } from "@refinedev/antd";
|
||||||
import { HttpError, IResourceComponentsProps, useTranslate } from "@refinedev/core";
|
import { HttpError, IResourceComponentsProps, useList, useTranslate } from "@refinedev/core";
|
||||||
import { Alert, DatePicker, Form, Input, InputNumber, message, Typography } from "antd";
|
import { Alert, Button, DatePicker, Form, Input, InputNumber, message, Typography } from "antd";
|
||||||
import TextArea from "antd/es/input/TextArea";
|
import TextArea from "antd/es/input/TextArea";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import React, { useState } from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
||||||
import { EntityType, useGetFields } from "../../utils/queryFields";
|
import { EntityType, useGetFields } from "../../utils/queryFields";
|
||||||
import { IVendor, IVendorParsedExtras } from "./model";
|
import { IVendor, IVendorParsedExtras } from "./model";
|
||||||
@@ -17,11 +19,19 @@ the form's onFinish method. Form.Item's normalize should do this, but it doesn't
|
|||||||
|
|
||||||
export const VendorEdit: React.FC<IResourceComponentsProps> = () => {
|
export const VendorEdit: React.FC<IResourceComponentsProps> = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
|
const navigate = useNavigate();
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
const [hasChanged, setHasChanged] = useState(false);
|
const [hasChanged, setHasChanged] = useState(false);
|
||||||
const extraFields = useGetFields(EntityType.vendor);
|
const extraFields = useGetFields(EntityType.vendor);
|
||||||
|
|
||||||
const { formProps, saveButtonProps } = useForm<IVendor, HttpError, IVendor, IVendor>({
|
// Get all vendor IDs for prev/next navigation
|
||||||
|
const { data: allVendors } = useList<IVendor>({
|
||||||
|
resource: "vendor",
|
||||||
|
pagination: { mode: "off" },
|
||||||
|
sorters: [{ field: "id", order: "asc" }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const { formProps, saveButtonProps, id } = useForm<IVendor, HttpError, IVendor, IVendor>({
|
||||||
liveMode: "manual",
|
liveMode: "manual",
|
||||||
onLiveEvent() {
|
onLiveEvent() {
|
||||||
// Warn the user if the vendor has been updated since the form was opened
|
// Warn the user if the vendor has been updated since the form was opened
|
||||||
@@ -30,6 +40,17 @@ export const VendorEdit: React.FC<IResourceComponentsProps> = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Calculate prev/next IDs for navigation
|
||||||
|
const { prevId, nextId } = useMemo(() => {
|
||||||
|
if (!allVendors?.data || !id) return { prevId: null, nextId: null };
|
||||||
|
const ids = allVendors.data.map((v) => v.id);
|
||||||
|
const currentIndex = ids.indexOf(Number(id));
|
||||||
|
return {
|
||||||
|
prevId: currentIndex > 0 ? ids[currentIndex - 1] : null,
|
||||||
|
nextId: currentIndex < ids.length - 1 ? ids[currentIndex + 1] : null,
|
||||||
|
};
|
||||||
|
}, [allVendors?.data, id]);
|
||||||
|
|
||||||
// Parse the extra fields from string values into real types
|
// Parse the extra fields from string values into real types
|
||||||
if (formProps.initialValues) {
|
if (formProps.initialValues) {
|
||||||
formProps.initialValues = ParsedExtras(formProps.initialValues);
|
formProps.initialValues = ParsedExtras(formProps.initialValues);
|
||||||
@@ -49,7 +70,28 @@ export const VendorEdit: React.FC<IResourceComponentsProps> = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Edit saveButtonProps={saveButtonProps}>
|
<Edit
|
||||||
|
saveButtonProps={saveButtonProps}
|
||||||
|
headerButtons={({ defaultButtons }) => (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
icon={<LeftOutlined />}
|
||||||
|
disabled={!prevId}
|
||||||
|
onClick={() => prevId && navigate(`/vendor/edit/${prevId}`)}
|
||||||
|
>
|
||||||
|
{t("buttons.prev")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
icon={<RightOutlined />}
|
||||||
|
disabled={!nextId}
|
||||||
|
onClick={() => nextId && navigate(`/vendor/edit/${nextId}`)}
|
||||||
|
>
|
||||||
|
{t("buttons.next")}
|
||||||
|
</Button>
|
||||||
|
{defaultButtons}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
<Form {...formProps} layout="vertical">
|
<Form {...formProps} layout="vertical">
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
Reference in New Issue
Block a user