From 26054ab278b8d01a675c0f73d604ef1efc4f6c3c Mon Sep 17 00:00:00 2001 From: Jonathan Ruddell Date: Thu, 4 Oct 2018 19:23:06 -0700 Subject: [PATCH] linting, only import local date mapper when entity uses local date --- src/entity/files.js | 5 +++++ templates/entity-detail-screen.ejs | 2 ++ templates/entity-edit-screen.ejs | 5 +++-- templates/saga.ejs | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/entity/files.js b/src/entity/files.js index 1c3add2cc..3050a72d3 100644 --- a/src/entity/files.js +++ b/src/entity/files.js @@ -19,6 +19,7 @@ module.exports = async function (generator, igniteContext) { const entityFileName = `${name}.json` const localEntityFilePath = `.jhipster/${entityFileName}` + let entityContainsLocalDate = false // load the entity config into memory let entityConfig = await fs.readJson(localEntityFilePath) entityConfig.fields.forEach((field) => { @@ -36,9 +37,13 @@ module.exports = async function (generator, igniteContext) { 'byte[]', 'ByteBuffer' ].includes(field.fieldType) + if (field.fieldType === 'LocalDate') { + entityContainsLocalDate = true + } }) props.entityConfig = entityConfig + props.entityContainsLocalDate = entityContainsLocalDate props.microserviceName = entityConfig.hasOwnProperty('microserviceName') ? (entityConfig.microserviceName + '/') : '' const apiFilePath = `${process.cwd()}/App/Services/Api.js` diff --git a/templates/entity-detail-screen.ejs b/templates/entity-detail-screen.ejs index 57615edbc..c1db67e65 100644 --- a/templates/entity-detail-screen.ejs +++ b/templates/entity-detail-screen.ejs @@ -4,7 +4,9 @@ import { connect } from 'react-redux' import <%= props.name %>Actions from '../Redux/<%= props.name %>Redux' import RoundedButton from '../Components/RoundedButton' import { Actions as NavigationActions } from 'react-native-router-flux' +<%_ if (props.entityContainsLocalDate) { _%> import { jsDateToLocalDate } from '../Transforms/DateTransforms' +<%_ } _%> // Styles import styles from './Styles/<%= props.name %>EntityDetailScreenStyle' diff --git a/templates/entity-edit-screen.ejs b/templates/entity-edit-screen.ejs index 6b69cba3d..55f9909d0 100644 --- a/templates/entity-edit-screen.ejs +++ b/templates/entity-edit-screen.ejs @@ -4,7 +4,9 @@ import { connect } from 'react-redux' import <%= props.name %>Actions from '../Redux/<%= props.name %>Redux' import { Actions as NavigationActions } from 'react-native-router-flux' import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view' +<%_ if (props.entityContainsLocalDate) { _%> import { jsDateToLocalDate } from '../Transforms/DateTransforms' +<%_ } _%> import t from 'tcomb-form-native' @@ -12,7 +14,6 @@ import t from 'tcomb-form-native' import styles from './Styles/<%= props.name %>EntityEditScreenStyle' let Form = t.form.Form - <%_ props.entityConfig.fields.forEach((field) => { if (field.fieldIsEnum) { _%> const <%= field.fieldType %> = t.enums({ @@ -20,7 +21,7 @@ const <%= field.fieldType %> = t.enums({ const enumValues = field.fieldValues.split(',') enumValues.forEach((enumValue, index) => { _%> - <%= enumValue %>: '<%= enumValue %>'<%= index !== enumValues.length -1 ? ',' : '' %> + <%= enumValue %>: '<%= enumValue %>'<%= index !== enumValues.length -1 ? ',' : '' %> <%_ }) //end of value loop _%> }) <%_ } // end of if statement diff --git a/templates/saga.ejs b/templates/saga.ejs index b8147b83d..f07b9e844 100644 --- a/templates/saga.ejs +++ b/templates/saga.ejs @@ -1,7 +1,10 @@ import { call, put } from 'redux-saga/effects' import <%= props.name %>Actions from '../Redux/<%= props.name %>Redux' import { callApi } from './CallApiSaga' +<%_ if (props.entityContainsLocalDate) { _%> import { localDateToJsDate } from '../Transforms/DateTransforms' +<%_ } _%> + export function * get<%= props.name %> (api, action) { const { <%= camelCase(props.name) %>Id } = action // make the call to the api