-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Home table #169
Home table #169
Changes from 19 commits
9bd5b7e
97b09cb
78513c4
276a590
693b261
ba84e8d
f6cd878
e7783f8
e4d33d3
6487a5a
e1437d3
679c225
2952b29
8c5bcd7
2192249
e6b4597
f45d9f7
6c103f1
514546b
37ce69e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import React, { useState, useRef, useEffect } from 'react'; | ||
|
||
import { | ||
EuiBasicTable, | ||
EuiSpacer, | ||
EuiLink, | ||
} from '@elastic/eui'; | ||
|
||
|
||
interface TableData { | ||
savedHistory: []; | ||
savedQuerySearch: (searchQuery: string, selectedDateRange: [], selectedTimeStamp, selectedFields: []) => void; | ||
} | ||
|
||
export function Table(options: TableData) { | ||
const [pageIndex, setPageIndex] = useState(0); | ||
const [pageSize, setPageSize] = useState(10); | ||
const hisRef = useRef(); | ||
hisRef.current = pageIndex; | ||
const thisRef = useRef(); | ||
thisRef.current = pageSize; | ||
|
||
|
||
const onTableChange = ({ page = {} }) => { | ||
const { index: pageIndex, size: pageSize } = page; | ||
|
||
setPageIndex(pageIndex); | ||
setPageSize(pageSize); | ||
}; | ||
|
||
const columns = [ | ||
{ | ||
field: 'data', | ||
name: 'Name', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Are we just showing the name in table? Or Are we adding Date Created and Date Modified to the table, like we have for notebooks and panels. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No we're just displaying the name of the query. All other details are just passed internally for dispatch |
||
render: (item)=>{return <EuiLink onClick={() => | ||
{options.savedQuerySearch(item.query, [item.date_start, item.date_end], item.timestamp, item.fields)}}> | ||
{item.name} | ||
</EuiLink>}, | ||
}, | ||
{ | ||
field: 'description', | ||
name: 'Description', | ||
}, | ||
]; | ||
|
||
|
||
|
||
const queries = options.savedHistory.map((h) => { | ||
const savedObject = h.hasOwnProperty('savedVisualization') | ||
? h.savedVisualization | ||
: h.savedQuery; | ||
return { | ||
data: { | ||
name: savedObject.name, | ||
query: savedObject.query, | ||
date_start: savedObject.selected_date_range.start, | ||
date_end : savedObject.selected_date_range.end, | ||
timestamp: savedObject.selected_timestamp?.name || '', | ||
fields: savedObject.selected_fields?.tokens || [] | ||
}, | ||
name: savedObject.name || '', | ||
description: savedObject.description || '', | ||
|
||
}; | ||
}); | ||
|
||
|
||
const totalItemCount = queries.length; | ||
|
||
const pagination = { | ||
pageIndex, | ||
pageSize, | ||
totalItemCount, | ||
pageSizeOptions: [5, 10, 20, 50], | ||
}; | ||
|
||
return ( | ||
<div> | ||
<EuiSpacer size="xl" /> | ||
<EuiBasicTable | ||
items={queries.slice(pageIndex * pageSize, pageIndex * pageSize + pageSize)} | ||
columns={columns} | ||
pagination={pagination} | ||
onChange={onTableChange} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Maybe a more descriptive name? Something like pageSizeRef.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I'll change it