Skip to content

Commit 84248fe

Browse files
authored
Merge pull request #449 from contentstack/feature/dropdown-field-choices
Feature/dropdown field choices
2 parents d878c86 + eedd60d commit 84248fe

File tree

4 files changed

+81
-55
lines changed

4 files changed

+81
-55
lines changed

api/src/services/contentMapper.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const putTestData = async (req: Request) => {
5757
});
5858

5959
FieldMapperModel.update((data: any) => {
60-
data.field_mapper = [...(data?.field_mapper ?? []), ...fields];
60+
data.field_mapper = [...(data?.field_mapper ?? []), ...(fields ?? [])];
6161
});
6262
contentTypes[index].fieldMapping = fieldIds;
6363
});

ui/src/components/ContentMapper/contentMapper.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export interface MappingFields {
173173
export interface MappingObj {
174174
label: string;
175175
options: Mapping;
176+
type: string
176177
}
177178

178179
export interface FieldHistoryObj {

ui/src/components/ContentMapper/index.tsx

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,101 +80,126 @@ const Fields: MappingFields = {
8080
'Single Line Textbox':'single_line_text',
8181
'Multi Line Textbox':'multi_line_text',
8282
'HTML Rich text Editor':'html',
83-
'JSON Rich Text Editor':'json'}
83+
'JSON Rich Text Editor':'json'},
84+
type : 'text'
8485
},
8586
'multi_line_text':{
8687
label : 'Multi Line Textbox',
8788
options : {
8889
'Multi Line Textbox': 'multi_line_text',
8990
'HTML Rich text Editor': 'html',
90-
'JSON Rich Text Editor':'json'}
91+
'JSON Rich Text Editor':'json'},
92+
type: 'multiline'
9193
},
9294
'json':{
9395
label:'JSON Rich Text Editor',
9496
options : {
9597
'JSON Rich Text Editor':'json',
9698
'HTML Rich text Editor': 'html'
97-
}
99+
},
100+
type: 'json',
98101
},
99102
'html':{
100103
label : 'HTML Rich text Editor',
101104
options : {
102105
'HTML Rich text Editor': 'html',
103-
'JSON Rich Text Editor':'json'}
106+
'JSON Rich Text Editor':'json'
107+
},
108+
type:'allow_rich_text'
104109

105110
},
106111
'markdown':{
107112
label : 'Markdown',
108113
options : {
109114
'Markdown':'markdown',
110115
'HTML Rich text Editor':'html',
111-
'JSON Rich Text Editor':'json'}
116+
'JSON Rich Text Editor':'json'
117+
},
118+
type: 'markdown'
112119
},
113120
'text':{
114121
label : 'Single Line Textbox',
115-
options: {'Single Line Textbox':'single_line_text'}
122+
options: {
123+
'Single Line Textbox':'single_line_text'
124+
},
125+
type:''
116126
},
117127
'url': {
118128
label: 'URL',
119-
options:{'URL':'url'}
129+
options:{'URL':'url'},
130+
type: ''
120131
},
121132
'file': {
122133
label:'File',
123134
options: {
124135
'File':'file'
125-
}
136+
},
137+
type: 'file',
126138
},
127139
'number': {
128140
label:'Number',
129141
options: {
130142
'Number':'number'
131-
}
143+
},
144+
type: 'number'
132145
},
133146
'isodate': { label :'Date',
134147
options: {
135148
'Date':'isodate'
136-
}
149+
},
150+
type: 'isodate'
137151
},
138152
'boolean': {
139153
label: 'Boolean',
140154
options: {
141155
'Boolean':'boolean'
142-
}
156+
},
157+
type: 'boolean',
143158
},
144159
'link': {
145160
label:'Link',
146161
options: {
147162
'Link':'link'
148-
}
163+
},
164+
type: 'link',
149165
},
150166
'reference':{
151167
label: 'Reference',
152168
options: {
153169
'Reference':'reference'
154-
}
170+
},
171+
type: 'reference',
155172
},
156173
'dropdown': {
157174
label:'Dropdown',
158175
options: {
159176
'Dropdown':'dropdown'
160-
}
177+
},
178+
type: 'enum',
161179
},
162180
'radio': {
163181
label :'Select',
164182
options: {
165183
'Select':'select'
166-
}
184+
},
185+
type: 'enum',
167186
},
168187
'checkbox': {
169188
label:'Select',
170-
options: {'Select':'checkbox'}
189+
options: {
190+
'Select':'checkbox'
191+
},
192+
type:'boolean'
171193
},
172194
'global_field':{
173195
label : 'Global',
174-
options: {'Global':'global_field'}},
196+
options: {'Global':'global_field'},
197+
type: ""
198+
},
175199
'group': {
176200
label: 'Group',
177-
options: {'Group':'group'}
201+
options: {'Group':'group'},
202+
type:'Group'
178203
}
179204

180205
}
@@ -1216,6 +1241,8 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
12161241
return value?.data_type === 'boolean';
12171242
case 'link':
12181243
return value?.data_type === 'link';
1244+
case 'markdown':
1245+
return value?.field_metadata?.markdown === true;
12191246
default:
12201247
return false;
12211248
}
@@ -1251,7 +1278,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
12511278
{
12521279
// Process nested schemas within the current group
12531280
for (const item of array) {
1254-
const fieldTypeToMatch = fieldsOfContentstack[item?.otherCmsType as keyof Mapping];
1281+
const fieldTypeToMatch = Fields[item?.backupFieldType as keyof Mapping]?.type;
12551282
if (item.id === data?.id) {
12561283
for (const key of existingField[groupArray[0]?.uid]?.value?.schema || []) {
12571284

@@ -1278,7 +1305,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
12781305
}
12791306
else {
12801307

1281-
const fieldTypeToMatch = fieldsOfContentstack[data?.otherCmsType as keyof Mapping];
1308+
const fieldTypeToMatch = Fields[data?.backupFieldType as keyof Mapping]?.type;
12821309
if (!array.some((item : FieldMapType) => item?.id === data?.id) && checkConditions(fieldTypeToMatch, value, data)) {
12831310
OptionsForRow.push(getMatchingOption(value, true, updatedDisplayName || '',uid ?? ''));
12841311
}
@@ -1349,8 +1376,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
13491376
}
13501377

13511378
if (contentTypeSchema && validateArray(contentTypeSchema)) {
1352-
const fieldTypeToMatch = fieldsOfContentstack[data?.otherCmsType as keyof Mapping];
1353-
1379+
const fieldTypeToMatch = Fields[data?.backupFieldType as keyof Mapping]?.type;
13541380
//check if UID of souce field is matching to exsting content type field UID
13551381
for (const value of contentTypeSchema) {
13561382
if (data?.uid === value?.uid || (data?.uid === value?.uid && data?.otherCmsType === value?.data_type)) {
@@ -1452,7 +1478,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
14521478
option = [{ label: OptionsForEachRow, value: OptionsForEachRow }];
14531479
}
14541480

1455-
console.log("data====", data, OptionsForRow);
14561481

14571482

14581483
const OptionValue: FieldTypes =

upload-api/src/routes/index.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,34 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
115115
file_details: config
116116
});
117117
});
118-
if (fileExt === 'zip') {
118+
if (fileExt === 'xml') {
119+
let xmlData = '';
120+
121+
// Collect the data from the stream as a string
122+
bodyStream.on('data', (chunk) => {
123+
if (typeof chunk !== 'string' && !Buffer.isBuffer(chunk)) {
124+
throw new Error('Expected chunk to be a string or a Buffer');
125+
} else {
126+
// Convert chunk to string (if it's a Buffer)
127+
xmlData += chunk.toString();
128+
}
129+
});
130+
131+
// When the stream ends, process the XML data
132+
bodyStream.on('end', async () => {
133+
if (!xmlData) {
134+
throw new Error('No data collected from the stream.');
135+
}
136+
137+
const data = await handleFileProcessing(fileExt, xmlData, cmsType,name);
138+
res.status(data?.status || 200).json(data);
139+
if (data?.status === 200) {
140+
const filePath = path.join(__dirname, '..', '..', 'extracted_files', "data.json");
141+
createMapper(filePath, projectId, app_token, affix, config);
142+
}
143+
});
144+
}
145+
else{
119146
// Create a writable stream to save the downloaded zip file
120147
let zipBuffer = Buffer.alloc(0);
121148

@@ -140,35 +167,7 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
140167
createMapper(filePath, projectId, app_token, affix, config);
141168
}
142169
});
143-
} else if (fileExt === 'xml') {
144-
let xmlData = '';
145-
146-
// Collect the data from the stream as a string
147-
bodyStream.on('data', (chunk) => {
148-
if (typeof chunk !== 'string' && !Buffer.isBuffer(chunk)) {
149-
throw new Error('Expected chunk to be a string or a Buffer');
150-
} else {
151-
// Convert chunk to string (if it's a Buffer)
152-
xmlData += chunk.toString();
153-
}
154-
});
155-
156-
// When the stream ends, process the XML data
157-
bodyStream.on('end', async () => {
158-
if (!xmlData) {
159-
throw new Error('No data collected from the stream.');
160-
}
161-
162-
const data = await handleFileProcessing(fileExt, xmlData, cmsType,name);
163-
res.status(data?.status || 200).json(data);
164-
if (data?.status === 200) {
165-
const filePath = path.join(__dirname, '..', '..', 'extracted_files', "data.json");
166-
createMapper(filePath, projectId, app_token, affix, config);
167-
}
168-
});
169-
}
170-
return;
171-
}
170+
}
172171
} else {
173172
const params = {
174173
Bucket: config?.awsData?.bucketName,
@@ -221,7 +220,8 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
221220
});
222221
}
223222

224-
} catch (err: any) {
223+
} }
224+
catch (err: any) {
225225
console.error('🚀 ~ router.get ~ err:', err);
226226
}
227227
});

0 commit comments

Comments
 (0)