Skip to content

Commit

Permalink
Merge branch 'release-2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Apr 10, 2019
2 parents baf78e2 + 524ee20 commit 7e33c04
Show file tree
Hide file tree
Showing 36 changed files with 740 additions and 421 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.3.0] (2019-04-10)

### Added

* [#672](https://github.com/dadi/publish/pull/672): add filters to Reference select view
* [#674](https://github.com/dadi/publish/pull/674): add filters to Media Library and Reference select view for Media fields
* [660b15b](https://github.com/dadi/publish/commit/660b15be7dbe09f0d53b7d172a7eebae6ec68f8b): add button for filtering document list view by selected state

### Fixed

* [806a215](https://github.com/dadi/publish/commit/806a2159bfad4b6fdf5bd28dac74b7181226272f): fix issue where invalid cookies would cause a blank page
* [ba1020c](https://github.com/dadi/publish/commit/ba1020c28b4ec8f216b14dece16bde04d45c7917): fix issue where changing the field which a filter operated on would reset the filter value if the field was of type `Number`


## [2.2.0] (2019-02-28)

### Changed
Expand Down
3 changes: 3 additions & 0 deletions app/lib/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ Router.prototype.webRoutes = function () {
}).catch(error => {
log.error({module: 'router'}, error)

res.clearCookie('accessToken', {path: '/'})
res.clearCookie('accessTokenExpiry', {path: '/'})

entryPointPage = entryPointPage
.replace(
'/*@@apiError@@*/',
Expand Down
11 changes: 8 additions & 3 deletions frontend/actions/documentsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,14 @@ export function setDocumentList (documents, query) {
}

export function setDocumentSelection (selectedDocuments) {
return {
selectedDocuments,
type: Types.SET_DOCUMENT_SELECTION
return (dispatch, getState) => {
const {filter = {}} = getState().router.search

dispatch({
isFilteringSelection: filter.$selected === true,
selectedDocuments,
type: Types.SET_DOCUMENT_SELECTION
})
}
}

Expand Down
11 changes: 6 additions & 5 deletions frontend/components/DocumentGridList/DocumentGridList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class DocumentGridList extends Component {
/**
* A hash map of the indices of the currently selected documents.
*/
selectedDocuments: proptypes.array,
selectedDocuments: proptypes.object,

/**
* The maximum number of documents that can be selected.
Expand All @@ -94,7 +94,9 @@ export default class DocumentGridList extends Component {
constructor(props) {
super(props)

this.debouncedResizeHandler = debounce(this.forceUpdate.bind(this), 500)
this.debouncedResizeHandler = debounce(() => {
this.forceUpdate()
}, 500)
}

componentDidMount() {
Expand Down Expand Up @@ -174,10 +176,9 @@ export default class DocumentGridList extends Component {
style={`width: ${100 / numberOfColumns}%`}
>
{column.map((item, index) => {
let isSelected = selectedDocuments[index] === true
let onSelect = this.handleItemSelect.bind(this, index)
const onSelect = this.handleItemSelect.bind(this, index)

return onRenderCard(item, onSelect, isSelected)
return onRenderCard(item, onSelect, Boolean(selectedDocuments[index]))
})}
</div>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
.wrapper {
background-image: linear-gradient(-180deg, #0b131f 10%, #17273f 100%);
border-top: 1px solid #282f39;
background-image: linear-gradient(-180deg, #0b131f 10%, #17273f 100%);
display: flex;
padding: 15px 20px;
align-items: center
}

@media (--breakpoint-medium) {
.wrapper {
align-items: center;
}
}

.actions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {h, Component} from 'preact'
import {route} from '@dadi/preact-router'
import Button from 'components/Button/Button'
import DocumentFilters from 'containers/DocumentFilters/DocumentFilters'
import ListController from 'components/ListController/ListController'
import proptypes from 'proptypes'
import Style from 'lib/Style'
import styles from './DocumentListController.css'

/**
Expand All @@ -25,6 +23,11 @@ export default class DocumentListController extends Component {
*/
createNewHref: proptypes.string,

/**
* The ID of the document being operated on.
*/
documentId: proptypes.string,

/**
* Whether to enable filters.
*/
Expand Down Expand Up @@ -53,7 +56,6 @@ export default class DocumentListController extends Component {
collection,
createNewHref,
enableFilters,
onBuildBaseUrl,
search = {}
} = this.props

Expand Down Expand Up @@ -119,6 +121,7 @@ export default class DocumentListController extends Component {

handleFiltersUpdate(newFilters) {
const {
documentId,
onBuildBaseUrl,
referencedField,
search
Expand All @@ -130,6 +133,7 @@ export default class DocumentListController extends Component {
filter: newFilterValue
})
const newUrl = onBuildBaseUrl({
createNew: Boolean(referencedField && !documentId),
referenceFieldSelect: referencedField,
search: newSearch
})
Expand Down
28 changes: 28 additions & 0 deletions frontend/components/DocumentListToolbar/DocumentListToolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,31 @@
display: none;
}
}

.selection-counter {
display: none;
padding-left: 8px;
visibility: hidden;
}

.selection-counter-visible {
display: inline-block;
visibility: visible;
}

@media (--breakpoint-large) {
.selection-counter {
display: inline-block;
}
}

.selection-counter-button {
border-bottom: 1px solid #eee;
cursor: pointer;
outline: 0;
padding: 0 1px;
}

.selection-counter:hover .selection-counter-button {
border-bottom-color: var(--theme-colour-data, #4A91FF);
}
34 changes: 30 additions & 4 deletions frontend/components/DocumentListToolbar/DocumentListToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ export default class DocumentListToolbar extends Component {
documentsMetada: proptypes.object,

/**
* A callback to be used to obtain the URL for a given page.
* A callback used to obtain the URL for a given page.
*/
onBuildPageUrl: proptypes.func
onBuildPageUrl: proptypes.func,

/**
* The list of selected documents.
*/
selectedDocuments: proptypes.array,

/**
* The URL for limiting the document list to only selected documents.
*/
showSelectedDocumentsUrl: proptypes.string
}

goToPage(value) {
Expand Down Expand Up @@ -61,7 +71,9 @@ export default class DocumentListToolbar extends Component {
const {
children,
documentsMetadata: metadata,
onBuildPageUrl
onBuildPageUrl,
selectedDocuments = [],
showSelectedDocumentsUrl
} = this.props

if (!metadata) return null
Expand All @@ -75,15 +87,29 @@ export default class DocumentListToolbar extends Component {

return result
}, {})
const selectionCounter = new Style(styles, 'selection-counter')
.addIf('selection-counter-visible', selectedDocuments.length > 0)

return (
<Toolbar>
{metadata.totalCount > 1 && (
<div class={styles.section}>
<span class={styles['count-label']}>
<span>Showing </span>
<strong>{`${metadata.offset + 1}-${Math.min(metadata.offset + metadata.limit, metadata.totalCount)} `}</strong>
of <strong>{metadata.totalCount}</strong>

{showSelectedDocumentsUrl && (
<span class={selectionCounter.getClasses()}>
(
<a
class={styles['selection-counter-button']}
href={showSelectedDocumentsUrl}
>
{selectedDocuments.length} selected
</a>
)
</span>
)}
</span>
</div>
)}
Expand Down
31 changes: 13 additions & 18 deletions frontend/components/DocumentTableList/DocumentTableList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class DocumentTableList extends Component {
/**
* A hash map of the indices of the currently selected documents.
*/
selectedDocuments: proptypes.array,
selectedDocuments: proptypes.object,

/**
* The maximum number of documents that can be selected.
Expand All @@ -83,14 +83,15 @@ export default class DocumentTableList extends Component {

getSelectedRows() {
const {documents, selectedDocuments} = this.props

return documents.reduce((selectedRows, item, index) => {
const selectedRows = documents.reduce((selectedRows, item, index) => {
if (selectedDocuments[item._id]) {
selectedRows[index] = true
}

return selectedDocuments
return selectedRows
}, {})

return selectedRows
}

handleRowRender(listableFields, value, data, column, index) {
Expand All @@ -107,13 +108,13 @@ export default class DocumentTableList extends Component {
return value
}

let editLink = onBuildBaseUrl({
const editLink = onBuildBaseUrl({
documentId: documentId || data._id,
search: null
})
let fieldSchema = collection.fields[column.id]
let renderedValue = this.renderField(column.id, fieldSchema, value)
let firstStringField = Object.keys(listableFields).filter(field => {
const fieldSchema = collection.fields[column.id]
const renderedValue = this.renderField(fieldSchema, value)
const firstStringField = Object.keys(listableFields).filter(field => {
return listableFields[field].type === 'String'
})[0]

Expand All @@ -133,8 +134,7 @@ export default class DocumentTableList extends Component {
const {
onBuildBaseUrl
} = this.props

let link = onBuildBaseUrl({
const link = onBuildBaseUrl({
search: {
order: sortOrder,
sort: sortBy
Expand All @@ -149,16 +149,13 @@ export default class DocumentTableList extends Component {
render() {
const {
collection,
config,
documents,
fields: fieldsToDisplay = [],
onBuildBaseUrl,
onSelect,
order,
referencedField,
selectedDocuments,
sort
} = this.props
const selectedRows = this.getSelectedRows()
const collectionFields = (collection && collection.fields) || {}
const listableFields = Object.keys(collectionFields).reduce((fields, fieldName) => {
if (fieldsToDisplay.includes(fieldName)) {
Expand All @@ -184,7 +181,7 @@ export default class DocumentTableList extends Component {
onRender={this.handleRowRender.bind(this, listableFields)}
onSelect={onSelect}
onSort={this.handleTableSort.bind(this)}
selectedRows={selectedRows}
selectedRows={selectedDocuments}
selectLimit={Infinity}
sortable={true}
sortBy={sort}
Expand All @@ -195,7 +192,6 @@ export default class DocumentTableList extends Component {

renderAnnotation(schema) {
const fieldType = getFieldType(schema)

const fieldComponentName = `Field${fieldType}`
const FieldComponentListHeadAnnotation = fieldComponents[fieldComponentName] &&
fieldComponents[fieldComponentName].listHeadAnnotation
Expand All @@ -207,15 +203,14 @@ export default class DocumentTableList extends Component {
}
}

renderField(fieldName, schema, value) {
renderField(schema, value) {
if (!schema) return

const {
api,
collection,
config
} = this.props

const fieldType = getFieldType(schema)
const fieldComponentName = `Field${fieldType}`
const FieldComponentList = fieldComponents[fieldComponentName] &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class FieldMediaReferenceSelect extends Component {
/**
* A hash map of the indices of the currently selected rows.
*/
selectedRows: proptypes.obj,
selectedRows: proptypes.object,

/**
* The maximum number of documents that can be selected.
Expand Down
9 changes: 8 additions & 1 deletion frontend/components/FieldNumber/FieldNumber.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import edit from './FieldNumberEdit'
import filterEdit from './FieldNumberFilterEdit'

export {edit, filterEdit}
const filterOperators = {
$gt: 'is greater than',
$gte: 'is greater than or equal to',
$lt: 'is less than',
$lte: 'is less than or equal to'
}

export {edit, filterEdit, filterOperators}
2 changes: 1 addition & 1 deletion frontend/components/FieldNumber/FieldNumberFilterEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class FieldStringFilter extends Component {
// If the initial value isn't accepted for this field type,
// we update it with one that is and propagate it to the
// parent.
if (typeof value !== 'string') {
if (typeof value !== 'number') {
onUpdate(null)
}
}
Expand Down
Loading

0 comments on commit 7e33c04

Please sign in to comment.