Skip to content

Commit

Permalink
fix: File generation issue with older excels and empty selecttion (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik authored May 29, 2024
2 parents 944aeab + 635b4ab commit 53dd69e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
12 changes: 6 additions & 6 deletions apps/api/src/app/shared/services/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ export class ExcelFileService {
.slice(0, 25) // exceljs don't allow heading more than 30 characters
);
}
addSelectSheet(wb: ExcelJS.Workbook, heading: IExcelFileHeading): string {
addSelectSheet(wb: any, heading: IExcelFileHeading): string {
const name = this.formatName(heading.key);
const companies = wb.addWorksheet(name);
const companyHeadings = [heading.key];
companies.addRow(companyHeadings);
heading.selectValues.forEach((value) => companies.addRow([value]));
const addedSheet = wb.addSheet(name);
addedSheet.cell('A1').value(heading.key);
heading.selectValues.forEach((value, index) => addedSheet.cell(`A${index + 2}`).value(value));

return name;
}
Expand Down Expand Up @@ -110,11 +109,12 @@ export class ExcelFileService {

headings.forEach((heading, index) => {
if (heading.type === ColumnTypesEnum.SELECT) {
const keyName = this.addSelectSheet(workbook, heading);
const columnName = this.getExcelColumnNameFromIndex(index + 1);
worksheet.range(`${columnName}2:${columnName}9999`).dataValidation({
type: 'list',
allowBlank: !heading.isRequired,
formula1: `"${heading.selectValues.join(',')}"`,
formula1: `${keyName}!$A$2:$A$9999`,
...(!heading.allowMultiSelect
? {
showErrorMessage: true,
Expand Down
11 changes: 8 additions & 3 deletions apps/widget/src/hooks/Phase1/usePhase1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useAPIState } from '@store/api.context';
import { useAppState } from '@store/app.context';
import { IFormvalues, IUploadValues } from '@types';
import { useImplerState } from '@store/impler.context';
import { ColumnTypesEnum, IErrorObject, IOption, ITemplate, IUpload } from '@impler/shared';
import { ColumnTypesEnum, IErrorObject, IOption, ISchemaItem, ITemplate, IUpload } from '@impler/shared';
import { FileMimeTypesEnum, IImportConfig, downloadFile } from '@impler/shared';
import { downloadFileFromURL, getFileNameFromUrl, notifier, ParentWindow } from '@util';

Expand Down Expand Up @@ -165,9 +165,14 @@ export function usePhase1({ goNext }: IUsePhase1Props) {
}

const foundTemplate = findTemplate();
let parsedSchema: ISchemaItem[] | undefined = undefined;
try {
if (schema) parsedSchema = JSON.parse(schema);
} catch (error) {}

if (foundTemplate && ((Array.isArray(data) && data.length > variables.baseIndex) || schema)) {
const isMultiSelect = Array.isArray(schema)
? schema.some((schemaItem) => schemaItem.type === ColumnTypesEnum.SELECT && schemaItem.allowMultiSelect)
const isMultiSelect = Array.isArray(parsedSchema)
? parsedSchema.some((schemaItem) => schemaItem.type === ColumnTypesEnum.SELECT && schemaItem.allowMultiSelect)
: foundTemplate.sampleFileUrl?.endsWith('xlsm');
downloadSample([foundTemplate._id, foundTemplate.name, !!isMultiSelect]);
} else if (foundTemplate && foundTemplate.sampleFileUrl) {
Expand Down
2 changes: 1 addition & 1 deletion apps/widget/src/hooks/Phase3/MultiSelectEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class MultiSelectEditor extends BaseEditor {
if (this.timer) this.hot.rootWindow.clearTimeout(this.timer);
}
getValue() {
return [...this.value].join(',');
return this.value.size ? [...this.value].join(',') : undefined;
}
setValue(value: string) {
this.value = new Set(value ? value.split(',') : []);
Expand Down

0 comments on commit 53dd69e

Please sign in to comment.