Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
renamed to SimpleRelationship
Browse files Browse the repository at this point in the history
Avoids a breaking change
  • Loading branch information
wheresrhys committed Oct 22, 2020
1 parent 30e45c4 commit b268b11
Show file tree
Hide file tree
Showing 23 changed files with 497 additions and 499 deletions.
6 changes: 3 additions & 3 deletions packages/tc-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ tc-ui provides 6 of these by default, but the user may provide more that impleme
- Text
- LargeText
- Number
- Relationship
- RichRelationship (i.e. a relationship which has annotations on the edge)
- Relationship (a relationship which may have annotations on the edge)
- SimpleRelationship (a relationship which has no annotations on the edge)
- Temporal
- Enum
- MultipleChoice

See tc-schema-sdk/data-accessors/primitive-types.js to see which components are used for rendering which default primitive data types

The 'CMS' pages do not make use of `Relationship` at present - all relationships use `RichRelationship`. This is in order to simplify the CMS code. The `Relationship` primitives are provided with an eye to two things
The 'CMS' pages do not make use of `SimpleRelationship` at present - all relationships use `Relationship`. This is in order to simplify the CMS code. The `SimpleRelationship` primitives are provided with an eye to two things

- making wider use of them to render views in the wider Biz Ops ecosystem _without_ having to always use `_rel` properties in GraphQL
- adding the ability to render `@cypher` driven properties in the CMS views at some point
Expand Down
2 changes: 1 addition & 1 deletion packages/tc-ui/src/lib/mappers/component-assigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const componentAssigner = ({
return hasMany ? components.MultipleChoice : components.Enum;
}
if (objectTypes.includes(type)) {
return components.RichRelationship;
return components.Relationship;
}
}

Expand Down
10 changes: 4 additions & 6 deletions packages/tc-ui/src/pages/edit/browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('./main.css');
const { init } = require('@financial-times/tc-schema-sdk');
const {
RichRelationship: { withEditComponent: attachRichRelationshipPicker },
Relationship: { withEditComponent: attachRelationshipPicker },
LargeText: { withEditComponent: attachDocumentEditor },
} = require('../../primitives/browser');

Expand All @@ -21,11 +21,9 @@ const initDocumentEditors = () => {
const initRelationshipSelectors = entireRecord => {
[
...document.querySelectorAll(
'[data-component="rich-relationship-picker"]:not([data-disabled])',
'[data-component="relationship"]:not([data-disabled])',
),
].forEach(container =>
attachRichRelationshipPicker(container, entireRecord),
);
].forEach(container => attachRelationshipPicker(container, entireRecord));
};

// TODO - the relationship editors should expose their bad state in some way
Expand All @@ -37,7 +35,7 @@ const preventBadSubmission = () => {
.addEventListener('submit', ev => {
const editorsInUnselectedState = [
...document.querySelectorAll(
'[data-component="rich-relationship-picker"][data-is-unresolved]',
'[data-component="relationship"][data-is-unresolved]',
),
];
if (editorsInUnselectedState.length) {
Expand Down
4 changes: 2 additions & 2 deletions packages/tc-ui/src/primitives/browser.js
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,
};
6 changes: 4 additions & 2 deletions packages/tc-ui/src/primitives/relationship/browser.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
require('../relationship-picker/main.css');
require('./main.css');
const React = require('react');
const { render } = require('react-dom');
const { RelationshipPicker } = require('../relationship-picker');
const { SelectedRelationship } = require('./lib/selected-relationship');

module.exports = {
withEditComponent: container =>
withEditComponent: (container, entireRecord) =>
render(
<RelationshipPicker
{...JSON.parse(container.dataset.props)}
entireRecord={entireRecord}
SelectedRelationship={SelectedRelationship}
componentName="relationship-picker"
componentName="relationship"
/>,
container.parentNode,
),
Expand Down
188 changes: 155 additions & 33 deletions packages/tc-ui/src/primitives/relationship/lib/selected-relationship.jsx
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 };
Loading

0 comments on commit b268b11

Please sign in to comment.