-
Notifications
You must be signed in to change notification settings - Fork 4
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(rjsf): add anchor widget with find-and-replace capabilities #59
Conversation
|
||
useEffect(() => { | ||
// @ts-expect-error | ||
if (!!options.change.every) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the instance of this widget (declared in your model's schema) has the change.every
field, run a find and replace with macro support.
|
||
return ( | ||
<a href={href} target="_blank" rel="noopener noreferrer"> | ||
{options.text || href} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow the schema to declare the link's text, or fallback to the href
.
@@ -1,9 +1,9 @@ | |||
import React, { useState, useEffect } from 'react' | |||
import type { WidgetProps } from '@rjsf/utils' | |||
import { getTemplate } from '@rjsf/utils' | |||
import { ID_PREFIX } from './constants' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lifted up to use in another file.
// Starting from the source string, iterate through every entry in "to", replacing with either a macro's return value or a value. | ||
return to.reduce((accumulator, current) => { | ||
// We may have a MACRO_NAME:FieldName combo, or we may have a value. | ||
const [macroNameOrValue, maybeFieldName] = current.split(':') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't write an ABFN grammar this time for our little macro DSL, but the idea is commended here. The tests show that you can pass in any combo: a value, a MACRO:value, or a MACRO, and this will still work.
"MyProperty": { | ||
"ui:widget": "anchor", | ||
"ui:options": { | ||
"href": "http://localhost:8080/service-request-from-config?variable_entry_id=******", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a cool solution, though I'd be interested in your thought process for using this vs. a named template like Handlebars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, honestly, more of a hindsight is 20/20 moment. I think Mustache / Handlebars would have worked great here! Even just using a named template would probably be an improvement. We could add that under another field (like every
, but maybe named
...but then maybe we'd need to make the change
an array, since every
=> to
wouldn't have the right relationship).
This RJSF widget was made for the Test Configuration model (currently only in UAT mEditor). I'll include the entire model schema you'll need, below.
To manually test this, please
To run the unit tests
packages/app
Test Configuration Model Schema (not just the RJSF schema and layout)