Browse Source

관제과 페이지 체크박스 작업중

master
sanguu516 2 months ago
parent
commit
87d510dc2d
  1. 116
      src/components/flight/ControlApprovalsTable.js
  2. 1
      src/redux/features/laanc/laancState.ts

116
src/components/flight/ControlApprovalsTable.js

@ -12,6 +12,7 @@ import {
getLaancAprvList getLaancAprvList
} from '@src/redux/features/laanc/laancThunk'; } from '@src/redux/features/laanc/laancThunk';
import { ERROR_MESSAGE, ERROR_TITLE } from '@src/configs/msgConst'; import { ERROR_MESSAGE, ERROR_TITLE } from '@src/configs/msgConst';
import { CgKey } from 'react-icons/cg';
export default function ControlApprovalsTable(props) { export default function ControlApprovalsTable(props) {
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -40,6 +41,8 @@ export default function ControlApprovalsTable(props) {
const [form] = Form.useForm(); const [form] = Form.useForm();
const [checkList, setCheckList] = useState([]);
// 수정 키 확인 // 수정 키 확인
const isEditing = record => record.key === editingKey; const isEditing = record => record.key === editingKey;
@ -703,7 +706,7 @@ export default function ControlApprovalsTable(props) {
const data = []; const data = [];
record.areaList.map((item, index) => { record.areaList.map((item, index) => {
data.push({ data.push({
key: `${item.planAreaSno}-${index}`, key: `${item.planSno}`,
applyNo: item.applyNo, applyNo: item.applyNo,
applyDt: item.applyDt, applyDt: item.applyDt,
zoneNo: item.zoneNo, zoneNo: item.zoneNo,
@ -765,7 +768,10 @@ export default function ControlApprovalsTable(props) {
}) })
}; };
})} })}
dataSource={data} dataSource={record.areaList.map((item, index) => ({
...item,
key: `child_${record.planSno}_${item.planAreaSno}`
}))}
pagination={false} pagination={false}
components={{ components={{
body: { body: {
@ -791,7 +797,10 @@ export default function ControlApprovalsTable(props) {
} }
})} })}
rowSelection={{ rowSelection={{
...rowSelection ...childRowSelection,
selectedRowKeys: checkList.filter(key =>
key.startsWith(`child_${record.planSno}_`)
)
}} }}
showHeader={false} showHeader={false}
rowHoverable={false} rowHoverable={false}
@ -971,19 +980,97 @@ export default function ControlApprovalsTable(props) {
} }
}; };
const rowSelection = { // 자식 테이블 체크박스
onChange: (selectedRowKeys, selectedRows) => { const childRowSelection = {
console.log( selectedRowKeys: checkList.filter(key => key.startsWith('child_')),
`selectedRowKeys: ${selectedRowKeys}`, onChange: (selectedRowKeys, selectedRows, info) => {
'selectedRows: ', const newCheckList = checkList.filter(key => !key.startsWith('child_'));
selectedRows // console.log('>>>>', selectedRowKeys);
);
}, },
onSelect: (record, selected, selectedRows) => { onSelect: (record, selected, selectedRows) => {
console.log(record, selected, selectedRows); const key = record.key;
const newCheckList = [];
if (selected) {
newCheckList.push(...checkList, key);
} else {
newCheckList.push(...checkList.filter(k => k !== key));
}
updateCheckList(newCheckList);
}
};
// 체크박스 업데이트
const updateCheckList = list => {
const newList = [...list];
// 부모 키 업데이트
laancAprvList.forEach(parent => {
const parentKey = `parent_${parent.planSno}`;
const childKeys = parent.areaList.map(
child => `child_${parent.planSno}_${child.planAreaSno}`
);
const allChildrenChecked = childKeys.every(key => newList.includes(key));
const someChildrenChecked = childKeys.some(key => newList.includes(key));
if (allChildrenChecked) {
if (!newList.includes(parentKey)) {
newList.push(parentKey);
}
} else if (!someChildrenChecked) {
const index = newList.indexOf(parentKey);
if (index > -1) {
newList.splice(index, 1);
}
}
});
setCheckList(newList);
};
// 부모 체크박스
const rowSelection = {
selectedRowKeys: checkList,
onSelect: (record, selected, selectedRows, nativeEvent) => {
const newCheckList = [...checkList];
const key = record.key;
if (key.startsWith('parent_')) {
const childKeys = record.areaList.map(child => {
// console.log('>>', checkList);
return `child_${record.planSno}_${child.planAreaSno}`;
});
if (selected) {
newCheckList.push(key, ...childKeys);
} else {
const index = newCheckList.indexOf(key);
if (index > -1) {
newCheckList.splice(index, 1);
}
childKeys.forEach(childKey => {
const childIndex = newCheckList.indexOf(childKey);
if (childIndex > -1) {
newCheckList.splice(childIndex, 1);
}
});
}
}
updateCheckList(newCheckList);
}, },
onSelectAll: (selected, selectedRows, changeRows) => { onSelectAll: (selected, selectedRows, changeRows) => {
console.log(selected, selectedRows, changeRows); const newCheckList = selected
? laancAprvList.flatMap(parent => [
`parent_${parent.planSno}`,
...parent.areaList.map(
child => `child_${parent.planSno}_${child.planAreaSno}`
)
])
: [];
updateCheckList(newCheckList);
} }
}; };
@ -1057,10 +1144,7 @@ export default function ControlApprovalsTable(props) {
}} }}
dataSource={laancAprvList.map((item, index) => ({ dataSource={laancAprvList.map((item, index) => ({
...item, ...item,
key: key: `parent_${item.planSno}`
item.areaList.length >= 1
? `${item.planAreaSno}-${index}`
: `${item.planAreaSno}`
}))} }))}
columns={mergedColumns} columns={mergedColumns}
rowClassName={record => { rowClassName={record => {

1
src/redux/features/laanc/laancState.ts

@ -656,6 +656,7 @@ export interface ILaancAprvListRs {
planSno: number; planSno: number;
zoneNo: string; zoneNo: string;
bufferZone: number; bufferZone: number;
purpose: string;
fltElev: number; fltElev: number;
lat: number; lat: number;
fltElevMax: number; fltElevMax: number;

Loading…
Cancel
Save