Skip to content

Commit

Permalink
Merge pull request #805 from complexdatacollective/fix/save-filter-crash
Browse files Browse the repository at this point in the history
Fixes not able to close stage editor when filter disabled & validation that references variables
  • Loading branch information
jthrilly authored Jun 14, 2023
2 parents 3e63063 + 6096571 commit f8af559
Show file tree
Hide file tree
Showing 19 changed files with 561 additions and 194 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '2.7.18'
# update apt cache
- name: Update apt cache
run: sudo apt-get update -y
# Set node version
- uses: actions/setup-node@v2
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '2.7.18'
# update apt cache
- name: Update apt cache
run: sudo apt-get update -y
# Set node version
- uses: actions/setup-node@v2
with:
Expand Down Expand Up @@ -55,6 +58,9 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '2.7.18'
# update apt cache
- name: Update apt cache
run: sudo apt-get update -y
# Set node version
- uses: actions/setup-node@v2
with:
Expand Down
97 changes: 53 additions & 44 deletions src/components/Codebook/Codebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import EntityType from './EntityType';
import ExternalEntity from './ExternalEntity';
import EgoType from './EgoType';
import CodebookCategory from './CodebookCategory';
import { getUsage, getUsageAsStageMeta } from './helpers';
import {
getStageMetaByIndex,
getUsage,
getUsageAsStageMeta,
getVariableMetaByIndex,
} from './helpers';

const Codebook = ({
edges,
Expand All @@ -21,59 +26,59 @@ const Codebook = ({
nodes,
}) => (
<div className="codebook">
{ !hasEgoVariables && !hasNodes && !hasEdges
{!hasEgoVariables && !hasNodes && !hasEdges
&& (
<p className="codebook__notice">
There are currently no types or variables defined in this protocol.
When you have created some interview stages, the types and variables will be shown here.
</p>
<p className="codebook__notice">
There are currently no types or variables defined in this protocol.
When you have created some interview stages, the types and variables will be shown here.
</p>
)}
{ hasEgoVariables
{hasEgoVariables
&& (
<CodebookCategory title="Ego">
<EgoType entity="ego" type="ego" />
</CodebookCategory>
<CodebookCategory title="Ego">
<EgoType entity="ego" type="ego" />
</CodebookCategory>
)}

{ hasNodes
{hasNodes
&& (
<CodebookCategory title="Node Types">
{nodes.map((node) => (
<EntityType
// eslint-disable-next-line react/jsx-props-no-spreading
{...node}
key={node.type}
/>
))}
</CodebookCategory>
<CodebookCategory title="Node Types">
{nodes.map((node) => (
<EntityType
// eslint-disable-next-line react/jsx-props-no-spreading
{...node}
key={node.type}
/>
))}
</CodebookCategory>
)}

{ hasEdges
{hasEdges
&& (
<CodebookCategory title="Edge Types">
{edges.map((edge) => (
<EntityType
// eslint-disable-next-line react/jsx-props-no-spreading
{...edge}
key={edge.type}
/>
))}
</CodebookCategory>
<CodebookCategory title="Edge Types">
{edges.map((edge) => (
<EntityType
// eslint-disable-next-line react/jsx-props-no-spreading
{...edge}
key={edge.type}
/>
))}
</CodebookCategory>
)}

{ hasNetworkAssets
{hasNetworkAssets
&& (
<CodebookCategory title="Network Assets">
{networkAssets.map(
(networkAsset) => (
<ExternalEntity
id={networkAsset.id}
name={networkAsset.name}
key={networkAsset.id}
/>
),
)}
</CodebookCategory>
<CodebookCategory title="Network Assets">
{networkAssets.map(
(networkAsset) => (
<ExternalEntity
id={networkAsset.id}
name={networkAsset.name}
key={networkAsset.id}
/>
),
)}
</CodebookCategory>
)}

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

// TODO: replace this with helpers getEntityProperties. This code was
// duplicated and needs to be reconciled.
const getEntityWithUsage = (state, index, mergeProps) => {
const search = utils.buildSearch([index]);

return (_, id) => {
const inUse = search.has(id);

const variableMeta = getVariableMetaByIndex(state);
const stageMetaByIndex = getStageMetaByIndex(state);

const usage = inUse
? getUsageAsStageMeta(state, getUsage(index, id))
? getUsageAsStageMeta(stageMetaByIndex, variableMeta, getUsage(index, id))
: [];

return {
Expand Down
17 changes: 8 additions & 9 deletions src/components/Codebook/EgoType.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const EgoType = ({
variables,
}) => (
<div className="codebook__entity">
{ variables.length > 0
{variables.length > 0
&& (
<div className="codebook__entity-variables codebook__entity-variables--no-border">
<h3>Variables:</h3>
<Variables
variables={variables}
entity="ego"
/>
</div>
<div className="codebook__entity-variables codebook__entity-variables--no-border">
<h3>Variables:</h3>
<Variables
variables={variables}
entity="ego"
/>
</div>
)}
</div>
);
Expand All @@ -33,7 +33,6 @@ EgoType.defaultProps = {

const mapStateToProps = (state) => {
const entityProperties = getEntityProperties(state, { entity: 'ego' });

return entityProperties;
};

Expand Down
7 changes: 6 additions & 1 deletion src/components/Codebook/Tag.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React from 'react';
import PropTypes from 'prop-types';

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

Tag.propTypes = {
children: PropTypes.node,
notUsed: PropTypes.bool,
};

Tag.defaultProps = {
children: null,
notUsed: false,
};

export default Tag;
17 changes: 13 additions & 4 deletions src/components/Codebook/UsageColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ const UsageColumn = ({
inUse,
usage,
}) => {
if (!inUse) { return (<Tag key="unused">not in use</Tag>); }
if (!inUse) { return (<Tag key="unused" notUsed>not in use</Tag>); }

const stages = usage
.map(({ id, label }) => (
<ScreenLink screen="stage" id={id} key={id}>{label}</ScreenLink>
));
.map(({ id, label }) => {
// If there is no id, don't create a link. This is the case for
// variables that are only in use as validation options.
if (!id) {
return (
<Tag key="validation-option">{label}</Tag>
);
}
return (
<ScreenLink screen="stage" id={id} key={id}>{label}</ScreenLink>
);
});

return (
<div className="codebook__variables-usage-container" key="usage">
Expand Down
46 changes: 45 additions & 1 deletion src/components/Codebook/__tests__/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
/* eslint-env jest */

import { getAllVariablesByUUID } from '../../../selectors/codebook';
import { getUsage, getUsageAsStageMeta } from '../helpers';

const state = {
protocol: {
present: {
codebook: {
ego: {
variables: {
1: {
name: 'name',
type: 'text',
},
},
},
node: {
person: {
variables: {
2: {
name: 'name',
type: 'text',
},
},
},
},
edge: {
friend: {
variables: {
3: {
name: 'name',
type: 'text',
},
},
},
},
},
stages: [
{ label: 'foo', id: 'abcd', other: 'ignored' },
{ label: 'bar', id: 'efgh', other: 'ignored' },
Expand All @@ -30,9 +61,22 @@ it('getUsage() ', () => {

it('getUsageAsStageMeta()', () => {
const usage = ['stages[0].foo.bar', 'stages[0].foo.bar.bazz', 'stages[1].foo.bar.bazz'];

const mockStageMetaByIndex = [
{ label: 'foo', id: 'abcd' },
{ label: 'bar', id: 'efgh' },
{ label: 'bazz', id: 'ijkl' },
];

const mockVariableMetaByIndex = getAllVariablesByUUID(state.protocol.present.codebook);

const expectedResult = [
{ label: 'foo', id: 'abcd' },
{ label: 'bar', id: 'efgh' },
];
expect(getUsageAsStageMeta(state, usage)).toEqual(expectedResult);
expect(getUsageAsStageMeta(
mockStageMetaByIndex,
mockVariableMetaByIndex,
usage,
)).toEqual(expectedResult);
});
Loading

0 comments on commit f8af559

Please sign in to comment.