-
Notifications
You must be signed in to change notification settings - Fork 1
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
resource-config: set collection-name on annotated field #397
Conversation
def27eb
to
757c50e
Compare
757c50e
to
055e116
Compare
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 creates an infinite loop. Do not merge this. I'll take a look at it.
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.
Switched the approach to setting the default
property in the schema. This allows ajv
to set the value once it makes it into jsonForms
.
Please test and make sure this is still working as expected for you.
Also... I am assuming we're taking the approach that only a single field should ever have this annotation.
const collectionNameFieldKey = useMemo(() => { | ||
if (resourceSchema.properties) { | ||
// Find the field with the collection name annotation | ||
const collectionNameField = | ||
Object.entries(resourceSchema.properties).find( | ||
([_, value]) => | ||
value && Annotations.defaultResourceConfigName in value | ||
) ?? []; | ||
|
||
// Try to fetch the key | ||
return collectionNameField[0]; | ||
} | ||
|
||
return null; | ||
}, [resourceSchema.properties]); |
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 chunk isn't too heavy but since we don't need to recalculate it often decided to move this into a stand alone memo.
const preparedResourceSchema = useMemo(() => { | ||
if (collectionNameFieldKey) { | ||
// Add a default property set to the stripped collection name | ||
const response = cloneDeep(resourceSchema); | ||
response.properties[collectionNameFieldKey].default = | ||
stripPathing(collectionName); | ||
return response; | ||
} | ||
|
||
return resourceSchema.properties; | ||
}, [collectionName, collectionNameFieldKey, resourceSchema]); |
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.
Make a memo of the schema which will either be the normal schema or one with the injected default value.
// Setup immer | ||
enableMapSet(); | ||
setAutoFreeze(false); |
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 allows AJV to more easily manipulate the data being passed to it. Related to this change but one I have been eyeing for a while so made it here.
@@ -30,6 +32,7 @@ export const addKeywords = (ajv: any) => { | |||
ajv.addKeyword('advanced'); // Should be collapsed by default (over ridden if section contains required fields) | |||
ajv.addKeyword('order'); // Used to order the fields in the UI | |||
ajv.addKeyword('x-oauth2-provider'); // Used to display OAuth | |||
ajv.addKeyword('x-collection-name'); // Used to default name in resource configs |
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.
We keep all custom annotations in here so we can keep them all documented together.
Changes
x-collection-name
with last piece of collection nameTests
Tested locally
Issues
#311
Content
N/A
Screenshots