Hiding a specific path when rendering a complex oneOf

TL;DR - is it safe to assume that the element scope can be parsed to find the property that is being rendered?

I have a custom renderer that renders a oneOf with a discriminator. The renderer ( ui/src/forms/overrides/material/complex/MaterialOneOfRenderer_Discriminator.tsx at main · estuary/ui · GitHub ) is a copy/paste/tweak of the MaterialOneOfRenderer from y’all.

In our custom version I am calling createCombinatorRenderInfos to get back oneOfRenderInfos and then filtering out the discriminator property from the UISchema’s elements property.

    oneOfRenderInfos.map((renderer) => {
        const { uischema: rendererUischema } = renderer as any;
        rendererUischema.elements = rendererUischema.elements.filter(
            (el: any) => {
                const pathSegments = el.scope?.split('/');
                if (pathSegments && pathSegments.length > 0) {
                    const lastSegment = decode(
                        pathSegments[pathSegments.length - 1]
                    );
                    return lastSegment !== discriminatorProperty;
                }

                return true;
            }
        );

        return renderer;
    });

This feels safe - but wanted to check that it is. Will the ending of the scope property normally be the name of a property? So far in my testing that seems right and looking are your code (like how deriveLabel does something similar) it seems this is how y’all find properties already but wanted to check.

Hi @travjenkins ,

yes the scope property is used to reference the property to render. Thus, it’s last segment always is the property itself as long as your UI Schema is configured correctly.

Best regards,
Lucas

1 Like