회로할당(승압설정) 오류 수정 및 Recoil 추가

This commit is contained in:
changkyu choi 2025-02-02 23:42:35 +09:00
parent 401d9c4104
commit f7dad461d8
3 changed files with 224 additions and 24 deletions

View File

@ -20,6 +20,8 @@ import { useTrestle } from '@/hooks/module/useTrestle'
import { selectedModuleState } from '@/store/selectedModuleOptions'
import { v4 as uuidv4 } from 'uuid'
import { stepUpListDataState } from '@/store/circuitTrestleAtom'
const ALLOCATION_TYPE = {
AUTO: 'auto',
PASSIVITY: 'passivity',
@ -45,6 +47,12 @@ export default function CircuitTrestleSetting({ id }) {
const selectedModules = useRecoilValue(selectedModuleState)
const { getPcsAutoRecommendList, getPcsVoltageChk } = useMasterController()
// ()
const [selectedStepUpValues, setSelectedStepUpValues] = useState({})
const [getStepUpSelections, setGetStepUpSelections] = useState(null)
const [stepUpListData, setStepUpListData] = useRecoilState(stepUpListDataState)
useEffect(() => {
if (!managementState) {
setManagementState(managementStateLoaded)
@ -59,6 +67,10 @@ export default function CircuitTrestleSetting({ id }) {
}
}, [tabNum])
useEffect(() => {
console.log('stepUpListData >>> ', stepUpListData)
}, [stepUpListData])
const onAutoRecommend = () => {
if (series.filter((s) => s.selected).length === 0) {
swalFire({
@ -331,6 +343,77 @@ export default function CircuitTrestleSetting({ id }) {
setAllocationType(ALLOCATION_TYPE.PASSIVITY)
}
// StepUp
const handleStepUpValuesSelected = (selectionData) => {
const { gooodsNo } = selectionData
setSelectedStepUpValues((prev) => ({
...prev,
[gooodsNo]: selectionData,
}))
}
// StepUp
const handleStepUpInitialize = (getCurrentSelections) => {
setGetStepUpSelections(() => getCurrentSelections)
}
// apply
const onApply = () => {
//
const currentSelections = getStepUpSelections ? getStepUpSelections() : {}
console.log('currentSelections >>> ', currentSelections)
//
const hasSelections = Object.values(currentSelections).some((stepUpConfig) => Object.values(stepUpConfig).length > 0)
console.log('hasSelections >>> ', hasSelections)
if (!hasSelections) {
swalFire({
title: '승압 설정값을 선택해주세요.1',
type: 'alert',
})
return
}
//
console.log('Applying StepUp configurations:', currentSelections)
// StepUp stepUpListData
//const stepUpData = getStepUpSelections().stepUpListData
//console.log('stepUpData >>> ', stepUpData)
// stepUpListData Recoil state
// setStepUpListData(stepUpData)
//
const configurations = Object.values(currentSelections)
.map((stepUpConfig) => {
const firstConfig = Object.values(stepUpConfig)[0] //
return {
pcsInfo: firstConfig.pcsInfo,
allocation: firstConfig.allocation,
}
})
.filter((config) => config.pcsInfo && config.allocation) //
console.log('Processed configurations:', configurations)
// stepUpListData Recoil state
setStepUpListData(configurations)
// apply
if (configurations.length > 0) {
apply()
} else {
swalFire({
title: '승압 설정값을 선택해주세요.2',
type: 'alert',
})
}
}
const onClickPrev = () => {
setAllocationType(ALLOCATION_TYPE.AUTO)
swalFire({
@ -388,6 +471,7 @@ export default function CircuitTrestleSetting({ id }) {
getUseModuleItemList, // List
getRoofSurfaceList, //
getPcsItemList, // PCS
onValuesSelected: handleStepUpValuesSelected, //
}
return (
@ -409,7 +493,7 @@ export default function CircuitTrestleSetting({ id }) {
</div>
{tabNum === 1 && allocationType === ALLOCATION_TYPE.AUTO && <PowerConditionalSelect {...powerConditionalSelectProps} />}
{tabNum === 1 && allocationType === ALLOCATION_TYPE.PASSIVITY && <PassivityCircuitAllocation {...passivityProps} />}
{tabNum === 2 && <StepUp {...stepUpProps} />}
{tabNum === 2 && <StepUp {...stepUpProps} onInitialize={handleStepUpInitialize} />}
{tabNum === 1 && allocationType === ALLOCATION_TYPE.AUTO && (
<div className="grid-btn-wrap">
<button className="btn-frame modal mr5" onClick={() => onAutoAllocation()}>
@ -435,7 +519,8 @@ export default function CircuitTrestleSetting({ id }) {
<button className="btn-frame modal mr5" onClick={() => setTabNum(1)}>
{getMessage('modal.common.prev')}
</button>
<button className="btn-frame modal act" onClick={() => apply()}>
{/* <button className="btn-frame modal act" onClick={() => apply()}> */}
<button className="btn-frame modal act" onClick={onApply}>
{getMessage('modal.common.save')}({getMessage('modal.circuit.trestle.setting.circuit.allocation')})
</button>
</div>

View File

@ -27,6 +27,9 @@ export default function StepUp(props) {
const [selectedRows, setSelectedRows] = useState({})
const [isManualSelection, setIsManualSelection] = useState({})
//
const [selectedValues, setSelectedValues] = useState({})
// useCanvasPopupStatusController(6)
// const canvasPopupStatusState = useRecoilValue(canvasPopupStatusStore)
// if (Object.keys(canvasPopupStatusState[6]).length !== 0) {
@ -76,14 +79,59 @@ export default function StepUp(props) {
}))
}
// PCS
// // PCS
// const formatStepUpListData = (dataArray = []) => {
// return dataArray?.map((stepUps) => ({
// ...stepUps,
// optionList: formatOptionList(stepUps.optionList),
// pcsItemList: formatPcsItemList(stepUps.pcsItemList),
// selectedPcsItem: formatPcsItemList(stepUps.pcsItemList),
// }))
// }
// PCS
const formatStepUpListData = (dataArray = []) => {
return dataArray?.map((stepUps) => ({
const formattedData = dataArray?.map((stepUps) => ({
...stepUps,
optionList: formatOptionList(stepUps.optionList),
pcsItemList: formatPcsItemList(stepUps.pcsItemList),
selectedPcsItem: formatPcsItemList(stepUps.pcsItemList),
}))
// selectedValues
const initialSelectedValues = {}
formattedData.forEach((stepUp) => {
stepUp.pcsItemList.forEach((pcsItem, pcsIdx) => {
const pcsKey = `${stepUp.id}_${pcsIdx}`
// (rmdYn === 'Y')
const recommendedRow = pcsItem.serQtyList.find((item) => item.rmdYn === 'Y')
if (recommendedRow) {
const selectionData = {
stepUpId: pcsItem.goodsNo,
pcsInfo: {
itemId: pcsItem.itemId,
goodsNo: pcsItem.goodsNo,
pcsMkrCd: pcsItem.pcsMkrCd,
pcsSerCd: pcsItem.pcsSerCd,
},
allocation: {
serQty: recommendedRow.serQty,
paralQty: recommendedRow.paralQty,
},
}
initialSelectedValues[stepUp.id] = {
...initialSelectedValues[stepUp.id],
[pcsKey]: selectionData,
}
}
})
})
setSelectedValues(initialSelectedValues)
return formattedData
}
// PCS
@ -133,21 +181,60 @@ export default function StepUp(props) {
}
//
const handleTabChange = (stepUpId, idx, tabNumber) => {
const handleTabChange = (goodsNo, idx, tabNumber) => {
setModuleTabs((prev) => ({
...prev,
[`${stepUpId}_${idx}`]: tabNumber,
[`${goodsNo}_${idx}`]: tabNumber,
}))
}
//
const handleRowClick = (stepUpId, pcsIdx, serQtyIdx) => {
const rowKey = `${stepUpId}_${pcsIdx}_${serQtyIdx}`
const pcsKey = `${stepUpId}_${pcsIdx}`
const handleRowClick = (goodsNo, pcsIdx, serQtyIdx, serQty, paralQty) => {
const rowKey = `${goodsNo}_${pcsIdx}_${serQtyIdx}`
const pcsKey = `${goodsNo}_${pcsIdx}`
console.log('goodsNo >> ', goodsNo, serQty, paralQty)
// PCS
const pcsItem = stepUpListData.find((stepUp) => stepUp.pcsItemList.find((item) => item.goodsNo === goodsNo))?.pcsItemList[pcsIdx]
if (!pcsItem) {
console.error('PCS item not found:', { goodsNo, pcsIdx })
return
}
// -
const selectionData = {
goodsNo: goodsNo,
pcsInfo: {
itemId: pcsItem?.itemId,
goodsNo: pcsItem?.goodsNo,
pcsMkrCd: pcsItem?.pcsMkrCd,
pcsSerCd: pcsItem?.pcsSerCd,
},
allocation: {
serQty: serQty,
paralQty: paralQty,
},
}
//
setSelectedValues((prev) => ({
...prev,
[goodsNo]: {
...prev[goodsNo],
[pcsKey]: selectionData,
},
}))
//
if (props.onValuesSelected) {
props.onValuesSelected(selectionData)
}
setSelectedRows((prev) => {
// stepUpId
const currentStepUpSelections = prev[stepUpId] || {}
const currentStepUpSelections = prev[goodsNo] || {}
// ,
if (currentStepUpSelections[pcsKey] === rowKey) {
@ -156,7 +243,7 @@ export default function StepUp(props) {
return {
...prev,
[stepUpId]: {
[goodsNo]: {
...currentStepUpSelections,
[pcsKey]: rowKey,
},
@ -166,13 +253,36 @@ export default function StepUp(props) {
// ,
setIsManualSelection((prev) => ({
...prev,
[stepUpId]: {
...prev[stepUpId],
[goodsNo]: {
...prev[goodsNo],
[pcsKey]: true,
},
}))
}
//
const getCurrentSelections = () => {
return selectedValues
}
// props getCurrentSelections
useEffect(() => {
if (props.onInitialize) {
props.onInitialize(getCurrentSelections)
}
}, [])
// stepUpListData useEffect
useEffect(() => {
if (props.onInitialize) {
// onInitialize props
props.onInitialize(() => ({
...getCurrentSelections(),
stepUpListData, // stepUpListData
}))
}
}, [stepUpListData])
return (
<>
<div className="properties-setting-wrap outer">
@ -194,18 +304,18 @@ export default function StepUp(props) {
</thead>
<tbody>
{stepUp.pcsItemList[idx].serQtyList.map((item, serQtyIdx) => {
const rowKey = `${stepUp.id}_${idx}_${serQtyIdx}`
const pcsKey = `${stepUp.id}_${idx}`
const rowKey = `${stepUp.pcsItemList[idx].goodsNo}_${idx}_${serQtyIdx}`
const pcsKey = `${stepUp.pcsItemList[idx].goodsNo}_${idx}`
return (
<tr
key={rowKey}
className={`${
(!isManualSelection[stepUp.id]?.[pcsKey] && item.rmdYn === 'Y') ||
(selectedRows[stepUp.id] && selectedRows[stepUp.id][pcsKey] === rowKey)
(!isManualSelection[stepUp.pcsItemList[idx].goodsNo]?.[pcsKey] && item.rmdYn === 'Y') ||
(selectedRows[stepUp.pcsItemList[idx].goodsNo] && selectedRows[stepUp.pcsItemList[idx].goodsNo][pcsKey] === rowKey)
? 'on'
: ''
}`}
onClick={() => handleRowClick(stepUp.id, idx, serQtyIdx)}
onClick={() => handleRowClick(stepUp.pcsItemList[idx].goodsNo, idx, serQtyIdx, item.serQty, item.paralQty)}
style={{ cursor: 'pointer' }}
>
<td className="al-r">{item.serQty}</td>
@ -219,20 +329,20 @@ export default function StepUp(props) {
</div>
<div className="module-box-tab mb10">
<button
className={`module-btn ${(moduleTabs[`${stepUp.id}_${idx}`] || 1) === 1 ? 'act' : ''}`}
onClick={() => handleTabChange(stepUp.id, idx, 1)}
className={`module-btn ${(moduleTabs[`${stepUp.pcsItemList[idx].goodsNo}_${idx}`] || 1) === 1 ? 'act' : ''}`}
onClick={() => handleTabChange(stepUp.pcsItemList[idx].goodsNo, idx, 1)}
>
{getMessage('modal.circuit.trestle.setting.step.up.allocation.connected')}
</button>
<button
className={`module-btn ${(moduleTabs[`${stepUp.id}_${idx}`] || 1) === 2 ? 'act' : ''}`}
onClick={() => handleTabChange(stepUp.id, idx, 2)}
className={`module-btn ${(moduleTabs[`${stepUp.pcsItemList[idx].goodsNo}_${idx}`] || 1) === 2 ? 'act' : ''}`}
onClick={() => handleTabChange(stepUp.pcsItemList[idx].goodsNo, idx, 2)}
>
{getMessage('modal.circuit.trestle.setting.step.up.allocation.option')}
</button>
</div>
<div className="circuit-table-flx-wrap">
{(moduleTabs[`${stepUp.id}_${idx}`] || 1) === 1 && (
{(moduleTabs[`${stepUp.pcsItemList[idx].goodsNo}_${idx}`] || 1) === 1 && (
<div className="circuit-table-flx-box">
<div className="roof-module-table min mb10">
<table>
@ -262,7 +372,7 @@ export default function StepUp(props) {
</div>
</div>
)}
{(moduleTabs[`${stepUp.id}_${idx}`] || 1) === 2 && (
{(moduleTabs[`${stepUp.pcsItemList[idx].goodsNo}_${idx}`] || 1) === 2 && (
<div className="circuit-table-flx-box">
<div className="roof-module-table min mb10">
<table>

View File

@ -44,3 +44,8 @@ export const moduleStatisticsState = atom({
},
dangerouslyAllowMutability: true,
})
export const stepUpListDataState = atom({
key: 'stepUpListDataState',
default: [],
})