Skip to content

Commit

Permalink
review I
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Apr 1, 2022
1 parent abeeecc commit 74113f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export const RuleErrorLog = (props: RuleErrorLogProps) => {

// Data grid states
const [logs, setLogs] = useState<IErrorLog[]>([]);
const [logList, setLogList] = useState<IErrorLog[]>([]);
const [pagination, setPagination] = useState<Pagination>({
pageIndex: 0,
pageSize: 10,
Expand Down Expand Up @@ -112,9 +111,6 @@ export const RuleErrorLog = (props: RuleErrorLogProps) => {
perPage: 1,
});
setLogs(result.errors);
const start = pagination.pageIndex * pagination.pageSize;
const logsSortDesc = result.errors.sort((a, b) => sortErrorLog(a, b, sort?.direction));
setLogList(logsSortDesc.slice(start, start + pagination.pageSize));
setPagination({
...pagination,
totalItemCount: result.totalErrors,
Expand Down Expand Up @@ -181,25 +177,17 @@ export const RuleErrorLog = (props: RuleErrorLogProps) => {
[dateFormat]
);

const logList = useMemo(() => {
const start = pagination.pageIndex * pagination.pageSize;
const logsSortDesc = logs.sort((a, b) => sortErrorLog(a, b, sort?.direction));
return logsSortDesc.slice(start, start + pagination.pageSize);
}, [logs, pagination.pageIndex, pagination.pageSize, sort?.direction]);

useEffect(() => {
loadEventLogs();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dateStart, dateEnd]);

useEffect(() => {
const start = pagination.pageIndex * pagination.pageSize;
setLogList(logs.slice(start, start + pagination.pageSize));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pagination]);

useEffect(() => {
setLogs((prevLogs) => prevLogs.sort((a, b) => sortErrorLog(a, b, sort?.direction)));
setPagination((prevPagination) => ({
...prevPagination,
pageIndex: 0,
}));
}, [sort?.direction]);

useEffect(() => {
if (isInitialized.current) {
loadEventLogs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,20 @@ export const RuleStatusDropdown: React.FunctionComponent<ComponentOpts> = ({

const onChangeEnabledStatus = useCallback(
async (enable: boolean) => {
if (item.enabled !== enable) {
setIsUpdating(true);
try {
if (enable) {
await enableRule();
} else {
await disableRule();
}
setIsEnabled(!isEnabled);
onRuleChanged();
} finally {
setIsUpdating(false);
if (item.enabled === enable) {
return;
}
setIsUpdating(true);
try {
if (enable) {
await enableRule();
} else {
await disableRule();
}
setIsEnabled(!isEnabled);
onRuleChanged();
} finally {
setIsUpdating(false);
}
},
[item.enabled, isEnabled, onRuleChanged, enableRule, disableRule]
Expand Down

0 comments on commit 74113f9

Please sign in to comment.