Skip to content

Commit

Permalink
feat(businessattribute): filter schema rows on business-attribute pro… (
Browse files Browse the repository at this point in the history
  • Loading branch information
deepgarg-visa authored Oct 1, 2024
1 parent 7340ec7 commit a078768
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,100 @@ describe('filterSchemaRows', () => {
expect(filteredRows).toMatchObject([{ fieldPath: 'shipment' }]);
expect(expandedRowsFromFilter).toMatchObject(new Set());
});

it('should properly filter schema rows based on business attribute properties description', () => {
const rowsWithSchemaFieldEntity = [
{
fieldPath: 'customer',
schemaFieldEntity: {
businessAttributes: {
businessAttribute: {
businessAttribute: { properties: { description: 'customer description' } },
},
},
},
},
{
fieldPath: 'testing',
schemaFieldEntity: {
businessAttributes: {
businessAttribute: {
businessAttribute: { properties: { description: 'testing description' } },
},
},
},
},
{
fieldPath: 'shipment',
schemaFieldEntity: {
businessAttributes: {
businessAttribute: {
businessAttribute: { properties: { description: 'shipment description' } },
},
},
},
},
] as SchemaField[];
const filterText = 'testing description';
const editableSchemaMetadata = { editableSchemaFieldInfo: [] };
const { filteredRows, expandedRowsFromFilter } = filterSchemaRows(
rowsWithSchemaFieldEntity,
editableSchemaMetadata,
filterText,
testEntityRegistry,
);

expect(filteredRows).toMatchObject([{ fieldPath: 'testing' }]);
expect(expandedRowsFromFilter).toMatchObject(new Set());
});

it('should properly filter schema rows based on business attribute properties tags', () => {
const rowsWithSchemaFieldEntity = [
{
fieldPath: 'customer',
schemaFieldEntity: {
businessAttributes: {
businessAttribute: {
businessAttribute: { properties: { tags: { tags: [{ tag: sampleTag }] } } },
},
},
},
},
{
fieldPath: 'testing',
schemaFieldEntity: {
businessAttributes: {
businessAttribute: {
businessAttribute: {
properties: { tags: { tags: [{ tag: { properties: { name: 'otherTag' } } }] } },
},
},
},
},
},
{
fieldPath: 'shipment',
schemaFieldEntity: {
businessAttributes: {
businessAttribute: {
businessAttribute: {
properties: { tags: { tags: [{ tag: { properties: { name: 'anotherTag' } } }] } },
},
},
},
},
},
] as SchemaField[];
const filterText = sampleTag.properties.name;
const editableSchemaMetadata = { editableSchemaFieldInfo: [] };
const { filteredRows, expandedRowsFromFilter } = filterSchemaRows(
rowsWithSchemaFieldEntity,
editableSchemaMetadata,
filterText,
testEntityRegistry,
);

expect(filteredRows).toMatchObject([{ fieldPath: 'customer' }]);
expect(expandedRowsFromFilter).toMatchObject(new Set());
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ function matchesTagsOrTermsOrDescription(field: SchemaField, filterText: string,
);
}

function matchesBusinessAttributesProperties(field: SchemaField, filterText: string, entityRegistry: EntityRegistry) {
if (!field.schemaFieldEntity?.businessAttributes) return false;
const businessAttributeProperties =
field.schemaFieldEntity?.businessAttributes?.businessAttribute?.businessAttribute?.properties;
return (
businessAttributeProperties?.description?.toLocaleLowerCase().includes(filterText) ||
businessAttributeProperties?.name?.toLocaleLowerCase().includes(filterText) ||
businessAttributeProperties?.glossaryTerms?.terms?.find((termAssociation) =>
entityRegistry
.getDisplayName(EntityType.GlossaryTerm, termAssociation.term)
.toLocaleLowerCase()
.includes(filterText),
) ||
businessAttributeProperties?.tags?.tags?.find((tagAssociation) =>
entityRegistry.getDisplayName(EntityType.Tag, tagAssociation.tag).toLocaleLowerCase().includes(filterText),
)
);
}

// returns list of fieldPaths for fields that have Terms or Tags or Descriptions matching the filterText
function getFilteredFieldPathsByMetadata(editableSchemaMetadata: any, entityRegistry, filterText) {
return (
Expand Down Expand Up @@ -56,7 +75,8 @@ export function filterSchemaRows(
if (
matchesFieldName(row.fieldPath, formattedFilterText) ||
matchesEditableTagsOrTermsOrDescription(row, filteredFieldPathsByEditableMetadata) ||
matchesTagsOrTermsOrDescription(row, formattedFilterText, entityRegistry) // non-editable tags, terms and description
matchesTagsOrTermsOrDescription(row, formattedFilterText, entityRegistry) || // non-editable tags, terms and description
matchesBusinessAttributesProperties(row, formattedFilterText, entityRegistry)
) {
finalFieldPaths.add(row.fieldPath);
}
Expand All @@ -65,7 +85,8 @@ export function filterSchemaRows(
if (
matchesFieldName(fieldName, formattedFilterText) ||
matchesEditableTagsOrTermsOrDescription(row, filteredFieldPathsByEditableMetadata) ||
matchesTagsOrTermsOrDescription(row, formattedFilterText, entityRegistry) // non-editable tags, terms and description
matchesTagsOrTermsOrDescription(row, formattedFilterText, entityRegistry) || // non-editable tags, terms and description
matchesBusinessAttributesProperties(row, formattedFilterText, entityRegistry)
) {
// if we match specifically on this field (not just its parent), add and expand all parents
splitFieldPath.reduce((previous, current) => {
Expand Down

0 comments on commit a078768

Please sign in to comment.