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

Improve certification feed #19632

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.openmetadata.service.formatter.factory;

import static org.openmetadata.service.Entity.FIELD_ASSETS;
import static org.openmetadata.service.Entity.FIELD_CERTIFICATION;
import static org.openmetadata.service.Entity.FIELD_DESCRIPTION;
import static org.openmetadata.service.Entity.FIELD_DOMAIN;
import static org.openmetadata.service.Entity.FIELD_EXTENSION;
Expand All @@ -33,6 +34,7 @@
import org.openmetadata.service.formatter.entity.PipelineFormatter;
import org.openmetadata.service.formatter.entity.QueryFormatter;
import org.openmetadata.service.formatter.field.AssetsFieldFormatter;
import org.openmetadata.service.formatter.field.CertificationFormatter;
import org.openmetadata.service.formatter.field.CustomPropertiesFormatter;
import org.openmetadata.service.formatter.field.DefaultFieldFormatter;
import org.openmetadata.service.formatter.field.DescriptionFormatter;
Expand Down Expand Up @@ -73,6 +75,7 @@ public static DefaultFieldFormatter getFieldParserObject(
case FIELD_EXTENSION -> new CustomPropertiesFormatter(decorator, thread, fieldChange);
case TEST_RESULT_FIELD -> new TestCaseResultFormatter(decorator, thread, fieldChange);
case FIELD_ASSETS -> new AssetsFieldFormatter(decorator, thread, fieldChange);
case FIELD_CERTIFICATION -> new CertificationFormatter(decorator, thread, fieldChange);
default -> new DefaultFieldFormatter(decorator, thread, fieldChange);
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.openmetadata.service.formatter.field;

import org.openmetadata.schema.entity.feed.CertificationFeedInfo;
import org.openmetadata.schema.entity.feed.FeedInfo;
import org.openmetadata.schema.entity.feed.Thread;
import org.openmetadata.schema.type.FieldChange;
import org.openmetadata.service.formatter.decorators.MessageDecorator;

public class CertificationFormatter extends DefaultFieldFormatter {
private static final String HEADER_MESSAGE = "%s %s certification %s for asset %s";

public CertificationFormatter(
MessageDecorator<?> messageDecorator, Thread thread, FieldChange fieldChange) {
super(messageDecorator, thread, fieldChange);
String[] fieldChangeNameParts = fieldChange.getName().split("\\.");
if (fieldChangeNameParts.length > 1) {
this.fieldChangeName = fieldChangeNameParts[1];
} else {
this.fieldChangeName = "";
}
}

@Override
public String formatAddedField() {
String message = getHeaderForCertificationUpdate("", "Added", thread.getEntityUrlLink());
populateCertificationInfo(Thread.FieldOperation.ADDED, message);
return message;
}

@Override
public String formatUpdatedField() {
String message = getHeaderForCertificationUpdate("", "Updated", thread.getEntityUrlLink());
populateCertificationInfo(Thread.FieldOperation.UPDATED, message);
return message;
}

@Override
public String formatDeletedField() {
String message = getHeaderForCertificationUpdate("", "Deleted", thread.getEntityUrlLink());
populateCertificationInfo(Thread.FieldOperation.DELETED, message);
return message;
}

private void populateCertificationInfo(Thread.FieldOperation operation, String threadMessage) {
CertificationFeedInfo certificationFeedInfo =
new CertificationFeedInfo()
.withPreviousValue(fieldChange.getOldValue())
.withUpdatedValue(fieldChange.getNewValue());
FeedInfo feedInfo =
new FeedInfo()
.withHeaderMessage(
getHeaderForCertificationUpdate(
thread.getUpdatedBy(), operation.value(), thread.getEntityUrlLink()))
.withFieldName(fieldChangeName)
.withEntitySpecificInfo(certificationFeedInfo);
populateThreadFeedInfo(
thread, threadMessage, Thread.CardStyle.CERTIFICATION, operation, feedInfo);
}

private String getHeaderForCertificationUpdate(
String prefix, String eventTypeMessage, String entityUrl) {
return String.format(HEADER_MESSAGE, prefix, eventTypeMessage, fieldChangeName, entityUrl);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$id": "https://open-metadata.org/schema/entity/feed/certification.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "CertificationFeedInfo",
"javaType": "org.openmetadata.schema.entity.feed.CertificationFeedInfo",
"description": "This schema defines the certification addition/updation/deletion schema on feed.",
"type": "object",
"properties": {
"previousValue": {
"description": "Previous Certification details."
},
"updatedValue": {
"description": "Updated Certification details."
}
},
"additionalProperties": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@
"testCaseResult",
"customProperties",
"assets",
"domain"
"domain",
"certification"
],
"default": "default"
},
Expand All @@ -267,6 +268,9 @@
{
"$ref": "./assets.json"
},
{
"$ref": "./certification.json"
},
{
"$ref": "./customProperty.json"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from '../../../../utils/FeedUtils';
import RichTextEditorPreviewerV1 from '../../../common/RichTextEditor/RichTextEditorPreviewerV1';
import ExploreSearchCard from '../../../ExploreV1/ExploreSearchCard/ExploreSearchCard';
import CertificationFeed from '../../ActivityFeedCardV2/FeedCardBody/CertificationFeed/CertificationFeed.component';
import DescriptionFeed from '../../ActivityFeedCardV2/FeedCardBody/DescriptionFeed/DescriptionFeed';
import TagsFeed from '../../ActivityFeedCardV2/FeedCardBody/TagsFeed/TagsFeed';
import './feed-card-body-v1.less';
Expand Down Expand Up @@ -80,6 +81,10 @@ const FeedCardBodyV1 = ({
return <TagsFeed feed={feed} />;
}

if (cardStyle === CardStyle.Certification) {
return <CertificationFeed feed={feed} />;
}

if (ASSET_CARD_STYLES.includes(cardStyle as CardStyle)) {
const entityInfo = feed.feedInfo?.entitySpecificInfo?.entity;
const isExecutableTestSuite =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Collate.
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -10,18 +10,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React, { useMemo } from 'react';
import { getTextDiffCustomProperty } from '../../../../../utils/EntityVersionUtils';
import { getTextDiffCertification } from '../../../../../utils/FeedUtils';
import RichTextEditorPreviewerV1 from '../../../../common/RichTextEditor/RichTextEditorPreviewerV1';
import { CustomPropertyFeedProps } from './CustomPropertyFeed.interface';
import { FeedCardBodyProps } from '../FeedCardBody.interface';

function CustomPropertyFeed({ feed }: Readonly<CustomPropertyFeedProps>) {
const CertificationFeed = ({ feed }: Readonly<FeedCardBodyProps>) => {
const message = useMemo(
() =>
getTextDiffCustomProperty(
feed.feedInfo?.fieldName ?? '',
feed.feedInfo?.entitySpecificInfo?.previousValue ?? '',
getTextDiffCertification(
feed.feedInfo?.entitySpecificInfo?.updatedValue ?? ''
),
[feed]
Expand All @@ -33,6 +30,6 @@ function CustomPropertyFeed({ feed }: Readonly<CustomPropertyFeedProps>) {
markdown={message}
/>
);
}
};

export default CustomPropertyFeed;
export default CertificationFeed;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { render, screen } from '@testing-library/react';
import React from 'react';
import { MOCK_CERTIFICATION_FEED } from '../../../../../mocks/CertificationFeed.mock';
import CertificationFeed from './CertificationFeed.component';

jest.mock('../../../../common/RichTextEditor/RichTextEditorPreviewerV1', () => {
return jest.fn().mockReturnValue(<p>RichTextEditorPreviewerV1</p>);
});

jest.mock('../../../../../utils/FeedUtils', () => ({
getTextDiffCertification: jest.fn(),
}));

describe('Description Feed', () => {
it('renders component when description is updated', () => {
render(<CertificationFeed feed={MOCK_CERTIFICATION_FEED} />);

expect(screen.getByText('RichTextEditorPreviewerV1')).toBeInTheDocument();
});
});

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
getFrontEndFormat,
} from '../../../../../utils/FeedUtils';
import RichTextEditorPreviewerV1 from '../../../../common/RichTextEditor/RichTextEditorPreviewerV1';
import { DescriptionFeedProps } from './DescriptionFeed.interface';
import { FeedCardBodyProps } from '../FeedCardBody.interface';

function DescriptionFeed({ feed }: Readonly<DescriptionFeedProps>) {
function DescriptionFeed({ feed }: Readonly<FeedCardBodyProps>) {
const { message, fieldOperation } = useMemo(() => {
return {
message: (feed.feedInfo?.entitySpecificInfo?.diffMessage ?? '')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Collate.
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -10,9 +10,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Thread } from '../../../../generated/entity/feed/thread';

import { Thread } from '../../../../../generated/entity/feed/thread';

export interface TagsFeedProps {
export interface FeedCardBodyProps {
feed: Thread;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { ReactComponent as DeletedIcon } from '../../../../../assets/svg/deleted

import { Tag } from '../../../../../generated/entity/feed/tag';
import TagsViewer from '../../../../Tag/TagsViewer/TagsViewer';
import { TagsFeedProps } from './TagsFeed.interface';
import { FeedCardBodyProps } from '../FeedCardBody.interface';

function TagsFeed({ feed }: Readonly<TagsFeedProps>) {
function TagsFeed({ feed }: Readonly<FeedCardBodyProps>) {
const { previousTags, updatedTags } = useMemo(() => {
return {
previousTags:
Expand Down

This file was deleted.

Loading
Loading