Преглед изворни кода

Added delete tag button to inventory's edit spool modal

maziggy пре 6 месеци
родитељ
комит
bf66f7a536
3 измењених фајлова са 30 додато и 4 уклоњено
  1. 29 3
      frontend/src/components/SpoolFormModal.tsx
  2. 0 0
      static/assets/index-C5QNmsOn.js
  3. 1 1
      static/index.html

+ 29 - 3
frontend/src/components/SpoolFormModal.tsx

@@ -1,7 +1,7 @@
 import { useState, useEffect, useMemo } from 'react';
 import { useMutation, useQueryClient } from '@tanstack/react-query';
 import { useTranslation } from 'react-i18next';
-import { X, Loader2, Save, Beaker, Palette, Zap } from 'lucide-react';
+import { X, Loader2, Save, Beaker, Palette, Zap, Tag } from 'lucide-react';
 import { api } from '../api/client';
 import type { InventorySpool, SlicerSetting, SpoolCatalogEntry, LocalPreset } from '../api/client';
 import { Button } from './Button';
@@ -360,6 +360,19 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
     },
   });
 
+  const deleteTagMutation = useMutation({
+    mutationFn: () =>
+      api.updateSpool(spool!.id, { tag_uid: null } as Parameters<typeof api.updateSpool>[1]),
+    onSuccess: async () => {
+      await queryClient.invalidateQueries({ queryKey: ['inventory-spools'] });
+      showToast(t('inventory.tagDeleted', 'Tag removed'), 'success');
+      onClose();
+    },
+    onError: (error: Error) => {
+      showToast(error.message, 'error');
+    },
+  });
+
   // Save K-profiles for selected calibrations
   const saveKProfiles = async (spoolId: number) => {
     if (selectedProfiles.size === 0) {
@@ -464,7 +477,7 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
     }
   };
 
-  const isPending = createMutation.isPending || bulkCreateMutation.isPending || updateMutation.isPending;
+  const isPending = createMutation.isPending || bulkCreateMutation.isPending || updateMutation.isPending || deleteTagMutation.isPending;
 
   return (
     <div className="fixed inset-0 z-50 flex items-center justify-center">
@@ -621,7 +634,19 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
         </div>
 
         {/* Footer */}
-        <div className="flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0">
+        <div className="flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0">
+          {isEditing && (
+            <Button
+              variant="secondary"
+              onClick={() => deleteTagMutation.mutate()}
+              disabled={isPending || !spool?.tag_uid}
+              className="mr-auto"
+            >
+              <Tag className="w-4 h-4" />
+              {t('inventory.deleteTag', 'Delete Tag')}
+            </Button>
+          )}
+          <div className="flex gap-2 ml-auto">
           <Button variant="secondary" onClick={onClose}>
             {t('common.cancel')}
           </Button>
@@ -641,6 +666,7 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
               </>
             )}
           </Button>
+          </div>
         </div>
       </div>
     </div>

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
static/assets/index-C5QNmsOn.js


+ 1 - 1
static/index.html

@@ -23,7 +23,7 @@
 
     <!-- Splash screens for iOS -->
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
-    <script type="module" crossorigin src="/assets/index-Sz3ts5Wy.js"></script>
+    <script type="module" crossorigin src="/assets/index-C5QNmsOn.js"></script>
     <link rel="stylesheet" crossorigin href="/assets/index-Dgxdt1Fd.css">
   </head>
   <body>

Неке датотеке нису приказане због велике количине промена