From a106854e52afd0455fbb47e7511b25fa8d700768 Mon Sep 17 00:00:00 2001 From: Sergey Melyukov Date: Thu, 19 Aug 2021 17:37:04 +0300 Subject: [PATCH] feat: added `params`-property to `ObjectMarker.define()` config --- CHANGELOG.md | 7 ++++--- src/core/object-marker.js | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bcb8d1c..1ae26895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Changed `hstack` to use flexbox for layout - Added `image` view - Changed `image-preview` to behave as `image` but on chess background +- Added `params`-property to `ObjectMarker.define()` config ## 1.0.0-beta.61 (31-03-2021) @@ -179,7 +180,7 @@ - Changed a bit default page in model free mode - Fixed `children` option ignorance in `itemConfig` when `limitLines` is used for `tree` view - Fixed `href` option to work for `button` view -- Fixed path generation in `signature` details +- Fixed path generation in `signature` details - Fixed context for `Widget#nav.menu` item rendering ## 1.0.0-beta.42 (08-10-2020) @@ -292,7 +293,7 @@ - `lookupRefs` - a list of string (a field name) or function (getter), that uses to retrieve additional values to identify original object - `page` - a string, marker should be a link to specified page - `ref` - a string (a field name) or a function (getter), a value that uses in link to page to identify object - - `title` - astring (a field name) or a function (getter), a text that represent an object, e.g. in `auto-link` + - `title` - astring (a field name) or a function (getter), a text that represent an object, e.g. in `auto-link` - `addQueryHelpers()` method the same as `Widget#addQueryHelpers()` - Added a set of default methods: - `marker(type?)` – returns any marker associated with a value, when `type` is specified only this type of marker may be returned @@ -685,7 +686,7 @@ - Changed `badge` view to take a data as a string - Made `link` view more adaptive to input data - Show 1 level expanded struct on `default` and `report` pages - + ## 1.0.0-beta.2 (26-11-2018) - Fixed `discovery-build` dependency issue diff --git a/src/core/object-marker.js b/src/core/object-marker.js index 7d922340..90fa8d8d 100644 --- a/src/core/object-marker.js +++ b/src/core/object-marker.js @@ -67,7 +67,8 @@ function createObjectMarker(config) { lookupRefs, page, getRef, - getTitle + getTitle, + getParams } = config; if (page) { @@ -153,6 +154,13 @@ function createObjectMarker(config) { marker = markers.get(resolvedValue); } else { const ref = getRef !== null ? getRef(resolvedValue) : null; + const params = []; + + for (const [name, value] of Object.entries(getParams(resolvedValue))) { + params.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`); + } + + const paramsString = params.length ? `&${params.join('&')}` : ''; marker = Object.freeze({ type: name, @@ -160,7 +168,7 @@ function createObjectMarker(config) { ref, title: getTitle(resolvedValue), href: page !== null && ref !== null - ? `#${encodeURIComponent(page)}:${encodeURIComponent(ref)}` + ? `#${encodeURIComponent(page)}:${encodeURIComponent(ref)}${paramsString}` : null }); @@ -200,6 +208,7 @@ export default class ObjectMarker extends Dict { const page = typeof config.page === 'string' ? config.page : null; const getRef = configGetter(name, config, 'ref', null); const getTitle = configGetter(name, config, 'title', getRef || (() => null)); + const getParams = configGetter(name, config, 'params', () => ({})); return super.define(name, createObjectMarker({ name, @@ -207,7 +216,8 @@ export default class ObjectMarker extends Dict { lookupRefs, page, getRef, - getTitle + getTitle, + getParams })); }