Skip to content

Commit

Permalink
[PR feedback] Change searchPlainText prop name to searchFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Sep 15, 2023
1 parent 17d31b5 commit feb7a91
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src-docs/src/views/tables/in_memory/in_memory_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default () => {
const [incremental, setIncremental] = useState(false);
const [filters, setFilters] = useState(false);
const [contentBetween, setContentBetween] = useState(false);
const [searchPlainText, setSearchPlainText] = useState(false);
const [textSearchFormat, setTextSearchFormat] = useState(false);

const search: EuiSearchBarProps = {
box: {
Expand Down Expand Up @@ -162,17 +162,17 @@ export default () => {
/>
<EuiSwitch
label="Plain text search"
checked={searchPlainText}
onChange={() => setSearchPlainText(!searchPlainText)}
checked={textSearchFormat}
onChange={() => setTextSearchFormat(!textSearchFormat)}
/>
</EuiFlexGroup>
<EuiSpacer size="l" />
<EuiInMemoryTable
tableCaption="Demo of EuiInMemoryTable with search"
items={searchPlainText ? usersWithSpecialCharacters : users}
items={textSearchFormat ? usersWithSpecialCharacters : users}
columns={columns}
search={search}
searchPlainText={searchPlainText}
searchFormat={textSearchFormat ? 'text' : 'eql'}
pagination={true}
sorting={true}
childrenBetween={
Expand Down
4 changes: 2 additions & 2 deletions src/components/basic_table/in_memory_table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ describe('EuiInMemoryTable', () => {
});
});

describe('plain text search', () => {
describe('text search format', () => {
it('allows searching for any text with special characters in it', () => {
const specialCharacterSearch = '!@#$%^&*(){}+=-_hello:world"`<>?/👋~.,;|';
const items = [
Expand All @@ -1450,7 +1450,7 @@ describe('EuiInMemoryTable', () => {
const { getByTestSubject, container } = render(
<EuiInMemoryTable
items={items}
searchPlainText
searchFormat="text"
search={{ box: { incremental: true, 'data-test-subj': 'searchbox' } }}
columns={columns}
/>
Expand Down
22 changes: 13 additions & 9 deletions src/components/basic_table/in_memory_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ type InMemoryTableProps<T> = Omit<
*/
search?: Search;
/**
* If passed as true, search ignores all filters and EQL syntax, and anything
* typed into the table search bar is treated as plain text.
* By default, tables use `eql` format for search which allows using advanced filters.
*
* This functionality allows users to search for strings with special characters
* such as quotes, parentheses, and colons, which are normally otherwise
* reserved for EQL syntax.
* However, certain special characters (such as quotes, parentheses, and colons)
* are reserved for EQL syntax and will error if used.
* If your table does not require filter search and instead requires searching for certain
* symbols, use a plain `text` search format instead (note that filters will be ignored
* in this format).
*
* @default "eql"
*/
searchPlainText?: boolean;
searchFormat?: 'eql' | 'text';
/**
* Configures #Pagination
*/
Expand Down Expand Up @@ -298,6 +301,7 @@ export class EuiInMemoryTable<T> extends Component<
static defaultProps = {
responsive: true,
tableLayout: 'fixed',
searchFormat: 'eql',
};
tableRef: React.RefObject<EuiBasicTable>;

Expand Down Expand Up @@ -545,12 +549,12 @@ export class EuiInMemoryTable<T> extends Component<
};

renderSearchBar() {
const { search, searchPlainText } = this.props;
const { search, searchFormat } = this.props;
if (!search) return;

let searchBar: ReactNode;

if (searchPlainText) {
if (searchFormat === 'text') {
const _searchBoxProps = (search as EuiSearchBarProps)?.box || {}; // Work around | boolean type
const { schema, ...searchBoxProps } = _searchBoxProps; // Destructure `schema` so it doesn't get rendered to DOM

Expand Down Expand Up @@ -695,7 +699,7 @@ export class EuiInMemoryTable<T> extends Component<
tableLayout,
items: _unuseditems,
search,
searchPlainText,
searchFormat,
onTableChange,
executeQueryOptions,
allowNeutralSort,
Expand Down
2 changes: 1 addition & 1 deletion upcoming_changelogs/7175.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- Updated `EuiInMemoryTable` with a new `searchPlainText` prop. This boolean flag allows the built-in search bar to ignore EQL syntax and search for plain strings with special characters and symbols.
- Updated `EuiInMemoryTable` with a new `searchFormat` prop (defaults to `eql`). When setting this prop to `text`, the built-in search bar will ignore EQL syntax and allow searching for plain strings with special characters and symbols.

**Bug fixes**

Expand Down

0 comments on commit feb7a91

Please sign in to comment.