Skip to content

Commit

Permalink
split visualize-dropdown : visualize and external-questionnaire
Browse files Browse the repository at this point in the history
  • Loading branch information
BulotF committed Aug 28, 2023
1 parent 6e5609c commit 1921833
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 74 deletions.
5 changes: 0 additions & 5 deletions src/constants/pogues-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,6 @@ export const FORMULA_LANGUAGE = {
VTL: 'VTL',
};

export const DROPDOWN_TYPE = {
VISUALIZATION: 'VISUALIZATION',
EXTERNAL_ELEMENT: 'EXTERNAL_ELEMENT',
};

export const CODELISTS_ACTIONS = {
EDIT: {
name: 'edit',
Expand Down
8 changes: 3 additions & 5 deletions src/layout/generic-input/components/generic-input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import PropTypes from 'prop-types';
import ReactModal from 'react-modal';
import NavigationPrompt from 'react-router-navigation-prompt';
import { Link } from 'react-router-dom';
import { COMPONENT_TYPE, DROPDOWN_TYPE } from 'constants/pogues-constants';
import { COMPONENT_TYPE } from 'constants/pogues-constants';
import { GENERIC_INPUT } from 'constants/dom-constants';
import Dictionary from 'utils/dictionary/dictionary';
import { VisualizeDropdown } from 'widgets/visualize-dropdown';
import { ExternalQuestionnaireDropdown } from 'widgets/external-questionnaire-dropdown';
import { ComponentNew } from 'layout/component-new';
import Loader from 'layout/loader';

const { QUESTION, SEQUENCE, SUBSEQUENCE, LOOP, FILTER, EXTERNAL_ELEMENT } =
COMPONENT_TYPE;
const { COMPONENT_ID } = GENERIC_INPUT;
const { VISUALIZATION } = DROPDOWN_TYPE;

// PropTypes and defaultProps

Expand Down Expand Up @@ -227,14 +227,13 @@ function GenericInput(props) {
{Dictionary.filtre}
</button>
)}
<VisualizeDropdown
<ExternalQuestionnaireDropdown
disabled={
selectedComponent &&
selectedComponent.type !== SEQUENCE &&
selectedComponent.type !== EXTERNAL_ELEMENT
}
top
typeDropDown={EXTERNAL_ELEMENT}
/>
<button
className="btn-yellow"
Expand All @@ -256,7 +255,6 @@ function GenericInput(props) {
) : (
<VisualizeDropdown
top
typeDropDown={VISUALIZATION}
disabled={!isQuestionnaireValid}
visualizeActiveQuestionnaire={visualizeActiveQuestionnaire}
token={token}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { compose } from 'redux';
import DropZone from './drop-zone/drop-zone';

import { QUESTIONNAIRE_COMPONENT } from 'constants/dom-constants';
import { COMPONENT_TYPE, DROPDOWN_TYPE } from 'constants/pogues-constants';
import { COMPONENT_TYPE } from 'constants/pogues-constants';

import { VisualizeDropdown } from 'widgets/visualize-dropdown';
import { markdownVtlToString } from 'forms/controls/rich-textarea';
Expand All @@ -31,7 +31,6 @@ import { getIntegrityErrors } from 'utils/integrity/utils';
const { COMPONENT_CLASS } = QUESTIONNAIRE_COMPONENT;
const { QUESTION, SEQUENCE, SUBSEQUENCE, FILTER, EXTERNAL_ELEMENT } =
COMPONENT_TYPE;
const { VISUALIZATION } = DROPDOWN_TYPE;

const scrollToRef = ref => window.scrollTo(0, ref.current.offsetTop);

Expand Down Expand Up @@ -214,7 +213,6 @@ const QuestionnaireComponent = props => {
</button>
)}
<VisualizeDropdown
typeDropDown={VISUALIZATION}
componentId={component.id}
visualizeActiveQuestionnaire={
visualizeActiveQuestionnaire
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const QuestionnaireList = props => {
);
const componentState = {
id: checkedQuestionnaire,
name: externalQuestionnaire.name,
name:
externalQuestionnaire.name ||
externalQuestionnaire.label.replace(' ', ''),
parent: activeQuestionnaire.id,
weight: weight,
children: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import React, { useEffect, useState, useRef, useCallback } from 'react';
import PropTypes from 'prop-types';
import classSet from 'react-classset';
import { Link } from 'react-router-dom';

import Dictionary from 'utils/dictionary/dictionary';

/**
* Component used in the actions toolbar and on each
* component of the questionnaire. Will display a button
* with a dropdown behavior with links to different
* visualizations of the PDF : WEB, PDF or ODT
*/
function ExternalQuestionnaireDropdown({ questionnaireId, disabled, top }) {
const [dropdownOpen, setDropdownOpen] = useState(false);
const wrapperRef = useRef(null);

const handleClickOutside = useCallback(event => {
if (wrapperRef && !wrapperRef.current.contains(event.target)) {
setDropdownOpen(false);
}
}, []);

useEffect(() => {
window.addEventListener('mousedown', handleClickOutside);
return () => {
window.removeEventListener('mousedown', handleClickOutside);
};
}, [handleClickOutside]);

/**
* Will toggle the dropdown menu
*/
const openDropDown = e => {
e.preventDefault();
e.stopPropagation();
setDropdownOpen(!dropdownOpen);
};

const classDropDown = classSet({
'btn-group': true,
dropup: top,
'flex-column': !top,
'flex-column-reverse': top,
open: dropdownOpen,
});
const classDropDownTrigger = classSet({
btn: true,
'dropdown-toggle': true,
'btn-yellow': false,
'btn-white': true,
disabled: disabled,
});
const classDropDownList = classSet({
'dropdown-menu': true,
});
const linksQuestionnaire = [
{
actionType: 'tcmRef',
actionLabel: Dictionary.tcmReference,
page: 'tcm-composition',
},
{
actionType: 'questRef',
actionLabel: Dictionary.questionnaireReference,
page: 'composition',
},
{
actionType: 'questMerge',
actionLabel: Dictionary.questionnaireMerge,
page: 'merge',
},
];
return (
<div className={classDropDown} ref={wrapperRef}>
<button
className={classDropDownTrigger}
disabled={disabled}
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded={dropdownOpen}
onClick={e => openDropDown(e)}
>
{Dictionary.externalElement}
<span className="caret" />
</button>

<ul className={classDropDownList}>
{linksQuestionnaire.map(link => {
return (
<li key={link.actionLabel}>
<Link to={`/questionnaire/${questionnaireId}/${link.page}`}>
{link.actionLabel}
</Link>
</li>
);
})}
</ul>
</div>
);
}

// PropTypes and defaultProps

ExternalQuestionnaireDropdown.propTypes = {
disabled: PropTypes.bool.isRequired,
top: PropTypes.bool.isRequired,
};

export default ExternalQuestionnaireDropdown;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { connect } from 'react-redux';

import ExternalQuestionnaireDropdown from '../components/external-questionnaire-dropdown';

const mapStateToProps = state => ({
questionnaireId: state.appState.activeQuestionnaire.id,
});

const ExternalQuestionnaireDropdownContainer = connect(mapStateToProps)(
ExternalQuestionnaireDropdown,
);

export default ExternalQuestionnaireDropdownContainer;
1 change: 1 addition & 0 deletions src/widgets/external-questionnaire-dropdown/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as ExternalQuestionnaireDropdown } from './containers/external-questionnaire-dropdown-container';
55 changes: 12 additions & 43 deletions src/widgets/visualize-dropdown/components/visualize-dropdown.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useState, useRef, useCallback } from 'react';
import PropTypes from 'prop-types';
import classSet from 'react-classset';
import { Link } from 'react-router-dom';

import Dictionary from 'utils/dictionary/dictionary';

Expand All @@ -12,13 +11,11 @@ import Dictionary from 'utils/dictionary/dictionary';
* visualizations of the PDF : WEB, PDF or ODT
*/
function VisualizeDropdown({
questionnaireId,
componentId,
token,
disabled,
top,
visualizeActiveQuestionnaire,
typeDropDown,
}) {
const [dropdownOpen, setDropdownOpen] = useState(false);
const wrapperRef = useRef(null);
Expand Down Expand Up @@ -65,8 +62,8 @@ function VisualizeDropdown({
const classDropDownTrigger = classSet({
btn: true,
'dropdown-toggle': true,
'btn-yellow': typeDropDown === 'VISUALIZATION',
'btn-white': typeDropDown !== 'VISUALIZATION',
'btn-yellow': true,
'btn-white': false,
disabled: disabled,
});
const classDropDownList = classSet({
Expand All @@ -84,23 +81,6 @@ function VisualizeDropdown({
{ actionType: 'spec', actionLabel: Dictionary.VISUALIZE_SPECIFICATION },
{ actionType: 'ddi', actionLabel: Dictionary.VISUALIZE_DDI },
];
const linksQuestionnaire = [
{
actionType: 'tcmRef',
actionLabel: Dictionary.tcmReference,
page: 'tcm-composition',
},
{
actionType: 'questRef',
actionLabel: Dictionary.questionnaireReference,
page: 'composition',
},
{
actionType: 'questMerge',
actionLabel: Dictionary.questionnaireMerge,
page: 'merge',
},
];
return (
<div className={classDropDown} ref={wrapperRef}>
<button
Expand All @@ -111,31 +91,20 @@ function VisualizeDropdown({
aria-expanded={dropdownOpen}
onClick={e => openDropDown(e)}
>
{typeDropDown === 'VISUALIZATION' && Dictionary.visualise}
{typeDropDown !== 'VISUALIZATION' && Dictionary.externalElement}
{Dictionary.visualise}
<span className="caret" />
</button>

<ul className={classDropDownList}>
{typeDropDown === 'VISUALIZATION'
? links.map(link => {
return (
<li key={link.actionLabel}>
<a href="#" onClick={e => visualize(e, link.actionType)}>
{link.actionLabel}
</a>
</li>
);
})
: linksQuestionnaire.map(link => {
return (
<li key={link.actionLabel}>
<Link to={`/questionnaire/${questionnaireId}/${link.page}`}>
{link.actionLabel}
</Link>
</li>
);
})}
{links.map(link => {
return (
<li key={link.actionLabel}>
<a href="#" onClick={e => visualize(e, link.actionType)}>
{link.actionLabel}
</a>
</li>
);
})}
</ul>
</div>
);
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/widgets/visualize-dropdown/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as VisualizeDropdown } from './containers/visualize-dropdown-container';
export { default as VisualizeDropdown } from './components/visualize-dropdown';
5 changes: 0 additions & 5 deletions src/widgets/visualize-dropdown/visualize-dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('Visualize Dropdown Component: ', () => {
disabled: false,
top: false,
componentId: 'component-id',
typeDropDown: 'VISUALIZATION',
};
const tree = renderer.create(<VisualizeDropdown {...props} />).toJSON();

Expand All @@ -23,7 +22,6 @@ describe('Visualize Dropdown Component: ', () => {
disabled: false,
top: true,
componentId: 'component-id',
typeDropDown: 'VISUALIZATION',
};
const tree = renderer.create(<VisualizeDropdown {...props} />).toJSON();

Expand All @@ -35,7 +33,6 @@ describe('Visualize Dropdown Component: ', () => {
disabled: true,
top: false,
componentId: 'component-id',
typeDropDown: 'VISUALIZATION',
};
const tree = renderer.create(<VisualizeDropdown {...props} />).toJSON();

Expand All @@ -47,7 +44,6 @@ describe('Visualize Dropdown Component: ', () => {
disabled: true,
top: false,
componentId: 'component-id',
typeDropDown: 'VISUALIZATION',
};
const wrapper = shallow(<VisualizeDropdown {...props} />);
expect(wrapper.find('div').hasClass('open')).toBeFalsy();
Expand All @@ -67,7 +63,6 @@ describe('Visualize Dropdown Component: ', () => {
disabled: true,
top: false,
componentId: 'component-id',
typeDropDown: 'VISUALIZATION',
};
const wrapper = shallow(<VisualizeDropdown {...props} />);
wrapper
Expand Down

0 comments on commit 1921833

Please sign in to comment.