-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3f1ff0
commit bd8f2ba
Showing
3 changed files
with
83 additions
and
1 deletion.
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
66 changes: 66 additions & 0 deletions
66
daiquiri/query/assets/js/query/components/forms/dropdowns/ExamplesDropdown.js
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,66 @@ | ||
import React, { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import classNames from 'classnames' | ||
import { isEmpty } from 'lodash' | ||
|
||
import { useUserExamplesQuery } from '../../../hooks/queries' | ||
|
||
const ExamplesDropdown = ({ onDoubleClick }) => { | ||
const { data: examples } = useUserExamplesQuery() | ||
|
||
const [activeItem, setActiveItem] = useState(null) | ||
const [filterValue, setFilterValue] = useState('') | ||
|
||
const handleClick = (item) => { | ||
if (item != activeItem) { | ||
setActiveItem(item) | ||
} | ||
} | ||
|
||
return ( | ||
<div className="mb-4"> | ||
<div className="card"> | ||
<div className="dq-browser"> | ||
<div className="dq-browser-title"> | ||
{gettext('Columns')} | ||
</div> | ||
<div className="dq-browser-filter"> | ||
<input | ||
type="text" | ||
className="form-control" | ||
placeholder={gettext('Filter experiments')} | ||
value={filterValue} | ||
onChange={(event) => setFilterValue(event.target.value)}> | ||
</input> | ||
</div> | ||
<ul className="dq-browser-list"> | ||
{ | ||
examples && examples.filter( | ||
(example) => (isEmpty(filterValue) || example.name.includes(filterValue)) | ||
).map((example) => ( | ||
<li key={example.id}> | ||
<button | ||
className={classNames('btn btn-link d-flex', {'active': activeItem === example})} | ||
onClick={() => handleClick(example)} | ||
onDoubleClick={() => onDoubleClick(example)} | ||
> | ||
<div>{example.name}</div> | ||
</button> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
</div> | ||
</div> | ||
<small className="form-text text-muted"> | ||
{gettext('A double click will replace the content of the query field with the example.')} | ||
</small> | ||
</div> | ||
) | ||
} | ||
|
||
ExamplesDropdown.propTypes = { | ||
onDoubleClick: PropTypes.func.isRequired | ||
} | ||
|
||
export default ExamplesDropdown |
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