Skip to content

Commit

Permalink
fix(Metadata Import): append object type if format is CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
adeelshahid committed Dec 10, 2018
1 parent b4dbb53 commit ffd4794
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"chalk": "^2.4.1",
"classnames": "^2.2.5",
"css-loader": "0.28.7",
"d2": "^30.0.0",
"d2": "^30.0.4",
"d2-manifest": "^1.0.0",
"dotenv": "4.0.0",
"dotenv-expand": "^4.2.0",
Expand Down
7 changes: 6 additions & 1 deletion src/helpers/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ const fields = {
),
mergeMode: getField('mergeMode', i18n.t('Merge Mode'), TYPE_RADIO),
objectList: getField('objectList', i18n.t('Object'), TYPE_SELECT),
objectType: getField('objectType', i18n.t('Object type'), TYPE_RADIO),
objectType: getField(
'objectType',
i18n.t('Object type'),
TYPE_RADIO,
CTX_CSV_OPTION
),
orgUnit: getField('orgUnit', i18n.t('Organisation unit'), TYPE_ORG_UNIT),
orgUnitIdScheme: getField(
'orgUnitIdScheme',
Expand Down
15 changes: 8 additions & 7 deletions src/pages/import/MetaData.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ export class MetaDataImport extends FormBase {
static menuIcon = <MetadataImportIcon />
icon = <MetadataImportIcon />

formWidth = 600
formWidth = 800
formTitle = i18n.t('Metadata Import')
submitLabel = i18n.t('Import')

fields = [
...getFormFields([
'upload',
'format',
'objectType',
'classKey',
'importMode',
'identifier',
Expand All @@ -59,7 +60,8 @@ export class MetaDataImport extends FormBase {
state = getFormValues([
'_context',
'upload',
'format:.json:json,xml',
'format:.json:json,xml,csv',
'objectType',
'classKey',
'importMode',
'identifier',
Expand Down Expand Up @@ -102,11 +104,10 @@ export class MetaDataImport extends FormBase {
}

onFormUpdate = (name, value) => {
if (name === 'upload') {
if (name === 'format') {
const { _context } = this.state
const { type } = value

if (type.endsWith('/csv') && _context !== CTX_CSV_OPTION) {
if (value === '.csv' && _context !== CTX_CSV_OPTION) {
this.changeContext(CTX_CSV_OPTION)
} else {
this.changeContext(CTX_DEFAULT)
Expand All @@ -116,13 +117,13 @@ export class MetaDataImport extends FormBase {

onSubmit = async () => {
try {
const { upload, format, classKey } = this.getFormState()
const { upload, format, objectType, classKey } = this.getFormState()
const formData = new FormData()
formData.set('upload', upload)

const contentType = getMimeType(upload.name.toLowerCase())
const append = contentType.endsWith('/csv')
? [`classKey=${classKey}`]
? [`classKey=${classKey}&objectType=${objectType}`]
: []
const params = getParamsFromFormState(
this.getFormState(),
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2996,10 +2996,10 @@ d2@^29.1.3:
jsdoc "^3.5.5"
whatwg-fetch "^2.0.3"

d2@^30.0.0:
version "30.0.0"
resolved "https://registry.yarnpkg.com/d2/-/d2-30.0.0.tgz#470b516f21bda6bda09b65579352e37225ca7e1d"
integrity sha512-x0BVi+C6pZrlpWe/HbO3O++Z1nbLucl19A/9QXONZ6u1yqbkpTeywYVhv2USaUz8ayqySWNMx43BO121GzrXog==
d2@^30.0.4:
version "30.0.4"
resolved "https://registry.yarnpkg.com/d2/-/d2-30.0.4.tgz#ba51a43e7daedeb47e01c45aef71649bad1b2159"
integrity sha512-GjTfqPq7KAakeN398jnzh0DO7kTofy18UoARJqcASU6RvcVjlJNnRpanHbbaSe05BrjVZx4j05niwDn/VVqJ4w==
dependencies:
docdash "^0.4.0"
jsdoc "^3.5.5"
Expand Down

0 comments on commit ffd4794

Please sign in to comment.