Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added params-property to ObjectMarker.define() config #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/core/object-marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function createObjectMarker(config) {
lookupRefs,
page,
getRef,
getTitle
getTitle,
getParams
} = config;

if (page) {
Expand Down Expand Up @@ -153,14 +154,21 @@ 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,
object: resolvedValue,
ref,
title: getTitle(resolvedValue),
href: page !== null && ref !== null
? `#${encodeURIComponent(page)}:${encodeURIComponent(ref)}`
? `#${encodeURIComponent(page)}:${encodeURIComponent(ref)}${paramsString}`
: null
});

Expand Down Expand Up @@ -200,14 +208,16 @@ 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,
indexRefs,
lookupRefs,
page,
getRef,
getTitle
getTitle,
getParams
}));
}

Expand Down