From 187d6ce5e3bdfa577d38e33654f9db9b7057b661 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Thu, 25 Jan 2018 16:13:38 +0200 Subject: [PATCH 1/8] Add category config, read category from publicData in ListingPage --- src/containers/ListingPage/ListingPage.js | 12 +++++++----- src/marketplace-custom-config.js | 7 +++++++ src/translations/en.json | 4 ---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/containers/ListingPage/ListingPage.js b/src/containers/ListingPage/ListingPage.js index 61218e44..3ae299d6 100644 --- a/src/containers/ListingPage/ListingPage.js +++ b/src/containers/ListingPage/ListingPage.js @@ -145,6 +145,11 @@ const gotoListingTab = (history, listing) => { ); }; +const categoryLabel = (categories, key) => { + const cat = categories.find(c => c.key === key); + return cat ? cat.label : key; +}; + // TODO: price unit (per x), custom fields, contact, reviews // N.B. All the presentational content needs to be extracted to their own components export class ListingPageComponent extends Component { @@ -261,13 +266,10 @@ export class ListingPageComponent extends Component { publicData, } = currentListing.attributes; - const { customAttributes } = currentListing.attributes; - const hasCategoryConfig = config.customAttributes && config.customAttributes.category; - const hasCategoryAttribute = customAttributes && customAttributes.category; const category = - hasCategoryConfig && hasCategoryAttribute ? ( + publicData && publicData.category ? ( - + {categoryLabel(config.custom.categories, publicData.category)} ) : null; diff --git a/src/marketplace-custom-config.js b/src/marketplace-custom-config.js index 05f8dba0..320420df 100644 --- a/src/marketplace-custom-config.js +++ b/src/marketplace-custom-config.js @@ -36,3 +36,10 @@ export const amenities = [ label: 'Own food allowed', }, ]; + +export const categories = [ + { key: 'road', label: 'Road' }, + { key: 'mountain', label: 'Mountain' }, + { key: 'track', label: 'Track' }, + { key: 'other', label: 'Other' }, +]; diff --git a/src/translations/en.json b/src/translations/en.json index 31325e87..aba440e7 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -255,10 +255,6 @@ "ListingPage.bookingHelp": "Start by choosing your dates.", "ListingPage.bookingHelpClosedListing": "Sorry, this listing has been closed.", "ListingPage.bookingTitle": "Book {title}", - "ListingPage.category.mountain": "Mountain", - "ListingPage.category.other": "Other", - "ListingPage.category.road": "Road", - "ListingPage.category.track": "Track", "ListingPage.closedListing": "This listing has been closed and can't be booked.", "ListingPage.closedListingButtonText": "Sorry, this listing has been closed.", "ListingPage.contactUser": "Contact", From 6c19e3658820157e751058caa51441166427cd9b Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 26 Jan 2018 11:33:14 +0200 Subject: [PATCH 2/8] Read category from publicData --- .../EditListingDescriptionPanel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js b/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js index 845bac4a..f68d848e 100644 --- a/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js +++ b/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js @@ -24,7 +24,7 @@ const EditListingDescriptionPanel = props => { const classes = classNames(rootClassName || css.root, className); const currentListing = ensureListing(listing); - const { description, title, customAttributes } = currentListing.attributes; + const { description, title, publicData } = currentListing.attributes; const listingTitle = title || ''; const listingLink = currentListing.id ? ( @@ -48,7 +48,7 @@ const EditListingDescriptionPanel = props => {

{panelTitle}

{ const { title, description, category } = values; From c2ecd93c88145bd824a394594f54aab6beac9004 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 26 Jan 2018 11:36:23 +0200 Subject: [PATCH 3/8] Use custom config for categories --- .../EditListingDescriptionPanel.js | 2 + .../EditListingDescriptionForm.js | 51 ++++++++++++++++--- .../EditListingDescriptionForm.test.js | 1 + .../EditListingDescriptionForm.test.js.snap | 36 +++++++++++++ src/translations/en.json | 3 ++ 5 files changed, 86 insertions(+), 7 deletions(-) diff --git a/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js b/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js index f68d848e..f2a0c343 100644 --- a/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js +++ b/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js @@ -6,6 +6,7 @@ import { ensureListing } from '../../util/data'; import { createSlug } from '../../util/urlHelpers'; import { NamedLink } from '../../components'; import { EditListingDescriptionForm } from '../../containers'; +import config from '../../config'; import css from './EditListingDescriptionPanel.css'; @@ -65,6 +66,7 @@ const EditListingDescriptionPanel = props => { updated={panelUpdated} updateError={errors.updateListingError} updateInProgress={updateInProgress} + categories={config.custom.categories} /> ); diff --git a/src/containers/EditListingDescriptionForm/EditListingDescriptionForm.js b/src/containers/EditListingDescriptionForm/EditListingDescriptionForm.js index 703d423c..25669f42 100644 --- a/src/containers/EditListingDescriptionForm/EditListingDescriptionForm.js +++ b/src/containers/EditListingDescriptionForm/EditListingDescriptionForm.js @@ -1,17 +1,48 @@ import React from 'react'; -import PropTypes from 'prop-types'; +import { bool, func, string, arrayOf, shape } from 'prop-types'; import { compose } from 'redux'; import { reduxForm, propTypes as formPropTypes } from 'redux-form'; import { intlShape, injectIntl, FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import { propTypes } from '../../util/types'; import { maxLength, required } from '../../util/validators'; -import { FieldCustomAttributeSelect, Form, Button, TextInputField } from '../../components'; +import { Form, Button, TextInputField, SelectField } from '../../components'; import css from './EditListingDescriptionForm.css'; const TITLE_MAX_LENGTH = 60; +const CustomCategorySelectFieldMaybe = props => { + const { name, id, categories, intl } = props; + const categoryLabel = intl.formatMessage({ + id: 'EditListingDescriptionForm.categoryLabel', + }); + const categoryPlaceholder = intl.formatMessage({ + id: 'EditListingDescriptionForm.categoryPlaceholder', + }); + const categoryRequired = required( + intl.formatMessage({ + id: 'EditListingDescriptionForm.categoryRequired', + }) + ); + return categories ? ( + + + {categories.map(c => ( + + ))} + + ) : null; +}; + const EditListingDescriptionFormComponent = props => { const { className, @@ -25,6 +56,7 @@ const EditListingDescriptionFormComponent = props => { updated, updateError, updateInProgress, + categories, } = props; const titleMessage = intl.formatMessage({ id: 'EditListingDescriptionForm.title' }); @@ -86,10 +118,11 @@ const EditListingDescriptionFormComponent = props => { validate={[required(descriptionRequiredMessage)]} /> - ); })} - @@ -85,24 +80,25 @@ class SelectSingleFilterComponent extends Component { } } -const { object, string, func } = PropTypes; - -SelectSingleFilterComponent.defaultProps = { +SelectSingleFilter.defaultProps = { rootClassName: null, className: null, }; -SelectSingleFilterComponent.propTypes = { +SelectSingleFilter.propTypes = { rootClassName: string, className: string, - customAttribute: string.isRequired, urlQueryParams: object.isRequired, + urlParam: string.isRequired, + paramLabel: string.isRequired, onSelect: func.isRequired, - // from injectIntl - intl: intlShape.isRequired, + options: arrayOf( + shape({ + key: string.isRequired, + label: string.isRequired, + }) + ).isRequired, }; -const SelectSingleFilter = injectIntl(SelectSingleFilterComponent); - export default SelectSingleFilter; diff --git a/src/components/SelectSingleFilterMobile/SelectSingleFilterMobile.js b/src/components/SelectSingleFilterMobile/SelectSingleFilterMobile.js index 2484bf05..966e94a1 100644 --- a/src/components/SelectSingleFilterMobile/SelectSingleFilterMobile.js +++ b/src/components/SelectSingleFilterMobile/SelectSingleFilterMobile.js @@ -1,12 +1,11 @@ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; +import { object, string, func, arrayOf, shape } from 'prop-types'; import classNames from 'classnames'; -import { FormattedMessage, injectIntl, intlShape } from 'react-intl'; +import { FormattedMessage } from 'react-intl'; -import config from '../../config'; import css from './SelectSingleFilterMobile.css'; -class SelectSingleFilterMobileComponent extends Component { +class SelectSingleFilterMobile extends Component { constructor(props) { super(props); this.state = { isOpen: true }; @@ -15,8 +14,8 @@ class SelectSingleFilterMobileComponent extends Component { } selectOption(option, e) { - const { customAttribute, onSelect } = this.props; - onSelect(customAttribute, option); + const { urlParam, onSelect } = this.props; + onSelect(urlParam, option); // blur event target if event is passed if (e && e.currentTarget) { @@ -29,17 +28,10 @@ class SelectSingleFilterMobileComponent extends Component { } render() { - const { rootClassName, className, customAttribute, urlQueryParams, intl } = this.props; + const { rootClassName, className, urlQueryParams, urlParam, paramLabel, options } = this.props; - const filterLabel = intl.formatMessage({ - id: `SelectSingleFilterMobile.${customAttribute}.label`, - }); - // custom attribute content - const ca = customAttribute && config.customAttributes[customAttribute]; - // name of the corresponding query parameter - const caParam = `ca_${customAttribute}`; // current value of this custom attribute filter - const currentValue = urlQueryParams[caParam]; + const currentValue = urlQueryParams[urlParam]; const labelClass = currentValue ? css.filterLabelSelected : css.filterLabel; @@ -53,22 +45,26 @@ class SelectSingleFilterMobileComponent extends Component {
- {ca.values.map(v => { + {options.map(option => { // check if this option is selected - const selected = currentValue === v; + const selected = currentValue === option.key; // menu item border class const optionBorderClass = selected ? css.optionBorderSelected : css.optionBorder; return ( - ); })} @@ -78,24 +74,25 @@ class SelectSingleFilterMobileComponent extends Component { } } -const { object, string, func } = PropTypes; - -SelectSingleFilterMobileComponent.defaultProps = { +SelectSingleFilterMobile.defaultProps = { rootClassName: null, className: null, }; -SelectSingleFilterMobileComponent.propTypes = { +SelectSingleFilterMobile.propTypes = { rootClassName: string, className: string, - customAttribute: string.isRequired, urlQueryParams: object.isRequired, + urlParam: string.isRequired, + paramLabel: string.isRequired, onSelect: func.isRequired, - // from injectIntl - intl: intlShape.isRequired, + options: arrayOf( + shape({ + key: string.isRequired, + label: string.isRequired, + }) + ).isRequired, }; -const SelectSingleFilterMobile = injectIntl(SelectSingleFilterMobileComponent); - export default SelectSingleFilterMobile; diff --git a/src/containers/SearchPage/SearchPage.js b/src/containers/SearchPage/SearchPage.js index d28675bf..c15d56dc 100644 --- a/src/containers/SearchPage/SearchPage.js +++ b/src/containers/SearchPage/SearchPage.js @@ -42,10 +42,12 @@ const MODAL_BREAKPOINT = 768; // Search is in modal on mobile layout const SEARCH_WITH_MAP_DEBOUNCE = 300; // Little bit of debounce before search is initiated. const BOUNDS_FIXED_PRECISION = 8; +const CATEGORY_URL_PARAM = 'ca_category'; + // extract search parameters, including a custom attribute named category const pickSearchParamsOnly = params => { - const { address, origin, bounds, ca_category } = params || {}; - return { address, origin, bounds, ca_category }; + const { address, origin, bounds, ...rest } = params || {}; + return { address, origin, bounds, [CATEGORY_URL_PARAM]: rest[CATEGORY_URL_PARAM] }; }; export class SearchPageComponent extends Component { @@ -185,6 +187,7 @@ export class SearchPageComponent extends Component { searchInProgress, searchListingsError, searchParams, + categories, } = this.props; // eslint-disable-next-line no-unused-vars const { mapSearch, page, ...searchInURL } = parse(location.search, { @@ -301,6 +304,7 @@ export class SearchPageComponent extends Component { searchListingsError={searchListingsError} onMapIconClick={onMapIconClick} onManageDisableScrolling={onManageDisableScrolling} + categories={categories} />
{ latlng: ['origin'], latlngBounds: ['bounds'], }); - const page = queryParams.page || 1; + const { page = 1, ...rest } = queryParams; return searchListings({ - ...queryParams, + ...rest, page, perPage: RESULT_PAGE_SIZE, include: ['author', 'images'], diff --git a/src/containers/SearchPage/SearchPage.test.js b/src/containers/SearchPage/SearchPage.test.js index 18e2520e..8c6d7922 100644 --- a/src/containers/SearchPage/SearchPage.test.js +++ b/src/containers/SearchPage/SearchPage.test.js @@ -41,6 +41,7 @@ describe('SearchPageComponent', () => { onSearchMapListings: noop, sendVerificationEmailInProgress: false, onResendVerificationEmail: noop, + categories: [{ key: 'cat1', label: 'Cat 1' }, { key: 'cat2', label: 'Cat 2' }], }; const tree = renderShallow(); expect(tree).toMatchSnapshot(); diff --git a/src/containers/SearchPage/__snapshots__/SearchPage.test.js.snap b/src/containers/SearchPage/__snapshots__/SearchPage.test.js.snap index b7a92ad1..39b17277 100644 --- a/src/containers/SearchPage/__snapshots__/SearchPage.test.js.snap +++ b/src/containers/SearchPage/__snapshots__/SearchPage.test.js.snap @@ -20,7 +20,19 @@ exports[`SearchPageComponent matches snapshot 1`] = `
- Date: Mon, 29 Jan 2018 10:08:26 +0200 Subject: [PATCH 6/8] Remove customAttribute config and data --- .../EditListingDescriptionPanel.js | 5 ++ .../EditListingWizard/EditListingWizard.js | 1 - .../EditListingWizard/EditListingWizardTab.js | 1 - .../TransactionPanel.test.js.snap | 84 ------------------- src/config.js | 36 -------- .../__snapshots__/ListingPage.test.js.snap | 1 - .../TransactionPage.test.js.snap | 2 - src/util/data.js | 4 +- src/util/test-data.js | 2 - src/util/types.js | 2 - 10 files changed, 7 insertions(+), 131 deletions(-) diff --git a/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js b/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js index f2a0c343..ecc9202f 100644 --- a/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js +++ b/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js @@ -56,7 +56,12 @@ const EditListingDescriptionPanel = props => { const updateValues = { title, description, + + // Save category also to the deprecated customAttributes + // so it can be used in search. + // TODO: remove when publicData is used in search customAttributes: { category }, + publicData: { category }, }; diff --git a/src/components/EditListingWizard/EditListingWizard.js b/src/components/EditListingWizard/EditListingWizard.js index 0206f3bb..9af01f48 100644 --- a/src/components/EditListingWizard/EditListingWizard.js +++ b/src/components/EditListingWizard/EditListingWizard.js @@ -185,7 +185,6 @@ EditListingWizard.propTypes = { // We cannot use propTypes.listing since the listing might be a draft. listing: shape({ attributes: shape({ - customAttributes: object, // structure (key: value) can be defined in management console publicData: object, description: string, geolocation: object, diff --git a/src/components/EditListingWizard/EditListingWizardTab.js b/src/components/EditListingWizard/EditListingWizardTab.js index 750c3851..888a040c 100644 --- a/src/components/EditListingWizard/EditListingWizardTab.js +++ b/src/components/EditListingWizard/EditListingWizardTab.js @@ -215,7 +215,6 @@ EditListingWizardTab.propTypes = { // We cannot use propTypes.listing since the listing might be a draft. listing: shape({ attributes: shape({ - customAttributes: object, // structure (key: value) can be defined in management console publicData: object, description: string, geolocation: object, diff --git a/src/components/TransactionPanel/__snapshots__/TransactionPanel.test.js.snap b/src/components/TransactionPanel/__snapshots__/TransactionPanel.test.js.snap index 1474eb95..1094879a 100644 --- a/src/components/TransactionPanel/__snapshots__/TransactionPanel.test.js.snap +++ b/src/components/TransactionPanel/__snapshots__/TransactionPanel.test.js.snap @@ -55,7 +55,6 @@ exports[`TransactionPanel - Order accepted matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -168,7 +167,6 @@ exports[`TransactionPanel - Order accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -300,7 +298,6 @@ exports[`TransactionPanel - Order accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -429,7 +426,6 @@ exports[`TransactionPanel - Order accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -558,7 +554,6 @@ exports[`TransactionPanel - Order accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -805,7 +800,6 @@ exports[`TransactionPanel - Order accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -915,7 +909,6 @@ exports[`TransactionPanel - Order autodeclined matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -1028,7 +1021,6 @@ exports[`TransactionPanel - Order autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -1160,7 +1152,6 @@ exports[`TransactionPanel - Order autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -1289,7 +1280,6 @@ exports[`TransactionPanel - Order autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -1418,7 +1408,6 @@ exports[`TransactionPanel - Order autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -1665,7 +1654,6 @@ exports[`TransactionPanel - Order autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -1775,7 +1763,6 @@ exports[`TransactionPanel - Order canceled matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -1888,7 +1875,6 @@ exports[`TransactionPanel - Order canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -2020,7 +2006,6 @@ exports[`TransactionPanel - Order canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -2149,7 +2134,6 @@ exports[`TransactionPanel - Order canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -2278,7 +2262,6 @@ exports[`TransactionPanel - Order canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -2525,7 +2508,6 @@ exports[`TransactionPanel - Order canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -2635,7 +2617,6 @@ exports[`TransactionPanel - Order declined matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -2748,7 +2729,6 @@ exports[`TransactionPanel - Order declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -2880,7 +2860,6 @@ exports[`TransactionPanel - Order declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -3009,7 +2988,6 @@ exports[`TransactionPanel - Order declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -3138,7 +3116,6 @@ exports[`TransactionPanel - Order declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -3385,7 +3362,6 @@ exports[`TransactionPanel - Order declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -3495,7 +3471,6 @@ exports[`TransactionPanel - Order delivered matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -3608,7 +3583,6 @@ exports[`TransactionPanel - Order delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -3740,7 +3714,6 @@ exports[`TransactionPanel - Order delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -3869,7 +3842,6 @@ exports[`TransactionPanel - Order delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -3998,7 +3970,6 @@ exports[`TransactionPanel - Order delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -4245,7 +4216,6 @@ exports[`TransactionPanel - Order delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -4355,7 +4325,6 @@ exports[`TransactionPanel - Order enquired matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -4468,7 +4437,6 @@ exports[`TransactionPanel - Order enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -4600,7 +4568,6 @@ exports[`TransactionPanel - Order enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -4729,7 +4696,6 @@ exports[`TransactionPanel - Order enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -4858,7 +4824,6 @@ exports[`TransactionPanel - Order enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -5105,7 +5070,6 @@ exports[`TransactionPanel - Order enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -5215,7 +5179,6 @@ exports[`TransactionPanel - Order preauthorized matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -5328,7 +5291,6 @@ exports[`TransactionPanel - Order preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -5460,7 +5422,6 @@ exports[`TransactionPanel - Order preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -5589,7 +5550,6 @@ exports[`TransactionPanel - Order preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -5718,7 +5678,6 @@ exports[`TransactionPanel - Order preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -5965,7 +5924,6 @@ exports[`TransactionPanel - Order preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -6069,7 +6027,6 @@ exports[`TransactionPanel - Sale accepted matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -6182,7 +6139,6 @@ exports[`TransactionPanel - Sale accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -6301,7 +6257,6 @@ exports[`TransactionPanel - Sale accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -6418,7 +6373,6 @@ exports[`TransactionPanel - Sale accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -6535,7 +6489,6 @@ exports[`TransactionPanel - Sale accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -6770,7 +6723,6 @@ exports[`TransactionPanel - Sale accepted matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -6861,7 +6813,6 @@ exports[`TransactionPanel - Sale autodeclined matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -6974,7 +6925,6 @@ exports[`TransactionPanel - Sale autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -7093,7 +7043,6 @@ exports[`TransactionPanel - Sale autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -7210,7 +7159,6 @@ exports[`TransactionPanel - Sale autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -7327,7 +7275,6 @@ exports[`TransactionPanel - Sale autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -7562,7 +7509,6 @@ exports[`TransactionPanel - Sale autodeclined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -7653,7 +7599,6 @@ exports[`TransactionPanel - Sale canceled matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -7766,7 +7711,6 @@ exports[`TransactionPanel - Sale canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -7885,7 +7829,6 @@ exports[`TransactionPanel - Sale canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -8002,7 +7945,6 @@ exports[`TransactionPanel - Sale canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -8119,7 +8061,6 @@ exports[`TransactionPanel - Sale canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -8354,7 +8295,6 @@ exports[`TransactionPanel - Sale canceled matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -8445,7 +8385,6 @@ exports[`TransactionPanel - Sale declined matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -8558,7 +8497,6 @@ exports[`TransactionPanel - Sale declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -8677,7 +8615,6 @@ exports[`TransactionPanel - Sale declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -8794,7 +8731,6 @@ exports[`TransactionPanel - Sale declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -8911,7 +8847,6 @@ exports[`TransactionPanel - Sale declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -9146,7 +9081,6 @@ exports[`TransactionPanel - Sale declined matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -9237,7 +9171,6 @@ exports[`TransactionPanel - Sale delivered matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -9350,7 +9283,6 @@ exports[`TransactionPanel - Sale delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -9469,7 +9401,6 @@ exports[`TransactionPanel - Sale delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -9586,7 +9517,6 @@ exports[`TransactionPanel - Sale delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -9703,7 +9633,6 @@ exports[`TransactionPanel - Sale delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -9938,7 +9867,6 @@ exports[`TransactionPanel - Sale delivered matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -10029,7 +9957,6 @@ exports[`TransactionPanel - Sale enquired matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -10142,7 +10069,6 @@ exports[`TransactionPanel - Sale enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -10261,7 +10187,6 @@ exports[`TransactionPanel - Sale enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -10378,7 +10303,6 @@ exports[`TransactionPanel - Sale enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -10495,7 +10419,6 @@ exports[`TransactionPanel - Sale enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -10730,7 +10653,6 @@ exports[`TransactionPanel - Sale enquired matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -10821,7 +10743,6 @@ exports[`TransactionPanel - Sale preauthorized matches snapshot 1`] = ` currentListing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -10934,7 +10855,6 @@ exports[`TransactionPanel - Sale preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -11053,7 +10973,6 @@ exports[`TransactionPanel - Sale preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -11170,7 +11089,6 @@ exports[`TransactionPanel - Sale preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -11287,7 +11205,6 @@ exports[`TransactionPanel - Sale preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -11522,7 +11439,6 @@ exports[`TransactionPanel - Sale preauthorized matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { diff --git a/src/config.js b/src/config.js index 2d8002da..75fe03a2 100644 --- a/src/config.js +++ b/src/config.js @@ -211,41 +211,6 @@ const stripeSupportedCountries = [ }, ]; -// Custom attributes are marketplace specific listing data (e.g. listing could have a category). -// Custom attributes can be defined through management console and code related to custom -// attributes should be changed accordingly. -// -// Here's an example what custom attributes might look like for bicycle listings. This code -// assumes that a custom attribute, called 'category', is created through management console -// with 4 possible values: 'road', 'mountain', 'track', and 'other'. -// -// When listing information is queried customAttributes is returned among other attributes: -// { -// id: 1, -// type: 'listing', -// attributes: { -// title: 'sauna', -// // and description, price, etc. -// customAttributes: { -// category: "mountain", -// // and other added custom attributes as "key: value" pairs -// }, -// }, -// } -const exampleCustomAttributes = { - category: { - select: 'single', // possible values: 'single' (only type supported atm.) - type: 'string', - values: ['road', 'mountain', 'track', 'other'], - }, -}; - -// To use the example custom attributes, set the -// REACT_APP_USE_EXAMPLE_CUSTOM_ATTRIBUTES variable to `true` in the -// gitignored `.env.development.local` file -const useExampleCustomAttributes = process.env.REACT_APP_USE_EXAMPLE_CUSTOM_ATTRIBUTES === 'true'; -const customAttributes = useExampleCustomAttributes ? exampleCustomAttributes : {}; - // Address information is used in SEO schema for Organization (http://schema.org/PostalAddress) const addressCountry = 'FI'; const addressRegion = 'Helsinki'; @@ -284,7 +249,6 @@ const config = { sdk: { clientId: sdkClientId, baseUrl: sdkBaseUrl }, currency, currencyConfig, - customAttributes, stripe: { publishableKey: stripePublishableKey, supportedCountries: stripeSupportedCountries }, canonicalRootURL, address: { diff --git a/src/containers/ListingPage/__snapshots__/ListingPage.test.js.snap b/src/containers/ListingPage/__snapshots__/ListingPage.test.js.snap index c1fcbaf5..713fd620 100644 --- a/src/containers/ListingPage/__snapshots__/ListingPage.test.js.snap +++ b/src/containers/ListingPage/__snapshots__/ListingPage.test.js.snap @@ -54,7 +54,6 @@ exports[`ListingPage matches snapshot 1`] = ` listing={ Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { diff --git a/src/containers/TransactionPage/__snapshots__/TransactionPage.test.js.snap b/src/containers/TransactionPage/__snapshots__/TransactionPage.test.js.snap index 6fffbd0d..a6eb12ed 100644 --- a/src/containers/TransactionPage/__snapshots__/TransactionPage.test.js.snap +++ b/src/containers/TransactionPage/__snapshots__/TransactionPage.test.js.snap @@ -148,7 +148,6 @@ exports[`TransactionPage - Order matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { @@ -346,7 +345,6 @@ exports[`TransactionPage - Sale matches snapshot 1`] = ` }, "listing": Object { "attributes": Object { - "customAttributes": Object {}, "deleted": false, "description": "listing1 description", "geolocation": LatLng { diff --git a/src/util/data.js b/src/util/data.js index 82ca3211..95c39bd8 100644 --- a/src/util/data.js +++ b/src/util/data.js @@ -165,7 +165,7 @@ export const ensureListing = listing => { const empty = { id: null, type: 'listing', - attributes: { customAttributes: {}, publicData: {} }, + attributes: { publicData: {} }, images: [], }; return { ...empty, ...listing }; @@ -180,7 +180,7 @@ export const ensureOwnListing = listing => { const empty = { id: null, type: 'ownListing', - attributes: { customAttributes: {}, publicData: {} }, + attributes: { publicData: {} }, images: [], }; return { ...empty, ...listing }; diff --git a/src/util/test-data.js b/src/util/test-data.js index 37903a15..d2124356 100644 --- a/src/util/test-data.js +++ b/src/util/test-data.js @@ -86,7 +86,6 @@ export const createListing = (id, attributes = {}, includes = {}) => ({ deleted: false, state: LISTING_STATE_PUBLISHED, price: new Money(5500, 'USD'), - customAttributes: {}, publicData: {}, ...attributes, }, @@ -104,7 +103,6 @@ export const createOwnListing = (id, attributes = {}, includes = {}) => ({ deleted: false, state: LISTING_STATE_PUBLISHED, price: new Money(5500, 'USD'), - customAttributes: {}, publicData: {}, ...attributes, }, diff --git a/src/util/types.js b/src/util/types.js index 1f2de950..ad6b6289 100644 --- a/src/util/types.js +++ b/src/util/types.js @@ -142,7 +142,6 @@ const listingAttributes = shape({ deleted: propTypes.value(false).isRequired, state: oneOf(LISTING_STATES).isRequired, price: propTypes.money, - customAttributes: object, publicData: object.isRequired, }); @@ -153,7 +152,6 @@ const ownListingAttributes = shape({ deleted: propTypes.value(false).isRequired, state: oneOf(LISTING_STATES).isRequired, price: propTypes.money, - customAttributes: object, publicData: object.isRequired, }); From acd01fb372661dbd454ad7fc43f599d8b5f681b5 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Tue, 30 Jan 2018 09:41:19 +0200 Subject: [PATCH 7/8] Use key as the fallback label for an option --- src/components/SelectSingleFilter/SelectSingleFilter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SelectSingleFilter/SelectSingleFilter.js b/src/components/SelectSingleFilter/SelectSingleFilter.js index 63b5818e..cb2336ba 100644 --- a/src/components/SelectSingleFilter/SelectSingleFilter.js +++ b/src/components/SelectSingleFilter/SelectSingleFilter.js @@ -8,7 +8,7 @@ import css from './SelectSingleFilter.css'; const optionLabel = (options, key) => { const option = options.find(o => o.key === key); - return option ? option.label : ''; + return option ? option.label : key; }; class SelectSingleFilter extends Component { From ffa7fdf19664a7553195ff68b73f29595bec5d9a Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Tue, 30 Jan 2018 09:50:32 +0200 Subject: [PATCH 8/8] Move internal field to its own file --- .../CustomCategorySelectFieldMaybe.js | 38 +++++++++++++++++++ .../EditListingDescriptionForm.js | 34 +---------------- 2 files changed, 40 insertions(+), 32 deletions(-) create mode 100644 src/containers/EditListingDescriptionForm/CustomCategorySelectFieldMaybe.js diff --git a/src/containers/EditListingDescriptionForm/CustomCategorySelectFieldMaybe.js b/src/containers/EditListingDescriptionForm/CustomCategorySelectFieldMaybe.js new file mode 100644 index 00000000..6e001fc0 --- /dev/null +++ b/src/containers/EditListingDescriptionForm/CustomCategorySelectFieldMaybe.js @@ -0,0 +1,38 @@ +import React from 'react'; +import { required } from '../../util/validators'; +import { SelectField } from '../../components'; + +import css from './EditListingDescriptionForm.css'; + +const CustomCategorySelectFieldMaybe = props => { + const { name, id, categories, intl } = props; + const categoryLabel = intl.formatMessage({ + id: 'EditListingDescriptionForm.categoryLabel', + }); + const categoryPlaceholder = intl.formatMessage({ + id: 'EditListingDescriptionForm.categoryPlaceholder', + }); + const categoryRequired = required( + intl.formatMessage({ + id: 'EditListingDescriptionForm.categoryRequired', + }) + ); + return categories ? ( + + + {categories.map(c => ( + + ))} + + ) : null; +}; + +export default CustomCategorySelectFieldMaybe; diff --git a/src/containers/EditListingDescriptionForm/EditListingDescriptionForm.js b/src/containers/EditListingDescriptionForm/EditListingDescriptionForm.js index 25669f42..e7241f5b 100644 --- a/src/containers/EditListingDescriptionForm/EditListingDescriptionForm.js +++ b/src/containers/EditListingDescriptionForm/EditListingDescriptionForm.js @@ -6,43 +6,13 @@ import { intlShape, injectIntl, FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import { propTypes } from '../../util/types'; import { maxLength, required } from '../../util/validators'; -import { Form, Button, TextInputField, SelectField } from '../../components'; +import { Form, Button, TextInputField } from '../../components'; +import CustomCategorySelectFieldMaybe from './CustomCategorySelectFieldMaybe'; import css from './EditListingDescriptionForm.css'; const TITLE_MAX_LENGTH = 60; -const CustomCategorySelectFieldMaybe = props => { - const { name, id, categories, intl } = props; - const categoryLabel = intl.formatMessage({ - id: 'EditListingDescriptionForm.categoryLabel', - }); - const categoryPlaceholder = intl.formatMessage({ - id: 'EditListingDescriptionForm.categoryPlaceholder', - }); - const categoryRequired = required( - intl.formatMessage({ - id: 'EditListingDescriptionForm.categoryRequired', - }) - ); - return categories ? ( - - - {categories.map(c => ( - - ))} - - ) : null; -}; - const EditListingDescriptionFormComponent = props => { const { className,