Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 공인IP
- listener 1883
- pm2
- c# datagridview 데이터 넣기
- datagridview 직접입력
- pm2 설치
- setInterval 외부 정지
- allow_anonymouse
- mosquitto.conf
- transfer
- invalid data
- setInterval 정지
- mosquitto
- pm2 상태 확인
- setInterval 중지
- html #select #option #multiple
- setInterval clear
- DatePicker
- 서버동기화
- 1883
- pm2 시작
- pm2 확인
- timepicker
- 맥 어드레스
- AntDesign
- 데이터테이블 데이터 넣기
- Replication
- DataGridView 직접 입력
- map이 undefined가 뜰 때
- mySQL_Replication
Archives
- Today
- Total
개발 노트
필터기능 구현 본문
1. 정렬 조건은 zutand에서 전역으로 관리
2. 렌더링부분과 count세는부분을 별도로 관리
import { useButtonStore } from '@/store/useButtonStore';
const RobotMilkingList: React.FC = () => {
const { activeFilterButton, setActiveFilterButton} = useButtonStore();
const [allCount, setAllCount] = useState(0);
const [normalCount, setNormalCount] = useState(0);
const [errorCount, setErrorCount] = useState(0);
const farmCodes = Object.keys(groupedMessages);
let sortedFarmCodes;
//정렬코드 생략
const handleClick = (e: React.MouseEvent<HTMLButtonElement>): void => {
const list = e.currentTarget.dataset.list;
if (!list) return;
setActiveFilterButton(list);
};
//렌더링 부분
const renderFarmList = () => {
let filteredFarmCodes;
switch (activeFilterButton) {
case 'error':
filteredFarmCodes = sortedFarmCodes.filter((farmCode) => (groupedMessages[farmCode].errorList.length > 0) && (groupedMessages[farmCode].robot.length > 0));
break;
case 'normal':
filteredFarmCodes = sortedFarmCodes.filter((farmCode) => (groupedMessages[farmCode].errorList.length === 0) && (groupedMessages[farmCode].robot.length > 0));
break;
case 'all':
default:
filteredFarmCodes = sortedFarmCodes.filter((farmCode) => groupedMessages[farmCode].robot.length > 0);
break;
}
return filteredFarmCodes.map((farmCode, index) => {
return (
<FarmItem
key={index}
farmCode={farmCode}
cpu={groupedMessages[farmCode].rman?.cpu}
ram={groupedMessages[farmCode].rman?.ram}
hdd={groupedMessages[farmCode].rman?.hdd}
sql={groupedMessages[farmCode].rman?.sql}
farmName={`${groupedMessages[farmCode].farmName} (${farmCode})`}
errorList={groupedMessages[farmCode].errorList.length > 0}
robotState={groupedMessages[farmCode].robot}
gateState={groupedMessages[farmCode].smartgate}
rmanTime={groupedMessages[farmCode].rman?.rmanTime}
webTime={groupedMessages[farmCode].web?.webTime}
/>
);
});
};
// 카운트를 업데이트하는 로직
useEffect(() => {
const allFiltered = sortedFarmCodes.filter((farmCode) => groupedMessages[farmCode].robot.length > 0);
const normalFiltered = sortedFarmCodes.filter((farmCode) => (groupedMessages[farmCode].errorList.length === 0) && (groupedMessages[farmCode].robot.length > 0));
const errorFiltered = sortedFarmCodes.filter((farmCode) => (groupedMessages[farmCode].errorList.length > 0) && (groupedMessages[farmCode].robot.length > 0));
setAllCount(allFiltered.length);
setNormalCount(normalFiltered.length);
setErrorCount(errorFiltered.length);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [sortedFarmCodes, activeFilterButton])
return (
<>
<section className="grid-container h-max w-full gap-y-2 py-2.5 pr-2.5">
<h2 className="sr-only">목장별 리스트</h2>
{renderFarmList()}
<SortButton />
<CountFarm allCount={allCount} normalCount={normalCount} errorCount={errorCount} onClick={handleClick}/>
</section>
</>
);
};
'React' 카테고리의 다른 글
로컬스토리지에 값 저장하기 (0) | 2024.03.22 |
---|---|
modal dialog component만들기 (0) | 2024.03.20 |
자료구조 변경 비교 (0) | 2024.03.13 |
Next.js에서 mysql2 연결하기 (net error 해결기) (0) | 2024.02.29 |
mqtt연결 시 connected반복 에러 (0) | 2024.02.28 |