woocommerce/plugins/woocommerce-admin/packages/navigation
Darren Ethier 33c5b41e3f Align WooCommerce javascript code standards/linting/styles with WordPress core. (https://github.com/woocommerce/woocommerce-admin/pull/3674)
* align code styles with the same configuration as Woo-Blocks

* initial pass of reformat-files

* applies manual fixes to various new linting errors surfaced by the configuration change.

* Fix state mutation in image-upload

* remove unused pre-commit-hook.js

* requestAnimationFrame -> window.requestAnimationFrame

* wc-api eslint changes

* eslint fixes on client/lib and client/settings

* client/header eslint changes

* fixes for client/dashboard part 1

* fixes client/dashboard part 2 of 2

* client/analytics part 1

* client/analytics continued

* client/analytics, last batch

* rename __mock__ directory

* pass in useEffect, useState from React component or function

* remove '+' from sprintf string argument

* use ref instead of findDOMNode

* reformat and repaply package.json changes

* install deps before running linter in Travis

* useGetCountryStateAutofill

* counryStateAutofill

* countryStateAutofill

Co-authored-by: Paul Sealock <psealock@gmail.com>
2020-02-14 15:23:21 +13:00
..
src Align WooCommerce javascript code standards/linting/styles with WordPress core. (https://github.com/woocommerce/woocommerce-admin/pull/3674) 2020-02-14 15:23:21 +13:00
.npmrc Build: Move `lib/nav-utils` and `lib/history` to `@woocommerce/navigation` (https://github.com/woocommerce/woocommerce-admin/pull/763) 2018-11-05 16:02:04 -05:00
CHANGELOG.md Add currency extension (https://github.com/woocommerce/woocommerce-admin/pull/3328) 2019-12-06 11:38:26 +13:00
README.md Decouple Navigation from `wcSettings`. (https://github.com/woocommerce/woocommerce-admin/pull/3294) 2019-11-22 12:07:26 -05:00
package.json Align WooCommerce javascript code standards/linting/styles with WordPress core. (https://github.com/woocommerce/woocommerce-admin/pull/3674) 2020-02-14 15:23:21 +13:00

README.md

Navigation

A collection of navigation-related functions for handling query parameter objects, serializing query parameters, updating query parameters, and triggering path changes.

Installation

Install the module

npm install @woocommerce/navigation --save

Usage

getHistory

A single history object used to perform path changes. This needs to be passed into ReactRouter to use the other path functions from this library.

import { getHistory } from '@woocommerce/navigation';

render() {
	return (
		<Router history={ getHistory() }>
			
		</Router>
	);
}

getPath() ⇒ String

Get the current path from history.

Returns: String - Current path.

getTimeRelatedQuery(query) ⇒ Object

Gets time related parameters from a query.

Returns: Object - Object containing the time related queries.

Param Type Description
query Object Query containing the parameters.

getIdsFromQuery(queryString) ⇒ Array

Get an array of IDs from a comma-separated query parameter.

Returns: Array - List of IDs converted to numbers.

Param Type Description
queryString string string value extracted from URL.

getNewPath(query, path, currentQuery) ⇒ String

Return a URL with set query parameters.

Returns: String - Updated URL merging query params into existing params.

Param Type Description
query Object object of params to be updated.
path String Relative path (defaults to current path).
currentQuery Object object of current query params (defaults to current querystring).

getQuery() ⇒ Object

Get the current query string, parsed into an object, from history.

Returns: Object - Current query object, defaults to empty object.

onQueryChange(param, path, query) ⇒ function

This function returns an event handler for the given param

Returns: function - A callback which will update param to the passed value when called.

Param Type Description
param string The parameter in the querystring which should be updated (ex page, per_page)
path string Relative path (defaults to current path).
query string object of current query params (defaults to current querystring).

updateQueryString(query, path, currentQuery)

Updates the query parameters of the current page.

Param Type Description
query Object object of params to be updated.
path String Relative path (defaults to current path).
currentQuery Object object of current query params (defaults to current querystring).

flattenFilters(filters) ⇒ Array

Collapse an array of filter values with subFilters into a 1-dimensional array.

Returns: Array - Flattened array of all filters.

Param Type Description
filters Array Set of filters with possible subfilters.

getActiveFiltersFromQuery(query, config) ⇒ Array.<activeFilters>

Given a query object, return an array of activeFilters, if any.

Returns: Array.<activeFilters> - - array of activeFilters

Param Type Description
query object query oject
config object config object

getDefaultOptionValue(config, options) ⇒ string | undefined

Get the default option's value from the configuration object for a given filter. The first option is used as default if no defaultOption is provided.

Returns: string | undefined - - the value of the default option.

Param Type Description
config object a filter config object.
options array select options.

getQueryFromActiveFilters(activeFilters, query, config) ⇒ object

Given activeFilters, create a new query object to update the url. Use previousFilters to Remove unused params.

Returns: object - - query object representing the new parameters

Param Type Description
activeFilters Array.<activeFilters> activeFilters shown in the UI
query object the current url query object
config object config object

getUrlKey(key, rule) ⇒ string

Get the url query key from the filter key and rule.

Returns: string - - url query key.

Param Type Description
key string filter key.
rule string filter rule.

activeFilter : Object

Describe activeFilter object.

Properties

Name Type Description
key string filter key.
[rule] string a modifying rule for a filter, eg 'includes' or 'is_not'.
value string filter value(s).