Skip to content

Commit f8af559

Browse files
authored
Merge pull request #805 from complexdatacollective/fix/save-filter-crash
Fixes not able to close stage editor when filter disabled & validation that references variables
2 parents 3e63063 + 6096571 commit f8af559

File tree

19 files changed

+561
-194
lines changed

19 files changed

+561
-194
lines changed

.github/workflows/dist.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
- uses: actions/setup-python@v4
1919
with:
2020
python-version: '2.7.18'
21+
# update apt cache
22+
- name: Update apt cache
23+
run: sudo apt-get update -y
2124
# Set node version
2225
- uses: actions/setup-node@v2
2326
with:

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
- uses: actions/setup-python@v4
1919
with:
2020
python-version: '2.7.18'
21+
# update apt cache
22+
- name: Update apt cache
23+
run: sudo apt-get update -y
2124
# Set node version
2225
- uses: actions/setup-node@v2
2326
with:
@@ -55,6 +58,9 @@ jobs:
5558
- uses: actions/setup-python@v4
5659
with:
5760
python-version: '2.7.18'
61+
# update apt cache
62+
- name: Update apt cache
63+
run: sudo apt-get update -y
5864
# Set node version
5965
- uses: actions/setup-node@v2
6066
with:

src/components/Codebook/Codebook.js

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import EntityType from './EntityType';
99
import ExternalEntity from './ExternalEntity';
1010
import EgoType from './EgoType';
1111
import CodebookCategory from './CodebookCategory';
12-
import { getUsage, getUsageAsStageMeta } from './helpers';
12+
import {
13+
getStageMetaByIndex,
14+
getUsage,
15+
getUsageAsStageMeta,
16+
getVariableMetaByIndex,
17+
} from './helpers';
1318

1419
const Codebook = ({
1520
edges,
@@ -21,59 +26,59 @@ const Codebook = ({
2126
nodes,
2227
}) => (
2328
<div className="codebook">
24-
{ !hasEgoVariables && !hasNodes && !hasEdges
29+
{!hasEgoVariables && !hasNodes && !hasEdges
2530
&& (
26-
<p className="codebook__notice">
27-
There are currently no types or variables defined in this protocol.
28-
When you have created some interview stages, the types and variables will be shown here.
29-
</p>
31+
<p className="codebook__notice">
32+
There are currently no types or variables defined in this protocol.
33+
When you have created some interview stages, the types and variables will be shown here.
34+
</p>
3035
)}
31-
{ hasEgoVariables
36+
{hasEgoVariables
3237
&& (
33-
<CodebookCategory title="Ego">
34-
<EgoType entity="ego" type="ego" />
35-
</CodebookCategory>
38+
<CodebookCategory title="Ego">
39+
<EgoType entity="ego" type="ego" />
40+
</CodebookCategory>
3641
)}
3742

38-
{ hasNodes
43+
{hasNodes
3944
&& (
40-
<CodebookCategory title="Node Types">
41-
{nodes.map((node) => (
42-
<EntityType
43-
// eslint-disable-next-line react/jsx-props-no-spreading
44-
{...node}
45-
key={node.type}
46-
/>
47-
))}
48-
</CodebookCategory>
45+
<CodebookCategory title="Node Types">
46+
{nodes.map((node) => (
47+
<EntityType
48+
// eslint-disable-next-line react/jsx-props-no-spreading
49+
{...node}
50+
key={node.type}
51+
/>
52+
))}
53+
</CodebookCategory>
4954
)}
5055

51-
{ hasEdges
56+
{hasEdges
5257
&& (
53-
<CodebookCategory title="Edge Types">
54-
{edges.map((edge) => (
55-
<EntityType
56-
// eslint-disable-next-line react/jsx-props-no-spreading
57-
{...edge}
58-
key={edge.type}
59-
/>
60-
))}
61-
</CodebookCategory>
58+
<CodebookCategory title="Edge Types">
59+
{edges.map((edge) => (
60+
<EntityType
61+
// eslint-disable-next-line react/jsx-props-no-spreading
62+
{...edge}
63+
key={edge.type}
64+
/>
65+
))}
66+
</CodebookCategory>
6267
)}
6368

64-
{ hasNetworkAssets
69+
{hasNetworkAssets
6570
&& (
66-
<CodebookCategory title="Network Assets">
67-
{networkAssets.map(
68-
(networkAsset) => (
69-
<ExternalEntity
70-
id={networkAsset.id}
71-
name={networkAsset.name}
72-
key={networkAsset.id}
73-
/>
74-
),
75-
)}
76-
</CodebookCategory>
71+
<CodebookCategory title="Network Assets">
72+
{networkAssets.map(
73+
(networkAsset) => (
74+
<ExternalEntity
75+
id={networkAsset.id}
76+
name={networkAsset.name}
77+
key={networkAsset.id}
78+
/>
79+
),
80+
)}
81+
</CodebookCategory>
7782
)}
7883

7984
</div>
@@ -92,14 +97,18 @@ Codebook.propTypes = {
9297
nodes: PropTypes.array.isRequired,
9398
};
9499

100+
// TODO: replace this with helpers getEntityProperties. This code was
101+
// duplicated and needs to be reconciled.
95102
const getEntityWithUsage = (state, index, mergeProps) => {
96103
const search = utils.buildSearch([index]);
97-
98104
return (_, id) => {
99105
const inUse = search.has(id);
100106

107+
const variableMeta = getVariableMetaByIndex(state);
108+
const stageMetaByIndex = getStageMetaByIndex(state);
109+
101110
const usage = inUse
102-
? getUsageAsStageMeta(state, getUsage(index, id))
111+
? getUsageAsStageMeta(stageMetaByIndex, variableMeta, getUsage(index, id))
103112
: [];
104113

105114
return {

src/components/Codebook/EgoType.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const EgoType = ({
99
variables,
1010
}) => (
1111
<div className="codebook__entity">
12-
{ variables.length > 0
12+
{variables.length > 0
1313
&& (
14-
<div className="codebook__entity-variables codebook__entity-variables--no-border">
15-
<h3>Variables:</h3>
16-
<Variables
17-
variables={variables}
18-
entity="ego"
19-
/>
20-
</div>
14+
<div className="codebook__entity-variables codebook__entity-variables--no-border">
15+
<h3>Variables:</h3>
16+
<Variables
17+
variables={variables}
18+
entity="ego"
19+
/>
20+
</div>
2121
)}
2222
</div>
2323
);
@@ -33,7 +33,6 @@ EgoType.defaultProps = {
3333

3434
const mapStateToProps = (state) => {
3535
const entityProperties = getEntityProperties(state, { entity: 'ego' });
36-
3736
return entityProperties;
3837
};
3938

src/components/Codebook/Tag.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
const Tag = ({ children }) => (<div className="codebook__tag">{children}</div>);
4+
const Tag = ({ children, notUsed = false }) => {
5+
const classes = notUsed ? 'codebook__tag codebook__tag--not-used' : 'codebook__tag';
6+
return (<div className={classes}>{children}</div>);
7+
};
58

69
Tag.propTypes = {
710
children: PropTypes.node,
11+
notUsed: PropTypes.bool,
812
};
913

1014
Tag.defaultProps = {
1115
children: null,
16+
notUsed: false,
1217
};
1318

1419
export default Tag;

src/components/Codebook/UsageColumn.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@ const UsageColumn = ({
77
inUse,
88
usage,
99
}) => {
10-
if (!inUse) { return (<Tag key="unused">not in use</Tag>); }
10+
if (!inUse) { return (<Tag key="unused" notUsed>not in use</Tag>); }
1111

1212
const stages = usage
13-
.map(({ id, label }) => (
14-
<ScreenLink screen="stage" id={id} key={id}>{label}</ScreenLink>
15-
));
13+
.map(({ id, label }) => {
14+
// If there is no id, don't create a link. This is the case for
15+
// variables that are only in use as validation options.
16+
if (!id) {
17+
return (
18+
<Tag key="validation-option">{label}</Tag>
19+
);
20+
}
21+
return (
22+
<ScreenLink screen="stage" id={id} key={id}>{label}</ScreenLink>
23+
);
24+
});
1625

1726
return (
1827
<div className="codebook__variables-usage-container" key="usage">

src/components/Codebook/__tests__/helpers.test.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
/* eslint-env jest */
22

3+
import { getAllVariablesByUUID } from '../../../selectors/codebook';
34
import { getUsage, getUsageAsStageMeta } from '../helpers';
45

56
const state = {
67
protocol: {
78
present: {
9+
codebook: {
10+
ego: {
11+
variables: {
12+
1: {
13+
name: 'name',
14+
type: 'text',
15+
},
16+
},
17+
},
18+
node: {
19+
person: {
20+
variables: {
21+
2: {
22+
name: 'name',
23+
type: 'text',
24+
},
25+
},
26+
},
27+
},
28+
edge: {
29+
friend: {
30+
variables: {
31+
3: {
32+
name: 'name',
33+
type: 'text',
34+
},
35+
},
36+
},
37+
},
38+
},
839
stages: [
940
{ label: 'foo', id: 'abcd', other: 'ignored' },
1041
{ label: 'bar', id: 'efgh', other: 'ignored' },
@@ -30,9 +61,22 @@ it('getUsage() ', () => {
3061

3162
it('getUsageAsStageMeta()', () => {
3263
const usage = ['stages[0].foo.bar', 'stages[0].foo.bar.bazz', 'stages[1].foo.bar.bazz'];
64+
65+
const mockStageMetaByIndex = [
66+
{ label: 'foo', id: 'abcd' },
67+
{ label: 'bar', id: 'efgh' },
68+
{ label: 'bazz', id: 'ijkl' },
69+
];
70+
71+
const mockVariableMetaByIndex = getAllVariablesByUUID(state.protocol.present.codebook);
72+
3373
const expectedResult = [
3474
{ label: 'foo', id: 'abcd' },
3575
{ label: 'bar', id: 'efgh' },
3676
];
37-
expect(getUsageAsStageMeta(state, usage)).toEqual(expectedResult);
77+
expect(getUsageAsStageMeta(
78+
mockStageMetaByIndex,
79+
mockVariableMetaByIndex,
80+
usage,
81+
)).toEqual(expectedResult);
3882
});

0 commit comments

Comments
 (0)