persist notification filter
Summary: persist the state of the redux store of `blacklistedPlugins`, so we don't show notifications for them. This also fixes a bug where defaultFilters were not shown in the filterbar. Reviewed By: passy Differential Revision: D12924356 fbshipit-source-id: ebc5d2f5d2d3acfb5ed63d4085b65b7a78a7b05a
This commit is contained in:
committed by
Facebook Github Bot
parent
f7063448e2
commit
9fb3a56303
@@ -60,5 +60,12 @@ export default combineReducers({
|
|||||||
connections,
|
connections,
|
||||||
),
|
),
|
||||||
pluginStates,
|
pluginStates,
|
||||||
notifications,
|
notifications: persistReducer(
|
||||||
|
{
|
||||||
|
key: 'notifications',
|
||||||
|
storage,
|
||||||
|
whitelist: ['blacklistedPlugins'],
|
||||||
|
},
|
||||||
|
notifications,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,11 +15,8 @@ import Text from '../Text.js';
|
|||||||
import FlexBox from '../FlexBox.js';
|
import FlexBox from '../FlexBox.js';
|
||||||
import Glyph from '../Glyph.js';
|
import Glyph from '../Glyph.js';
|
||||||
import FilterToken from './FilterToken.js';
|
import FilterToken from './FilterToken.js';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import styled from '../../styled/index.js';
|
import styled from '../../styled/index.js';
|
||||||
|
|
||||||
const SEARCHABLE_STORAGE_KEY = (key: string) => `SEARCHABLE_STORAGE_KEY_${key}`;
|
|
||||||
|
|
||||||
const SearchBar = styled(Toolbar)({
|
const SearchBar = styled(Toolbar)({
|
||||||
height: 42,
|
height: 42,
|
||||||
padding: 6,
|
padding: 6,
|
||||||
@@ -110,12 +107,8 @@ const Searchable = (
|
|||||||
placeholder: 'Search...',
|
placeholder: 'Search...',
|
||||||
};
|
};
|
||||||
|
|
||||||
static contextTypes = {
|
|
||||||
plugin: PropTypes.string,
|
|
||||||
};
|
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
filters: [],
|
filters: this.props.defaultFilters || [],
|
||||||
focusedToken: -1,
|
focusedToken: -1,
|
||||||
searchTerm: '',
|
searchTerm: '',
|
||||||
hasFocus: false,
|
hasFocus: false,
|
||||||
@@ -127,19 +120,20 @@ const Searchable = (
|
|||||||
window.document.addEventListener('keydown', this.onKeyDown);
|
window.document.addEventListener('keydown', this.onKeyDown);
|
||||||
const {defaultFilters} = this.props;
|
const {defaultFilters} = this.props;
|
||||||
let savedState;
|
let savedState;
|
||||||
let key = this.context.plugin + this.props.tableKey;
|
|
||||||
try {
|
if (this.props.tableKey) {
|
||||||
savedState = JSON.parse(
|
try {
|
||||||
window.localStorage.getItem(SEARCHABLE_STORAGE_KEY(key)) || 'null',
|
savedState = JSON.parse(
|
||||||
);
|
window.localStorage.getItem(this.getPersistKey()) || 'null',
|
||||||
} catch (e) {
|
);
|
||||||
window.localStorage.removeItem(SEARCHABLE_STORAGE_KEY(key));
|
} catch (e) {
|
||||||
}
|
window.localStorage.removeItem(this.getPersistKey());
|
||||||
if (savedState) {
|
|
||||||
if (this.props.onFilterChange != null) {
|
|
||||||
this.props.onFilterChange(savedState.filters);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (savedState) {
|
||||||
if (defaultFilters != null) {
|
if (defaultFilters != null) {
|
||||||
|
// merge default filter with persisted filters
|
||||||
const savedStateFilters = savedState.filters;
|
const savedStateFilters = savedState.filters;
|
||||||
defaultFilters.forEach(defaultFilter => {
|
defaultFilters.forEach(defaultFilter => {
|
||||||
const filterIndex = savedStateFilters.findIndex(
|
const filterIndex = savedStateFilters.findIndex(
|
||||||
@@ -160,21 +154,20 @@ const Searchable = (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
searchTerm: savedState.searchTerm || '',
|
searchTerm: savedState.searchTerm || this.state.searchTerm,
|
||||||
filters: savedState.filters || [],
|
filters: savedState.filters || this.state.filters,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps: Props, prevState: State) {
|
componentDidUpdate(prevProps: Props, prevState: State) {
|
||||||
if (
|
if (
|
||||||
this.context.plugin &&
|
this.props.tableKey &&
|
||||||
(prevState.searchTerm !== this.state.searchTerm ||
|
(prevState.searchTerm !== this.state.searchTerm ||
|
||||||
prevState.filters !== this.state.filters)
|
prevState.filters !== this.state.filters)
|
||||||
) {
|
) {
|
||||||
let key = this.context.plugin + this.props.tableKey;
|
|
||||||
window.localStorage.setItem(
|
window.localStorage.setItem(
|
||||||
SEARCHABLE_STORAGE_KEY(key),
|
this.getPersistKey(),
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
searchTerm: this.state.searchTerm,
|
searchTerm: this.state.searchTerm,
|
||||||
filters: this.state.filters,
|
filters: this.state.filters,
|
||||||
@@ -343,6 +336,8 @@ const Searchable = (
|
|||||||
searchTerm: '',
|
searchTerm: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
getPersistKey = () => `SEARCHABLE_STORAGE_KEY_${this.props.tableKey || ''}`;
|
||||||
|
|
||||||
render(): React.Node {
|
render(): React.Node {
|
||||||
const {placeholder, actions, ...props} = this.props;
|
const {placeholder, actions, ...props} = this.props;
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user