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

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

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 43 441x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import type {
    ICardConfig,
    IEnrichedSchema,
    IHandlerProxy,
    IResolvedModelSpec,
} from '@feasibleone/blong';
import type {LayoutConfig} from '../../hooks/useLayout.js';
 
export async function subjectObjectOpen(model: IResolvedModelSpec, blong: IHandlerProxy<unknown>) {
    const {objectTitle, keyField, browser, methods, subject, object} = model;
 
    return async () => ({
        title: `Edit ${objectTitle}`,
        permission: browser.permission.edit,
        icon: 'pi pi-pencil',
        component: async (params?: Record<string, unknown>) => {
            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);
            const loadParams = params ? {[keyField]: params[keyField]} : undefined;
            function OpenPage(props: Record<string, unknown>) {
                return Editor({
                    schema,
                    cards: model.cards as Record<string, ICardConfig>,
                    layout: 'edit',
                    layouts: model.layouts as Record<string, LayoutConfig>,
                    loadAction: methods.get,
                    loadParams,
                    saveAction: methods.edit,
                    mode: 'edit',
                    editable: true,
                    title: `Edit ${objectTitle}`,
                    ...props,
                });
            }
 
            return OpenPage;
        },
    });
}