All files / blong-browser/src/model/component subjectObjectBrowse.ts

100% Statements 42/42
83.33% Branches 5/6
100% Functions 3/3
100% Lines 42/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 431x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import type {IEnrichedSchema, IHandlerProxy, IResolvedModelSpec} from '@feasibleone/blong';
 
export async function subjectObjectBrowse(
    model: IResolvedModelSpec,
    blong: IHandlerProxy<unknown>,
) {
    const {subject, object, browser, cards, layouts} = model;
 
    return async () => ({
        title: browser.title,
        permission: browser.permission.browse,
        icon: browser.icon,
        component: async () => {
            const [schemaOverride, {Editor}] = await Promise.all([
                blong.handler.subjectObjectSchema<IEnrichedSchema>({subject, object}, {}),
                import('../../components/Editor/Editor.js'),
            ]);
 
            const schema = blong.lib.merge({}, model.schema, schemaOverride);
            function BrowsePage(props: Record<string, unknown>) {
                return Editor({
                    schema,
                    toolbar: [
                        {label: '', icon: 'pi pi-refresh', action: '__refresh__', title: 'Refresh'},
                        ...(browser.toolbar ?? []),
                    ],
                    cards,
                    layouts,
                    layout: 'browse',
                    editable: false,
                    editMode: false,
                    refreshNamespace: `${subject}.${object}`,
                    title: browser.title,
                    className: 'blong-subject-object-browse',
                    ...props,
                });
            }
 
            return BrowsePage as unknown as React.ComponentType;
        },
    });
}