Component
diff --git a/src/components/DefinitionEntry.js b/src/components/DefinitionEntry.js
index bc24e603a..c4bd4646e 100644
--- a/src/components/DefinitionEntry.js
+++ b/src/components/DefinitionEntry.js
@@ -3,7 +3,7 @@
import React from 'react'
import PropTypes from 'prop-types'
-import { TwoLineEntry, QuickEditModel, SourcePicker, FileCountRenderer } from './'
+import { TwoLineEntry, QuickEditModel, FileCountRenderer } from './'
import { Checkbox, OverlayTrigger, Tooltip, Popover } from 'react-bootstrap'
import { Tag } from 'antd'
import { get, isEqual, union } from 'lodash'
@@ -34,7 +34,7 @@ class DefinitionEntry extends React.Component {
}
}
static propTypes = {
- onChange: PropTypes.func,
+ onChange: PropTypes.func.isRequired,
onCurate: PropTypes.func,
onInspect: PropTypes.func,
activeFacets: PropTypes.array,
@@ -60,7 +60,7 @@ class DefinitionEntry extends React.Component {
const newChanges = { ...component.changes }
if (isChanged && proposedValue !== null) newChanges[field] = proposedValue
else delete newChanges[field]
- onChange && onChange(component, newChanges, field)
+ onChange(component, newChanges, field)
}
}
@@ -90,10 +90,10 @@ class DefinitionEntry extends React.Component {
) : null
- const releasedDate = definition?.described?.releaseDate ? (
-
{definition.described.releaseDate}
- ) : (
-
-- -- --
+ const releasedDate = (
+
+ {this.renderFieldWithToolTipIfDifferent('described.releaseDate', a => a || '-- -- --')}
+
)
const curationTag = isCurationPending ? (
@@ -125,7 +125,7 @@ class DefinitionEntry extends React.Component {
renderWithToolTipIfDifferent(field, content, placement = 'right', transform = x => x) {
const toolTip = (
- Original: {transform(get(this.props.otherDefinition, field))}
+ Original: {transform(this.getOriginalValue(field))}
)
return this.ifDifferent(
@@ -137,14 +137,19 @@ class DefinitionEntry extends React.Component {
)
}
+ renderFieldWithToolTipIfDifferent(field, transform = a => a) {
+ const displayValue = transform(this.getValue(field))
+ return this.renderWithToolTipIfDifferent(
+ field,
+ {displayValue},
+ undefined,
+ transform
+ )
+ }
+
renderMessage(definition) {
const licenseExpression = definition ? this.getValue('licensed.declared') : null
- return licenseExpression
- ? this.renderWithToolTipIfDifferent(
- 'licensed.declared',
- {licenseExpression}
- )
- : null
+ return licenseExpression ? this.renderFieldWithToolTipIfDifferent('licensed.declared') : null
}
getPercentage(count, total) {
@@ -190,6 +195,23 @@ class DefinitionEntry extends React.Component {
this.setState({ modelOpen: !this.state.modelOpen })
}
+ handleSaveEdit = updates => {
+ const { onChange, definition, component } = this.props
+
+ const newChanges = Object.entries(updates).reduce((changes, [key, value]) => {
+ let field
+ if (key === 'declared') field = 'licensed.declared'
+ if (key === 'sourceComponent') field = 'described.sourceLocation'
+ if (key === 'release') field = 'described.releaseDate'
+ return field ? Contribution.applyChanges(definition, changes, field, value) : changes
+ }, {})
+
+ if (Object.keys(newChanges).length !== 0) {
+ const combinedChanges = { ...component.changes, ...newChanges }
+ onChange(component, combinedChanges)
+ }
+ }
+
renderPanel(rawDefinition) {
if (!rawDefinition)
return (
@@ -201,13 +223,12 @@ class DefinitionEntry extends React.Component {
// TODO: find a way of calling this method less frequently. It's relatively expensive.
const definition = this.foldFacets(rawDefinition, this.props.activeFacets)
const { licensed } = definition
- const { readOnly, onRevert } = this.props
return (
{this.renderLabel('Declared')}:
-
{this.getValue('licensed.declared')}
+ {this.renderFieldWithToolTipIfDifferent('licensed.declared')}
{/* {this.renderWithToolTipIfDifferent(
'licensed.declared',
{this.renderLabel('Source')}:
-
{Contribution.printCoordinates(this.getValue('described.sourceLocation'))}
+ {this.renderFieldWithToolTipIfDifferent('described.sourceLocation', a => Contribution.printCoordinates(a))}
{/* {this.renderWithToolTipIfDifferent(
'described.sourceLocation',
{this.renderLabel('Release')}:
-
{Contribution.printDate(this.getValue('described.releaseDate'))}
+ {this.renderFieldWithToolTipIfDifferent(
+ 'described.releaseDate',
+ a => Contribution.printDate(a) || '-- -- --'
+ )}
{/* {this.renderWithToolTipIfDifferent(
'described.releaseDate',
true}
- placeholder={'Source location'}
- revertable
- onRevert={() => onRevert('described.sourceLocation')}
+ onSave={this.handleSaveEdit}
/>
-
+ {toggleCollapseExpandAll && (
+
+ )}
diff --git a/src/components/Navigation/Pages/PageBrowse/PageBrowse.js b/src/components/Navigation/Pages/PageBrowse/PageBrowse.js
index 1ebb79d24..12aace61d 100644
--- a/src/components/Navigation/Pages/PageBrowse/PageBrowse.js
+++ b/src/components/Navigation/Pages/PageBrowse/PageBrowse.js
@@ -10,7 +10,7 @@ import difference from 'lodash/difference'
import classNames from 'classnames'
import { ROUTE_ROOT } from '../../../../utils/routingConstants'
import { getCurationsAction } from '../../../../actions/curationActions'
-import { uiBrowseUpdateList, uiNavigation, uiBrowseGet } from '../../../../actions/ui'
+import { uiBrowseUpdateFilterList, uiBrowseUpdateList, uiNavigation, uiBrowseGet } from '../../../../actions/ui'
import SystemManagedList from '../../../SystemManagedList'
import Section from '../../../Section'
import ComponentList from '../../../ComponentList'
@@ -34,7 +34,8 @@ class PageBrowse extends SystemManagedList {
this.state = {
activeSort: 'releaseDate-desc',
searchFocused: false,
- selectedProvider: providers[0]
+ selectedProvider: providers[0],
+ searchTerm: ''
}
this.onFilter = this.onFilter.bind(this)
this.onSort = this.onSort.bind(this)
@@ -63,13 +64,19 @@ class PageBrowse extends SystemManagedList {
}
onBrowse = value => {
- this.setState({ activeName: value }, () => this.updateData())
+ this.setState({ activeName: value, searchTerm: '' }, () => this.updateData())
}
onFocusChange = value => {
this.setState({ searchFocused: value })
}
+ onSearch = value => {
+ this.setState({ searchTerm: value })
+ const valueToSearch = this.state.selectedProvider.value + '/' + value
+ this.props.dispatch(uiBrowseUpdateFilterList(this.props.token, valueToSearch))
+ }
+
tableTitle() {
return 'Browse'
}
@@ -156,7 +163,6 @@ class PageBrowse extends SystemManagedList {
this.revertAll('browse')}
- toggleCollapseExpandAll={this.toggleCollapseExpandAll}
doPromptContribute={this.doPromptContribute}
/>
)
@@ -164,6 +170,10 @@ class PageBrowse extends SystemManagedList {
onProviderChange(item) {
this.setState({ selectedProvider: item })
+ if (this.state.searchTerm) {
+ const valueToSearch = item.value + '/' + this.state.searchTerm
+ this.props.dispatch(uiBrowseUpdateFilterList(this.props.token, valueToSearch))
+ }
}
// Overrides the default onFilter method
@@ -332,10 +342,8 @@ class PageBrowse extends SystemManagedList {
/>
-
-
+
+
this.revertDefinition(definition, value, 'browse')}
onChange={this.onChangeComponent}
- onInspect={this.onInspect}
renderFilterBar={this.renderFilterBar}
curations={curations}
definitions={definitions}
diff --git a/src/components/Navigation/Pages/PageBrowse/__tests__/ButtonsBar.test.js b/src/components/Navigation/Pages/PageBrowse/__tests__/ButtonsBar.test.js
index b4182be04..cdc164b39 100644
--- a/src/components/Navigation/Pages/PageBrowse/__tests__/ButtonsBar.test.js
+++ b/src/components/Navigation/Pages/PageBrowse/__tests__/ButtonsBar.test.js
@@ -12,7 +12,7 @@ describe('ButtonsBar', () => {
})
it("checks if buttons are enabled when there aren't changes", async () => {
- const wrapper = await shallow()
+ const wrapper = await shallow()
const toggleCollapseButton = wrapper.find({ children: 'Toggle Collapse' })
expect(toggleCollapseButton.exists()).toBeTruthy()
const contributeButton = wrapper.find({ children: 'Contribute' })
@@ -21,7 +21,9 @@ describe('ButtonsBar', () => {
})
it('checks if buttons are disabled when there are changes', async () => {
- const wrapper = await shallow()
+ const wrapper = await shallow(
+
+ )
const toggleCollapseButton = wrapper.find({ children: 'Toggle Collapse' })
expect(toggleCollapseButton.exists()).toBeTruthy()
const contributeButton = wrapper.find({ children: 'Contribute' })
diff --git a/src/components/Navigation/Pages/PageDefinitions/ButtonsBar.js b/src/components/Navigation/Pages/PageDefinitions/ButtonsBar.js
index cb8606963..f10fd0f27 100644
--- a/src/components/Navigation/Pages/PageDefinitions/ButtonsBar.js
+++ b/src/components/Navigation/Pages/PageDefinitions/ButtonsBar.js
@@ -5,6 +5,11 @@ import ButtonWithTooltip from '../../Ui/ButtonWithTooltip'
import ShareButton from '../../Ui/ShareButton'
export default class ButtonsBar extends Component {
+ constructor(props) {
+ super(props)
+ this.onSelect = this.onSelect.bind(this)
+ }
+
static propTypes = {
components: PropTypes.object,
hasChanges: PropTypes.bool,
diff --git a/src/components/Navigation/Pages/PageDefinitions/PageDefinitions.js b/src/components/Navigation/Pages/PageDefinitions/PageDefinitions.js
index e52852dc7..ef6e3d701 100644
--- a/src/components/Navigation/Pages/PageDefinitions/PageDefinitions.js
+++ b/src/components/Navigation/Pages/PageDefinitions/PageDefinitions.js
@@ -23,7 +23,6 @@ import UrlShare from '../../../../utils/urlShare'
export class PageDefinitions extends UserManagedList {
constructor(props) {
super(props)
- this.onAddComponent = this.onAddComponent.bind(this)
this.doSave = this.doSave.bind(this)
this.doSaveAsUrl = this.doSaveAsUrl.bind(this)
this.revertAll = this.revertAll.bind(this)
@@ -225,7 +224,7 @@ export class PageDefinitions extends UserManagedList {
path={path}
currentDefinition={currentDefinition}
component={currentComponent}
- readOnly={this.readOnly}
+ readOnly={true}
/>
)}
{showSavePopup && (
diff --git a/src/components/Navigation/Ui/ComponentButtons.js b/src/components/Navigation/Ui/ComponentButtons.js
index 9036dfc53..acf9a4797 100644
--- a/src/components/Navigation/Ui/ComponentButtons.js
+++ b/src/components/Navigation/Ui/ComponentButtons.js
@@ -1,12 +1,17 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { get } from 'lodash'
-import { ButtonToolbar, Dropdown as BSDropdown } from 'react-bootstrap'
+import { Button, ButtonGroup, ButtonToolbar, Dropdown as BSDropdown } from 'react-bootstrap'
import EntitySpec from '../../../utils/entitySpec'
import { ROUTE_DEFINITIONS } from '../../../utils/routingConstants'
import { withResize } from '../../../utils/WindowProvider'
+import Definition from '../../../utils/definition'
+import { ORIGINS } from '../../../api/clearlyDefined'
import MoreVertIcon from '@material-ui/icons/MoreVert'
import { IconButton } from '@material-ui/core'
+import ButtonWithTooltip from './ButtonWithTooltip'
+import { Menu, Dropdown, Icon } from 'antd'
+
class ComponentButtons extends Component {
constructor(props) {
super(props)
@@ -30,25 +35,33 @@ class ComponentButtons extends Component {
return ['github', 'sourcearchive', 'debsrc'].includes(component.provider)
}
+ _isProviderSupported(component) {
+ return !!get(ORIGINS, component.provider)
+ }
+
removeComponent(component, event) {
event.stopPropagation()
+ this.handleMenu()
const { onRemove } = this.props
onRemove && onRemove(component)
}
revertComponent(component, param) {
+ this.handleMenu()
const { onRevert } = this.props
onRevert && onRevert(component, param)
}
inspectComponent(component, definition, event) {
event.stopPropagation()
+ this.handleMenu()
const action = this.props.onInspect
action && action(component, definition)
}
addSourceForComponent(component, event) {
event.stopPropagation()
+ this.handleMenu()
const definition = this.props.getDefinition(component)
const sourceLocation = get(definition, 'described.sourceLocation')
const sourceEntity = sourceLocation && EntitySpec.fromObject(sourceLocation)
@@ -58,6 +71,7 @@ class ComponentButtons extends Component {
showVersionSelectorPopup(component, multiple, event) {
event.domEvent.stopPropagation()
+ this.handleMenu()
this.props.showVersionSelectorPopup(component, multiple)
}
@@ -77,111 +91,109 @@ class ComponentButtons extends Component {
)
}
+ renderDropdown(currentComponent) {
+ return (
+
+
+ Switch version
+
+
+ Add more versions
+
+
+ }
+ >
+
+
+ )
+ }
+
renderButtonGroup() {
- const { definition, currentComponent, hasChange } = this.props
+ const {
+ definition,
+ currentComponent,
+ hasChange,
+ readOnly,
+ onAddComponent,
+ onInspect,
+ onRemove,
+ hideVersionSelector
+ } = this.props
const component = EntitySpec.fromObject(currentComponent)
+
+ const isSourceComponent = this.isSourceComponent(component)
+ const isSourceEmpty = Definition.isSourceEmpty(definition)
+ const isDefinitionEmpty = Definition.isDefinitionEmpty(definition)
+ const isProviderSupported = this._isProviderSupported(component)
return (
<>
-
{
- this.handleMenu()
- }}
- className="clearly-menu-btns"
- >
- View Components
-
-
-
-
-
- {/*
-
- {!isSourceComponent && !readOnly && !isSourceEmpty && (
-
-
-
- )}
- {!isDefinitionEmpty && (
-
+
+ {!isSourceComponent && !readOnly && !isSourceEmpty && onAddComponent && (
+
+
+
+ )}
+ {!isDefinitionEmpty && onInspect && (
+
-
- )}
- event.stopPropagation()}
- >
-
-
- {!hideVersionSelector && (
-
- <>
-
-
- Switch version
-
-
- Add more versions
-
-
- }
+
+
+
+ )}
+ {
+ this.handleMenu()
+ event.stopPropagation()
+ }}
+ >
+
+
+ {!hideVersionSelector && isProviderSupported && (
+
+ {this.renderDropdown(currentComponent)}
+
+ )}
+ {!readOnly && onRemove && (
+
+
+
+ )}
+ {!readOnly && !isDefinitionEmpty && (
+
+
- )}
- {!readOnly && !isDefinitionEmpty && (
-
- this.revertComponent(component)}
- disabled={!hasChange(component)}
- >
-
-
-
- )}
- */}
+
+
+
+ )}
+
+
>
)
}
diff --git a/src/components/Navigation/Ui/ListDataRenderer.js b/src/components/Navigation/Ui/ListDataRenderer.js
index 8498ef8bd..fa887d1ed 100644
--- a/src/components/Navigation/Ui/ListDataRenderer.js
+++ b/src/components/Navigation/Ui/ListDataRenderer.js
@@ -30,7 +30,7 @@ export default class ListDataRenderer extends Component {
document.body.addEventListener('showTooltip', this.handleShowTooltip)
}
- componentWillMount() {
+ componentWillUnmount() {
document.body.removeEventListener('showTooltip', this.handleShowTooltip)
}
diff --git a/src/components/Navigation/Ui/ShareButton.js b/src/components/Navigation/Ui/ShareButton.js
index 4c570939c..f82c783f7 100644
--- a/src/components/Navigation/Ui/ShareButton.js
+++ b/src/components/Navigation/Ui/ShareButton.js
@@ -13,18 +13,18 @@ export default class ShareButton extends Component {
const disabled = !components || components.list.length === 0
return (
-
)
}
diff --git a/src/components/Navigation/Ui/VersionSelector.js b/src/components/Navigation/Ui/VersionSelector.js
index 783647fd6..1ae283f3d 100644
--- a/src/components/Navigation/Ui/VersionSelector.js
+++ b/src/components/Navigation/Ui/VersionSelector.js
@@ -29,7 +29,7 @@ class VersionSelector extends Component {
const fullname = component.namespace ? `${component.namespace}/${component.name}` : component.name
try {
const label = multiple
- ? `Pick one or move versions of ${fullname} to add to the definitions list`
+ ? `Add one or more versions of ${fullname}`
: `Pick a different version of ${fullname}`
const options = await getRevisions(token, fullname, component.type, component.provider)
this.setState({ options, label })
@@ -58,7 +58,7 @@ class VersionSelector extends Component {
const { options, label, selected } = this.state
return (
- 0 ? 'static' : true}>
+ 0 ? 'static' : true} dialogClassName='version-selector'>
{label}
@@ -67,8 +67,10 @@ class VersionSelector extends Component {