This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
23 changed files
with
497 additions
and
499 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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
const Relationship = require('./relationship/browser'); | ||
const RichRelationship = require('./rich-relationship/browser'); | ||
const SimpleRelationship = require('./simple-relationship/browser'); | ||
const LargeText = require('./large-text/browser'); | ||
|
||
module.exports = { | ||
Relationship, | ||
RichRelationship, | ||
SimpleRelationship, | ||
LargeText, | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
188 changes: 155 additions & 33 deletions
188
packages/tc-ui/src/primitives/relationship/lib/selected-relationship.jsx
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 |
---|---|---|
@@ -1,37 +1,159 @@ | ||
const React = require('react'); | ||
const { RelationshipProperties } = require('./rich-relationship-properties'); | ||
|
||
const SelectedRelationship = ({ | ||
value, | ||
disabled, | ||
onRelationshipRemove, | ||
index, | ||
}) => ( | ||
<li | ||
data-name={value.name} | ||
data-code={value.code} | ||
className="treecreeper-selected-relationship" | ||
key={index} | ||
> | ||
<span> | ||
<span className="o-layout-typography"> | ||
{value.name || value.code} | ||
</span> | ||
|
||
<span> | ||
<button | ||
type="button" | ||
disabled={disabled ? 'disabled' : null} | ||
className={`o-buttons o-buttons--secondary o-buttons--small relationship-remove-button ${ | ||
disabled ? 'disabled' : '' | ||
}`} | ||
onClick={onRelationshipRemove} | ||
data-index={`remove-${index}`} | ||
> | ||
Remove | ||
</button> | ||
</span> | ||
</span> | ||
</li> | ||
); | ||
class SelectedRelationship extends React.Component { | ||
constructor(props) { | ||
super(); | ||
this.props = props; | ||
this.state = { | ||
isMounted: false, | ||
isEditing: this.props.annotate, | ||
// so that to show annotation fields when a relationship is created | ||
annotate: this.props.annotate, | ||
}; | ||
|
||
this.showRichRelationshipEditor = this.showRichRelationshipEditor.bind( | ||
this, | ||
); | ||
} | ||
|
||
componentDidMount() { | ||
this.setState(prevState => { | ||
const { isMounted } = prevState; | ||
return { | ||
isMounted: !isMounted, | ||
}; | ||
}); | ||
} | ||
|
||
toggleAnnotation() { | ||
this.setState(prevState => { | ||
const { annotate } = prevState; | ||
return { | ||
annotate: !annotate, | ||
}; | ||
}); | ||
} | ||
|
||
showRichRelationshipEditor(event) { | ||
this.setState( | ||
{ | ||
isEditing: true, | ||
}, | ||
() => this.toggleAnnotation(), | ||
); | ||
event.stopPropagation(); | ||
} | ||
|
||
render() { | ||
const { | ||
value, | ||
disabled, | ||
onRelationshipRemove, | ||
index, | ||
properties, | ||
propertyName, | ||
hasError, | ||
} = this.props; | ||
|
||
const { isMounted, isEditing, annotate } = this.state; | ||
const relationshipPropKeys = properties && Object.keys(properties); | ||
const canBeAnnotated = | ||
relationshipPropKeys && relationshipPropKeys.length > 0; | ||
const hasAnnotations = | ||
relationshipPropKeys && | ||
relationshipPropKeys.filter(propName => value[propName]); | ||
|
||
const annotateButtonLabel = | ||
hasAnnotations && hasAnnotations.length | ||
? 'Edit details' | ||
: 'Add details'; | ||
const annotateButtonIcon = | ||
hasAnnotations && hasAnnotations.length | ||
? ` o-icons-icon--edit` | ||
: ` o-icons-icon--plus`; | ||
return ( | ||
<> | ||
<li | ||
data-name={value.name} | ||
data-code={value.code} | ||
className="treecreeper-selected-relationship" | ||
key={index} | ||
> | ||
<span> | ||
<span className="o-layout-typography"> | ||
{value.name || value.code} | ||
</span> | ||
<span> | ||
<button | ||
type="button" | ||
disabled={disabled ? 'disabled' : null} | ||
className={`o-buttons o-buttons--secondary o-buttons--small relationship-remove-button ${ | ||
disabled ? 'disabled' : '' | ||
}`} | ||
onClick={onRelationshipRemove} | ||
data-index={`remove-${index}`} | ||
> | ||
Remove | ||
</button> | ||
{canBeAnnotated ? ( | ||
<div | ||
className="demo-tooltip-container" | ||
id={`id-${propertyName}-${index}`} | ||
> | ||
<button | ||
type="button" | ||
disabled={ | ||
disabled || | ||
isEditing || | ||
(hasError && hasAnnotations.length) | ||
? 'disabled' | ||
: null | ||
} | ||
className={`o-buttons o-buttons--secondary o-buttons--small relationship-annotate-button ${ | ||
disabled ? 'disabled' : '' | ||
}`} | ||
onClick={ | ||
this.showRichRelationshipEditor | ||
} | ||
data-index={`annotate-${index}`} | ||
id={`id-${propertyName}-${index}`} | ||
> | ||
<span>{annotateButtonLabel}</span> | ||
<span | ||
className={`relationship-annotate-icon o-icons-icon ${annotateButtonIcon}`} | ||
/> | ||
</button> | ||
<div | ||
data-o-component="o-tooltip" | ||
data-o-tooltip-position="above" | ||
data-o-tooltip-target={`id-${propertyName}-${index}`} | ||
data-o-tooltip-show-on-hover="true" | ||
> | ||
<div className="o-tooltip-content"> | ||
Helps you to save more information | ||
about this relationship | ||
</div> | ||
</div> | ||
</div> | ||
) : null} | ||
</span> | ||
</span> | ||
{(isMounted && annotate && canBeAnnotated) || | ||
(hasError && hasAnnotations.length) ? ( | ||
<span | ||
className="treecreeper-relationship-annotate" | ||
key={index} | ||
> | ||
<RelationshipProperties | ||
key={index} | ||
{...this.props} | ||
/> | ||
</span> | ||
) : null} | ||
</li> | ||
</> | ||
); | ||
} | ||
} | ||
module.exports = { SelectedRelationship }; |
Oops, something went wrong.