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

Business Attributes: UI Schema Field Entity Changes #30

Merged
merged 1 commit into from
Apr 1, 2024
Merged
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 @@ -100,7 +100,7 @@ export default function SchemaTable({

const schemaFields = schemaMetadata ? schemaMetadata.fields : inputFields;

const descriptionRender = useDescriptionRenderer(editableSchemaMetadata);
const descriptionRender = useDescriptionRenderer();
const usageStatsRenderer = useUsageStatsRenderer(usageStats);
const tagRenderer = useTagsAndTermsRenderer(
editableSchemaMetadata,
Expand All @@ -121,9 +121,8 @@ export default function SchemaTable({
false,
);
const businessAttributeRenderer = useBusinessAttributeRenderer(
editableSchemaMetadata,
filterText,
false,
false
);
const schemaTitleRenderer = useSchemaTitleRenderer(schemaMetadata, setSelectedFkFieldPath, filterText);
const schemaBlameRenderer = useSchemaBlameRenderer(schemaFieldBlameList);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import React from 'react';
import { EditableSchemaMetadata, SchemaField } from '../../../../../../../../types.generated';
import { SchemaField } from '../../../../../../../../types.generated';
import useBusinessAttributeRenderer from '../../utils/useBusinessAttributeRenderer';
import { SectionHeader, StyledDivider } from './components';
import SchemaEditableContext from '../../../../../../../shared/SchemaEditableContext';

interface Props {
expandedField: SchemaField;
editableSchemaMetadata?: EditableSchemaMetadata | null;
}

export default function FieldAttribute({ expandedField, editableSchemaMetadata }: Props) {
export default function FieldAttribute({ expandedField }: Props) {
const isSchemaEditable = React.useContext(SchemaEditableContext);
const attributeRenderer = useBusinessAttributeRenderer(
editableSchemaMetadata,
'',
isSchemaEditable,
);
Expand All @@ -22,7 +20,7 @@ export default function FieldAttribute({ expandedField, editableSchemaMetadata }
<SectionHeader>Business Attribute</SectionHeader>
{/* pass in globalTags since this is a shared component, tags will not be shown or used */}
<div data-testid={`schema-field-${expandedField.fieldPath}-businessAttribute`}>
{attributeRenderer(editableSchemaMetadata, expandedField)}
{attributeRenderer('', expandedField)}
</div>
<StyledDivider />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export default function FieldDescription({ expandedField, editableFieldInfo }: P
});

const displayedDescription = editableFieldInfo?.description || expandedField.description;
const baDescription = editableFieldInfo?.businessAttributes?.businessAttribute?.businessAttribute?.properties?.description;
const baUrn = editableFieldInfo?.businessAttributes?.businessAttribute?.businessAttribute?.urn;
const baDescription = expandedField?.schemaFieldEntity?.businessAttributes?.businessAttribute?.businessAttribute?.properties?.description;
const baUrn = expandedField?.schemaFieldEntity?.businessAttributes?.businessAttribute?.businessAttribute?.urn;

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import React from 'react';
import { EditableSchemaMetadata, EntityType, SchemaField } from '../../../../../../../types.generated';
import { pathMatchesNewPath } from '../../../../../dataset/profile/schema/utils/utils';
import { useMutationUrn, useRefetch } from '../../../../EntityContext';
import { EntityType, SchemaField } from '../../../../../../../types.generated';
import { useRefetch } from '../../../../EntityContext';
import { useSchemaRefetch } from '../SchemaContext';
import BusinessAttributeGroup from '../../../../../../shared/businessAttribute/BusinessAttributeGroup';

export default function useBusinessAttributeRenderer(
editableSchemaMetadata: EditableSchemaMetadata | null | undefined,
filterText: string,
canEdit: boolean,
) {
const urn = useMutationUrn();
const refetch = useRefetch();
const schemaRefetch = useSchemaRefetch();

Expand All @@ -20,17 +17,13 @@ export default function useBusinessAttributeRenderer(
};

return (businessAttribute: string, record: SchemaField): JSX.Element => {
const relevantEditableFieldInfo = editableSchemaMetadata?.editableSchemaFieldInfo.find(
(candidateEditableFieldInfo) => pathMatchesNewPath(candidateEditableFieldInfo.fieldPath, record.fieldPath),
);

return (
<BusinessAttributeGroup
businessAttribute={relevantEditableFieldInfo?.businessAttributes?.businessAttribute}
businessAttribute={record?.schemaFieldEntity?.businessAttributes?.businessAttribute|| undefined}
canRemove={canEdit}
buttonProps={{ size: 'small' }}
canAddAttribute={canEdit}
entityUrn={urn}
entityUrn={record?.schemaFieldEntity?.urn}
entityType={EntityType.Dataset}
entitySubresource={record.fieldPath}
highlightText={filterText}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { useState } from 'react';
import DOMPurify from 'dompurify';
import { EditableSchemaMetadata, SchemaField, SubResourceType } from '../../../../../../../types.generated';
import { SchemaField, SubResourceType } from '../../../../../../../types.generated';
import DescriptionField from '../../../../../dataset/profile/schema/components/SchemaDescriptionField';
import { pathMatchesNewPath } from '../../../../../dataset/profile/schema/utils/utils';
import { useUpdateDescriptionMutation } from '../../../../../../../graphql/mutations.generated';
import { useMutationUrn, useRefetch } from '../../../../EntityContext';
import { useSchemaRefetch } from '../SchemaContext';

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

return (description: string, record: SchemaField, index: number): JSX.Element => {
const relevantEditableFieldInfo = editableSchemaMetadata?.editableSchemaFieldInfo.find(
(candidateEditableFieldInfo) => pathMatchesNewPath(candidateEditableFieldInfo.fieldPath, record.fieldPath),
);
const displayedDescription = relevantEditableFieldInfo?.description || description;
const displayedDescription = record?.description || description;
const sanitizedDescription = DOMPurify.sanitize(displayedDescription);
const original = record.description ? DOMPurify.sanitize(record.description) : undefined;
const businessAttributeDescription =
relevantEditableFieldInfo?.businessAttributes?.businessAttribute?.businessAttribute?.properties
record?.schemaFieldEntity?.businessAttributes?.businessAttribute?.businessAttribute?.properties
?.description || '';

const handleExpandedRows = (expanded) => setExpandedRows((prev) => ({ ...prev, [index]: expanded }));
Expand All @@ -43,7 +39,7 @@ export default function useDescriptionRenderer(editableSchemaMetadata: EditableS
baExpanded={!!expandedBARows[index]}
description={sanitizedDescription}
original={original}
isEdited={!!relevantEditableFieldInfo?.description}
isEdited={!!record.description}
onUpdate={(updatedDescription) =>
updateDescription({
variables: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export default function useTagsAndTermsRenderer(
(candidateEditableFieldInfo) => pathMatchesNewPath(candidateEditableFieldInfo.fieldPath, record.fieldPath),
);

const businessAttributeTags = relevantEditableFieldInfo?.businessAttributes?.businessAttribute?.businessAttribute?.properties?.tags?.tags || [];
const businessAttributeTerms = relevantEditableFieldInfo?.businessAttributes?.businessAttribute?.businessAttribute?.properties?.glossaryTerms?.terms || [];
const businessAttributeTags = record?.schemaFieldEntity?.businessAttributes?.businessAttribute?.businessAttribute?.properties?.tags?.tags || [];
const businessAttributeTerms = record?.schemaFieldEntity?.businessAttributes?.businessAttribute?.businessAttribute?.properties?.glossaryTerms?.terms || [];

return (
<TagTermGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GlobalOutlined } from '@ant-design/icons';
import React from 'react';
import Highlight from 'react-highlighter';
import { useEntityRegistry } from '../../useEntityRegistry';
import { BusinessAttributeAssociation, EntityType, SubResourceType } from '../../../types.generated';
import { BusinessAttributeAssociation, EntityType } from '../../../types.generated';
import { useHasMatchedFieldByUrn } from '../../search/context/SearchResultContext';
import { MatchedFieldName } from '../../search/matches/constants';
import { useRemoveBusinessAttributeMutation } from '../../../graphql/mutations.generated';
Expand All @@ -25,7 +25,6 @@ const StyledAttribute = styled(Tag)<{ fontSize?: number; highlightAttribute?: bo
interface Props {
businessAttribute: BusinessAttributeAssociation | undefined;
entityUrn?: string;
entitySubresource?: string;
canRemove?: boolean;
readOnly?: boolean;
highlightText?: string;
Expand All @@ -42,7 +41,6 @@ export default function AttributeContent({
fontSize,
onOpenModal,
entityUrn,
entitySubresource,
refetch,
}: Props) {
const entityRegistry = useEntityRegistry();
Expand Down Expand Up @@ -71,8 +69,8 @@ export default function AttributeContent({
businessAttributeUrn: attributeToRemove.businessAttribute.urn,
resourceUrn: {
resourceUrn: attributeToRemove.associatedUrn || entityUrn || '',
subResource: entitySubresource,
subResourceType: entitySubresource ? SubResourceType.DatasetField : null,
subResource: null,
subResourceType: null,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button, Typography } from 'antd';
import React, { useState } from 'react';
import { PlusOutlined } from '@ant-design/icons';
import { EMPTY_MESSAGES } from '../../entity/shared/constants';
import { BusinessAttributeAssociation, EntityType, SubResourceType } from '../../../types.generated';
import { BusinessAttributeAssociation, EntityType } from '../../../types.generated';
import EditBusinessAttributeModal from './AddBusinessAttributeModal';
import StyledAttribute from './StyledAttribute';

Expand Down Expand Up @@ -93,8 +93,8 @@ export default function BusinessAttributeGroup({
resources={[
{
resourceUrn: entityUrn,
subResource: entitySubresource,
subResourceType: entitySubresource ? SubResourceType.DatasetField : null,
subResource: null,
subResourceType: null,
},
]}
/>
Expand Down
Loading