Skip to content

Commit

Permalink
Fix a bug in CSV export where the column "isInstanceOf" would be adde…
Browse files Browse the repository at this point in the history
…d in addition to "relations.isInstanceOf"
  • Loading branch information
tkleinke committed Dec 2, 2024
1 parent e84f159 commit b783c00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion desktop/src/app/components/export/csv/csv-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export module CSVExport {
combineHierarchicalRelations: boolean = true,
addScanCode: boolean = false) {

fieldDefinitions = fieldDefinitions.filter(field => field.inputType !== Field.InputType.RELATION);
fieldDefinitions = fieldDefinitions.filter(field => {
return !Field.InputType.RELATION_INPUT_TYPES.includes(field.inputType);
});

const headings: string[] = makeHeadings(
fieldDefinitions, relations, combineHierarchicalRelations, addScanCode
Expand Down
14 changes: 14 additions & 0 deletions desktop/test/unit/components/export/csv/csv-export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function makeFieldDefinitions(fieldNames: string[]) {
if (fieldName.startsWith('period')) inputType = 'dropdownRange';
if (fieldName.startsWith('relation')) inputType = 'relation';
if (fieldName.startsWith('composite')) inputType = 'composite';
if (fieldName.startsWith('isInstanceOf')) inputType = 'instanceOf';

return { name: fieldName, inputType: inputType };
}) as Array<Field>;
Expand Down Expand Up @@ -88,6 +89,19 @@ describe('CSVExport', () => {
});


test('export instanceOf field', () => {

const fields = makeFieldDefinitions(['identifier', 'shortDescription', 'isInstanceOf']);
const resource = ifResource('i1', 'identifier1', { en: 'shortDescription1' }, 'category');
resource.relations = { isInstanceOf: ['identifier2'] } as any;

const result = CSVExport.createExportable([resource], fields, ['liesWithin', 'isInstanceOf'], ['en'], ',')
.csvData;
expect(result[0]).toBe('"identifier","shortDescription.en","relations.isInstanceOf","relations.isChildOf"');
expect(result[1]).toBe('"identifier1","shortDescription1","identifier2",""');
});


function expectCorrectChildOfTarget(resource, t, expectation) {

const result = CSVExport.createExportable([resource], t, Relation.Hierarchy.ALL, ['en'], ',').csvData;
Expand Down

0 comments on commit b783c00

Please sign in to comment.