mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-10 13:51:01 +00:00
Add option to duplicate an existing custom state
This commit is contained in:
@@ -23,7 +23,12 @@ import { useUserState } from '../../states/UserState';
|
|||||||
import type { TableColumn } from '../Column';
|
import type { TableColumn } from '../Column';
|
||||||
import type { TableFilter } from '../Filter';
|
import type { TableFilter } from '../Filter';
|
||||||
import { InvenTreeTable } from '../InvenTreeTable';
|
import { InvenTreeTable } from '../InvenTreeTable';
|
||||||
import { type RowAction, RowDeleteAction, RowEditAction } from '../RowActions';
|
import {
|
||||||
|
type RowAction,
|
||||||
|
RowDeleteAction,
|
||||||
|
RowDuplicateAction,
|
||||||
|
RowEditAction
|
||||||
|
} from '../RowActions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table for displaying list of custom states
|
* Table for displaying list of custom states
|
||||||
@@ -118,8 +123,11 @@ export default function CustomStateTable() {
|
|||||||
}, [getLogicalState]);
|
}, [getLogicalState]);
|
||||||
|
|
||||||
const newCustomStateFields = useCustomStateFields();
|
const newCustomStateFields = useCustomStateFields();
|
||||||
|
const duplicateCustomStateFields = useCustomStateFields();
|
||||||
const editCustomStateFields = useCustomStateFields();
|
const editCustomStateFields = useCustomStateFields();
|
||||||
|
|
||||||
|
const [initialStateData, setInitialStateData] = useState<any>({});
|
||||||
|
|
||||||
const newCustomState = useCreateApiFormModal({
|
const newCustomState = useCreateApiFormModal({
|
||||||
url: ApiEndpoints.custom_state_list,
|
url: ApiEndpoints.custom_state_list,
|
||||||
title: t`Add State`,
|
title: t`Add State`,
|
||||||
@@ -127,6 +135,14 @@ export default function CustomStateTable() {
|
|||||||
table: table
|
table: table
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const duplicateCustomState = useCreateApiFormModal({
|
||||||
|
url: ApiEndpoints.custom_state_list,
|
||||||
|
title: t`Add State`,
|
||||||
|
fields: duplicateCustomStateFields,
|
||||||
|
initialData: initialStateData,
|
||||||
|
table: table
|
||||||
|
});
|
||||||
|
|
||||||
const [selectedCustomState, setSelectedCustomState] = useState<
|
const [selectedCustomState, setSelectedCustomState] = useState<
|
||||||
number | undefined
|
number | undefined
|
||||||
>(undefined);
|
>(undefined);
|
||||||
@@ -156,6 +172,13 @@ export default function CustomStateTable() {
|
|||||||
editCustomState.open();
|
editCustomState.open();
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
RowDuplicateAction({
|
||||||
|
hidden: !user.hasAddRole(UserRoles.admin),
|
||||||
|
onClick: () => {
|
||||||
|
setInitialStateData(record);
|
||||||
|
duplicateCustomState.open();
|
||||||
|
}
|
||||||
|
}),
|
||||||
RowDeleteAction({
|
RowDeleteAction({
|
||||||
hidden: !user.hasDeleteRole(UserRoles.admin),
|
hidden: !user.hasDeleteRole(UserRoles.admin),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
@@ -172,7 +195,10 @@ export default function CustomStateTable() {
|
|||||||
return [
|
return [
|
||||||
<AddItemButton
|
<AddItemButton
|
||||||
key={'add'}
|
key={'add'}
|
||||||
onClick={() => newCustomState.open()}
|
onClick={() => {
|
||||||
|
setInitialStateData({});
|
||||||
|
newCustomState.open();
|
||||||
|
}}
|
||||||
tooltip={t`Add State`}
|
tooltip={t`Add State`}
|
||||||
/>
|
/>
|
||||||
];
|
];
|
||||||
@@ -182,6 +208,7 @@ export default function CustomStateTable() {
|
|||||||
<>
|
<>
|
||||||
{newCustomState.modal}
|
{newCustomState.modal}
|
||||||
{editCustomState.modal}
|
{editCustomState.modal}
|
||||||
|
{duplicateCustomState.modal}
|
||||||
{deleteCustomState.modal}
|
{deleteCustomState.modal}
|
||||||
<InvenTreeTable
|
<InvenTreeTable
|
||||||
url={apiUrl(ApiEndpoints.custom_state_list)}
|
url={apiUrl(ApiEndpoints.custom_state_list)}
|
||||||
|
Reference in New Issue
Block a user