Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PUI] Installed items #8202

Merged
merged 6 commits into from
Sep 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add PUI form to uninstall stock item
SchrodingersGat committed Sep 27, 2024
commit afe89f56554a55d608d6f5e746a5cb81b95984ab
1 change: 1 addition & 0 deletions src/frontend/src/enums/ApiEndpoints.tsx
Original file line number Diff line number Diff line change
@@ -134,6 +134,7 @@ export enum ApiEndpoints {
stock_assign = 'stock/assign/',
stock_status = 'stock/status/',
stock_install = 'stock/:id/install/',
stock_uninstall = 'stock/:id/uninstall/',
stock_serialize = 'stock/:id/serialize/',
build_test_statistics = 'test-statistics/by-build/:id/',
part_test_statistics = 'test-statistics/by-part/:id/',
16 changes: 16 additions & 0 deletions src/frontend/src/forms/StockForms.tsx
Original file line number Diff line number Diff line change
@@ -215,6 +215,22 @@ export function useCreateStockItem() {
});
}

/**
* Form set for manually removing (uninstalling) a StockItem from an existing StockItem
*/
export function useStockItemUninstallFields(): ApiFormFieldSet {
return useMemo(() => {
return {
location: {
filters: {
structural: false
}
},
note: {}
};
}, []);
}

/**
* Form set for manually installing a StockItem into an existing StockItem
*/
25 changes: 22 additions & 3 deletions src/frontend/src/tables/stock/InstalledItemsTable.tsx
Original file line number Diff line number Diff line change
@@ -7,7 +7,10 @@ import { AddItemButton } from '../../components/buttons/AddItemButton';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { ModelType } from '../../enums/ModelType';
import { UserRoles } from '../../enums/Roles';
import { useStockItemInstallFields } from '../../forms/StockForms';
import {
useStockItemInstallFields,
useStockItemUninstallFields
} from '../../forms/StockForms';
import { useCreateApiFormModal } from '../../hooks/UseForm';
import { useTable } from '../../hooks/UseTable';
import { apiUrl } from '../../states/ApiState';
@@ -37,6 +40,22 @@ export default function InstalledItemsTable({
fields: installItemFields
});

const [selectedRecord, setSelectedRecord] = useState<any>({});

const uninstallItemFields = useStockItemUninstallFields();

const uninstallItem = useCreateApiFormModal({
url: apiUrl(ApiEndpoints.stock_uninstall),
pk: selectedRecord.pk,
title: t`Uninstall Item`,
table: table,
successMessage: t`Item uninstalled`,
fields: uninstallItemFields,
initialData: {
location: stockItem.location ?? stockItem.part_detail?.default_location
}
});

const tableColumns: TableColumn[] = useMemo(() => {
return [
{
@@ -81,8 +100,6 @@ export default function InstalledItemsTable({
];
}, [stockItem, user]);

const [selectedRecord, setSelectedRecord] = useState<any>({});

const rowActions = useCallback(
(record: any) => {
return [
@@ -91,6 +108,7 @@ export default function InstalledItemsTable({
tooltip: t`Uninstall stock item`,
onClick: () => {
setSelectedRecord(record);
uninstallItem.open();
},
icon: <IconUnlink />,
hidden: !user.hasChangeRole(UserRoles.stock)
@@ -103,6 +121,7 @@ export default function InstalledItemsTable({
return (
<>
{installItem.modal}
{uninstallItem.modal}
{stockItem.pk ? (
<InvenTreeTable
url={apiUrl(ApiEndpoints.stock_item_list)}
Loading