Added "Add Spool" button on filament list page

Resolves #281
This commit is contained in:
Donkie
2024-01-30 18:57:23 +01:00
parent 4d65dea1e9
commit 36926c9ccf
3 changed files with 13 additions and 1 deletions

View File

@@ -217,6 +217,9 @@
},
"form": {
"filament_updated": "This filament has been updated by someone/something else since you opened this page. Saving will overwrite those changes!"
},
"buttons": {
"add_spool": "Add Spool"
}
},
"vendor": {

View File

@@ -5,7 +5,7 @@ import { Table, Button, Dropdown } from "antd";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { IFilament } from "./model";
import { EditOutlined, EyeOutlined, FilterOutlined, PlusSquareOutlined } from "@ant-design/icons";
import { EditOutlined, EyeOutlined, FileOutlined, FilterOutlined, PlusSquareOutlined } from "@ant-design/icons";
import { TableState, useInitialTableState, useStoreInitialState } from "../../utils/saveload";
import {
DateColumn,
@@ -146,10 +146,12 @@ export const FilamentList: React.FC<IResourceComponentsProps> = () => {
}
const { editUrl, showUrl, cloneUrl } = useNavigation();
const filamentAddSpoolUrl = (id: number): string => `/spool/create?filament_id=${id}`;
const actions = (record: IFilamentCollapsed) => [
{ name: t("buttons.show"), icon: <EyeOutlined />, link: showUrl("filament", record.id) },
{ name: t("buttons.edit"), icon: <EditOutlined />, link: editUrl("filament", record.id) },
{ name: t("buttons.clone"), icon: <PlusSquareOutlined />, link: cloneUrl("filament", record.id) },
{ name: t("filament.buttons.add_spool"), icon: <FileOutlined />, link: filamentAddSpoolUrl(record.id) },
];
const commonProps = {

View File

@@ -47,6 +47,13 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
formProps.initialValues.filament_id = formProps.initialValues.filament.id;
}
// If the query variable filament_id is set, set the filament_id field to that value
const query = new URLSearchParams(window.location.search);
const filament_id = query.get("filament_id");
if (filament_id) {
formProps.initialValues.filament_id = parseInt(filament_id);
}
const handleSubmit = async (redirectTo: "list" | "edit" | "create") => {
const values = StringifiedExtras(await form.validateFields());
if (quantity > 1) {