u
This commit is contained in:
@@ -26,6 +26,10 @@ import LensBlurIcon from '@mui/icons-material/LensBlur';
|
||||
import CalculateIcon from '@mui/icons-material/Calculate';
|
||||
import QrCodeScannerIcon from '@mui/icons-material/QrCodeScanner';
|
||||
import DirectionsIcon from '@mui/icons-material/Directions';
|
||||
import EditNoteIcon from '@mui/icons-material/EditNote';
|
||||
import Button from '@mui/material/Button';
|
||||
import { enqueueSnackbar } from 'notistack';
|
||||
import { deliveryEditorAutomat, setLastDeliveryPath } from '../../automats';
|
||||
import HealingMarkdown from './HealingMarkdown';
|
||||
import {
|
||||
VfsAttachmentLink,
|
||||
@@ -95,6 +99,8 @@ const TOOL_ICON_MAP = {
|
||||
ean_checksum: QrCodeScannerIcon,
|
||||
'set-user-route': DirectionsIcon,
|
||||
set_user_route: DirectionsIcon,
|
||||
draft_delivery_manifest: EditNoteIcon,
|
||||
'draft-delivery-manifest': EditNoteIcon,
|
||||
};
|
||||
|
||||
function formatMessageTime(isoString) {
|
||||
@@ -486,16 +492,145 @@ class UrlFaviconIcon extends PureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
export function isDraftDeliveryManifestTool(name) {
|
||||
if (!name || typeof name !== 'string') return false;
|
||||
const n = name.trim().toLowerCase();
|
||||
return n === 'draft_delivery_manifest' || n === 'draft-delivery-manifest';
|
||||
}
|
||||
|
||||
function tryExtractObject(val) {
|
||||
if (!val) return null;
|
||||
if (typeof val === 'object') return val;
|
||||
if (typeof val === 'string') {
|
||||
const trimmed = val.trim();
|
||||
try {
|
||||
return JSON.parse(trimmed);
|
||||
} catch {}
|
||||
const match = trimmed.match(/\{[\s\S]*\}/);
|
||||
if (match) {
|
||||
try {
|
||||
return JSON.parse(match[0]);
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function parseDraftDeliveryManifest(tool) {
|
||||
if (!tool) return null;
|
||||
const candidates = [tool.parameters, tool.arguments, tool.content, tool.result, tool];
|
||||
for (const c of candidates) {
|
||||
const obj = tryExtractObject(c);
|
||||
if (obj && typeof obj === 'object') {
|
||||
if (obj.manifest && typeof obj.manifest === 'object') {
|
||||
return obj.manifest;
|
||||
}
|
||||
if (obj.basedata || obj.baseData || obj.items || obj.lines || obj.lineitems) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class DraftDeliveryManifestUseButton extends PureComponent {
|
||||
state = {
|
||||
applied: false,
|
||||
};
|
||||
|
||||
handleClick = async (e) => {
|
||||
e?.stopPropagation();
|
||||
const { tool } = this.props;
|
||||
const manifest = parseDraftDeliveryManifest(tool);
|
||||
if (!manifest) {
|
||||
enqueueSnackbar('Keine gültigen Lieferscheindaten gefunden', { variant: 'warning' });
|
||||
return;
|
||||
}
|
||||
|
||||
deliveryEditorAutomat.actions.loadDraftManifest(manifest);
|
||||
setLastDeliveryPath('/lieferung/neu');
|
||||
|
||||
this.setState({ applied: true });
|
||||
setTimeout(() => {
|
||||
this.setState({ applied: false });
|
||||
}, 2500);
|
||||
|
||||
const count =
|
||||
manifest.items?.numberOfItemsToAdd ??
|
||||
(Array.isArray(manifest.items?.items)
|
||||
? manifest.items.items.length
|
||||
: Array.isArray(manifest.items)
|
||||
? manifest.items.length
|
||||
: Array.isArray(manifest.lines)
|
||||
? manifest.lines.length
|
||||
: 0);
|
||||
|
||||
enqueueSnackbar(
|
||||
count > 0
|
||||
? `${count} Positionen in den Lieferschein-Editor geladen`
|
||||
: 'Lieferschein in den Editor geladen',
|
||||
{ variant: 'success' }
|
||||
);
|
||||
|
||||
try {
|
||||
const { router } = await import('../../appRouter');
|
||||
if (router?.navigate) {
|
||||
const curPath =
|
||||
router.state?.location?.pathname ||
|
||||
(typeof window !== 'undefined' ? window.location.pathname : '');
|
||||
if (!curPath.startsWith('/lieferung/neu')) {
|
||||
void router.navigate('/lieferung/neu');
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[DraftDeliveryManifestUseButton] Navigation failed:', err);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { applied } = this.state;
|
||||
return (
|
||||
<Button
|
||||
size="small"
|
||||
variant={applied ? 'contained' : 'outlined'}
|
||||
color={applied ? 'success' : 'primary'}
|
||||
onClick={this.handleClick}
|
||||
sx={{
|
||||
height: 20,
|
||||
minHeight: 20,
|
||||
py: 0,
|
||||
px: 0.9,
|
||||
fontSize: '0.72rem',
|
||||
fontWeight: 700,
|
||||
textTransform: 'none',
|
||||
lineHeight: 1,
|
||||
borderRadius: '4px',
|
||||
borderColor: applied ? undefined : 'rgba(0, 0, 0, 0.23)',
|
||||
bgcolor: applied ? 'success.main' : 'transparent',
|
||||
color: applied ? '#ffffff' : 'inherit',
|
||||
'&:hover': {
|
||||
bgcolor: applied ? 'success.dark' : 'action.hover',
|
||||
borderColor: applied ? undefined : 'primary.main',
|
||||
},
|
||||
}}
|
||||
>
|
||||
{applied ? '✓ Use' : 'Use'}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function WorkIconView({ tool }) {
|
||||
if (!tool || !tool.name) return null;
|
||||
const isGreen = tool?.state === 'green';
|
||||
const isUrlGet = tool?.name === 'url_get';
|
||||
const isDraftDelivery = isDraftDeliveryManifestTool(tool?.name);
|
||||
const ToolNameIcon = tool?.name ? TOOL_ICON_MAP[tool.name] : null;
|
||||
const prefix = ToolNameIcon ? tool?.name : null;
|
||||
const tooltipText = formatToolTooltip(tool?.content, tool?.result, tool?.parameters || tool?.arguments, prefix);
|
||||
const targetUrl = isUrlGet ? extractUrlFromTool(tool) : null;
|
||||
|
||||
return (
|
||||
const iconElement = (
|
||||
<ClickTooltip
|
||||
title={
|
||||
<Box
|
||||
@@ -554,6 +689,17 @@ function WorkIconView({ tool }) {
|
||||
</Box>
|
||||
</ClickTooltip>
|
||||
);
|
||||
|
||||
if (isDraftDelivery) {
|
||||
return (
|
||||
<Box sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.5 }}>
|
||||
{iconElement}
|
||||
<DraftDeliveryManifestUseButton tool={tool} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return iconElement;
|
||||
}
|
||||
|
||||
function UsageChipView({ usage }) {
|
||||
|
||||
Reference in New Issue
Block a user