-
Notifications
You must be signed in to change notification settings - Fork 29
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
Basit Ayantunde
committed
Nov 21, 2023
1 parent
b517b48
commit 9de09ea
Showing
15 changed files
with
253 additions
and
45 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
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
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 @@ | ||
// Copyright (c) Microsoft Corporation and others. Licensed under the MIT license. | ||
// SPDX-License-Identifier: MIT | ||
|
||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { getCondaSearch } from '../../../api/clearlyDefined' | ||
import { AsyncTypeahead } from 'react-bootstrap-typeahead' | ||
import searchSvg from '../../../images/icons/searchSvg.svg' | ||
|
||
export default class CondaSelector extends Component { | ||
static propTypes = { | ||
onChange: PropTypes.func | ||
} | ||
|
||
constructor(props) { | ||
super(props) | ||
this.state = { isLoading: false, options: [], focus: false } | ||
this.getOptions = this.getOptions.bind(this) | ||
this.onChange = this.onChange.bind(this) | ||
} | ||
|
||
onChange(values) { | ||
const { onChange } = this.props | ||
const value = values.length === 0 ? null : values[0] | ||
value && onChange && onChange({ type: 'conda', provider: this.props.provider, name: value.id }, 'package') | ||
} | ||
|
||
async getOptions(value) { | ||
try { | ||
this.setState({ ...this.state, isLoading: true }) | ||
console.log(`value: ${value}, provider: ${this.props.provider}`) | ||
const options = await getCondaSearch(this.props.token, `${value}/${this.props.provider}`) | ||
this.setState({ ...this.state, options, isLoading: false }) | ||
} catch (error) { | ||
this.setState({ ...this.state, options: [], isLoading: false }) | ||
} | ||
} | ||
|
||
render() { | ||
const { options, isLoading, focus } = this.state | ||
return ( | ||
<div className={`harvest-searchbar ${focus ? 'active' : ''}`}> | ||
<div className="search-logo"> | ||
<img src={searchSvg} alt="search" /> | ||
</div> | ||
<AsyncTypeahead | ||
id="conda-selector" | ||
className="harvest-search" | ||
useCache={false} | ||
options={options} | ||
placeholder={'Pick a Conda Package to harvest'} | ||
onChange={this.onChange} | ||
labelKey="id" | ||
onFocus={() => this.setState({ ...this.state, focus: true })} | ||
onBlur={() => this.setState({ ...this.state, focus: false })} | ||
clearButton | ||
highlightOnlyResult | ||
emptyLabel="" | ||
selectHintOnEnter | ||
isLoading={isLoading} | ||
onSearch={this.getOptions} | ||
/> | ||
</div> | ||
) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/components/Providers/VersionPickers/CondaVersionPicker.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,77 @@ | ||
// Copyright (c) Microsoft Corporation and others. Licensed under the MIT license. | ||
// SPDX-License-Identifier: MIT | ||
|
||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { getCondaRevisions } from '../../../api/clearlyDefined' | ||
import Autocomplete from '../../Navigation/Ui/Autocomplete' | ||
|
||
export default class CondaVersionPicker extends Component { | ||
static propTypes = { | ||
onChange: PropTypes.func, | ||
request: PropTypes.object.isRequired, | ||
defaultInputValue: PropTypes.string | ||
} | ||
|
||
constructor(props) { | ||
super(props) | ||
this.state = { customValues: [], options: [] } | ||
this.onChange = this.onChange.bind(this) | ||
this.filter = this.filter.bind(this) | ||
} | ||
|
||
componentDidMount() { | ||
this.getOptions('') | ||
} | ||
|
||
async getOptions(value) { | ||
try { | ||
console.log(`request: ${this.props.request}`) | ||
const { name, provider } = this.props.request | ||
console.log(`name: ${name}, provider: ${provider}`) | ||
const options = await getCondaRevisions(this.props.token, `${name}/${provider}`) | ||
this.setState({ ...this.state, options }) | ||
} catch (error) { | ||
this.setState({ ...this.state, options: [] }) | ||
} | ||
} | ||
|
||
onChange(values) { | ||
const { onChange } = this.props | ||
if (!onChange) return | ||
let value = values.length === 0 ? null : values[0] | ||
if (!value) return onChange(value) | ||
if (value.customOption) { | ||
value = value.label | ||
this.setState({ ...this.state, customValues: [...this.state.customValues, value] }) | ||
} | ||
onChange(value) | ||
} | ||
|
||
filter(option, props) { | ||
if (this.props.request.revision) return true | ||
return option.toLowerCase().indexOf(props.text.toLowerCase()) !== -1 | ||
} | ||
|
||
render() { | ||
const { defaultInputValue } = this.props | ||
const { customValues, options } = this.state | ||
const list = customValues.concat(options) | ||
return ( | ||
<Autocomplete | ||
id="conda-version-picker" | ||
options={list} | ||
defaultInputValue={defaultInputValue} | ||
placeholder={options.length === 0 ? 'Could not fetch versions, type a Conda version' : 'Pick a Conda version'} | ||
onChange={this.onChange} | ||
bodyContainer | ||
clearButton | ||
allowNew | ||
newSelectionPrefix="Version:" | ||
emptyLabel="" | ||
filterBy={this.filter} | ||
selectHintOnEnter | ||
/> | ||
) | ||
} | ||
} |
Oops, something went wrong.