import React from 'react'; import CategoriesCheckboxTree from 'wdk-client/Components/CheckboxTree/CategoriesCheckboxTree'; import { CategoryTreeNode, getAllLeafIds } from 'wdk-client/Utils/CategoryUtils'; import { getChangeHandler } from 'wdk-client/Utils/ComponentUtils'; import { Ontology } from 'wdk-client/Utils/OntologyUtils'; import { Question, RecordClass } from 'wdk-client/Utils/WdkModel'; import { State } from 'wdk-client/StoreModules/DownloadFormStoreModule'; import ReporterSortMessage from 'wdk-client/Views/ReporterForm/ReporterSortMessage'; import { addPk, getAllReportScopedAttributes, getAttributeSelections, getAttributeTree, getAttributesChangeHandler, getTableTree, } from 'wdk-client/Views/ReporterForm/reporterUtils'; import { LinksPosition } from '@veupathdb/coreui/dist/components/inputs/checkboxes/CheckboxTree/CheckboxTree'; type Props = { scope: string; question: Question; recordClass: RecordClass; summaryView: string; ontology: Ontology; formState: any; formUiState: any; updateFormState: (state: T) => T; updateFormUiState: (uiState: U) => U; onSubmit: () => void; includeSubmit: boolean; } function WdkServiceJsonReporterForm(props: Props) { let { scope, question, recordClass, ontology, formState, formUiState, updateFormState, updateFormUiState, onSubmit, includeSubmit } = props; let getUpdateHandler = (fieldName: string) => getChangeHandler(fieldName, updateFormState, formState); let getUiUpdateHandler = (fieldName: string) => getChangeHandler(fieldName, updateFormUiState, formUiState); return (
{ includeSubmit &&
}
); } namespace WdkServiceJsonReporterForm { export function getInitialState(downloadFormState: State) { let attribs: string[], tables: string[]; let { scope, question, recordClass, ontology, preferences } = downloadFormState; if (preferences == null || ontology == null || question == null || recordClass == null) { console.warn('DownloadForm state is missing data. Using empty attribute and tables.', downloadFormState); attribs = tables = []; } // select all attribs and tables for record page, else column user prefs and no tables else { let allReportScopedAttrs = getAllReportScopedAttributes( ontology, recordClass.fullName, question ); attribs = (scope === 'results' ? addPk(getAttributeSelections(preferences, question, allReportScopedAttrs), recordClass) : addPk(allReportScopedAttrs, recordClass)); tables = (scope === 'results' ? [] : getAllLeafIds(getTableTree(ontology, recordClass.fullName))); } return { formState: { attributes: attribs, tables: tables, attributeFormat: 'text' }, formUiState: { expandedAttributeNodes: null, attributeSearchText: "", expandedTableNodes: null, tableSearchText: "" } }; } } export default WdkServiceJsonReporterForm;