-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add Conda Support #1028
Open
lamarrr
wants to merge
7
commits into
clearlydefined:master
Choose a base branch
from
lamarrr:conda-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Conda Support #1028
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bde2b29
added conda support
8c39081
integrated changes from crawler
67a75c3
updated conda harvester
a3e30ee
[conda] fixed getOptions to include namespace/subdir
5db30b5
Merge branch 'master' into conda-support
lumaxis b528b70
Merge branch 'master' into conda-support
lumaxis deb6b05
Merge branch 'master' into conda-support
elrayle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,65 @@ | ||
// 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 }) | ||
const options = await getCondaSearch(this.props.token, `${this.props.provider}/${value}`) | ||
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> | ||
) | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
// 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 { | ||
const { name, namespace, provider } = this.props.request | ||
const options = await getCondaRevisions(this.props.token, `${provider}/${namespace || '-'}/${name}`) | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is a duplicate of line 124