| | |
| | | import React, { useState, useEffect, useMemo } from 'react'; |
| | | import React, { useState, useEffect } from 'react'; |
| | | import { useTranslate } from "react-admin"; |
| | | import { |
| | | Drawer, |
| | |
| | | import { PAGE_DRAWER_WIDTH } from '@/config/setting'; |
| | | import AreaBasicTab from './AreaBasicTab'; |
| | | import AreaAdvancedTab from './AreaAdvancedTab'; |
| | | import { getAreaInfo, fetchAgvListAll } from '../http'; |
| | | import { getAreaInfo, fetchAgvListAll, updateAreaData, removeArea } from '../http'; |
| | | |
| | | const getAgvOptionId = (option) => { |
| | | if (typeof option === 'string') { |
| | | return option; |
| | | if (option == null) { |
| | | return ''; |
| | | } |
| | | return option?.value ?? option?.id ?? option?.agvNo ?? option?.code ?? option?.name ?? ''; |
| | | if (typeof option === 'string' || typeof option === 'number') { |
| | | return String(option); |
| | | } |
| | | return option?.id ?? ''; |
| | | }; |
| | | |
| | | const areAgvSelectionsEqual = (aIds = [], bIds = []) => { |
| | |
| | | |
| | | const mapSelectionToOptions = (selection = [], options = []) => { |
| | | const optionMap = new Map(options.map(option => [getAgvOptionId(option), option])); |
| | | return selection.map(item => optionMap.get(getAgvOptionId(item)) || item); |
| | | return selection |
| | | .map(item => optionMap.get(item) || null) |
| | | .filter(Boolean); |
| | | |
| | | }; |
| | | |
| | | const AreaSettings = (props) => { |
| | |
| | | }, [sprite]); |
| | | |
| | | useEffect(() => { |
| | | if (!open) { |
| | | return; |
| | | } |
| | | fetchAgvListAll().then((options) => { |
| | | setAgvOptions(options || []); |
| | | }); |
| | | }, []); |
| | | }, [open]); |
| | | |
| | | useEffect(() => { |
| | | if (curAreaInfo) { |
| | |
| | | setActiveTab(newValue); |
| | | }; |
| | | |
| | | const handleSaveBasic = () => { |
| | | // placeholder for save logic |
| | | setInitialBasic({ |
| | | const handleSaveBasic = async () => { |
| | | console.log(agvList); |
| | | const id = sprite?.data?.id; |
| | | if (!id) { |
| | | return; |
| | | } |
| | | const payload = { |
| | | id, |
| | | name, |
| | | agvIds: agvList.map(getAgvOptionId), |
| | | }); |
| | | }; |
| | | const data = await updateAreaData(payload); |
| | | if (data) { |
| | | setCurAreaInfo(data); |
| | | } |
| | | }; |
| | | |
| | | const handleDeleteArea = async () => { |
| | | const id = sprite?.data?.id; |
| | | if (!id) { |
| | | return; |
| | | } |
| | | const success = await removeArea(id); |
| | | if (success) { |
| | | onCancel?.(); |
| | | } |
| | | }; |
| | | |
| | | const handleSaveAdvanced = () => { |
| | | // placeholder for save logic |
| | | }; |
| | | |
| | | const codeListText = (codeList || []).join('\n'); |
| | | const basicDirty = name !== initialBasic.name |
| | | || !areAgvSelectionsEqual( |
| | | agvList.map(getAgvOptionId), |
| | | initialBasic.agvIds |
| | | ); |
| | | |
| | | return ( |
| | | <> |
| | | <Drawer |
| | |
| | | agvOptions={agvOptions} |
| | | agvList={agvList} |
| | | setAgvList={setAgvList} |
| | | codeListText={codeListText} |
| | | codeList={codeList} |
| | | onSave={handleSaveBasic} |
| | | disableSave={!basicDirty} |
| | | onDelete={handleDeleteArea} |
| | | canDelete={Boolean(sprite?.data?.id)} |
| | | /> |
| | | )} |
| | | {activeTab === 1 && ( |