forked from opensearch-project/dashboards-flow-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve search response rendering; other minor fixes (opensearch-proj…
…ect#523) Signed-off-by: Tyler Ohlsen <[email protected]>
- Loading branch information
Showing
12 changed files
with
419 additions
and
186 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { Results } from './results'; |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { | ||
EuiPanel, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiSmallButtonGroup, | ||
} from '@elastic/eui'; | ||
import { SearchResponse } from '../../../common'; | ||
import { ResultsTable } from './results_table'; | ||
import { ResultsJSON } from './results_json'; | ||
|
||
interface ResultsProps { | ||
response: SearchResponse; | ||
} | ||
|
||
enum VIEW { | ||
HITS_TABLE = 'hits_table', | ||
RAW_JSON = 'raw_json', | ||
} | ||
|
||
/** | ||
* Basic component to view OpenSearch response results. Can view hits in a tabular format, | ||
* or the raw JSON response. | ||
*/ | ||
export function Results(props: ResultsProps) { | ||
// selected view state | ||
const [selectedView, setSelectedView] = useState<VIEW>(VIEW.HITS_TABLE); | ||
|
||
return ( | ||
<EuiPanel | ||
hasBorder={false} | ||
hasShadow={false} | ||
paddingSize="none" | ||
style={{ height: '10vh', overflowY: 'scroll', overflowX: 'hidden' }} | ||
> | ||
<EuiFlexGroup | ||
direction="column" | ||
gutterSize="xs" | ||
style={{ height: '100%' }} | ||
> | ||
<EuiFlexItem grow={false}> | ||
<EuiSmallButtonGroup | ||
legend="Choose how to view your data" | ||
options={[ | ||
{ | ||
id: VIEW.HITS_TABLE, | ||
label: 'Hits', | ||
}, | ||
{ | ||
id: VIEW.RAW_JSON, | ||
label: 'Raw JSON', | ||
}, | ||
]} | ||
idSelected={selectedView} | ||
onChange={(id) => setSelectedView(id as VIEW)} | ||
data-testid="resultsToggleButtonGroup" | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true}> | ||
<> | ||
{selectedView === VIEW.HITS_TABLE && ( | ||
<ResultsTable hits={props.response?.hits?.hits || []} /> | ||
)} | ||
{selectedView === VIEW.RAW_JSON && ( | ||
<ResultsJSON response={props.response} /> | ||
)} | ||
</> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiCodeEditor } from '@elastic/eui'; | ||
import { customStringify, SearchResponse } from '../../../common'; | ||
|
||
interface ResultsJSONProps { | ||
response: SearchResponse; | ||
} | ||
|
||
/** | ||
* Small component to render the raw search response. | ||
*/ | ||
export function ResultsJSON(props: ResultsJSONProps) { | ||
return ( | ||
<EuiCodeEditor | ||
mode="json" | ||
theme="textmate" | ||
width="100%" | ||
height="100%" | ||
value={customStringify(props.response)} | ||
readOnly={true} | ||
setOptions={{ | ||
fontSize: '12px', | ||
autoScrollEditorIntoView: true, | ||
wrap: true, | ||
}} | ||
tabSize={2} | ||
/> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { | ||
EuiText, | ||
EuiButtonIcon, | ||
RIGHT_ALIGNMENT, | ||
EuiInMemoryTable, | ||
EuiCodeEditor, | ||
EuiPanel, | ||
} from '@elastic/eui'; | ||
import { customStringify, SearchHit } from '../../../common'; | ||
|
||
interface ResultsTableProps { | ||
hits: SearchHit[]; | ||
} | ||
|
||
/** | ||
* Small component to display a list of search results with pagination. | ||
* Can expand each entry to view the full _source response | ||
*/ | ||
export function ResultsTable(props: ResultsTableProps) { | ||
const [itemIdToExpandedRowMap, setItemIdToExpandedRowMap] = useState<{ | ||
[itemId: string]: any; | ||
}>({}); | ||
|
||
const toggleDetails = (hit: SearchHit) => { | ||
const itemIdToExpandedRowMapValues = { ...itemIdToExpandedRowMap }; | ||
if (itemIdToExpandedRowMapValues[hit._id]) { | ||
delete itemIdToExpandedRowMapValues[hit._id]; | ||
} else { | ||
itemIdToExpandedRowMapValues[hit._id] = ( | ||
<EuiPanel | ||
style={{ height: '20vh' }} | ||
hasShadow={false} | ||
hasBorder={false} | ||
paddingSize="none" | ||
> | ||
<EuiCodeEditor | ||
mode="json" | ||
theme="textmate" | ||
width="100%" | ||
height="100%" | ||
value={customStringify(hit._source)} | ||
readOnly={true} | ||
setOptions={{ | ||
fontSize: '12px', | ||
autoScrollEditorIntoView: true, | ||
wrap: true, | ||
}} | ||
tabSize={2} | ||
/> | ||
</EuiPanel> | ||
); | ||
} | ||
setItemIdToExpandedRowMap(itemIdToExpandedRowMapValues); | ||
}; | ||
|
||
return ( | ||
<EuiInMemoryTable | ||
itemId="_id" | ||
itemIdToExpandedRowMap={itemIdToExpandedRowMap} | ||
items={props.hits} | ||
isExpandable={true} | ||
compressed={true} | ||
pagination={true} | ||
tableLayout="auto" | ||
columns={[ | ||
{ | ||
field: '_id', | ||
name: '', | ||
sortable: false, | ||
render: (_, item: SearchHit) => { | ||
return ( | ||
<EuiText | ||
size="s" | ||
color="subdued" | ||
style={{ | ||
whiteSpace: 'nowrap', | ||
overflow: 'hidden', | ||
width: '20vw', | ||
}} | ||
> | ||
{customStringify(item._source)} | ||
</EuiText> | ||
); | ||
}, | ||
}, | ||
{ | ||
align: RIGHT_ALIGNMENT, | ||
width: '40px', | ||
isExpander: true, | ||
render: (item: SearchHit) => ( | ||
<EuiButtonIcon | ||
onClick={() => toggleDetails(item)} | ||
aria-label={ | ||
itemIdToExpandedRowMap[item._id] ? 'Collapse' : 'Expand' | ||
} | ||
iconType={ | ||
itemIdToExpandedRowMap[item._id] ? 'arrowUp' : 'arrowDown' | ||
} | ||
/> | ||
), | ||
}, | ||
]} | ||
/> | ||
); | ||
} |
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.