mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-15 19:45:46 +00:00
feat(frontend): add edit-part function in part table (#9775)
* add edit-part function in part table * fix code style using `pre-commit run -a` --------- Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
@ -1,13 +1,13 @@
|
|||||||
import { t } from '@lingui/core/macro';
|
import { t } from '@lingui/core/macro';
|
||||||
import { Group, Text } from '@mantine/core';
|
import { Group, Text } from '@mantine/core';
|
||||||
import { type ReactNode, useMemo } from 'react';
|
import { IconShoppingCart } from '@tabler/icons-react';
|
||||||
|
import { type ReactNode, useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
||||||
import { ModelType } from '@lib/enums/ModelType';
|
import { ModelType } from '@lib/enums/ModelType';
|
||||||
import { UserRoles } from '@lib/enums/Roles';
|
import { UserRoles } from '@lib/enums/Roles';
|
||||||
import { apiUrl } from '@lib/functions/Api';
|
import { apiUrl } from '@lib/functions/Api';
|
||||||
import type { TableFilter } from '@lib/types/Filters';
|
import type { TableFilter } from '@lib/types/Filters';
|
||||||
import { IconShoppingCart } from '@tabler/icons-react';
|
|
||||||
import { AddItemButton } from '../../components/buttons/AddItemButton';
|
import { AddItemButton } from '../../components/buttons/AddItemButton';
|
||||||
import { ActionDropdown } from '../../components/items/ActionDropdown';
|
import { ActionDropdown } from '../../components/items/ActionDropdown';
|
||||||
import OrderPartsWizard from '../../components/wizards/OrderPartsWizard';
|
import OrderPartsWizard from '../../components/wizards/OrderPartsWizard';
|
||||||
@ -16,13 +16,15 @@ import { usePartFields } from '../../forms/PartForms';
|
|||||||
import { InvenTreeIcon } from '../../functions/icons';
|
import { InvenTreeIcon } from '../../functions/icons';
|
||||||
import {
|
import {
|
||||||
useBulkEditApiFormModal,
|
useBulkEditApiFormModal,
|
||||||
useCreateApiFormModal
|
useCreateApiFormModal,
|
||||||
|
useEditApiFormModal
|
||||||
} from '../../hooks/UseForm';
|
} from '../../hooks/UseForm';
|
||||||
import { useTable } from '../../hooks/UseTable';
|
import { useTable } from '../../hooks/UseTable';
|
||||||
import { useUserState } from '../../states/UserState';
|
import { useUserState } from '../../states/UserState';
|
||||||
import type { TableColumn } from '../Column';
|
import type { TableColumn } from '../Column';
|
||||||
import { DescriptionColumn, LinkColumn, PartColumn } from '../ColumnRenderers';
|
import { DescriptionColumn, LinkColumn, PartColumn } from '../ColumnRenderers';
|
||||||
import { InvenTreeTable, type InvenTreeTableProps } from '../InvenTreeTable';
|
import { InvenTreeTable, type InvenTreeTableProps } from '../InvenTreeTable';
|
||||||
|
import { type RowAction, RowEditAction } from '../RowActions';
|
||||||
import { TableHoverCard } from '../TableHoverCard';
|
import { TableHoverCard } from '../TableHoverCard';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -345,6 +347,16 @@ export function PartListTable({
|
|||||||
modelType: ModelType.part
|
modelType: ModelType.part
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [selectedPart, setSelectedPart] = useState<number>(-1);
|
||||||
|
|
||||||
|
const editPart = useEditApiFormModal({
|
||||||
|
url: ApiEndpoints.part_list,
|
||||||
|
pk: selectedPart,
|
||||||
|
title: t`Edit Part`,
|
||||||
|
fields: usePartFields({ create: false }),
|
||||||
|
onFormSuccess: table.refreshTable
|
||||||
|
});
|
||||||
|
|
||||||
const setCategory = useBulkEditApiFormModal({
|
const setCategory = useBulkEditApiFormModal({
|
||||||
url: ApiEndpoints.part_list,
|
url: ApiEndpoints.part_list,
|
||||||
items: table.selectedIds,
|
items: table.selectedIds,
|
||||||
@ -357,6 +369,23 @@ export function PartListTable({
|
|||||||
|
|
||||||
const orderPartsWizard = OrderPartsWizard({ parts: table.selectedRecords });
|
const orderPartsWizard = OrderPartsWizard({ parts: table.selectedRecords });
|
||||||
|
|
||||||
|
const rowActions = useCallback(
|
||||||
|
(record: any): RowAction[] => {
|
||||||
|
const can_edit = user.hasChangePermission(ModelType.part);
|
||||||
|
|
||||||
|
return [
|
||||||
|
RowEditAction({
|
||||||
|
hidden: !can_edit,
|
||||||
|
onClick: () => {
|
||||||
|
setSelectedPart(record.pk);
|
||||||
|
editPart.open();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
];
|
||||||
|
},
|
||||||
|
[user, editPart]
|
||||||
|
);
|
||||||
|
|
||||||
const tableActions = useMemo(() => {
|
const tableActions = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
<ActionDropdown
|
<ActionDropdown
|
||||||
@ -397,6 +426,7 @@ export function PartListTable({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{newPart.modal}
|
{newPart.modal}
|
||||||
|
{editPart.modal}
|
||||||
{setCategory.modal}
|
{setCategory.modal}
|
||||||
{orderPartsWizard.wizard}
|
{orderPartsWizard.wizard}
|
||||||
<InvenTreeTable
|
<InvenTreeTable
|
||||||
@ -409,6 +439,7 @@ export function PartListTable({
|
|||||||
modelType: ModelType.part,
|
modelType: ModelType.part,
|
||||||
tableFilters: tableFilters,
|
tableFilters: tableFilters,
|
||||||
tableActions: tableActions,
|
tableActions: tableActions,
|
||||||
|
rowActions: rowActions,
|
||||||
enableSelection: true,
|
enableSelection: true,
|
||||||
enableReports: true,
|
enableReports: true,
|
||||||
enableLabels: true,
|
enableLabels: true,
|
||||||
|
Reference in New Issue
Block a user