Skip to content

Commit 4212d2b

Browse files
Merge pull request #763 from complexdatacollective/fix/protocol-summary-variables
protocol summary variable pills and behaviors
2 parents f0e5593 + 25a2032 commit 4212d2b

File tree

12 files changed

+91
-47
lines changed

12 files changed

+91
-47
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { compose } from 'recompose';
4+
import RuleText from '@components/Query/Rules/PreviewText';
5+
import withDisplayOptions from '@components/Query/Rules/withDisplayOptions';
6+
7+
const Rule = ({
8+
type, options,
9+
}) => (
10+
<RuleText type={type} options={options} />
11+
);
12+
13+
Rule.propTypes = {
14+
type: PropTypes.string.isRequired,
15+
// eslint-disable-next-line react/forbid-prop-types
16+
options: PropTypes.object.isRequired,
17+
};
18+
19+
export default compose(
20+
withDisplayOptions,
21+
)(Rule);

src/lib/ProtocolSummary/components/Rules.js

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,31 @@
11
import React, { useContext } from 'react';
22
import PropTypes from 'prop-types';
3-
import RuleText, { Join } from '@components/Query/Rules/PreviewText';
3+
import { Join } from '@components/Query/Rules/PreviewText';
44
import SummaryContext from './SummaryContext';
5-
import { getVariableName, getEntityName } from './helpers';
6-
7-
const labelRules = (codebook, index, rules) => rules
8-
.map(({ type, options }) => {
9-
const labeledOptions = {
10-
...options,
11-
};
12-
13-
if (options.attribute) {
14-
labeledOptions.attribute = getVariableName(index, options.attribute);
15-
}
16-
17-
if (options.type) {
18-
const entity = type === 'alter' ? 'node' : 'edge';
19-
labeledOptions.type = getEntityName(codebook, entity, options.type);
20-
}
21-
22-
return { type, options: labeledOptions };
23-
});
5+
import Rule from './Rule';
246

257
const Rules = ({ filter }) => {
268
const {
279
protocol,
28-
index,
2910
} = useContext(SummaryContext);
3011

3112
if (!filter) { return null; }
3213

3314
const {
3415
join,
16+
rules,
3517
} = filter;
3618

37-
const rules = labelRules(protocol.codebook, index, filter.rules);
38-
3919
return (
4020
<div className="protocol-summary-rules">
4121
{ rules.map(({ type, options }, n) => (
42-
// eslint-disable-next-line react/no-array-index-key
43-
<div className="protocol-summary-rules__rule" key={n}>
44-
<RuleText type={type} options={options} />
22+
<>
23+
{/* eslint-disable-next-line react/no-array-index-key */}
24+
<div className="protocol-summary-rules__rule" key={n}>
25+
<Rule type={type} options={options} codebook={protocol.codebook} />
26+
</div>
4527
{ n !== rules.length - 1 && join && <Join value={join} /> }
46-
</div>
28+
</>
4729
))}
4830
</div>
4931
);

src/lib/ProtocolSummary/components/Stage/Behaviours.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { map } from 'lodash';
34
import MiniTable from '../MiniTable';
45
import { renderValue } from '../helpers';
56

7+
const behaviorLabel = (behaviourValue, behaviourKey) => {
8+
switch (behaviourKey) {
9+
case 'allowRepositioning':
10+
return { label: 'Repositioning enabled', value: behaviourValue };
11+
case 'automaticLayout':
12+
return { label: 'Automatic layout enabled', value: behaviourValue.enabled };
13+
case 'minNodes':
14+
return { label: 'Minimum nodes on stage', value: behaviourValue };
15+
case 'maxNodes':
16+
return { label: 'Maximum nodes on stage', value: behaviourValue };
17+
case 'freeDraw':
18+
return { label: 'Freedraw enabled', value: behaviourValue };
19+
default:
20+
return { label: behaviourKey, value: behaviourValue };
21+
}
22+
};
23+
24+
const behaviourRows = (behaviours) => map(behaviours, (behaviourValue, behaviourKey) => {
25+
const labelValue = behaviorLabel(behaviourValue, behaviourKey);
26+
return [
27+
labelValue.label,
28+
renderValue(labelValue.value),
29+
];
30+
});
31+
632
const Behaviours = ({ behaviours }) => {
733
if (!behaviours) { return null; }
834

@@ -12,16 +38,7 @@ const Behaviours = ({ behaviours }) => {
1238
<h2 className="section-heading">Behaviours</h2>
1339
<MiniTable
1440
rotated
15-
rows={[
16-
[
17-
'Repositioning enabled',
18-
renderValue(behaviours.allowRepositioning),
19-
],
20-
[
21-
'Freedraw enabled',
22-
renderValue(behaviours.freeDraw),
23-
],
24-
]}
41+
rows={behaviourRows(behaviours)}
2542
/>
2643
</div>
2744
</div>

src/lib/ProtocolSummary/components/Stage/Form.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import Markdown from '@codaco/ui/lib/components/Fields/Markdown';
44
import SummaryContext from '../SummaryContext';
55
import MiniTable from '../MiniTable';
66
import Variable from '../Variable';
7-
8-
const getVariableMeta = (index, variable) => (
9-
index.find(({ id }) => id === variable) || {}
10-
);
7+
import { getVariableMeta } from '../helpers';
118

129
const Form = ({ form }) => {
1310
const {

src/lib/ProtocolSummary/components/Stage/Presets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const Presets = ({ presets }) => {
4040
'Highlight attributes',
4141
<ul>
4242
{
43-
get(preset, 'preset.highlight', []).map((id) => (
43+
get(preset, 'highlight', []).map((id) => (
4444
<li key={id}>
4545
<Variable id={id} link />
4646
<br />

src/lib/ProtocolSummary/components/Stage/Prompt.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ const directionLabel = (direction) => (
1313
);
1414

1515
const SortOrder = ({ rules }) => {
16+
if (!rules) return null;
17+
1618
const result = rules
1719
.map(({ property, direction }) => (
1820
<li key={property}>
19-
<Variable id={property} />
21+
{(property === '*') ? '*' : <Variable id={property} />}
2022
{' '}
2123
<small>
2224
(
@@ -41,7 +43,7 @@ const attributes = [
4143
['highlight.allowHighlighting', 'Allow highlighting', (allow) => renderValue(allow)],
4244
['highlight.variable', 'Highlight variable', (id) => <Variable id={id} />],
4345
['negativeLabel', 'Negative Option Label', (text) => text],
44-
['sortOrder.property', 'Sort by property', (rules) => <SortOrder rules={rules} />],
46+
['sortOrder', 'Sort by property', (rules) => <SortOrder rules={rules} />],
4547
['binSortOrder', 'Bin sort order', (rules) => <SortOrder rules={rules} />],
4648
['bucketSortOrder', 'Bucket sort order', (rules) => <SortOrder rules={rules} />],
4749
['otherVariable', 'Other variable', (id) => <Variable id={id} />],

src/lib/ProtocolSummary/components/Stage/SkipLogic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const SkipLogic = ({ skipLogic }) => {
1616
<div className="protocol-summary-stage__skip-logic">
1717
<MiniTable
1818
rotated
19+
wide
1920
rows={[
2021
['Action', action],
2122
['Rules', <Rules filter={filter} />],

src/lib/ProtocolSummary/components/Stage/Stage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const Stage = ({
101101
<h2 className="section-heading">Network Filtering</h2>
102102
<MiniTable
103103
rotated
104+
wide
104105
rows={[
105106
['Rules', <Filter filter={configuration.filter} />],
106107
]}

src/lib/ProtocolSummary/components/Variable.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import React, { useContext } from 'react';
22
import PropTypes from 'prop-types';
3+
import { SimpleVariablePill } from '@components/Form/Fields/VariablePicker/VariablePill';
34
import SummaryContext from './SummaryContext';
45
import DualLink from './DualLink';
5-
import { getVariableName } from './helpers';
6+
import { getVariableName, getVariableMeta } from './helpers';
67

78
const Variable = ({
89
id,
910
}) => {
11+
if (!id) return null;
12+
1013
const {
1114
index,
1215
} = useContext(SummaryContext);
16+
const meta = getVariableMeta(index, id);
1317

1418
return (
1519
<DualLink
1620
to={`#variable-${id}`}
1721
className="protocol-summary-variable"
1822
>
19-
{getVariableName(index, id)}
23+
<SimpleVariablePill label={getVariableName(index, id)} type={meta.type} />
2024
</DualLink>
2125
);
2226
};

src/lib/ProtocolSummary/components/Variables.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
toPairs, get, find, isEmpty, sortBy,
77
} from 'lodash';
88
import Markdown from '@codaco/ui/lib/components/Fields/Markdown';
9+
import { SimpleVariablePill } from '@components/Form/Fields/VariablePicker/VariablePill';
910
import SummaryContext from './SummaryContext';
1011
import DualLink from './DualLink';
1112
import MiniTable from './MiniTable';
@@ -73,7 +74,7 @@ const Variables = ({ variables }) => {
7374

7475
return (
7576
<tr key={variableId} id={`variable-${variableId}`}>
76-
<td>{name}</td>
77+
<td><SimpleVariablePill label={name} type={type} /></td>
7778
<td>
7879
{type}
7980
<br />

src/lib/ProtocolSummary/components/helpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export const getVariableName = (index, variableId) => {
1616
return entry && entry.name;
1717
};
1818

19+
export const getVariableMeta = (index, variable) => (
20+
index.find(({ id }) => id === variable) || {}
21+
);
22+
1923
export const getEntityName = (codebook, entity, type) => (
2024
get(codebook, [entity, type, 'name'])
2125
);

src/lib/ProtocolSummary/styles/_protocol-summary.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
}
4343

4444
.protocol-summary-rules {
45+
.protocol-summary-rules__rule {
46+
--base-node-size: 5.6rem;
47+
display: flex;
48+
align-items: center;
49+
width: 100%;
50+
flex-grow: 1;
51+
}
52+
4553
&__rule:not(:last-child) {
4654
margin-bottom: unit(1);
4755
}
@@ -118,6 +126,12 @@
118126
font-family: -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
119127
font-size: 10pt;
120128
}
129+
130+
.variable-pill {
131+
zoom: .8;
132+
max-width: 24rem;
133+
margin: .5rem;
134+
}
121135
}
122136

123137
.protocol-summary-controls {

0 commit comments

Comments
 (0)