Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iniitial table cleanup #3224

Merged
merged 6 commits into from
May 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions jsapp/js/assetUtils.es6
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,20 @@ export function getAssetDisplayName(asset) {
}

/**
* @param {Object} question - Part of BE asset data
* @param {Object} questionOrChoice - Part of BE asset data
* @param {number} [translationIndex] - defaults to first (default) language
* @returns {string} usable name of the question when possible, "Unlabelled" otherwise.
* @returns {string} usable name of the question or choice when possible, "Unlabelled" otherwise.
*/
export function getQuestionDisplayName(question, translationIndex = 0) {
if (question.label && Array.isArray(question.label)) {
return question.label[translationIndex];
} else if (question.label && !Array.isArray(question.label)) {
export function getQuestionOrChoiceDisplayName(questionOrChoice, translationIndex = 0) {
if (questionOrChoice.label && Array.isArray(questionOrChoice.label)) {
return questionOrChoice.label[translationIndex];
} else if (questionOrChoice.label && !Array.isArray(questionOrChoice.label)) {
// in rare cases the label could be a string
return question.label;
} else if (question.name) {
return question.name;
} else if (question.$autoname) {
return question.$autoname;
return questionOrChoice.label;
} else if (questionOrChoice.name) {
return questionOrChoice.name;
} else if (questionOrChoice.$autoname) {
return questionOrChoice.$autoname;
} else {
t('Unlabelled');
}
Expand Down Expand Up @@ -432,7 +432,7 @@ export function getFlatQuestionsList(survey, translationIndex = 0, includeMeta =
let openedRepeatGroupsCount = 0;
survey.forEach((row) => {
if (row.type === 'begin_group' || row.type === 'begin_repeat') {
openedGroups.push(getQuestionDisplayName(row, translationIndex));
openedGroups.push(getQuestionOrChoiceDisplayName(row, translationIndex));
}
if (row.type === 'end_group' || row.type === 'end_repeat') {
openedGroups.pop();
Expand All @@ -453,7 +453,7 @@ export function getFlatQuestionsList(survey, translationIndex = 0, includeMeta =
type: row.type,
name: rowName,
isRequired: Boolean(row.required),
label: getQuestionDisplayName(row, translationIndex),
label: getQuestionOrChoiceDisplayName(row, translationIndex),
path: flatPaths[rowName],
parents: openedGroups.slice(0),
hasRepatParent: openedRepeatGroupsCount >= 1,
Expand Down Expand Up @@ -553,7 +553,7 @@ export default {
getLanguageIndex,
getLanguagesDisplayString,
getOrganizationDisplayString,
getQuestionDisplayName,
getQuestionOrChoiceDisplayName,
getRowName,
getSectorDisplayString,
getSurveyFlatPaths,
Expand Down
2 changes: 1 addition & 1 deletion jsapp/js/components/formSubScreens.es6
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import assetUtils from 'js/assetUtils';
import DocumentTitle from 'react-document-title';
import SharingForm from './permissions/sharingForm';
import ProjectSettings from './modalForms/projectSettings';
import DataTable from './table';
import DataTable from 'js/components/submissions/table';
import ProjectExportsCreator from 'js/components/projectDownloads/projectExportsCreator';
import ProjectExportsList from 'js/components/projectDownloads/projectExportsList';
import {PROJECT_SETTINGS_CONTEXTS} from '../constants';
Expand Down
18 changes: 10 additions & 8 deletions jsapp/js/components/modal.es6
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import BulkEditSubmissionsForm from './modalForms/bulkEditSubmissionsForm.es6';
import ProjectSettings from './modalForms/projectSettings';
import RESTServicesForm from './RESTServices/RESTServicesForm';
import SharingForm from './permissions/sharingForm';
import Submission from './modalForms/submission';
import TableColumnFilter from './modalForms/tableColumnFilter';
import SubmissionModal from 'js/components/submissions/submissionModal';
import TableColumnFilter from 'js/components/submissions/tableColumnFilter';
import TranslationSettings from './modalForms/translationSettings';
import TranslationTable from './modalForms/translationTable';

Expand Down Expand Up @@ -316,12 +316,14 @@ class Modal extends React.Component {
</div>
}
{ this.props.params.type === MODAL_TYPES.SUBMISSION && this.state.sid &&
<Submission sid={this.state.sid}
asset={this.props.params.asset}
ids={this.props.params.ids}
isDuplicated={this.props.params.isDuplicated}
duplicatedSubmission={this.props.params.duplicatedSubmission}
tableInfo={this.props.params.tableInfo || false} />
<SubmissionModal
sid={this.state.sid}
asset={this.props.params.asset}
ids={this.props.params.ids}
isDuplicated={this.props.params.isDuplicated}
duplicatedSubmission={this.props.params.duplicatedSubmission}
tableInfo={this.props.params.tableInfo || false}
/>
}
{ this.props.params.type === MODAL_TYPES.SUBMISSION && !this.state.sid &&
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {renderQuestionTypeIcon} from 'js/assetUtils';
import {
DISPLAY_GROUP_TYPES,
getSubmissionDisplayData,
} from 'js/submissionUtils';
} from 'js/components/submissions/submissionUtils';
import {
META_QUESTION_TYPES,
QUESTION_TYPES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,28 @@ import {actions} from 'js/actions';
import mixins from 'js/mixins';
import {bem} from 'js/bem';
import {LoadingSpinner} from 'js/ui';
import {notify, launchPrinting} from 'utils';
import {launchPrinting} from 'utils';
import {stores} from 'js/stores';
import {
VALIDATION_STATUSES_LIST,
MODAL_TYPES,
GROUP_TYPES_BEGIN,
GROUP_TYPES_END
} from 'js/constants';
import SubmissionDataTable from 'js/components/submissionDataTable';
import SubmissionDataTable from './submissionDataTable';
import Checkbox from 'js/components/common/checkbox';

const DETAIL_NOT_FOUND = '{\"detail\":\"Not found.\"}';

class Submission extends React.Component {
class SubmissionModal extends React.Component {
constructor(props) {
super(props);
let translations = this.props.asset.content.translations,
translationOptions = [];
let translations = this.props.asset.content.translations;
let translationOptions = [];

if (translations.length > 1) {
translationOptions = translations.map((trns) => {
return {
value: trns,
label: trns || t('Unnamed language')
label: trns || t('Unnamed language'),
};
});
}
Expand All @@ -56,7 +54,7 @@ class Submission extends React.Component {
promptRefresh: false,
translationIndex: 0,
translationOptions: translationOptions,
showXMLNames: false
showXMLNames: false,
};

autoBind(this);
Expand Down Expand Up @@ -88,7 +86,7 @@ class Submission extends React.Component {
let next = -1;

if (this.props.ids && sid) {
const c = this.props.ids.findIndex((k) => {return k === parseInt(sid);});
const c = this.props.ids.findIndex((k) => k === parseInt(sid));
let tableInfo = this.props.tableInfo || false;
if (this.props.ids[c - 1]) {
prev = this.props.ids[c - 1];
Expand All @@ -114,7 +112,7 @@ class Submission extends React.Component {
submission: data,
loading: false,
next: next,
previous: prev
previous: prev,
});
}).fail((error) => {
if (error.responseText) {
Expand All @@ -134,7 +132,7 @@ class Submission extends React.Component {
componentWillReceiveProps(nextProps) {
this.setState({
sid: nextProps.sid,
promptRefresh: false
promptRefresh: false,
});

this.getSubmission(nextProps.asset.uid, nextProps.sid);
Expand All @@ -151,7 +149,7 @@ class Submission extends React.Component {
},
oncancel: () => {
dialog.destroy();
}
},
};
dialog.set(opts).show();
}
Expand Down Expand Up @@ -183,7 +181,7 @@ class Submission extends React.Component {
triggerRefresh() {
this.getSubmission(this.props.asset.uid, this.props.sid);
this.setState({
promptRefresh: false
promptRefresh: false,
});
// Prompt table to refresh submission list
actions.resources.refreshTableSubmissions();
Expand All @@ -196,7 +194,7 @@ class Submission extends React.Component {
sid: sid,
asset: this.props.asset,
ids: this.props.ids,
tableInfo: this.props.tableInfo || false
tableInfo: this.props.tableInfo || false,
});
}

Expand All @@ -206,7 +204,7 @@ class Submission extends React.Component {
stores.pageState.showModal({
type: MODAL_TYPES.SUBMISSION,
sid: false,
page: 'prev'
page: 'prev',
});
}

Expand All @@ -216,7 +214,7 @@ class Submission extends React.Component {
stores.pageState.showModal({
type: MODAL_TYPES.SUBMISSION,
sid: false,
page: 'next'
page: 'next',
});
}

Expand All @@ -233,9 +231,9 @@ class Submission extends React.Component {
}

languageChange(e) {
let index = this.state.translationOptions.findIndex((x) => {return x === e;});
let index = this.state.translationOptions.findIndex((x) => x === e);
this.setState({
translationIndex: index || 0
translationIndex: index || 0,
});
}

Expand Down Expand Up @@ -460,9 +458,12 @@ class Submission extends React.Component {
</a>
}

<bem.Button m='icon' className='report-button__print'
onClick={launchPrinting}
data-tip={t('Print')}>
<bem.Button
m='icon'
className='report-button__print'
onClick={launchPrinting}
data-tip={t('Print')}
>
<i className='k-icon-print' />
</bem.Button>

Expand Down Expand Up @@ -490,7 +491,7 @@ class Submission extends React.Component {
}
}

reactMixin(Submission.prototype, Reflux.ListenerMixin);
reactMixin(Submission.prototype, mixins.permissions);
reactMixin(SubmissionModal.prototype, Reflux.ListenerMixin);
reactMixin(SubmissionModal.prototype, mixins.permissions);

export default Submission;
export default SubmissionModal;
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ export function getSubmissionDisplayData(survey, choices, translationIndex, subm
// score and rank don't have list name on them and they need to use
// the one of their parent
if (row.type === SCORE_ROW_TYPE || row.type === RANK_LEVEL_TYPE) {
const parentGroupRow = survey.find((row) => {
return getRowName(row) === parentGroup.name;
});
const parentGroupRow = survey.find((row) =>
getRowName(row) === parentGroup.name
);
rowListName = getRowListName(parentGroupRow);
}

Expand Down Expand Up @@ -265,9 +265,9 @@ function populateMatrixData(
*/
Object.keys(flatPaths).forEach((questionName) => {
if (flatPaths[questionName].startsWith(`${matrixGroupPath}/`)) {
const questionSurveyObj = survey.find((row) => {
return getRowName(row) === questionName;
});
const questionSurveyObj = survey.find((row) =>
getRowName(row) === questionName
);

/*
* NOTE: Submission data for a Matrix question is kept in an unusal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
matrixRepeatSurveyChoices,
matrixRepeatSurveySubmission,
matrixRepeatSurveyDisplayData,
} from 'js/submissionUtils.mocks';
import {getSubmissionDisplayData} from 'js/submissionUtils';
} from './submissionUtils.mocks';
import {getSubmissionDisplayData} from './submissionUtils';

describe('getSubmissionDisplayData', () => {
it('should return a valid data for a survey with a group', () => {
Expand Down
Loading