-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(react): update schema description edit behavior #2718
Merged
shirshanka
merged 4 commits into
datahub-project:master
from
topwebtek7:FeatReactEditSchemaDescription
Jun 18, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
80ba546
fix(react): update schema description edit behavior
topwebtek7 e477e6c
fix(react): update showing add-description button on hover descriptio…
topwebtek7 a724060
fix(react): update descriptionmodal to dont save empty string
topwebtek7 6bb654b
fix(react): fix minor update in schema description
topwebtek7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||||||
|
@@ -7,10 +8,23 @@ 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 DescriptionContainer = styled.div` | ||||||
position: relative; | ||||||
display: flex; | ||||||
flex-direction: row; | ||||||
width: 100%; | ||||||
height: 100%; | ||||||
min-height: 22px; | ||||||
&:hover ${EditIcon} { | ||||||
display: block; | ||||||
} | ||||||
`; | ||||||
|
||||||
const DescriptionText = styled(MarkdownViewer)` | ||||||
|
@@ -25,6 +39,10 @@ const EditedLabel = styled(Typography.Text)` | |||||
font-style: italic; | ||||||
`; | ||||||
|
||||||
const AddNewDescription = styled(Tag)` | ||||||
cursor: pointer; | ||||||
`; | ||||||
|
||||||
type Props = { | ||||||
description: string; | ||||||
updatedDescription?: string | null; | ||||||
|
@@ -37,11 +55,18 @@ export default function DescriptionField({ description, updatedDescription, onUp | |||||
const [showAddModal, setShowAddModal] = useState(false); | ||||||
|
||||||
const onCloseModal = () => setShowAddModal(false); | ||||||
const currentDesc: string = !!updatedDescription || updatedDescription === '' ? updatedDescription : description; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about just doing
Suggested change
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(); | ||||||
}; | ||||||
|
||||||
|
@@ -52,23 +77,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 === null && ( | ||||||
topwebtek7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
<AddNewDescription color="success" onClick={() => setShowAddModal(true)}> | ||||||
+ Add Description | ||||||
</AddNewDescription> | ||||||
topwebtek7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
)} | ||||||
</DescriptionContainer> | ||||||
); | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?