Close #2050 Squashed commit of the following: commit 3bc6a409034989b914306e1c33da274730ca623e Author: ArtemBaskal <a.baskal@adguard.com> Date: Fri Sep 4 20:58:09 2020 +0300 Change dashboard block confirm message commit d4d47c3557e2166ee04db25a71b782bfbfe3b865 Merge: e8865827fc43e2acAuthor: ArtemBaskal <a.baskal@adguard.com> Date: Fri Sep 4 14:56:34 2020 +0300 Merge branch 'master' into feature/2050 commit e8865827879955b1ef62c9ff85798d07bfa4627d Author: ArtemBaskal <a.baskal@adguard.com> Date: Fri Sep 4 13:46:10 2020 +0300 Rename classname commit 648151c54e493c63622e014cb9cd1cb450f25478 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 3 19:09:21 2020 +0300 Decrease arrow size commit 4feadab707c613d31225dfa9443a9a836db37ba1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 3 18:27:41 2020 +0300 Rename button class commit c3919d8ae8d1431657ce61afad2c20e5806f279a Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 3 10:35:15 2020 +0300 Review changes: extract variables commit 0ac809584c391e41a1749a844bc1075e05a92345 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 3 10:13:57 2020 +0300 Display dashboard button on hover commit 1395287c2383e2248a2a5d39451403bd73141e55 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 2 21:24:04 2020 +0300 Do not hide button on option open commit 947f254b7aea26f289b66b66fac46dba11ea3952 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 2 21:20:19 2020 +0300 Add buttons for mobile screen commit df05697f87163a2b716d82653884e631f2fa6cf3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 2 20:18:20 2020 +0300 Change dashboard button styles commit 16655f2d6b0d79d1fa027ec2310bb0268fffaf6a Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 2 20:04:28 2020 +0300 Change button styles, rename button options commit 1ac22e875d8b26c16830bf6edb85dadcc19ff287 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 2 19:30:16 2020 +0300 Review changes commit c590119875439d85927bdd334658e003bc1f0563 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 2 17:58:08 2020 +0300 Remove default query logs form values commit 141329563417f5337f5659d5500f4cbe16d64bd2 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 2 17:41:23 2020 +0300 Update blocking buttons options logic, fix button svg size commit 9e4f39aa6cb8e134d80d496b8a248b2fe6aceb99 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 2 16:30:48 2020 +0300 Fix button position commit 8aabff7daccb87ae02c2302e62e296b3cfc17608 Merge: 415a03346b614295Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 1 17:29:55 2020 +0300 Merge branch 'master' into feature/2050 commit 415a0334561733d92a0f7badd68101ef554dc689 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 1 17:05:51 2020 +0300 Add blocking options commit bc6aed92b6e12f27c2604501275b53bb8159d5bc Merge: 0de4fb3a 40b74522 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 1 15:49:06 2020 +0300 Merge branch 'feature/infinite_scroll_query_logs' into feature/2050 commit 40b745225112cf8d664220ed8f484b0aa16e997c Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 1 15:46:27 2020 +0300 Remove dynamic translation of toasts commit 0de4fb3a4cd785c6b52e860e204c6e13d356b178 Merge: 1ab14471 f08fa7b8 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 1 15:07:30 2020 +0300 Merge branch 'feature/infinite_scroll_query_logs' into feature/2050 ... and 51 more commits
203 lines
6.5 KiB
JavaScript
203 lines
6.5 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import { Trans } from 'react-i18next';
|
|
import Modal from 'react-modal';
|
|
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
|
|
import { useHistory } from 'react-router-dom';
|
|
import queryString from 'query-string';
|
|
import classNames from 'classnames';
|
|
import {
|
|
BLOCK_ACTIONS,
|
|
SMALL_SCREEN_SIZE,
|
|
} from '../../helpers/constants';
|
|
import Loading from '../ui/Loading';
|
|
import Filters from './Filters';
|
|
import Disabled from './Disabled';
|
|
import { getFilteringStatus } from '../../actions/filtering';
|
|
import { getClients } from '../../actions';
|
|
import { getDnsConfig } from '../../actions/dnsConfig';
|
|
import {
|
|
getLogsConfig,
|
|
resetFilteredLogs,
|
|
setFilteredLogs,
|
|
toggleDetailedLogs,
|
|
} from '../../actions/queryLogs';
|
|
import InfiniteTable from './InfiniteTable';
|
|
import './Logs.css';
|
|
import { BUTTON_PREFIX } from './Cells/helpers';
|
|
|
|
const processContent = (data) => Object.entries(data)
|
|
.map(([key, value]) => {
|
|
if (!value) {
|
|
return null;
|
|
}
|
|
|
|
const isTitle = value === 'title';
|
|
const isButton = key.startsWith(BUTTON_PREFIX);
|
|
const isBoolean = typeof value === 'boolean';
|
|
const isHidden = isBoolean && value === false;
|
|
|
|
let keyClass = 'key-colon';
|
|
|
|
if (isTitle) {
|
|
keyClass = 'title--border';
|
|
}
|
|
if (isButton || isBoolean) {
|
|
keyClass = '';
|
|
}
|
|
|
|
return isHidden ? null : <div key={key}>
|
|
<div
|
|
className={classNames(`key__${key}`, keyClass, {
|
|
'font-weight-bold': isBoolean && value === true,
|
|
})}>
|
|
<Trans>{isButton ? value : key}</Trans>
|
|
</div>
|
|
<div className={`value__${key} text-pre text-truncate`}>
|
|
<Trans>{(isTitle || isButton || isBoolean) ? '' : value || '—'}</Trans>
|
|
</div>
|
|
</div>;
|
|
});
|
|
|
|
const Logs = () => {
|
|
const dispatch = useDispatch();
|
|
const history = useHistory();
|
|
|
|
const {
|
|
response_status: response_status_url_param = '',
|
|
search: search_url_param = '',
|
|
} = queryString.parse(history.location.search);
|
|
|
|
const {
|
|
enabled,
|
|
processingGetConfig,
|
|
processingAdditionalLogs,
|
|
processingGetLogs,
|
|
} = useSelector((state) => state.queryLogs, shallowEqual);
|
|
const filter = useSelector((state) => state.queryLogs.filter, shallowEqual);
|
|
const logs = useSelector((state) => state.queryLogs.logs, shallowEqual);
|
|
|
|
const search = filter?.search || search_url_param;
|
|
const response_status = filter?.response_status || response_status_url_param;
|
|
|
|
const [isSmallScreen, setIsSmallScreen] = useState(window.innerWidth < SMALL_SCREEN_SIZE);
|
|
const [detailedDataCurrent, setDetailedDataCurrent] = useState({});
|
|
const [buttonType, setButtonType] = useState(BLOCK_ACTIONS.BLOCK);
|
|
const [isModalOpened, setModalOpened] = useState(false);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
const closeModal = () => setModalOpened(false);
|
|
|
|
useEffect(() => {
|
|
(async () => {
|
|
setIsLoading(true);
|
|
await dispatch(setFilteredLogs({
|
|
search,
|
|
response_status,
|
|
}));
|
|
setIsLoading(false);
|
|
})();
|
|
}, [response_status, search]);
|
|
|
|
const mediaQuery = window.matchMedia(`(max-width: ${SMALL_SCREEN_SIZE}px)`);
|
|
const mediaQueryHandler = (e) => {
|
|
setIsSmallScreen(e.matches);
|
|
if (e.matches) {
|
|
dispatch(toggleDetailedLogs(false));
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
try {
|
|
mediaQuery.addEventListener('change', mediaQueryHandler);
|
|
} catch (e1) {
|
|
try {
|
|
// Safari 13.1 do not support mediaQuery.addEventListener('change', handler)
|
|
mediaQuery.addListener(mediaQueryHandler);
|
|
} catch (e2) {
|
|
console.error(e2);
|
|
}
|
|
}
|
|
|
|
(async () => {
|
|
setIsLoading(true);
|
|
dispatch(getFilteringStatus());
|
|
dispatch(getClients());
|
|
try {
|
|
await Promise.all([
|
|
dispatch(getLogsConfig()),
|
|
dispatch(getDnsConfig()),
|
|
]);
|
|
} catch (err) {
|
|
console.error(err);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
})();
|
|
|
|
return () => {
|
|
try {
|
|
mediaQuery.removeEventListener('change', mediaQueryHandler);
|
|
} catch (e1) {
|
|
try {
|
|
// Safari 13.1 do not support mediaQuery.addEventListener('change', handler)
|
|
mediaQuery.removeListener(mediaQueryHandler);
|
|
} catch (e2) {
|
|
console.error(e2);
|
|
}
|
|
}
|
|
|
|
dispatch(resetFilteredLogs());
|
|
};
|
|
}, []);
|
|
|
|
const renderPage = () => <>
|
|
<Filters
|
|
filter={{
|
|
response_status,
|
|
search,
|
|
}}
|
|
setIsLoading={setIsLoading}
|
|
processingGetLogs={processingGetLogs}
|
|
processingAdditionalLogs={processingAdditionalLogs}
|
|
/>
|
|
<InfiniteTable
|
|
isLoading={isLoading}
|
|
items={logs}
|
|
isSmallScreen={isSmallScreen}
|
|
setDetailedDataCurrent={setDetailedDataCurrent}
|
|
setButtonType={setButtonType}
|
|
setModalOpened={setModalOpened}
|
|
/>
|
|
<Modal portalClassName='grid' isOpen={isSmallScreen && isModalOpened}
|
|
onRequestClose={closeModal}
|
|
style={{
|
|
content: {
|
|
width: '100%',
|
|
height: 'fit-content',
|
|
left: 0,
|
|
top: 47,
|
|
padding: '1rem 1.5rem 1rem',
|
|
},
|
|
overlay: {
|
|
backgroundColor: 'rgba(0,0,0,0.5)',
|
|
},
|
|
}}
|
|
>
|
|
<svg
|
|
className="icon icon--24 icon-cross d-block d-md-none cursor--pointer"
|
|
onClick={closeModal}>
|
|
<use xlinkHref="#cross" />
|
|
</svg>
|
|
{processContent(detailedDataCurrent, buttonType)}
|
|
</Modal>
|
|
</>;
|
|
|
|
return <>
|
|
{enabled && processingGetConfig && <Loading />}
|
|
{enabled && !processingGetConfig && renderPage()}
|
|
{!enabled && !processingGetConfig && <Disabled />}
|
|
</>;
|
|
};
|
|
|
|
export default Logs;
|