Introduce way to clear SearchableTable search term on mount

Summary:
In order to link to this plugin multiple times, we want to be able to clear the existing search term on entry.

This change adds a check to the `componentDidMount` section of `Searchable` to see if we want to update the existing search term from the saved state, or use the one inherited from props.

We call it from the Network tab depending on if an explicit default search term has been set, so normal navigation to and from the plugin still preserves the default behavior -- only when we enter from a `selectPlugin` call does this overwrite the existing term.

Reviewed By: mweststrate

Differential Revision: D19794860

fbshipit-source-id: 4a2b1221acc0732ffc321a16a5eee8348da019f5
This commit is contained in:
Jonathan Thomas
2020-02-11 07:20:44 -08:00
committed by Facebook Github Bot
parent 9cc5158975
commit 014524ec26
2 changed files with 6 additions and 1 deletions

View File

@@ -501,6 +501,7 @@ class NetworkTable extends PureComponent<NetworkTableProps, NetworkTableState> {
allowBodySearch={true}
zebra={false}
actions={<Button onClick={this.props.clear}>Clear Table</Button>}
clearSearchTerm={this.props.searchTerm !== ''}
defaultSearchTerm={this.props.searchTerm}
/>
</NetworkTable.ContextMenu>

View File

@@ -113,6 +113,7 @@ type Props = {
columns?: TableColumns;
onFilterChange: (filters: Array<Filter>) => void;
defaultFilters: Array<Filter>;
clearSearchTerm: boolean;
defaultSearchTerm: string;
allowRegexSearch: boolean;
allowBodySearch: boolean;
@@ -144,6 +145,7 @@ const Searchable = (
static defaultProps = {
placeholder: 'Search...',
clearSearchTerm: false,
};
state: State = {
@@ -204,7 +206,9 @@ const Searchable = (
}
});
}
const searchTerm = savedState.searchTerm || this.state.searchTerm;
const searchTerm = this.props.clearSearchTerm
? this.props.defaultSearchTerm
: savedState.searchTerm || this.state.searchTerm;
this.setState({
searchTerm: searchTerm,
filters: savedState.filters || this.state.filters,