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

New SimplePlugin: InheritKeywords #204

Closed
elbakerino opened this issue Oct 10, 2022 · 2 comments
Closed

New SimplePlugin: InheritKeywords #204

elbakerino opened this issue Oct 10, 2022 · 2 comments
Labels
plugin use-case Questions regarding a use-case and possible examples for others widget
Projects

Comments

@elbakerino
Copy link
Member

A plugin that uses parentSchema to inject some keywords, when existing in parentSchema, to the child schema.

This makes it possible for nested schema-levels to inherit some (configurable?) keywords.

  • readOnly is the best example
  • hideTitle/hidden must be checked, may conflict with props overrides
  • ?
@elbakerino elbakerino added widget plugin use-case Questions regarding a use-case and possible examples for others labels Oct 10, 2022
@elbakerino elbakerino added this to To do in ui-schema via automation Oct 10, 2022
@averybross
Copy link
Contributor

averybross commented Oct 11, 2022

Proposed:

const InheritKeywords = (keywords: string[]) => ({
    should: () => true,
    handle: ({ errors, valid, parentSchema, schema }: any) => {
        let newSchema = schema

        if (parentSchema) {
            keywords.forEach(keyword => {
                let foundKeyword = parentSchema.get(keyword)
                if (foundKeyword !== undefined) {
                    newSchema = newSchema.set(keyword, foundKeyword)

                }
            });
        }
        return { schema: newSchema }
    }
});

Usage:

export const getCustomWidgets: () => CustomWidgetsBinding = () => {

    return ({
        ...widgets,
        pluginSimpleStack: [
            ...widgets.pluginSimpleStack,
            InheritKeywords(['readOnly'])
        ]
    })
}

@elbakerino
Copy link
Member Author

Released in v0.4.5

ui-schema automation moved this from To do to Done Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin use-case Questions regarding a use-case and possible examples for others widget
Projects
ui-schema
  
Done
Development

No branches or pull requests

2 participants