Revert "ADG-7473 get table page size from local storage"

This reverts commit b6bf48a269.
This commit is contained in:
Ildar Kamalov 2023-10-09 19:43:02 +03:00
parent 960f3a1814
commit 830250640e
8 changed files with 34 additions and 70 deletions

View File

@ -13,7 +13,6 @@ import { BLOCK_ACTIONS, STATUS_COLORS } from '../../helpers/constants';
import { toggleClientBlock } from '../../actions/access';
import { renderFormattedClientCell } from '../../helpers/renderFormattedClientCell';
import { getStats } from '../../actions/stats';
import { LocalStorageHelper, LOCAL_STORAGE_KEYS } from '../../helpers/localStorageHelper';
const getClientsPercentColor = (percent) => {
if (percent > 50) {
@ -136,8 +135,7 @@ const Clients = ({
showPagination={false}
noDataText={t('no_clients_found')}
minRows={6}
defaultPageSize={LocalStorageHelper.getItem(LOCAL_STORAGE_KEYS.CLIENTS_PAGE_SIZE) || 100}
onPageSizeChange={(size) => LocalStorageHelper.setItem(LOCAL_STORAGE_KEYS.CLIENTS_PAGE_SIZE, size)}
defaultPageSize={100}
className="-highlight card-table-overflow--limited clients__table"
getTrProps={(_state, rowInfo) => {
if (!rowInfo) {

View File

@ -4,7 +4,6 @@ import ReactTable from 'react-table';
import { withTranslation } from 'react-i18next';
import { sortIp } from '../../../helpers/helpers';
import { MODAL_TYPE } from '../../../helpers/constants';
import { LocalStorageHelper, LOCAL_STORAGE_KEYS } from '../../../helpers/localStorageHelper';
class Table extends Component {
cellWrap = ({ value }) => (
@ -86,8 +85,7 @@ class Table extends Component {
loading={processing || processingAdd || processingDelete}
className="-striped -highlight card-table-overflow"
showPagination
defaultPageSize={LocalStorageHelper.getItem(LOCAL_STORAGE_KEYS.REWRITES_PAGE_SIZE) || 10}
onPageSizeChange={(size) => LocalStorageHelper.setItem(LOCAL_STORAGE_KEYS.REWRITES_PAGE_SIZE, size)}
defaultPageSize={10}
minRows={5}
ofText="/"
previousText={t('previous_btn')}

View File

@ -6,7 +6,6 @@ import CellWrap from '../ui/CellWrap';
import { MODAL_TYPE } from '../../helpers/constants';
import { formatDetailedDateTime } from '../../helpers/helpers';
import { isValidAbsolutePath } from '../../helpers/form';
import { LOCAL_STORAGE_KEYS, LocalStorageHelper } from '../../helpers/localStorageHelper';
class Table extends Component {
getDateCell = (row) => CellWrap(row, formatDetailedDateTime);
@ -127,17 +126,12 @@ class Table extends Component {
loading, filters, t, whitelist,
} = this.props;
const localStorageKey = whitelist
? LOCAL_STORAGE_KEYS.ALLOWLIST_PAGE_SIZE
: LOCAL_STORAGE_KEYS.BLOCKLIST_PAGE_SIZE;
return (
<ReactTable
data={filters}
columns={this.columns}
showPagination
defaultPageSize={LocalStorageHelper.getItem(localStorageKey) || 10}
onPageSizeChange={(size) => LocalStorageHelper.setItem(localStorageKey, size)}
defaultPageSize={10}
loading={loading}
minRows={6}
ofText="/"

View File

@ -9,7 +9,6 @@ import CellWrap from '../../ui/CellWrap';
import whoisCell from './whoisCell';
import LogsSearchLink from '../../ui/LogsSearchLink';
import { sortIp } from '../../../helpers/helpers';
import { LocalStorageHelper, LOCAL_STORAGE_KEYS } from '../../../helpers/localStorageHelper';
const COLUMN_MIN_WIDTH = 200;
@ -86,10 +85,7 @@ class AutoClients extends Component {
]}
className="-striped -highlight card-table-overflow"
showPagination
defaultPageSize={LocalStorageHelper.getItem(LOCAL_STORAGE_KEYS.AUTO_CLIENTS_PAGE_SIZE) || 10}
onPageSizeChange={(size) => (
LocalStorageHelper.setItem(LOCAL_STORAGE_KEYS.AUTO_CLIENTS_PAGE_SIZE, size)
)}
defaultPageSize={10}
minRows={5}
ofText="/"
previousText={t('previous_btn')}

View File

@ -19,7 +19,6 @@ import Card from '../../../ui/Card';
import CellWrap from '../../../ui/CellWrap';
import LogsSearchLink from '../../../ui/LogsSearchLink';
import Modal from '../Modal';
import { LocalStorageHelper, LOCAL_STORAGE_KEYS } from '../../../../helpers/localStorageHelper';
const ClientsTable = ({
clients,
@ -343,10 +342,7 @@ const ClientsTable = ({
]}
className="-striped -highlight card-table-overflow"
showPagination
defaultPageSize={LocalStorageHelper.getItem(LOCAL_STORAGE_KEYS.CLIENTS_PAGE_SIZE) || 10}
onPageSizeChange={(size) => (
LocalStorageHelper.setItem(LOCAL_STORAGE_KEYS.CLIENTS_PAGE_SIZE, size)
)}
defaultPageSize={10}
minRows={5}
ofText="/"
previousText={t('previous_btn')}

View File

@ -553,4 +553,6 @@ export const DISABLE_PROTECTION_TIMINGS = {
TOMORROW: 24 * 60 * 60 * 1000,
};
export const LOCAL_STORAGE_THEME_KEY = 'account_theme';
export const LOCAL_TIMEZONE_VALUE = 'Local';

View File

@ -26,8 +26,8 @@ import {
STANDARD_WEB_PORT,
SPECIAL_FILTER_ID,
THEMES,
LOCAL_STORAGE_THEME_KEY,
} from './constants';
import { LOCAL_STORAGE_KEYS, LocalStorageHelper } from './localStorageHelper';
/**
* @param time {string} The time to format
@ -680,13 +680,37 @@ export const setHtmlLangAttr = (language) => {
window.document.documentElement.lang = language;
};
/**
* Set local storage field
*
* @param {string} key
* @param {string} value
*/
export const setStorageItem = (key, value) => {
if (window.localStorage) {
window.localStorage.setItem(key, value);
}
};
/**
* Get local storage field
*
* @param {string} key
*/
export const getStorageItem = (key) => (window.localStorage
? window.localStorage.getItem(key)
: null);
/**
* Set local storage theme field
*
* @param {string} theme
*/
export const setTheme = (theme) => {
LocalStorageHelper.setItem(LOCAL_STORAGE_KEYS.THEME, theme);
setStorageItem(LOCAL_STORAGE_THEME_KEY, theme);
};
/**
@ -695,7 +719,7 @@ export const setTheme = (theme) => {
* @returns {string}
*/
export const getTheme = () => LocalStorageHelper.getItem(LOCAL_STORAGE_KEYS.THEME) || THEMES.light;
export const getTheme = () => getStorageItem(LOCAL_STORAGE_THEME_KEY) || THEMES.light;
/**
* Sets UI theme.

View File

@ -1,44 +0,0 @@
export const LOCAL_STORAGE_KEYS = {
THEME: 'account_theme',
BLOCKLIST_PAGE_SIZE: 'blocklist_page_size',
ALLOWLIST_PAGE_SIZE: 'allowlist_page_size',
CLIENTS_PAGE_SIZE: 'clients_page_size',
REWRITES_PAGE_SIZE: 'rewrites_page_size',
AUTO_CLIENTS_PAGE_SIZE: 'auto_clients_page_size',
};
export const LocalStorageHelper = {
setItem(key, value) {
try {
localStorage.setItem(key, JSON.stringify(value));
} catch (error) {
console.error(`Error setting ${key} in local storage: ${error.message}`);
}
},
getItem(key) {
try {
const item = localStorage.getItem(key);
return item ? JSON.parse(item) : null;
} catch (error) {
console.error(`Error getting ${key} from local storage: ${error.message}`);
return null;
}
},
removeItem(key) {
try {
localStorage.removeItem(key);
} catch (error) {
console.error(`Error removing ${key} from local storage: ${error.message}`);
}
},
clear() {
try {
localStorage.clear();
} catch (error) {
console.error(`Error clearing local storage: ${error.message}`);
}
},
};