-
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.
Merge pull request #984 from clearlydefined/master
Update prod with latest changes
- Loading branch information
Showing
15 changed files
with
249 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// (c) Copyright 2022, SAP SE and ClearlyDefined contributors. Licensed under the MIT license. | ||
// SPDX-License-Identifier: MIT | ||
|
||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { getCocoaPodsSearch } from '../api/clearlyDefined' | ||
import { AsyncTypeahead } from 'react-bootstrap-typeahead' | ||
import searchSvg from '../images/icons/searchSvg.svg' | ||
import 'react-bootstrap-typeahead/css/Typeahead.css' | ||
|
||
export default class CocoaPodsSelector extends Component { | ||
static propTypes = { | ||
onChange: PropTypes.func | ||
} | ||
|
||
constructor(props) { | ||
super(props) | ||
this.state = { isLoading: false, options: [], focus: true } | ||
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: 'pod', provider: 'cocoapods', name: value.id }, 'package') | ||
} | ||
|
||
async getOptions(value) { | ||
try { | ||
this.setState({ ...this.state, isLoading: true }) | ||
const options = await getCocoaPodsSearch(this.props.token, 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="pod-selector" | ||
className="harvest-search" | ||
useCache={false} | ||
options={options} | ||
placeholder={'Pick a CocoaPod 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> | ||
) | ||
} | ||
} |
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,91 @@ | ||
// (c) Copyright 2022, SAP SE and ClearlyDefined contributors. Licensed under the MIT license. | ||
// SPDX-License-Identifier: MIT | ||
|
||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { getCocoaPodsRevisions } from '../api/clearlyDefined' | ||
import Autocomplete from './Navigation/Ui/Autocomplete' | ||
import searchSvg from '../images/icons/searchSvg.svg' | ||
|
||
export default class CocoaPodsVersionPicker extends Component { | ||
static propTypes = { | ||
onChange: PropTypes.func, | ||
request: PropTypes.object.isRequired, | ||
defaultInputValue: PropTypes.string | ||
} | ||
|
||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
customValues: [], | ||
options: [], | ||
focus: false | ||
} | ||
this.onChange = this.onChange.bind(this) | ||
this.filter = this.filter.bind(this) | ||
} | ||
|
||
componentDidMount() { | ||
this.getOptions('') | ||
} | ||
|
||
async getOptions(value) { | ||
try { | ||
const { name } = this.props.request | ||
const options = await getCocoaPodsRevisions(this.props.token, 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, request } = this.props | ||
const selected = request.revision ? [request.revision] : [] | ||
const { customValues, options, focus } = this.state | ||
const list = customValues.concat(options) | ||
return ( | ||
<div className={`harvest-searchbar ${focus ? 'active' : ''}`}> | ||
<div className="search-logo"> | ||
<img src={searchSvg} alt="search" /> | ||
</div>{' '} | ||
<Autocomplete | ||
id="cocoapods-version-picker" | ||
selected={selected} | ||
options={list} | ||
defaultInputValue={defaultInputValue} | ||
placeholder={ | ||
options.length === 0 ? 'Could not fetch versions, type a CocoaPod version' : 'Pick a CocoaPod version' | ||
} | ||
onChange={this.onChange} | ||
onFocus={() => this.setState({ ...this.state, focus: true })} | ||
onBlur={() => this.setState({ ...this.state, focus: false })} | ||
positionFixed | ||
clearButton | ||
allowNew | ||
newSelectionPrefix="Version:" | ||
emptyLabel="" | ||
filterBy={this.filter} | ||
selectHintOnEnter | ||
/> | ||
</div> | ||
) | ||
} | ||
} |
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
Oops, something went wrong.