From cfe86267eef93b8be5e0f12fd1c96894da4f33c4 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Fri, 17 May 2024 15:40:07 +0530 Subject: [PATCH] MINOR: fix the header in deleted team feed (#16317) * fix the header in deleted team feed * added unit test --- .../ui/src/constants/Feeds.constants.ts | 8 -- .../resources/ui/src/utils/FeedUtils.test.tsx | 114 +++++++++++++++++- .../main/resources/ui/src/utils/FeedUtils.tsx | 20 +-- 3 files changed, 115 insertions(+), 27 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/constants/Feeds.constants.ts b/openmetadata-ui/src/main/resources/ui/src/constants/Feeds.constants.ts index 2f2123808fb..0c7fc76d4fc 100644 --- a/openmetadata-ui/src/main/resources/ui/src/constants/Feeds.constants.ts +++ b/openmetadata-ui/src/main/resources/ui/src/constants/Feeds.constants.ts @@ -11,7 +11,6 @@ * limitations under the License. */ -import { EntityType } from '../enums/entity.enum'; import { CardStyle } from '../generated/entity/feed/thread'; export const EntityRegExPattern = /<#E::([^<>]+?)::([^<>]+?)(?:::([^<>]+?))?>/; @@ -99,10 +98,3 @@ export const ASSET_CARD_STYLES = [ CardStyle.EntitySoftDeleted, CardStyle.EntityDeleted, ]; - -export const NON_DATA_ASSET_ENTITIES = [ - EntityType.TEAM, - EntityType.BOT, - EntityType.APPLICATION, - EntityType.EVENT_SUBSCRIPTION, -]; diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.test.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.test.tsx index 274a83e352c..31378f2e476 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.test.tsx @@ -10,9 +10,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import { FQN_SEPARATOR_CHAR } from '../constants/char.constants'; import { EntityType, FqnPart } from '../enums/entity.enum'; +import { CardStyle, FieldOperation } from '../generated/entity/feed/thread'; import { getPartialNameFromTableFQN } from './CommonUtils'; import { entityDisplayName, @@ -20,6 +20,7 @@ import { getEntityField, getEntityFQN, getEntityType, + getFeedHeaderTextFromCardStyle, suggestions, } from './FeedUtils'; @@ -162,3 +163,114 @@ describe('Feed Utils', () => { ); }); }); + +describe('getFeedHeaderTextFromCardStyle', () => { + it('should return element for created application', () => { + const result = getFeedHeaderTextFromCardStyle( + FieldOperation.Added, + CardStyle.EntityCreated, + undefined, + EntityType.APPLICATION + ); + + const stringResult = JSON.stringify(result); + + expect(stringResult).toContain('label.installed-lowercase'); + expect(stringResult).toContain('label.app-lowercase'); + }); + + it('should return element for deleted application', () => { + const result = getFeedHeaderTextFromCardStyle( + FieldOperation.Deleted, + CardStyle.EntityDeleted, + undefined, + EntityType.APPLICATION + ); + + const stringResult = JSON.stringify(result); + + expect(stringResult).toContain('label.uninstalled-lowercase'); + expect(stringResult).toContain('label.app-lowercase'); + }); + + it('should return element for created team', () => { + const result = getFeedHeaderTextFromCardStyle( + FieldOperation.Added, + CardStyle.EntityCreated, + undefined, + EntityType.TEAM + ); + + const stringResult = JSON.stringify(result); + + expect(stringResult).toContain('label.added-lowercase'); + }); + + it('should return element for soft deleted team', () => { + const result = getFeedHeaderTextFromCardStyle( + FieldOperation.Deleted, + CardStyle.EntitySoftDeleted, + undefined, + EntityType.TEAM + ); + + const stringResult = JSON.stringify(result); + + expect(stringResult).toContain('label.soft-deleted-lowercase'); + }); + + it('should return element for deleted team', () => { + const result = getFeedHeaderTextFromCardStyle( + FieldOperation.Deleted, + CardStyle.EntityDeleted, + undefined, + EntityType.TEAM + ); + + const stringResult = JSON.stringify(result); + + expect(stringResult).toContain('label.deleted-lowercase'); + expect(stringResult).toContain('text-danger'); + }); + + it('should return element for created CustomProperties', () => { + const result = getFeedHeaderTextFromCardStyle( + FieldOperation.Added, + CardStyle.CustomProperties, + undefined, + EntityType.TABLE + ); + + const stringResult = JSON.stringify(result); + + expect(stringResult).toContain('message.feed-custom-property-header'); + }); + + it('should return element element for created testCaseResult', () => { + const result = getFeedHeaderTextFromCardStyle( + FieldOperation.Added, + CardStyle.TestCaseResult, + undefined, + EntityType.TEST_CASE + ); + + const stringResult = JSON.stringify(result); + + expect(stringResult).toContain('message.feed-test-case-header'); + }); + + it('should return element for updated description', () => { + const result = getFeedHeaderTextFromCardStyle( + FieldOperation.Updated, + CardStyle.Description, + undefined, + EntityType.TABLE + ); + + const stringResult = JSON.stringify(result); + + expect(stringResult).toContain('message.feed-field-action-entity-header'); + expect(stringResult).toContain('label.description'); + expect(stringResult).toContain('label.updated-lowercase'); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.tsx index fff358a3d12..2093c1057bb 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.tsx @@ -36,7 +36,6 @@ import { hashtagRegEx, linkRegEx, mentionRegEx, - NON_DATA_ASSET_ENTITIES, teamsLinkRegEx, } from '../constants/Feeds.constants'; import { EntityType, FqnPart, TabSpecificField } from '../enums/entity.enum'; @@ -807,27 +806,12 @@ export const getFeedHeaderTextFromCardStyle = ( case CardStyle.EntityCreated: case CardStyle.EntityDeleted: case CardStyle.EntitySoftDeleted: - if (NON_DATA_ASSET_ENTITIES.includes(entityType as EntityType)) { - return entityType === EntityType.APPLICATION ? ( + if (entityType === EntityType.APPLICATION) { + return ( {getActionLabelFromCardStyle(cardStyle, true)}{' '} {i18next.t('label.app-lowercase')} - ) : ( - } - values={{ - entity: i18next.t( - `label.${ - entityType === EntityType.EVENT_SUBSCRIPTION - ? 'alert' - : entityType - }-lowercase` - ), - action: getActionLabelFromCardStyle(cardStyle), - }} - /> ); }