Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: File generation issue with older excels and empty selecttion #578

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading