-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(website): [playground] rebase changes on v6
- Loading branch information
Showing
54 changed files
with
1,730 additions
and
1,792 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,52 @@ | ||
import clsx from 'clsx'; | ||
import type { Selector } from 'esquery'; | ||
import React, { useState } from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import { ErrorViewer } from './ErrorsViewer'; | ||
import styles from './ESQueryFilter.module.css'; | ||
import Text from './inputs/Text'; | ||
|
||
export interface ESQueryFilterProps { | ||
readonly onChange: (value: Selector) => void; | ||
readonly onError: (value?: Error) => void; | ||
readonly onChange: (value?: Selector) => void; | ||
} | ||
|
||
export function ESQueryFilter({ | ||
onChange, | ||
onError, | ||
}: ESQueryFilterProps): JSX.Element { | ||
const [value, setValue] = useState(''); | ||
export function ESQueryFilter({ onChange }: ESQueryFilterProps): JSX.Element { | ||
const [esQueryError, setEsQueryError] = useState<Error>(); | ||
const [inputValue, setInputValue] = useState(''); | ||
|
||
useEffect(() => { | ||
onChange(undefined); | ||
}, [onChange]); | ||
|
||
const changeEvent = (value: string): void => { | ||
setValue(value); | ||
setInputValue(value); | ||
try { | ||
const queryParsed = window.esquery.parse(value); | ||
onChange(queryParsed); | ||
onError(undefined); | ||
setEsQueryError(undefined); | ||
} catch (e: unknown) { | ||
onError(e instanceof Error ? e : new Error(String(e))); | ||
setEsQueryError(e instanceof Error ? e : new Error(String(e))); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={styles.searchContainer}> | ||
<Text | ||
value={value} | ||
type="search" | ||
name="esquery" | ||
onChange={changeEvent} | ||
placeholder="ESQuery filter" | ||
/> | ||
</div> | ||
<> | ||
<div className={clsx(styles.searchContainer, 'margin-bottom--xs')}> | ||
<Text | ||
value={inputValue} | ||
type="search" | ||
name="esquery" | ||
onChange={changeEvent} | ||
placeholder="ESQuery filter" | ||
/> | ||
</div> | ||
{esQueryError && ( | ||
<ErrorViewer | ||
type="warning" | ||
title="Invalid Selector" | ||
value={esQueryError} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.