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

tweak(adminPanel): RN-1409: Inclusion of Additional Data Fields in Entity Hierarchy Export File #5852

Merged
merged 18 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ export class ExportEntityHierarchiesRoute extends Route<ExportEntityHierarchiesR
hierarchy,
hierarchy,
{
fields: ['name', 'code', 'parent_code'],
fields: [
'grandparent_name',
'grandparent_code',
'parent_name',
'parent_code',
'name',
'code',
'type',
'attributes',
],
},
false,
false,
Expand Down
5 changes: 5 additions & 0 deletions packages/database/src/modelClasses/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ export class EntityRecord extends DatabaseRecord {
return ancestors && ancestors.length > 0 ? ancestors[0] : undefined;
}

async getGrandParent(hierarchyId) {
const ancestors = await this.getAncestors(hierarchyId, { generational_distance: 2 });
return ancestors && ancestors.length > 0 ? ancestors[0] : undefined;
}

async getAncestors(hierarchyId, criteria) {
return this.model.getAncestorsOfEntities(hierarchyId, [this.id], criteria);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ const getParentCode = async (
return (await entity.getParent(hierarchyId))?.code;
};

const getGrandParentCode = async (
entity: EntityRecord,
context: {
hierarchyId: string;
},
) => {
const { hierarchyId } = context;
return (await entity.getGrandParent(hierarchyId))?.code;
};

const getChildrenCodes = async (
entity: EntityRecord,
context: {
Expand Down Expand Up @@ -46,6 +56,16 @@ const getParentName = async (
return (await entity.getParent(hierarchyId))?.name;
};

const getGrandParentName = async (
entity: EntityRecord,
context: {
hierarchyId: string;
},
) => {
const { hierarchyId } = context;
return (await entity.getGrandParent(hierarchyId))?.name;
};

const getPoint = (entity: EntityRecord) => {
return entity.getPoint();
};
Expand Down Expand Up @@ -92,6 +112,8 @@ export const extendedFieldFunctions = {
bounds: getBounds,
qualified_name: getQualifiedName,
parent_name: getParentName,
grandparent_name: getGrandParentName,
grandparent_code: getGrandParentCode,
};

export const isExtendedField = (field: string): field is keyof typeof extendedFieldFunctions =>
Expand Down