Dashboard Utility Agent
2.0.0
2.0.0
  • About
  • Portals
    • Card
    • Publish flow
    • Suggest search
  • Changelog
Powered by GitBook
On this page
  • About
  • How to use

Was this helpful?

  1. Portals

Suggest search

PreviousPublish flowNextChangelog

Last updated 5 years ago

Was this helpful?

About

Returns a component that handles suggest searches towards Open Content and builds up a query that will return a set of requested items

Can also be configured to handle date searches:

Handles created date sorting by default but through config can add multiple sorting fields

How to use

import { Component } from 'react'
import { usePortal, getMappedId } from 'Dashboard'
import SSConfigFunc from './SuggestSearchConfig'


class MyClass extends Component {
    constructor(props) {
        super(props)
        
        this.autoSearch = true
        this.ocInstance = {} //instance of Content Agent oc instance
        this.suggestSearch = null
        
        this.state = {
            isSearching: false,
            start: 0,
            limit: 15
        }
    }

    componentDidMount() {
        this.suggestSearch = usePortal(getMappedId('@plugin_bundle', 'portal', 'MY_SS_PORTAL_ID'))
    }
    
    render() {
        const {localize} = this.props
        const {start, limit} this.state
        const SuggestSearch = this.suggestSearch
        const suggestSearchConfig = SSConfigFunc({
            start: start,
            limit: limit
        })
        
        return (
            {SuggestSearch &&
                <SuggestSearch
                    dateSearch
                    cacheLastSearch
                    cacheKey={this.props.id}
                    onSearch={this.onSearch}
                    ocInstance={this.ocInstance}
                    autoSearch={this.autoSearch}
                    suggestSearchConfig={suggestSearchConfig}
                    className={"@plugin_bundle_class-suggest-search"}
                    searching={isSearching => this.setState({ isSearching })}
                    localizations={{
                        searchAgain: localize.searchAgain,
                        saveSearch: localize.saveSearch,
                        savedSearches: localize.savedSearches,
                        from: localize.from,
                        to: localize.to,
                        placeholder: localize.placeholder,
                        updated: localize.updated,
                        created: localize.created
                    }}
                />
            }
        )
    }
}
import { register } from 'Dashboard'

(() => {
    register({
        bundle: "@plugin_bundle",

        application: MyApplication,
        settings: MySettings,

        requirements: {
            actions: [],
            portals: [
                {
                    id: 'MY_SS_PORTAL_ID',
                    name: 'Suggest search portal',
                    description: 'A portal to render suggest search',
                }
            ]
        }
    })
})()
export default ({start, limit}) => {
    suggestFields: [
            {
                name: 'PubStatus', 
                order: 10
            }, 
            {
                name: 'Tags', 
                order: 15 
            },
            {
                name: 'Authors',
                order: 20
            }
        ],
        suggestLabels: {
            'PubStatus': 'Status', 
            'Tags': 'Tagg', 
            'Authors': 'Författare'
        },
        searchOptions: {
            start: start,
            limit: limit,
            property: [
                'uuid', 
                'PubStatus', 
                'Tag', 
                'Authors',
                'ConceptRelations.headline'
            ],
            filters: [
                {
                    property: 'ConceptRelations',
                    q: 'ConceptStatus: usable',
                    start: 0,
                    limit: 1
                }
            ],
            defaultQuery: '*:* NOT PubStatus:draft',
            filterQuery: 'contenttype:Article',
            sortField: 'updated',
            sortAscending: false
        },
        dateOptions: {
            properties: [
                {
                    sortable: true,
                    label: 'Publish date',
                    value: 'WriterPubStart'
                }
            ],
        },
        freeTextOrder: 0
}

Property

Description

Default

dateSearch

A boolean whether dateSearch should be displayed

false

cacheLastSearch

A boolean whether last search will be cached

false

cacheKey

A string to identify the specific cache payload

onSearch

Callback function when a search has occurred

ocInstance

A instance of Content Agent open content object

autoSearch

Trigger a search when component did mount

false

suggestSearchConfig

Search config (see below)

searching

A callback function when searching is triggered, returns searching state (true/false)

localizations

A object for translating strings

const suggestSearchConfig = {
    suggestFields: [
        {
            name: 'PubStatus', 
            order: 10
        }, 
        {
            name: 'Tags', 
            order: 15 
        },
        {
            name: 'Authors',
            order: 20
        }
    ],
    suggestLabels: {
        'PubStatus': 'Status', 
        'Tags': 'Tagg', 
        'Authors': 'Författare'
    },
    searchOptions: {
        start: 0,
        limit: 15,
        property: [
            'uuid', 
            'PubStatus', 
            'Tag', 
            'Authors',
            'ConceptRelations.headline'
        ],
        filters: [
            {
                property: 'ConceptRelations',
                q: 'ConceptStatus: usable',
                start: 0,
                limit: 1
            }
        ],
        defaultQuery: '*:* NOT PubStatus:draft',
        filterQuery: 'contenttype:Article',
        sortField: 'updated',
        sortAscending: false
    },
    dateOptions: { // requires dateSearch true as a property
        properties: [
            {
                sortable: true,
                label: 'Publish date',
                value: 'WriterPubStart'
            }
        ],
    },
    freeTextOrder: 0
}

Key

Value

suggestFields

Array of objects containing information what to trigger suggestions on

{ name: 'indexfield to to suggest against', order: integer to determine order of output in list }

suggestLabels

Object containing labels for the suggestions fields

searchOptions

{ start: search start index, limit: number of hits to get back, property: properties to fetch with the search, filters: array of objects containing sub filters for query, defaultQuery: the default query to search for, filterQuery: a filter that will always be added, sortField: a property that the query will be sorted on, sortAscending: a boolean to determine sorting order }

dateOptions

{ properties: [ sortable: boolean if the property is sortable label: label to output value: OC date property ] }