Skip to content

Commit

Permalink
chore: reduce max line length to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
plinnegan committed Nov 3, 2021
1 parent 0a2412f commit 41bb74f
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ module.exports = {
semi: false,
singleQuote: true,
quoteProps: 'consistent',
printWidth: 120,
printWidth: 100,
}
42 changes: 35 additions & 7 deletions src/calculateInds.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ function calculatePis(rowId, dsUid, deUid, piUid, coMaps, metadata, generatedPis
}

function getMappingAttr(piUid, attributeValues) {
const attrVal = attributeValues.filter(attrVal => attrVal.attribute.id === config.indCustomAttr.id)
const attrVal = attributeValues.filter(
attrVal => attrVal.attribute.id === config.indCustomAttr.id
)
if (attrVal.length === 0) {
throw new MappingGenerationError(
`Program indicator ${piUid.id} does not have de mapping attribute value for custom attribute ${config.indCustomAttr.id}`
`Program indicator ${piUid.id} does not have de mapping attribute value for custom ` +
`attribute ${config.indCustomAttr.id}`
)
} else {
return attrVal[0].value
Expand Down Expand Up @@ -173,14 +176,18 @@ function generateInd(indUid, piSource, indTypeUid) {
}

function calculateIndGroup(rowId, generatedIndGroups, createUpdateInds) {
const IndGroups = generatedIndGroups.filter(indGroup => indGroup.name.includes(`indMappingGroup-${rowId}`))
const IndGroups = generatedIndGroups.filter(indGroup =>
indGroup.name.includes(`indMappingGroup-${rowId}`)
)
let indGroup
if (IndGroups.length) {
indGroup = IndGroups[0]
} else {
const uid = makeUid()
indGroup = {
name: `indMappingGroup-${rowId} (/api/analytics/dataValueSet.json?dimension=dx:IN_GROUP-${uid}&outputIdScheme=ATTRIBUTE:${config.indCustomAttr.id}) (generated)`,
name:
`indMappingGroup-${rowId} (/api/analytics/dataValueSet.json?dimension=dx:IN_GROUP-` +
`${uid}&outputIdScheme=ATTRIBUTE:${config.indCustomAttr.id}) (generated)`,
id: uid,
}
}
Expand Down Expand Up @@ -214,7 +221,15 @@ function calculateInds(createUpdatePis, deletePis, generatedInds, indTypes) {
}
}

export default function generateDataMapping(rowId, dsUid, deUid, piUid, coMaps, baseMetadata, generatedMetadata) {
export default function generateDataMapping(
rowId,
dsUid,
deUid,
piUid,
coMaps,
baseMetadata,
generatedMetadata
) {
const indTypes = baseMetadata.indicatorTypes.indicatorTypes
const {
programIndicators: generatedPis,
Expand All @@ -225,8 +240,21 @@ export default function generateDataMapping(rowId, dsUid, deUid, piUid, coMaps,
...generatedMetadata.generatedInds,
...generatedMetadata.generatedIndGroups,
}
const { createUpdatePis, deletePis } = calculatePis(rowId, dsUid, deUid, piUid, coMaps, baseMetadata, generatedPis)
const { createUpdateInds, deleteInds } = calculateInds(createUpdatePis, deletePis, generatedInds, indTypes)
const { createUpdatePis, deletePis } = calculatePis(
rowId,
dsUid,
deUid,
piUid,
coMaps,
baseMetadata,
generatedPis
)
const { createUpdateInds, deleteInds } = calculateInds(
createUpdatePis,
deletePis,
generatedInds,
indTypes
)
const indGroup = calculateIndGroup(rowId, generatedIndGroups, createUpdateInds)
return {
createUpdateMetadata: {
Expand Down
9 changes: 7 additions & 2 deletions src/components/CoFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const CoFilters = ({ rowData, setRowData, coMappings, setCoMappings }) => {
const coUids = Object.keys(coMappings)
return (
<>
{coUids.length === 0 && <p style={noCoStyle}>No category options for the selected data element</p>}
{coUids.length === 0 && (
<p style={noCoStyle}>No category options for the selected data element</p>
)}
{coUids.length > 0 && (
<Table>
<TableHead>
Expand Down Expand Up @@ -53,7 +55,10 @@ CoFilters.propTypes = {
deName: PropTypes.string.isRequired,
dsName: PropTypes.string.isRequired,
piName: PropTypes.string.isRequired,
coFilters: PropTypes.shape({ name: PropTypes.string.isRequired, id: PropTypes.string.isRequired }),
coFilters: PropTypes.shape({
name: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
}),
}).isRequired,
setRowData: PropTypes.func.isRequired,
coMappings: PropTypes.objectOf(
Expand Down
9 changes: 7 additions & 2 deletions src/components/ImportSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const ImportSummary = ({ handleClose, importResults }) => {
<Modal large>
<ModalTitle>Import Summary</ModalTitle>
<ModalContent>
<h4 style={{ color: success ? 'green' : 'red' }}>Import {success ? 'succeeded' : 'failed'}</h4>
<h4 style={{ color: success ? 'green' : 'red' }}>
Import {success ? 'succeeded' : 'failed'}
</h4>
<p>{message}</p>
</ModalContent>
<ModalActions>
Expand All @@ -22,7 +24,10 @@ const ImportSummary = ({ handleClose, importResults }) => {

ImportSummary.propTypes = {
handleClose: PropTypes.func,
importResults: PropTypes.shape({ success: PropTypes.bool.isRequired, message: PropTypes.string.isRequired }),
importResults: PropTypes.shape({
success: PropTypes.bool.isRequired,
message: PropTypes.string.isRequired,
}),
}

export default ImportSummary
7 changes: 6 additions & 1 deletion src/components/Mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ const Mapping = ({ coMaps, rowDataIn, metadata, handleClose, handleUpdate }) =>
/>
<br />
<br />
<CoFilters rowData={rowData} setRowData={setRowData} coMappings={coMappings} setCoMappings={setCoMappings} />
<CoFilters
rowData={rowData}
setRowData={setRowData}
coMappings={coMappings}
setCoMappings={setCoMappings}
/>
</ModalContent>
<ModalActions>
<ButtonStrip>
Expand Down
28 changes: 21 additions & 7 deletions src/components/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ const generatedMeta = {
resource: 'programIndicators',
params: {
filter: 'name:like:rowId-',
fields: 'id,code,description,aggregateExportCategoryOptionCombo,aggregateExportAttributeOptionCombo',
fields:
'id,code,description,aggregateExportCategoryOptionCombo,aggregateExportAttributeOptionCombo',
paging: 'false',
},
},
generatedInds: {
resource: 'indicators',
params: {
filter: 'name:like:rowId-',
fields: 'id,code,description,aggregateExportCategoryOptionCombo,aggregateExportAttributeOptionCombo',
fields:
'id,code,description,aggregateExportCategoryOptionCombo,aggregateExportAttributeOptionCombo',
paging: 'false',
},
},
Expand Down Expand Up @@ -189,7 +191,15 @@ const Page = ({ metadata, existingConfig }) => {
const coFilters = { ...coMaps, ...coRowFilters }
setRowsLoading({ ...rowsLoading, [rowId]: true })
try {
const results = generateDataMapping(rowId, dsUid, deUid, piUid, coFilters, metadata, generatedMetadata)
const results = generateDataMapping(
rowId,
dsUid,
deUid,
piUid,
coFilters,
metadata,
generatedMetadata
)
if (results.needsDelete) {
engine.mutate(deleteMutation, {
variables: { data: results.deleteMetadata },
Expand Down Expand Up @@ -276,9 +286,10 @@ const Page = ({ metadata, existingConfig }) => {
<div className={classes.pageDiv}>
<h1>Program Dataset Connector</h1>
<p>
This application is used to link program indicators to a data elements in a specific data set. This is used to
generate copies of the program indicator for each of the disaggregations assigned to the data element in the
data set (including dissagregations on the data set itself)
This application is used to link program indicators to a data elements in a specific data
set. This is used to generate copies of the program indicator for each of the
disaggregations assigned to the data element in the data set (including dissagregations on
the data set itself)
</p>
<br />
<br />
Expand All @@ -292,7 +303,10 @@ const Page = ({ metadata, existingConfig }) => {
></Mapping>
)}
{showImportStatus && (
<ImportSummary handleClose={() => setShowImportStatus(false)} importResults={importResults} />
<ImportSummary
handleClose={() => setShowImportStatus(false)}
importResults={importResults}
/>
)}
<InputField
className={classes.filterInput}
Expand Down
15 changes: 13 additions & 2 deletions src/components/RowCatFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import PropTypes from 'prop-types'
import React, { useState } from 'react'
import { getBaseUrl } from '../utils'

const RowCatFilter = ({ coUid, catName, catFilter, coMappings, rowData, setRowData, handleClick }) => {
const RowCatFilter = ({
coUid,
catName,
catFilter,
coMappings,
rowData,
setRowData,
handleClick,
}) => {
const [rowFilter, setRowFilter] = useState(catFilter)
const [filterError, setFilterError] = useState('')
const { appUrl } = useConfig()
Expand Down Expand Up @@ -81,7 +89,10 @@ RowCatFilter.propTypes = {
deName: PropTypes.string.isRequired,
dsName: PropTypes.string.isRequired,
piName: PropTypes.string.isRequired,
coFilters: PropTypes.shape({ name: PropTypes.string.isRequired, id: PropTypes.string.isRequired }),
coFilters: PropTypes.shape({
name: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
}),
}).isRequired,
setRowData: PropTypes.func.isRequired,
}
Expand Down
21 changes: 17 additions & 4 deletions src/components/RowFieldSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ import React from 'react'
const RowFieldSelect = ({ metadata, rowData, label, updateFields, onSelect }) => {
const handleSelect = e => {
const selectedMeta = metadata.filter(meta => meta.id === e.selected)[0]
onSelect({ ...rowData, [updateFields.uid]: selectedMeta.id, [updateFields.name]: selectedMeta.name })
onSelect({
...rowData,
[updateFields.uid]: selectedMeta.id,
[updateFields.name]: selectedMeta.name,
})
}
return (
<SingleSelectField label={label} filterable selected={rowData[updateFields.uid]} onChange={e => handleSelect(e)}>
<SingleSelectField
label={label}
filterable
selected={rowData[updateFields.uid]}
onChange={e => handleSelect(e)}
>
{metadata.map(({ id, name }) => (
<SingleSelectOption label={name} key={id} value={id} />
))}
Expand All @@ -17,7 +26,8 @@ const RowFieldSelect = ({ metadata, rowData, label, updateFields, onSelect }) =>
}

RowFieldSelect.propTypes = {
metadata: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.string, name: PropTypes.string })).isRequired,
metadata: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.string, name: PropTypes.string }))
.isRequired,
rowData: PropTypes.shape({
deUid: PropTypes.string.isRequired,
dsUid: PropTypes.string.isRequired,
Expand All @@ -28,7 +38,10 @@ RowFieldSelect.propTypes = {
piName: PropTypes.string.isRequired,
}).isRequired,
label: PropTypes.string.isRequired,
updateFields: PropTypes.shape({ uid: PropTypes.string.isRequired, name: PropTypes.string.isRequired }).isRequired,
updateFields: PropTypes.shape({
uid: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
}).isRequired,
onSelect: PropTypes.func.isRequired,
}

Expand Down

0 comments on commit 41bb74f

Please sign in to comment.