Skip to content

Commit

Permalink
fix(ui) Show edited field descriptions in schema table (datahub-proje…
Browse files Browse the repository at this point in the history
…ct#10314)

Co-authored-by: david-leifker <[email protected]>
  • Loading branch information
2 people authored and sleeperdeep committed Jun 25, 2024
1 parent 28247e7 commit 8a3efea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default function SchemaTable({

const schemaFields = schemaMetadata ? schemaMetadata.fields : inputFields;

const descriptionRender = useDescriptionRenderer();
const descriptionRender = useDescriptionRenderer(editableSchemaMetadata);
const usageStatsRenderer = useUsageStatsRenderer(usageStats);
const tagRenderer = useTagsAndTermsRenderer(
editableSchemaMetadata,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useState } from 'react';
import DOMPurify from 'dompurify';
import { SchemaField, SubResourceType } from '../../../../../../../types.generated';
import { EditableSchemaMetadata, SchemaField, SubResourceType } from '../../../../../../../types.generated';
import DescriptionField from '../../../../../dataset/profile/schema/components/SchemaDescriptionField';
import { useUpdateDescriptionMutation } from '../../../../../../../graphql/mutations.generated';
import { useMutationUrn, useRefetch } from '../../../../EntityContext';
import { useSchemaRefetch } from '../SchemaContext';
import { pathMatchesNewPath } from '../../../../../dataset/profile/schema/utils/utils';

export default function useDescriptionRenderer() {
export default function useDescriptionRenderer(editableSchemaMetadata: EditableSchemaMetadata | null | undefined) {
const urn = useMutationUrn();
const refetch = useRefetch();
const schemaRefetch = useSchemaRefetch();
Expand All @@ -20,7 +21,10 @@ export default function useDescriptionRenderer() {
};

return (description: string, record: SchemaField, index: number): JSX.Element => {
const displayedDescription = record?.description || description;
const relevantEditableFieldInfo = editableSchemaMetadata?.editableSchemaFieldInfo.find(
(candidateEditableFieldInfo) => pathMatchesNewPath(candidateEditableFieldInfo.fieldPath, record.fieldPath),
);
const displayedDescription = relevantEditableFieldInfo?.description || description;
const sanitizedDescription = DOMPurify.sanitize(displayedDescription);
const original = record.description ? DOMPurify.sanitize(record.description) : undefined;
const businessAttributeDescription =
Expand All @@ -39,7 +43,7 @@ export default function useDescriptionRenderer() {
baExpanded={!!expandedBARows[index]}
description={sanitizedDescription}
original={original}
isEdited={!!record.description}
isEdited={!!relevantEditableFieldInfo?.description}
onUpdate={(updatedDescription) =>
updateDescription({
variables: {
Expand Down

0 comments on commit 8a3efea

Please sign in to comment.