Skip to content

Commit 459c5c7

Browse files
committed
Merge branch 'master' into prod
2 parents f8ed3c3 + 0c7f7aa commit 459c5c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+542
-385
lines changed

src/actions/definitionActions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function checkForMissingDefinition(token, isFirstAttempt = false) {
5656
).filter(x => x)
5757
const missingDefinitions = map(
5858
workspaceComponents,
59-
item => !get(item, 'described.tools') && EntitySpec.fromObject(item).toPath()
59+
item => !get(item, 'described.tools') && EntitySpec.fromObject(item.coordinates).toPath()
6060
).filter(x => x)
6161
if (missingDefinitions.length > 0) {
6262
if (isFirstAttempt)

src/components/ComponentList.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ class ComponentList extends React.Component {
145145
render() {
146146
const { loadMoreRows, noRowsRenderer, list, listLength } = this.props
147147
const { sortOrder, contentSeq } = this.state
148+
const showFilterBar = false
148149
return (
149-
<div className="clearly-table-body flex-grow">
150+
<div className={`clearly-table-body flex-grow ${showFilterBar ? 'show-filter' : ''}`}>
150151
<div className="clearly-header">
151152
<div className="table-header-fcloumn">
152153
<h4>Component</h4>

src/components/DefinitionEntry.js

+46-43
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import React from 'react'
55
import PropTypes from 'prop-types'
6-
import { TwoLineEntry, QuickEditModel, SourcePicker, FileCountRenderer } from './'
6+
import { TwoLineEntry, QuickEditModel, FileCountRenderer } from './'
77
import { Checkbox, OverlayTrigger, Tooltip, Popover } from 'react-bootstrap'
88
import { Tag } from 'antd'
99
import { get, isEqual, union } from 'lodash'
@@ -34,7 +34,7 @@ class DefinitionEntry extends React.Component {
3434
}
3535
}
3636
static propTypes = {
37-
onChange: PropTypes.func,
37+
onChange: PropTypes.func.isRequired,
3838
onCurate: PropTypes.func,
3939
onInspect: PropTypes.func,
4040
activeFacets: PropTypes.array,
@@ -60,7 +60,7 @@ class DefinitionEntry extends React.Component {
6060
const newChanges = { ...component.changes }
6161
if (isChanged && proposedValue !== null) newChanges[field] = proposedValue
6262
else delete newChanges[field]
63-
onChange && onChange(component, newChanges, field)
63+
onChange(component, newChanges, field)
6464
}
6565
}
6666

@@ -90,10 +90,10 @@ class DefinitionEntry extends React.Component {
9090
<ScoreRenderer scores={scores} definition={definition} />
9191
</span>
9292
) : null
93-
const releasedDate = definition?.described?.releaseDate ? (
94-
<span className="releasedDate-table">{definition.described.releaseDate}</span>
95-
) : (
96-
<span className="releasedDate-table">-- -- --</span>
93+
const releasedDate = (
94+
<span className="releasedDate-table">
95+
{this.renderFieldWithToolTipIfDifferent('described.releaseDate', a => a || '-- -- --')}
96+
</span>
9797
)
9898
const curationTag = isCurationPending ? (
9999
<span>
@@ -125,7 +125,7 @@ class DefinitionEntry extends React.Component {
125125
renderWithToolTipIfDifferent(field, content, placement = 'right', transform = x => x) {
126126
const toolTip = (
127127
<Tooltip id={`tooltip-${field}`} className="definition__tooltip">
128-
Original: {transform(get(this.props.otherDefinition, field))}
128+
Original: {transform(this.getOriginalValue(field))}
129129
</Tooltip>
130130
)
131131
return this.ifDifferent(
@@ -137,14 +137,19 @@ class DefinitionEntry extends React.Component {
137137
)
138138
}
139139

140+
renderFieldWithToolTipIfDifferent(field, transform = a => a) {
141+
const displayValue = transform(this.getValue(field))
142+
return this.renderWithToolTipIfDifferent(
143+
field,
144+
<span className={this.classIfDifferent(field)}>{displayValue}</span>,
145+
undefined,
146+
transform
147+
)
148+
}
149+
140150
renderMessage(definition) {
141151
const licenseExpression = definition ? this.getValue('licensed.declared') : null
142-
return licenseExpression
143-
? this.renderWithToolTipIfDifferent(
144-
'licensed.declared',
145-
<span className={this.classIfDifferent('licensed.declared')}>{licenseExpression}</span>
146-
)
147-
: null
152+
return licenseExpression ? this.renderFieldWithToolTipIfDifferent('licensed.declared') : null
148153
}
149154

150155
getPercentage(count, total) {
@@ -190,6 +195,23 @@ class DefinitionEntry extends React.Component {
190195
this.setState({ modelOpen: !this.state.modelOpen })
191196
}
192197

198+
handleSaveEdit = updates => {
199+
const { onChange, definition, component } = this.props
200+
201+
const newChanges = Object.entries(updates).reduce((changes, [key, value]) => {
202+
let field
203+
if (key === 'declared') field = 'licensed.declared'
204+
if (key === 'sourceComponent') field = 'described.sourceLocation'
205+
if (key === 'release') field = 'described.releaseDate'
206+
return field ? Contribution.applyChanges(definition, changes, field, value) : changes
207+
}, {})
208+
209+
if (Object.keys(newChanges).length !== 0) {
210+
const combinedChanges = { ...component.changes, ...newChanges }
211+
onChange(component, combinedChanges)
212+
}
213+
}
214+
193215
renderPanel(rawDefinition) {
194216
if (!rawDefinition)
195217
return (
@@ -201,13 +223,12 @@ class DefinitionEntry extends React.Component {
201223
// TODO: find a way of calling this method less frequently. It's relatively expensive.
202224
const definition = this.foldFacets(rawDefinition, this.props.activeFacets)
203225
const { licensed } = definition
204-
const { readOnly, onRevert } = this.props
205226
return (
206227
<div className="row row-panel-details">
207228
<div className="col-md-6 d-flex justify-content-start align-items-center">
208229
<span className="panel-details__title">{this.renderLabel('Declared')}:</span>
209230
<div className="panel-details__value">
210-
<p>{this.getValue('licensed.declared')}</p>
231+
{this.renderFieldWithToolTipIfDifferent('licensed.declared')}
211232
{/* {this.renderWithToolTipIfDifferent(
212233
'licensed.declared',
213234
<LicensesRenderer
@@ -232,7 +253,7 @@ class DefinitionEntry extends React.Component {
232253
<div className="col-md-6 d-flex justify-content-start align-items-center">
233254
<span className="panel-details__title">{this.renderLabel('Source')}:</span>
234255
<div className="panel-details__value">
235-
<p>{Contribution.printCoordinates(this.getValue('described.sourceLocation'))}</p>
256+
{this.renderFieldWithToolTipIfDifferent('described.sourceLocation', a => Contribution.printCoordinates(a))}
236257
{/* {this.renderWithToolTipIfDifferent(
237258
'described.sourceLocation',
238259
<ModalEditor
@@ -263,7 +284,10 @@ class DefinitionEntry extends React.Component {
263284
<div className="col-md-6 d-flex justify-content-start align-items-center">
264285
<span className="panel-details__title">{this.renderLabel('Release')}:</span>
265286
<div className="panel-details__value">
266-
<p>{Contribution.printDate(this.getValue('described.releaseDate'))}</p>
287+
{this.renderFieldWithToolTipIfDifferent(
288+
'described.releaseDate',
289+
a => Contribution.printDate(a) || '-- -- --'
290+
)}
267291
{/* {this.renderWithToolTipIfDifferent(
268292
'described.releaseDate',
269293
<InlineEditor
@@ -292,33 +316,12 @@ class DefinitionEntry extends React.Component {
292316
<QuickEditModel
293317
open={this.state.modelOpen}
294318
closeModel={this.handleModel}
295-
definition={definition}
296-
field={'described.sourceLocation'}
297-
extraClass={this.classIfDifferent('described.sourceLocation')}
298-
readOnly={readOnly}
299-
initialValue={{
300-
declared: this.getOriginalValue('licensed.declared'),
301-
source: Contribution.printCoordinates(this.getOriginalValue('described.sourceLocation')),
302-
release: Contribution.printDate(this.getOriginalValue('described.releaseDate')),
303-
repo: ''
304-
}}
305-
values={{
319+
initialValues={{
306320
declared: this.getValue('licensed.declared'),
307-
source: Contribution.printCoordinates(this.getValue('described.sourceLocation')),
308-
release: Contribution.printDate(this.getValue('described.releaseDate')),
309-
repo: ''
310-
}}
311-
onChange={{
312-
declared: this.fieldChange('licensed.declared'),
313-
source: this.fieldChange('described.sourceLocation', isEqual, Contribution.toSourceLocation),
314-
release: this.fieldChange('described.releaseDate'),
315-
repo: ''
321+
sourceComponent: this.getValue('described.sourceLocation'),
322+
release: Contribution.printDate(this.getValue('described.releaseDate'))
316323
}}
317-
editor={SourcePicker}
318-
validator={value => true}
319-
placeholder={'Source location'}
320-
revertable
321-
onRevert={() => onRevert('described.sourceLocation')}
324+
onSave={this.handleSaveEdit}
322325
/>
323326
<button onClick={this.handleModel} className="quick-edit-btn">
324327
Edit

src/components/FullDetailView/AbstractFullDetailsView.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export class AbstractFullDetailsView extends Component {
3232

3333
return modalView ? (
3434
<Modal
35-
closable={false}
35+
closable={!!this.handleClose}
36+
onCancel={this.handleClose}
3637
footer={null}
3738
// if it's mobile do not center the Modal
3839
centered={!isMobile}
@@ -50,7 +51,6 @@ export class AbstractFullDetailsView extends Component {
5051
readOnly={readOnly}
5152
modalView={modalView}
5253
onChange={this.onChange}
53-
handleClose={this.handleClose}
5454
handleSave={this.handleSave}
5555
handleRevert={this.handleRevert}
5656
previewDefinition={previewDefinition}

src/components/FullDetailView/FullDetailComponent.js

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class FullDetailComponent extends Component {
2929
}
3030
}
3131
static propTypes = {
32-
handleClose: PropTypes.func,
3332
handleSave: PropTypes.func,
3433
handleRevert: PropTypes.func,
3534
curations: PropTypes.object.isRequired,

src/components/FullDetailView/FullDetailPage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ export class FullDetailPage extends AbstractFullDetailsView {
166166
}
167167

168168
handleClose() {
169-
const { onClose } = this.props
169+
const { readOnly, onClose } = this.props
170170
const { changes } = this.state
171-
if (isEmpty(changes)) return onClose()
171+
if (readOnly || isEmpty(changes)) return onClose()
172172
const key = `open${Date.now()}`
173173
notification.open({
174174
message: 'Unsaved Changes',

src/components/Navigation/Pages/PageBrowse/ButtonsBar.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ export default class ButtonsBar extends Component {
2121
<span>&nbsp;Revert Changes</span>
2222
</Button>
2323
</ButtonWithTooltip>
24-
<Button bsStyle="default" onClick={toggleCollapseExpandAll}>
25-
Toggle Collapse
26-
</Button>
24+
{toggleCollapseExpandAll && (
25+
<Button bsStyle="default" onClick={toggleCollapseExpandAll}>
26+
Toggle Collapse
27+
</Button>
28+
)}
2729
<Button bsStyle="success" disabled={hasChanges} onClick={doPromptContribute} data-test-id="contribute-button">
2830
Contribute
2931
</Button>

src/components/Navigation/Pages/PageBrowse/PageBrowse.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import difference from 'lodash/difference'
1010
import classNames from 'classnames'
1111
import { ROUTE_ROOT } from '../../../../utils/routingConstants'
1212
import { getCurationsAction } from '../../../../actions/curationActions'
13-
import { uiBrowseUpdateList, uiNavigation, uiBrowseGet } from '../../../../actions/ui'
13+
import { uiBrowseUpdateFilterList, uiBrowseUpdateList, uiNavigation, uiBrowseGet } from '../../../../actions/ui'
1414
import SystemManagedList from '../../../SystemManagedList'
1515
import Section from '../../../Section'
1616
import ComponentList from '../../../ComponentList'
@@ -34,7 +34,8 @@ class PageBrowse extends SystemManagedList {
3434
this.state = {
3535
activeSort: 'releaseDate-desc',
3636
searchFocused: false,
37-
selectedProvider: providers[0]
37+
selectedProvider: providers[0],
38+
searchTerm: ''
3839
}
3940
this.onFilter = this.onFilter.bind(this)
4041
this.onSort = this.onSort.bind(this)
@@ -63,13 +64,19 @@ class PageBrowse extends SystemManagedList {
6364
}
6465

6566
onBrowse = value => {
66-
this.setState({ activeName: value }, () => this.updateData())
67+
this.setState({ activeName: value, searchTerm: '' }, () => this.updateData())
6768
}
6869

6970
onFocusChange = value => {
7071
this.setState({ searchFocused: value })
7172
}
7273

74+
onSearch = value => {
75+
this.setState({ searchTerm: value })
76+
const valueToSearch = this.state.selectedProvider.value + '/' + value
77+
this.props.dispatch(uiBrowseUpdateFilterList(this.props.token, valueToSearch))
78+
}
79+
7380
tableTitle() {
7481
return 'Browse'
7582
}
@@ -156,14 +163,17 @@ class PageBrowse extends SystemManagedList {
156163
<ButtonsBar
157164
hasChanges={!this.hasChanges()}
158165
revertAll={() => this.revertAll('browse')}
159-
toggleCollapseExpandAll={this.toggleCollapseExpandAll}
160166
doPromptContribute={this.doPromptContribute}
161167
/>
162168
)
163169
}
164170

165171
onProviderChange(item) {
166172
this.setState({ selectedProvider: item })
173+
if (this.state.searchTerm) {
174+
const valueToSearch = item.value + '/' + this.state.searchTerm
175+
this.props.dispatch(uiBrowseUpdateFilterList(this.props.token, valueToSearch))
176+
}
167177
}
168178

169179
// Overrides the default onFilter method
@@ -332,10 +342,8 @@ class PageBrowse extends SystemManagedList {
332342
/>
333343
</div>
334344
<div className="col-12">
335-
<Section
336-
className="flex-grow-column clearly-component-wrap"
337-
>
338-
<div className={classNames('clearly-table flex-grow', { loading: components.isFetching })}>
345+
<Section className="flex-grow-column" name={this.tableTitle()} actionButton={this.renderButtons()}>
346+
<div className={classNames('section-body flex-grow', { loading: components.isFetching })}>
339347
<i className="fas fa-spinner fa-spin" />
340348
<ComponentList
341349
role="tree"
@@ -346,7 +354,6 @@ class PageBrowse extends SystemManagedList {
346354
loadMoreRows={this.loadMoreRows}
347355
onRevert={(definition, value) => this.revertDefinition(definition, value, 'browse')}
348356
onChange={this.onChangeComponent}
349-
onInspect={this.onInspect}
350357
renderFilterBar={this.renderFilterBar}
351358
curations={curations}
352359
definitions={definitions}

src/components/Navigation/Pages/PageBrowse/__tests__/ButtonsBar.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('ButtonsBar', () => {
1212
})
1313

1414
it("checks if buttons are enabled when there aren't changes", async () => {
15-
const wrapper = await shallow(<ButtonsBar hasChanges={false} />)
15+
const wrapper = await shallow(<ButtonsBar hasChanges={false} toggleCollapseExpandAll={jest.fn()} />)
1616
const toggleCollapseButton = wrapper.find({ children: 'Toggle Collapse' })
1717
expect(toggleCollapseButton.exists()).toBeTruthy()
1818
const contributeButton = wrapper.find({ children: 'Contribute' })
@@ -21,7 +21,9 @@ describe('ButtonsBar', () => {
2121
})
2222

2323
it('checks if buttons are disabled when there are changes', async () => {
24-
const wrapper = await shallow(<ButtonsBar components={components} hasChanges={true} />)
24+
const wrapper = await shallow(
25+
<ButtonsBar components={components} hasChanges={true} toggleCollapseExpandAll={jest.fn()} />
26+
)
2527
const toggleCollapseButton = wrapper.find({ children: 'Toggle Collapse' })
2628
expect(toggleCollapseButton.exists()).toBeTruthy()
2729
const contributeButton = wrapper.find({ children: 'Contribute' })

src/components/Navigation/Pages/PageDefinitions/ButtonsBar.js

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import ButtonWithTooltip from '../../Ui/ButtonWithTooltip'
55
import ShareButton from '../../Ui/ShareButton'
66

77
export default class ButtonsBar extends Component {
8+
constructor(props) {
9+
super(props)
10+
this.onSelect = this.onSelect.bind(this)
11+
}
12+
813
static propTypes = {
914
components: PropTypes.object,
1015
hasChanges: PropTypes.bool,

src/components/Navigation/Pages/PageDefinitions/PageDefinitions.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import UrlShare from '../../../../utils/urlShare'
2323
export class PageDefinitions extends UserManagedList {
2424
constructor(props) {
2525
super(props)
26-
this.onAddComponent = this.onAddComponent.bind(this)
2726
this.doSave = this.doSave.bind(this)
2827
this.doSaveAsUrl = this.doSaveAsUrl.bind(this)
2928
this.revertAll = this.revertAll.bind(this)
@@ -225,7 +224,7 @@ export class PageDefinitions extends UserManagedList {
225224
path={path}
226225
currentDefinition={currentDefinition}
227226
component={currentComponent}
228-
readOnly={this.readOnly}
227+
readOnly={true}
229228
/>
230229
)}
231230
{showSavePopup && (

0 commit comments

Comments
 (0)