Skip to content

Commit

Permalink
Update HAL browser to support more templated links formats.
Browse files Browse the repository at this point in the history
Specifically, the HAL browser will now support link expansions in the
format: http://example/{?foo,bar}

This is an alternative to: http://example/{?foo}{?bar}
  • Loading branch information
evert committed Jan 2, 2020
1 parent 36f1fd2 commit 917979c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/components/forms/templated-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@ export default function parseTemplatedLinks(links: Link[], options: SureOptions)
// More formats might be added if they are requested.

// This regex finds blocks like {?foo}
const reg = /{\?[A-Za-z]+}/g;
const reg = /{\?[A-Za-z,]+}/g;

const matches = link.href.match(reg);
if (matches) {
for (const match of matches) {
// Stripping off {? and }
fields.push({
name: match.slice(2, -1),
value: '',
label: match.slice(2, -1),
});
const fieldNames = match.slice(2, -1);

// Splitting at ','
for(const fieldName of fieldNames.split(',')) {
fields.push({
name: fieldName,
value: '',
label: fieldName,
});
}
}
}

Expand Down

0 comments on commit 917979c

Please sign in to comment.