Skip to content

Commit

Permalink
feat: Deprecation 'Note' changed to Markdown Renderable (datahub-proj…
Browse files Browse the repository at this point in the history
…ect#9396)

Setting auto merge after test cases are passed
  • Loading branch information
kushagra-apptware authored Dec 18, 2023
1 parent caef677 commit e58e2bf
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import React from 'react';
import { Button, DatePicker, Form, Input, message, Modal } from 'antd';
import { Button, DatePicker, Form, message, Modal } from 'antd';
import styled from 'styled-components';
import { useBatchUpdateDeprecationMutation } from '../../../../graphql/mutations.generated';
import { handleBatchError } from '../utils';
import { Editor } from '../tabs/Documentation/components/editor/Editor';
import { ANTD_GRAY } from '../constants';

type Props = {
urns: string[];
onClose: () => void;
refetch?: () => void;
};

const StyledEditor = styled(Editor)`
border: 1px solid ${ANTD_GRAY[4.5]};
`;

export const UpdateDeprecationModal = ({ urns, onClose, refetch }: Props) => {
const [batchUpdateDeprecation] = useBatchUpdateDeprecationMutation();
const [form] = Form.useForm();
Expand Down Expand Up @@ -64,10 +71,11 @@ export const UpdateDeprecationModal = ({ urns, onClose, refetch }: Props) => {
</Button>
</>
}
width='40%'
>
<Form form={form} name="addDeprecationForm" onFinish={handleOk} layout="vertical">
<Form.Item name="note" label="Note" rules={[{ whitespace: true }, { min: 0, max: 100 }]}>
<Input placeholder="Add Note" autoFocus />
<Form.Item name="note" label="Note" rules={[{ whitespace: true }]}>
<StyledEditor/>
</Form.Item>
<Form.Item name="decommissionTime" label="Decommission Date">
<DatePicker style={{ width: '100%' }} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { InfoCircleOutlined } from '@ant-design/icons';
import { Divider, message, Modal, Popover, Tooltip, Typography } from 'antd';
import { blue } from '@ant-design/colors';
Expand All @@ -8,6 +8,8 @@ import { Deprecation } from '../../../../../types.generated';
import { getLocaleTimezone } from '../../../../shared/time/timeUtils';
import { ANTD_GRAY } from '../../constants';
import { useBatchUpdateDeprecationMutation } from '../../../../../graphql/mutations.generated';
import { Editor } from '../../tabs/Documentation/components/editor/Editor';
import StripMarkdownText, { removeMarkdown } from './StripMarkdownText';

const DeprecatedContainer = styled.div`
height: 18px;
Expand Down Expand Up @@ -38,11 +40,6 @@ const DeprecatedTitle = styled(Typography.Text)`
font-weight: bold;
`;

const DeprecatedSubTitle = styled(Typography.Text)`
display: block;
margin-bottom: 5px;
`;

const LastEvaluatedAtLabel = styled.div`
padding: 0;
margin: 0;
Expand Down Expand Up @@ -70,15 +67,42 @@ const IconGroup = styled.div`
}
`;

const DescriptionContainer = styled.div`
position: relative;
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
min-height: 22px;
margin-bottom: 14px;
`;
const StyledViewer = styled(Editor)`
padding-right: 8px;
display: block;
.remirror-editor.ProseMirror {
padding: 0;
}
`;

const ExpandedActions = styled.div`
height: 10px;
`;
const ReadLessText = styled(Typography.Link)`
margin-right: 4px;
`;
type Props = {
urn: string;
deprecation: Deprecation;
refetch?: () => void;
showUndeprecate: boolean | null;
};
const ABBREVIATED_LIMIT = 80;

export const DeprecationPill = ({ deprecation, urn, refetch, showUndeprecate }: Props) => {
const [batchUpdateDeprecationMutation] = useBatchUpdateDeprecationMutation();
const [expanded, setExpanded] = useState(false);
const overLimit = deprecation?.note && removeMarkdown(deprecation?.note).length > 80;
/**
* Deprecation Decommission Timestamp
*/
Expand Down Expand Up @@ -131,14 +155,56 @@ export const DeprecationPill = ({ deprecation, urn, refetch, showUndeprecate }:

return (
<Popover
overlayStyle={{ maxWidth: 240 }}
overlayStyle={{ maxWidth: 480 }}
placement="right"
content={
hasDetails ? (
<>
{deprecation?.note !== '' && <DeprecatedTitle>Deprecation note</DeprecatedTitle>}
{isDividerNeeded && <ThinDivider />}
{deprecation?.note !== '' && <DeprecatedSubTitle>{deprecation.note}</DeprecatedSubTitle>}
<DescriptionContainer>
{expanded || !overLimit ? (
<>
{
deprecation?.note && deprecation?.note !== '' &&
<>
<StyledViewer content={deprecation.note} readOnly />
<ExpandedActions>
{overLimit && (
<ReadLessText
onClick={() => {
setExpanded(false);
}}
>
Read Less
</ReadLessText>
)}
</ExpandedActions>
</>
}
</>
) : (
<>
<StripMarkdownText
limit={ABBREVIATED_LIMIT}
readMore={
<>
<Typography.Link
onClick={() => {
setExpanded(true);
}}
>
Read More
</Typography.Link>
</>
}
shouldWrap
>
{deprecation.note}
</StripMarkdownText>
</>
)}
</DescriptionContainer>
{deprecation?.decommissionTime !== null && (
<Typography.Text type="secondary">
<Tooltip placement="right" title={decommissionTimeGMT}>
Expand Down
2 changes: 1 addition & 1 deletion smoke-test/tests/cypress/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Cypress.Commands.add("deleteFromDropdown", () => {

Cypress.Commands.add("addViaFormModal", (text, modelHeader) => {
cy.waitTextVisible(modelHeader);
cy.get(".ant-form-item-control-input-content > input[type='text']").first().type(text);
cy.get('.ProseMirror-focused').type(text);
cy.get(".ant-modal-footer > button:nth-child(2)").click();
});

Expand Down

0 comments on commit e58e2bf

Please sign in to comment.