From 5e1115c1f27644491db12de0c03b07c94be39cb3 Mon Sep 17 00:00:00 2001 From: Andrey Eremchenko Date: Thu, 26 Aug 2021 19:54:09 +0700 Subject: [PATCH 1/4] Show placeholders with 'Empty' text for empty fields in the card dialog. --- .../src/components/cardDetail/cardDetailProperties.tsx | 2 +- webapp/src/components/gallery/galleryCard.tsx | 2 +- webapp/src/components/kanban/kanbanCard.tsx | 2 +- .../src/components/properties/dateRange/dateRange.tsx | 10 ++++++++-- webapp/src/components/properties/link/link.tsx | 3 ++- webapp/src/components/properties/multiSelect.tsx | 2 +- webapp/src/components/propertyValueElement.tsx | 9 ++++++--- webapp/src/components/table/tableRow.tsx | 2 +- 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/webapp/src/components/cardDetail/cardDetailProperties.tsx b/webapp/src/components/cardDetail/cardDetailProperties.tsx index be728bf8b..ebabdd7e2 100644 --- a/webapp/src/components/cardDetail/cardDetailProperties.tsx +++ b/webapp/src/components/cardDetail/cardDetailProperties.tsx @@ -58,7 +58,7 @@ const CardDetailProperties = React.memo((props: Props) => { contents={contents} comments={comments} propertyTemplate={propertyTemplate} - emptyDisplayValue='Empty' + showEmptyPlaceholder={true} /> ) diff --git a/webapp/src/components/gallery/galleryCard.tsx b/webapp/src/components/gallery/galleryCard.tsx index 4bec4af1f..0c1407fa0 100644 --- a/webapp/src/components/gallery/galleryCard.tsx +++ b/webapp/src/components/gallery/galleryCard.tsx @@ -149,7 +149,7 @@ const GalleryCard = React.memo((props: Props) => { readOnly={true} card={card} propertyTemplate={template} - emptyDisplayValue='' + showEmptyPlaceholder={false} /> ))} diff --git a/webapp/src/components/kanban/kanbanCard.tsx b/webapp/src/components/kanban/kanbanCard.tsx index 916af303e..5d1e8cf05 100644 --- a/webapp/src/components/kanban/kanbanCard.tsx +++ b/webapp/src/components/kanban/kanbanCard.tsx @@ -105,7 +105,7 @@ const KanbanCard = React.memo((props: Props) => { contents={contents} comments={comments} propertyTemplate={template} - emptyDisplayValue='' + showEmptyPlaceholder={false} /> ))} diff --git a/webapp/src/components/properties/dateRange/dateRange.tsx b/webapp/src/components/properties/dateRange/dateRange.tsx index 50048a0c2..a8f07d1cc 100644 --- a/webapp/src/components/properties/dateRange/dateRange.tsx +++ b/webapp/src/components/properties/dateRange/dateRange.tsx @@ -22,6 +22,7 @@ import {Utils} from '../../../utils' type Props = { className: string value: string + showEmptyPlaceholder?: boolean onChange: (value: string) => void } @@ -35,7 +36,7 @@ type DateProperty = { const loadedLocales: Record = {} function DateRange(props: Props): JSX.Element { - const {className, value, onChange} = props + const {className, value, showEmptyPlaceholder, onChange} = props const intl = useIntl() const timeZoneOffset = new Date().getTimezoneOffset() * 60 * 1000 @@ -151,12 +152,17 @@ function DateRange(props: Props): JSX.Element { setShowDialog(false) } + let buttonText = displayValue + if (!buttonText && showEmptyPlaceholder) { + buttonText = intl.formatMessage({id: 'DateRange.empty', defaultMessage: 'Empty'}) + } + return (
{showDialog && diff --git a/webapp/src/components/properties/link/link.tsx b/webapp/src/components/properties/link/link.tsx index ac3a01477..f1e24b983 100644 --- a/webapp/src/components/properties/link/link.tsx +++ b/webapp/src/components/properties/link/link.tsx @@ -12,6 +12,7 @@ import LinkIcon from '../../../widgets/icons/Link' type Props = { value: string readonly?: boolean + placeholder?: string onChange: (value: string) => void onSave: () => void onCancel: () => void @@ -38,7 +39,7 @@ const URLProperty = (props: Props): JSX.Element => {
{ ))} {values.length === 0 && ( - + )}
) diff --git a/webapp/src/components/propertyValueElement.tsx b/webapp/src/components/propertyValueElement.tsx index 48929d161..e9e74a980 100644 --- a/webapp/src/components/propertyValueElement.tsx +++ b/webapp/src/components/propertyValueElement.tsx @@ -36,17 +36,18 @@ type Props = { contents: Array comments: CommentBlock[] propertyTemplate: IPropertyTemplate - emptyDisplayValue: string + showEmptyPlaceholder: boolean } const PropertyValueElement = (props:Props): JSX.Element => { const [value, setValue] = useState(props.card.fields.properties[props.propertyTemplate.id] || '') const [serverValue, setServerValue] = useState(props.card.fields.properties[props.propertyTemplate.id] || '') - const {card, propertyTemplate, readOnly, emptyDisplayValue, board, contents, comments} = props + const {card, propertyTemplate, readOnly, showEmptyPlaceholder, board, contents, comments} = props const intl = useIntl() const propertyValue = card.fields.properties[propertyTemplate.id] const displayValue = OctoUtils.propertyDisplayValue(card, propertyValue, propertyTemplate, intl) + const emptyDisplayValue = showEmptyPlaceholder ? intl.formatMessage({id: 'PropertyValueElement.empty', defaultMessage: 'Empty'}) : '' const finalDisplayValue = displayValue || emptyDisplayValue const [open, setOpen] = useState(false) @@ -201,6 +202,7 @@ const PropertyValueElement = (props:Props): JSX.Element => { mutator.changePropertyValue(card, propertyTemplate.id, newValue)} /> ) @@ -209,6 +211,7 @@ const PropertyValueElement = (props:Props): JSX.Element => { setValue(propertyValue)} @@ -260,7 +263,7 @@ const PropertyValueElement = (props:Props): JSX.Element => { return ( { contents={contents} comments={comments} propertyTemplate={template} - emptyDisplayValue='' + showEmptyPlaceholder={false} />
) })} From e299940cadd5428eeb9776308d42d0a12534066b Mon Sep 17 00:00:00 2001 From: Andrey Eremchenko Date: Thu, 26 Aug 2021 23:04:01 +0700 Subject: [PATCH 2/4] Unit test for `DateRange` fixed. Snapshots updated. --- .../dateRange/__snapshots__/dateRange.test.tsx.snap | 6 +----- .../src/components/properties/dateRange/dateRange.test.tsx | 6 ++++-- .../properties/link/__snapshots__/link.test.tsx.snap | 1 - 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/webapp/src/components/properties/dateRange/__snapshots__/dateRange.test.tsx.snap b/webapp/src/components/properties/dateRange/__snapshots__/dateRange.test.tsx.snap index 2a92f7502..ad99753d8 100644 --- a/webapp/src/components/properties/dateRange/__snapshots__/dateRange.test.tsx.snap +++ b/webapp/src/components/properties/dateRange/__snapshots__/dateRange.test.tsx.snap @@ -43,11 +43,7 @@ exports[`components/properties/dateRange returns default correctly 1`] = ` class="Button " type="button" > - - - + diff --git a/webapp/src/components/properties/dateRange/dateRange.test.tsx b/webapp/src/components/properties/dateRange/dateRange.test.tsx index 0e14fb845..b511a06cf 100644 --- a/webapp/src/components/properties/dateRange/dateRange.test.tsx +++ b/webapp/src/components/properties/dateRange/dateRange.test.tsx @@ -60,6 +60,7 @@ describe('components/properties/dateRange', () => { , ) @@ -68,7 +69,7 @@ describe('components/properties/dateRange', () => { const fifteenth = Date.UTC(date.getFullYear(), date.getMonth(), 15, 12) const {getByText, getByTitle} = render(component) - const dayDisplay = getByTitle('Empty') + const dayDisplay = getByText('Empty') userEvent.click(dayDisplay) const day = getByText('15') @@ -86,13 +87,14 @@ describe('components/properties/dateRange', () => { , ) // open modal const {getByText, getByTitle} = render(component) - const dayDisplay = getByTitle('Empty') + const dayDisplay = getByText('Empty') userEvent.click(dayDisplay) // select start date diff --git a/webapp/src/components/properties/link/__snapshots__/link.test.tsx.snap b/webapp/src/components/properties/link/__snapshots__/link.test.tsx.snap index 00dddfb53..cdc7abf9d 100644 --- a/webapp/src/components/properties/link/__snapshots__/link.test.tsx.snap +++ b/webapp/src/components/properties/link/__snapshots__/link.test.tsx.snap @@ -7,7 +7,6 @@ exports[`components/properties/link returns link properties correctly 1`] = ` > From 13bc220e52a3aec33c37ea5d5f8d920c27e36218 Mon Sep 17 00:00:00 2001 From: Andrey Eremchenko Date: Mon, 6 Sep 2021 22:19:55 +0700 Subject: [PATCH 3/4] More consistent styles for empty placeholders. --- .../dateRange/__snapshots__/dateRange.test.tsx.snap | 2 +- .../components/properties/dateRange/dateRange.scss | 9 +++++---- .../components/properties/dateRange/dateRange.tsx | 2 +- .../properties/user/__snapshots__/user.test.tsx.snap | 4 ++-- webapp/src/components/properties/user/user.tsx | 12 +++++++++++- webapp/src/widgets/label.scss | 7 +++++++ webapp/src/widgets/valueSelector.tsx | 4 ++++ 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/webapp/src/components/properties/dateRange/__snapshots__/dateRange.test.tsx.snap b/webapp/src/components/properties/dateRange/__snapshots__/dateRange.test.tsx.snap index ad99753d8..16275b6d0 100644 --- a/webapp/src/components/properties/dateRange/__snapshots__/dateRange.test.tsx.snap +++ b/webapp/src/components/properties/dateRange/__snapshots__/dateRange.test.tsx.snap @@ -37,7 +37,7 @@ exports[`components/properties/dateRange handle clear 1`] = ` exports[`components/properties/dateRange returns default correctly 1`] = `
@@ -44,7 +42,7 @@ exports[`components/propertyValueElement should match snapshot, person, array va
@@ -132,7 +130,7 @@ exports[`components/propertyValueElement should match snapshot, url, array value > diff --git a/webapp/src/components/properties/dateRange/dateRange.test.tsx b/webapp/src/components/properties/dateRange/dateRange.test.tsx index c9e1ec393..87986518b 100644 --- a/webapp/src/components/properties/dateRange/dateRange.test.tsx +++ b/webapp/src/components/properties/dateRange/dateRange.test.tsx @@ -251,6 +251,7 @@ describe('components/properties/dateRange', () => { , ) @@ -263,7 +264,7 @@ describe('components/properties/dateRange', () => { const today = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) const {getByText, getByTitle} = render(component) - const dayDisplay = getByTitle('Empty') + const dayDisplay = getByText('Empty') userEvent.click(dayDisplay) const day = getByText('Today') diff --git a/webapp/src/components/propertyValueElement.test.tsx b/webapp/src/components/propertyValueElement.test.tsx index 7ed877c2a..0e71e69e4 100644 --- a/webapp/src/components/propertyValueElement.test.tsx +++ b/webapp/src/components/propertyValueElement.test.tsx @@ -39,7 +39,7 @@ describe('components/propertyValueElement', () => { contents={[]} comments={[comments]} propertyTemplate={propertyTemplate || board.fields.cardProperties[0]} - emptyDisplayValue={'empty'} + showEmptyPlaceholder={true} />, ) @@ -57,7 +57,7 @@ describe('components/propertyValueElement', () => { contents={[]} comments={[comments]} propertyTemplate={propertyTemplate || board.fields.cardProperties[0]} - emptyDisplayValue={'empty'} + showEmptyPlaceholder={true} />, ) @@ -91,7 +91,7 @@ describe('components/propertyValueElement', () => { contents={[]} comments={[comments]} propertyTemplate={propertyTemplate} - emptyDisplayValue={'empty'} + showEmptyPlaceholder={true} />, ) @@ -116,7 +116,7 @@ describe('components/propertyValueElement', () => { contents={[]} comments={[comments]} propertyTemplate={propertyTemplate} - emptyDisplayValue={'empty'} + showEmptyPlaceholder={true} />, ) @@ -141,7 +141,7 @@ describe('components/propertyValueElement', () => { contents={[]} comments={[comments]} propertyTemplate={propertyTemplate} - emptyDisplayValue={'empty'} + showEmptyPlaceholder={true} />, ) @@ -166,7 +166,7 @@ describe('components/propertyValueElement', () => { contents={[]} comments={[comments]} propertyTemplate={propertyTemplate} - emptyDisplayValue={'empty'} + showEmptyPlaceholder={true} />, ) @@ -191,7 +191,7 @@ describe('components/propertyValueElement', () => { contents={[]} comments={[comments]} propertyTemplate={propertyTemplate} - emptyDisplayValue={'empty'} + showEmptyPlaceholder={true} />, ) const {container} = render(component)