Skip to content

Commit

Permalink
Merge branch 'master' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
mpcen committed Oct 3, 2022
2 parents f8ed3c3 + 0c7f7aa commit 459c5c7
Show file tree
Hide file tree
Showing 47 changed files with 542 additions and 385 deletions.
2 changes: 1 addition & 1 deletion src/actions/definitionActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function checkForMissingDefinition(token, isFirstAttempt = false) {
).filter(x => x)
const missingDefinitions = map(
workspaceComponents,
item => !get(item, 'described.tools') && EntitySpec.fromObject(item).toPath()
item => !get(item, 'described.tools') && EntitySpec.fromObject(item.coordinates).toPath()
).filter(x => x)
if (missingDefinitions.length > 0) {
if (isFirstAttempt)
Expand Down
3 changes: 2 additions & 1 deletion src/components/ComponentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ class ComponentList extends React.Component {
render() {
const { loadMoreRows, noRowsRenderer, list, listLength } = this.props
const { sortOrder, contentSeq } = this.state
const showFilterBar = false
return (
<div className="clearly-table-body flex-grow">
<div className={`clearly-table-body flex-grow ${showFilterBar ? 'show-filter' : ''}`}>
<div className="clearly-header">
<div className="table-header-fcloumn">
<h4>Component</h4>
Expand Down
89 changes: 46 additions & 43 deletions src/components/DefinitionEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -90,10 +90,10 @@ class DefinitionEntry extends React.Component {
<ScoreRenderer scores={scores} definition={definition} />
</span>
) : null
const releasedDate = definition?.described?.releaseDate ? (
<span className="releasedDate-table">{definition.described.releaseDate}</span>
) : (
<span className="releasedDate-table">-- -- --</span>
const releasedDate = (
<span className="releasedDate-table">
{this.renderFieldWithToolTipIfDifferent('described.releaseDate', a => a || '-- -- --')}
</span>
)
const curationTag = isCurationPending ? (
<span>
Expand Down Expand Up @@ -125,7 +125,7 @@ class DefinitionEntry extends React.Component {
renderWithToolTipIfDifferent(field, content, placement = 'right', transform = x => x) {
const toolTip = (
<Tooltip id={`tooltip-${field}`} className="definition__tooltip">
Original: {transform(get(this.props.otherDefinition, field))}
Original: {transform(this.getOriginalValue(field))}
</Tooltip>
)
return this.ifDifferent(
Expand All @@ -137,14 +137,19 @@ class DefinitionEntry extends React.Component {
)
}

renderFieldWithToolTipIfDifferent(field, transform = a => a) {
const displayValue = transform(this.getValue(field))
return this.renderWithToolTipIfDifferent(
field,
<span className={this.classIfDifferent(field)}>{displayValue}</span>,
undefined,
transform
)
}

renderMessage(definition) {
const licenseExpression = definition ? this.getValue('licensed.declared') : null
return licenseExpression
? this.renderWithToolTipIfDifferent(
'licensed.declared',
<span className={this.classIfDifferent('licensed.declared')}>{licenseExpression}</span>
)
: null
return licenseExpression ? this.renderFieldWithToolTipIfDifferent('licensed.declared') : null
}

getPercentage(count, total) {
Expand Down Expand Up @@ -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 (
Expand All @@ -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 (
<div className="row row-panel-details">
<div className="col-md-6 d-flex justify-content-start align-items-center">
<span className="panel-details__title">{this.renderLabel('Declared')}:</span>
<div className="panel-details__value">
<p>{this.getValue('licensed.declared')}</p>
{this.renderFieldWithToolTipIfDifferent('licensed.declared')}
{/* {this.renderWithToolTipIfDifferent(
'licensed.declared',
<LicensesRenderer
Expand All @@ -232,7 +253,7 @@ class DefinitionEntry extends React.Component {
<div className="col-md-6 d-flex justify-content-start align-items-center">
<span className="panel-details__title">{this.renderLabel('Source')}:</span>
<div className="panel-details__value">
<p>{Contribution.printCoordinates(this.getValue('described.sourceLocation'))}</p>
{this.renderFieldWithToolTipIfDifferent('described.sourceLocation', a => Contribution.printCoordinates(a))}
{/* {this.renderWithToolTipIfDifferent(
'described.sourceLocation',
<ModalEditor
Expand Down Expand Up @@ -263,7 +284,10 @@ class DefinitionEntry extends React.Component {
<div className="col-md-6 d-flex justify-content-start align-items-center">
<span className="panel-details__title">{this.renderLabel('Release')}:</span>
<div className="panel-details__value">
<p>{Contribution.printDate(this.getValue('described.releaseDate'))}</p>
{this.renderFieldWithToolTipIfDifferent(
'described.releaseDate',
a => Contribution.printDate(a) || '-- -- --'
)}
{/* {this.renderWithToolTipIfDifferent(
'described.releaseDate',
<InlineEditor
Expand Down Expand Up @@ -292,33 +316,12 @@ class DefinitionEntry extends React.Component {
<QuickEditModel
open={this.state.modelOpen}
closeModel={this.handleModel}
definition={definition}
field={'described.sourceLocation'}
extraClass={this.classIfDifferent('described.sourceLocation')}
readOnly={readOnly}
initialValue={{
declared: this.getOriginalValue('licensed.declared'),
source: Contribution.printCoordinates(this.getOriginalValue('described.sourceLocation')),
release: Contribution.printDate(this.getOriginalValue('described.releaseDate')),
repo: ''
}}
values={{
initialValues={{
declared: this.getValue('licensed.declared'),
source: Contribution.printCoordinates(this.getValue('described.sourceLocation')),
release: Contribution.printDate(this.getValue('described.releaseDate')),
repo: ''
}}
onChange={{
declared: this.fieldChange('licensed.declared'),
source: this.fieldChange('described.sourceLocation', isEqual, Contribution.toSourceLocation),
release: this.fieldChange('described.releaseDate'),
repo: ''
sourceComponent: this.getValue('described.sourceLocation'),
release: Contribution.printDate(this.getValue('described.releaseDate'))
}}
editor={SourcePicker}
validator={value => true}
placeholder={'Source location'}
revertable
onRevert={() => onRevert('described.sourceLocation')}
onSave={this.handleSaveEdit}
/>
<button onClick={this.handleModel} className="quick-edit-btn">
Edit
Expand Down
4 changes: 2 additions & 2 deletions src/components/FullDetailView/AbstractFullDetailsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class AbstractFullDetailsView extends Component {

return modalView ? (
<Modal
closable={false}
closable={!!this.handleClose}
onCancel={this.handleClose}
footer={null}
// if it's mobile do not center the Modal
centered={!isMobile}
Expand All @@ -50,7 +51,6 @@ export class AbstractFullDetailsView extends Component {
readOnly={readOnly}
modalView={modalView}
onChange={this.onChange}
handleClose={this.handleClose}
handleSave={this.handleSave}
handleRevert={this.handleRevert}
previewDefinition={previewDefinition}
Expand Down
1 change: 0 additions & 1 deletion src/components/FullDetailView/FullDetailComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class FullDetailComponent extends Component {
}
}
static propTypes = {
handleClose: PropTypes.func,
handleSave: PropTypes.func,
handleRevert: PropTypes.func,
curations: PropTypes.object.isRequired,
Expand Down
4 changes: 2 additions & 2 deletions src/components/FullDetailView/FullDetailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ export class FullDetailPage extends AbstractFullDetailsView {
}

handleClose() {
const { onClose } = this.props
const { readOnly, onClose } = this.props
const { changes } = this.state
if (isEmpty(changes)) return onClose()
if (readOnly || isEmpty(changes)) return onClose()
const key = `open${Date.now()}`
notification.open({
message: 'Unsaved Changes',
Expand Down
8 changes: 5 additions & 3 deletions src/components/Navigation/Pages/PageBrowse/ButtonsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ export default class ButtonsBar extends Component {
<span>&nbsp;Revert Changes</span>
</Button>
</ButtonWithTooltip>
<Button bsStyle="default" onClick={toggleCollapseExpandAll}>
Toggle Collapse
</Button>
{toggleCollapseExpandAll && (
<Button bsStyle="default" onClick={toggleCollapseExpandAll}>
Toggle Collapse
</Button>
)}
<Button bsStyle="success" disabled={hasChanges} onClick={doPromptContribute} data-test-id="contribute-button">
Contribute
</Button>
Expand Down
25 changes: 16 additions & 9 deletions src/components/Navigation/Pages/PageBrowse/PageBrowse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -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'
}
Expand Down Expand Up @@ -156,14 +163,17 @@ class PageBrowse extends SystemManagedList {
<ButtonsBar
hasChanges={!this.hasChanges()}
revertAll={() => this.revertAll('browse')}
toggleCollapseExpandAll={this.toggleCollapseExpandAll}
doPromptContribute={this.doPromptContribute}
/>
)
}

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
Expand Down Expand Up @@ -332,10 +342,8 @@ class PageBrowse extends SystemManagedList {
/>
</div>
<div className="col-12">
<Section
className="flex-grow-column clearly-component-wrap"
>
<div className={classNames('clearly-table flex-grow', { loading: components.isFetching })}>
<Section className="flex-grow-column" name={this.tableTitle()} actionButton={this.renderButtons()}>
<div className={classNames('section-body flex-grow', { loading: components.isFetching })}>
<i className="fas fa-spinner fa-spin" />
<ComponentList
role="tree"
Expand All @@ -346,7 +354,6 @@ class PageBrowse extends SystemManagedList {
loadMoreRows={this.loadMoreRows}
onRevert={(definition, value) => this.revertDefinition(definition, value, 'browse')}
onChange={this.onChangeComponent}
onInspect={this.onInspect}
renderFilterBar={this.renderFilterBar}
curations={curations}
definitions={definitions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('ButtonsBar', () => {
})

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

it('checks if buttons are disabled when there are changes', async () => {
const wrapper = await shallow(<ButtonsBar components={components} hasChanges={true} />)
const wrapper = await shallow(
<ButtonsBar components={components} hasChanges={true} toggleCollapseExpandAll={jest.fn()} />
)
const toggleCollapseButton = wrapper.find({ children: 'Toggle Collapse' })
expect(toggleCollapseButton.exists()).toBeTruthy()
const contributeButton = wrapper.find({ children: 'Contribute' })
Expand Down
5 changes: 5 additions & 0 deletions src/components/Navigation/Pages/PageDefinitions/ButtonsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -225,7 +224,7 @@ export class PageDefinitions extends UserManagedList {
path={path}
currentDefinition={currentDefinition}
component={currentComponent}
readOnly={this.readOnly}
readOnly={true}
/>
)}
{showSavePopup && (
Expand Down
Loading

0 comments on commit 459c5c7

Please sign in to comment.