Notes
Notes - notes.io |
import PropTypes from 'prop-types';
import { graphql, compose, withApollo } from 'react-apollo';
import { connect } from 'react-redux';
import StepComponent from './../../components/StepComponent';
import {
getStaticTemplateDataFromQuery,
getUDATemplateDataQuery
} from './EditTemplateQuery';
import {
setUDAData as setUDADataAction,
setMasterData as setMasterDataAction,
setOtherData as setOtherDataAction,
setTemplateId as setTemplateIdAction,
setAfterMapping,
setFieldsForRecordTypeList
} from '../../action';
import { getAppPageParams } from '../../../../login/reducer';
import { getMasterData } from '../../reducer';
export class EditTemplate extends Component {
constructor(props) {
super(props);
this.state = {
charEncodingFormatList: [],
product: [],
selectedProductType: '',
selectedSubProductType: '',
selectedFileType: '',
templateId: ''
};
props.setUDAData();
props.setMasterData();
props.setOtherData();
props.setTemplateId();
props.setAfterMapping();
props.setFieldsForRecordTypeList();
}
componentWillReceiveProps = (nextProps) => {
const tempId = nextProps.templateId;
if (tempId !== undefined) {
this.setState({
templateId: tempId
});
}
const reduxObjForFirstPage = nextProps.editData;
if (reduxObjForFirstPage !== undefined) {
let fileTypeLabel;
switch (reduxObjForFirstPage.fileType) {
case 'D':
fileTypeLabel = 'Delimited';
break;
case 'F':
fileTypeLabel = 'Fixed Length';
break;
default:
fileTypeLabel = 'Excel File';
}
this.setState({
selectedProductType: reduxObjForFirstPage.applicationId,
selectedSubProductType: reduxObjForFirstPage.appSubType,
selectedFileType: fileTypeLabel
});
}
this.setState({
stepIndex: nextProps.location.state
? nextProps.location.state.stepIndex
: 0
});
const {
getProductSubProductConfig,
getCharacterEncodingFormats,
getFileTypeValues,
getFieldSeparatorValues,
getFieldWrapperValues,
getHeaderRecordValues,
getTransactionRecordValues,
getRecordTypes,
getDateFormats
} = nextProps.getStaticTemplateData;
const { getUDATemplateData } = nextProps.getUDATempData;
const { productSubProductList } =
getProductSubProductConfig !== undefined && getProductSubProductConfig;
const { characterEncodingFormatList } =
getCharacterEncodingFormats !== undefined && getCharacterEncodingFormats;
const { fileTypeOptions } =
getFileTypeValues !== undefined && getFileTypeValues;
const { fieldSeparatorValuesList } =
getFieldSeparatorValues !== undefined && getFieldSeparatorValues;
const { fieldWrapperValuesList } =
getFieldWrapperValues !== undefined && getFieldWrapperValues;
const { headerRecordValueList } =
getHeaderRecordValues !== undefined && getHeaderRecordValues;
const { transactionRecordValueList } =
getTransactionRecordValues !== undefined && getTransactionRecordValues;
const { recordTypeList } = getRecordTypes !== undefined && getRecordTypes;
const { dateFormatList } = getDateFormats !== undefined && getDateFormats;
const udaData = [];
if (getUDATemplateData !== undefined) {
const {
templateId,
recordMappingMasterResponse,
recordMappingOtherRecordsResponseList,
templateResponseHeaderList,
templateResponseDetailList,
templateResponseTrailerList,
templateResponseDetailForOtherRecordTypeList
} = getUDATemplateData;
// console.log(templateResponseDetailForOtherRecordTypeList);
if (templateId !== undefined) {
this.props.setTemplateId(templateId);
}
if (recordMappingMasterResponse !== undefined) {
this.props.setMasterData(recordMappingMasterResponse);
}
if (recordMappingOtherRecordsResponseList !== undefined) {
this.props.setOtherData(recordMappingOtherRecordsResponseList);
}
let recordType;
let headerObj;
let detailObj;
let trailerObj;
let obj1;
let obj2;
if (
templateResponseHeaderList !== undefined ||
templateResponseDetailList !== undefined ||
templateResponseTrailerList !== undefined
) {
let recTypeSelection;
if (templateResponseHeaderList && templateResponseHeaderList.length) {
recTypeSelection = templateResponseHeaderList[0].recType;
} else if (
templateResponseDetailList &&
templateResponseDetailList.length
) {
recTypeSelection = templateResponseDetailList[0].recType;
} else if (
templateResponseTrailerList &&
templateResponseTrailerList.length
) {
recTypeSelection = templateResponseTrailerList[0].recType;
} else {
recTypeSelection = '';
}
recordType = recTypeSelection;
headerObj = this.getStructuredObject(
templateResponseHeaderList,
'Header'
);
detailObj = this.getStructuredObject(
templateResponseDetailList,
recordType
);
trailerObj = this.getStructuredObject(
templateResponseTrailerList,
'Trailer'
);
obj1 = {
headerRecordList: headerObj,
detailRecordList: detailObj,
trailerRecordList: trailerObj,
recType: recordType
};
udaData.push(obj1);
}
if (
templateResponseDetailForOtherRecordTypeList &&
templateResponseDetailForOtherRecordTypeList.length
) {
recordType = templateResponseDetailForOtherRecordTypeList[0].recType;
detailObj = this.getStructuredObject(
templateResponseDetailForOtherRecordTypeList[0]
.templateRecordResponseList,
recordType
);
obj2 = {
recType: recordType,
detailRecordList: detailObj
};
udaData.push(obj2);
}
if (udaData) {
this.props.setUDAData(udaData);
}
}
this.setState({
product: productSubProductList,
charEncodingFormatList: characterEncodingFormatList,
fileTypeOptions,
fieldSeparatorValuesList,
fieldWrapperValuesList,
headerRecordValueList,
transactionRecordValueList,
recordTypeList,
dateFormatList
});
};
getStructuredObject = (data, type) => {
const structuredRecordList = [];
let recordTypeLineNos = data.map((row) => row.recTypeLineNo);
recordTypeLineNos = recordTypeLineNos.filter(
(value, index, self) => self.indexOf(value) === index
);
const recordMappingArray = {
recordMappingConcatResponseList: 'recordMappingConcatRequestList',
recordMappingFormulaResponseList: 'recordMappingFormulaRequestList',
recordMappingDynamicOutputResponseList:
'recordMappingDynamicOutputRequestList',
recordMappingIfThenElseResponseList: 'recordMappingIfThenElseRequestList',
recordMappingSplitResponseList: 'recordMappingSplitRequestList',
recordMappingSubStringResponseList: 'recordMappingSubStringRequestList',
recordMappingTruncateResponseList: 'recordMappingTruncateRequestList',
dateOperation: 'dateOperation',
replaceStringResponse: 'replaceStringRequest',
startingPosition: 'startingPosition',
seqofoperations: 'seqofoperations',
base64Encode: 'base64Encode',
base64Decode: 'base64Decode',
swiftValidate: 'swiftValidate',
charEncodingConverter: 'charEncodingConverter',
prefixValue: 'prefixValue',
suffixValue: 'suffixValue'
};
for (let i = 0; i < recordTypeLineNos.length; i++) {
structuredRecordList[i] = [];
data.map((item) => {
if (recordTypeLineNos[i] === item.recTypeLineNo) {
const recordMappingInfoRequest = {};
if (item.recordMappingInfoResponse !== null) {
Object.keys(item.recordMappingInfoResponse).forEach(
(responseKey) => {
let removeTypeOfType =
item.recordMappingInfoResponse[responseKey];
if (
item.recordMappingInfoResponse[responseKey] &&
typeof item.recordMappingInfoResponse[responseKey] ===
'object' &&
item.recordMappingInfoResponse[responseKey].length
) {
removeTypeOfType = item.recordMappingInfoResponse[
responseKey
].map((mappingItem) => {
const { __typename, ...newitem } = mappingItem;
return newitem;
});
}
if (responseKey !== '__typename') {
recordMappingInfoRequest[
recordMappingArray[responseKey]
] = removeTypeOfType;
// item.recordMappingInfoResponse[responseKey];
}
}
);
}
structuredRecordList[i].push({
fieldName: item.fieldName,
recType: type,
recTypeLineNo: item.recTypeLineNo,
fieldSequence: item.fieldSequence,
dataType: item.dataType,
fieldMaxLength: item.fieldMaxLength,
mandatory: item.mandatory,
length: item.length,
defaultValue: item.defaultValue,
dateFormat: item.dateFormat,
deleteFlag: item.deleteFlag,
fieldValueFromFile: '',
recordMappingInfoRequest
});
}
return true;
});
}
return structuredRecordList;
};
render() {
return (
<StepComponent
history={this.props.history}
isEditable
charEncodingList={this.state.charEncodingFormatList}
fileTypeOptions={this.state.fileTypeOptions}
fieldSeparatorListItems={this.state.fieldSeparatorValuesList}
fieldWrapperListItems={this.state.fieldWrapperValuesList}
headerTrailerListItems={this.state.headerRecordValueList}
transactionListItems={this.state.transactionRecordValueList}
productAndSubProductOptions={this.state.product}
recordTypeList={this.state.recordTypeList}
dateFormatList={this.state.dateFormatList}
stepIndex={this.state.stepIndex}
selectedProductType={this.state.selectedProductType}
selectedSubProductType={this.state.selectedSubProductType}
selectedFileType={this.state.selectedFileType}
templateId={this.state.templateId}
/>
);
}
}
EditTemplate.propTypes = {
history: PropTypes.shape({}),
/** location property of component */
location: PropTypes.shape({
/** holds the state of location */
state: PropTypes.shape({
/** holds the stepIndex of state */
stepIndex: PropTypes.number
})
}),
getStaticTemplateData: PropTypes.object,
getUDATempData: PropTypes.object,
setTemplateId: PropTypes.func,
setMasterData: PropTypes.func,
setOtherData: PropTypes.func,
setUDAData: PropTypes.func,
setAfterMapping: PropTypes.func,
setFieldsForRecordTypeList: PropTypes.func,
templateId: PropTypes.string,
editData: PropTypes.object
};
const mapStateToProps = (state) => ({
templateId: getAppPageParams(state),
editData: getMasterData(state)
});
const mapDispatchToProps = (dispatch) => ({
setUDAData: (udaData) => {
setUDADataAction(udaData, dispatch);
},
setMasterData: (masterData) => {
setMasterDataAction(masterData, dispatch);
},
setOtherData: (otherData) => {
setOtherDataAction(otherData, dispatch);
},
setTemplateId: (templateId) => {
setTemplateIdAction(templateId, dispatch);
},
setAfterMapping: (data) => {
setAfterMapping(data, dispatch);
},
setFieldsForRecordTypeList: (fieldsForRecordTypeList) => {
setFieldsForRecordTypeList(fieldsForRecordTypeList, dispatch);
}
});
const reduxWrapper = connect(
mapStateToProps,
mapDispatchToProps
);
export default compose(
reduxWrapper,
graphql(getStaticTemplateDataFromQuery, { name: 'getStaticTemplateData' }),
graphql(getUDATemplateDataQuery, {
name: 'getUDATempData',
options: (ownProps) => ({
fetchPolicy: 'network-only',
variables: {
getUDATemplateDataRequest: { templateId: 'asdw' }
}
})
})
)(withApollo(EditTemplate));
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team