Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -25,6 +25,9 @@ import DescriptionField from './SchemaDescriptionField';
import analytics, { EventType, EntityActionType } from '../../../../analytics';

const MAX_FIELD_PATH_LENGTH = 100;
const SchemaContainer = styled.div`
margin-bottom: 100px;
`;
const ViewRawButtonContainer = styled.div`
display: flex;
justify-content: flex-end;
Expand Down Expand Up @@ -259,7 +262,7 @@ export default function SchemaView({ urn, schema, editableSchemaMetadata, update
};

return (
<>
<SchemaContainer>
{schema?.platformSchema?.__typename === 'TableSchema' && schema?.platformSchema?.schema?.length > 0 && (
<ViewRawButtonContainer>
<Button onClick={() => setShowRaw(!showRaw)}>{showRaw ? 'Tabular' : 'Raw'}</Button>
Expand All @@ -285,6 +288,6 @@ export default function SchemaView({ urn, schema, editableSchemaMetadata, update
/>
)
)}
</>
</SchemaContainer>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Typography, message } from 'antd';
import { Typography, message, Tag } from 'antd';
import { EditOutlined } from '@ant-design/icons';
import React, { useState } from 'react';
import styled from 'styled-components';
import { FetchResult } from '@apollo/client';
Expand All @@ -7,10 +8,32 @@ import { UpdateDatasetMutation } from '../../../../../graphql/dataset.generated'
import UpdateDescriptionModal from '../../../shared/DescriptionModal';
import MarkdownViewer from '../../../shared/MarkdownViewer';

const EditIcon = styled(EditOutlined)`
cursor: pointer;
padding: 2px;
margin-left: 8px;
display: none;
`;

const AddNewDescription = styled(Tag)`
cursor: pointer;
display: none;
`;

const DescriptionContainer = styled.div`
position: relative;
display: flex;
flex-direction: row;
width: 100%;
height: 100%;
min-height: 22px;
&:hover ${EditIcon} {
display: block;
}

&:hover ${AddNewDescription} {
display: block;
}
`;

const DescriptionText = styled(MarkdownViewer)`
Expand All @@ -37,11 +60,18 @@ export default function DescriptionField({ description, updatedDescription, onUp
const [showAddModal, setShowAddModal] = useState(false);

const onCloseModal = () => setShowAddModal(false);
const currentDesc: string = !!updatedDescription || updatedDescription === '' ? updatedDescription : description;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is difficult to parse. What is happening here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just doing

Suggested change
const currentDesc: string = !!updatedDescription || updatedDescription === '' ? updatedDescription : description;
const currentDesc: string = !!updatedDescription ? updatedDescription : description;

since we aren't supporting saving blank descriptions anyway?


const onUpdateModal = async (desc: string | null) => {
message.loading({ content: 'Updating...' });
await onUpdate(desc || '');
message.success({ content: 'Updated!', duration: 2 });
try {
await onUpdate(desc || '');
message.destroy();
message.success({ content: 'Updated!', duration: 2 });
} catch (e) {
message.destroy();
message.error({ content: `Update Failed! \n ${e.message || ''}`, duration: 2 });
}
onCloseModal();
};

Expand All @@ -52,23 +82,26 @@ export default function DescriptionField({ description, updatedDescription, onUp
e.stopPropagation();
}}
>
<DescriptionText
source={updatedDescription || description}
editable
onEditClicked={() => setShowAddModal(true)}
/>
{updatedDescription && <EditedLabel>(edited)</EditedLabel>}
<DescriptionText source={currentDesc} />
<EditIcon twoToneColor="#52c41a" onClick={() => setShowAddModal(true)} />
{(!!updatedDescription || updatedDescription === '') && <EditedLabel>(edited)</EditedLabel>}
{showAddModal && (
<div>
<UpdateDescriptionModal
title="Update description"
description={updatedDescription || description}
title={currentDesc ? 'Update description' : 'Add description'}
description={currentDesc}
original={description}
onClose={onCloseModal}
onSubmit={onUpdateModal}
isAddDesc={currentDesc === null}
/>
</div>
)}
{!currentDesc && currentDesc !== '' && (
<AddNewDescription color="success" onClick={() => setShowAddModal(true)}>
+ Add Description
</AddNewDescription>
)}
</DescriptionContainer>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Props = {
};

export default function UpdateDescriptionModal({ title, description, original, onClose, onSubmit, isAddDesc }: Props) {
const [updatedDesc, setDesc] = useState(description || original);
const [updatedDesc, setDesc] = useState(description || description === '' ? description : original);

return (
<Modal
Expand Down
4 changes: 1 addition & 3 deletions datahub-web-react/src/app/entity/shared/MarkdownViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { EditOutlined } from '@ant-design/icons';
import MDEditor from '@uiw/react-md-editor';
import styled from 'styled-components';

// const { Text } = Typography;

const EditIcon = styled(EditOutlined)`
cursor: pointer;
position: absolute;
Expand Down Expand Up @@ -111,7 +109,7 @@ export default function MarkdownViewer({ source, limit = 150, editable, onEditCl
{showAll ? 'show less' : 'show more'}
</CustomButton>
)}
<EditIcon twoToneColor="#52c41a" onClick={onEditClicked} />
{editable && <EditIcon twoToneColor="#52c41a" onClick={onEditClicked} />}
</MarkdownContainer>
);
}