private createDialogValues()

in gui/frontend/src/modules/mrs/dialogs/MrsDbObjectDialog.tsx [145:362]


    private createDialogValues(request: IDialogRequest,
        services: IMrsServiceData[], schemas: IMrsSchemaData[], rowOwnershipFields: string[],
        title?: string): IDialogValues {

        let selectedService = services.find((service) => {
            return service.id === request.values?.serviceId;
        });

        if (selectedService === undefined) {
            selectedService = services.find((service) => {
                return service.isCurrent === 1;
            });
        }

        if (services.length > 0 && !selectedService) {
            selectedService = services[0];
        }

        const selectedSchema = schemas.find((schema) => {
            return request.values?.dbSchemaId === schema.id;
        });

        let updateDisabled;
        if (!this.createDbObject) {
            updateDisabled = [CommonDialogValueOption.Disabled];
        }

        const mainSection: IDialogSection = {
            caption: title,
            values: {
                service: {
                    type: "choice",
                    caption: "REST Service Path",
                    value: selectedService?.fullServicePath ?? "",
                    choices: services.map((service) => {
                        return service.fullServicePath ?? "";
                    }),
                    horizontalSpan: 2,
                    description: "The path of the REST Service",
                    options: updateDisabled,
                },
                schema: {
                    type: "choice",
                    caption: "REST Schema Path",
                    value: selectedSchema?.requestPath,
                    choices: schemas.map((schema) => {
                        return schema.requestPath;
                    }),
                    horizontalSpan: 2,
                    description: "The path of the REST Schema",
                    options: updateDisabled,
                },
                requestPath: {
                    type: "text",
                    caption: "REST Object Path",
                    value: request.values?.requestPath as string,
                    horizontalSpan: 2,
                    description: "The path, has to starts with /",
                    options: [CommonDialogValueOption.AutoFocus],
                },
                flags: {
                    type: "description",
                    caption: "Access Control",
                    horizontalSpan: 1,
                    options: [
                        CommonDialogValueOption.Grouped,
                        CommonDialogValueOption.NewGroup,
                    ],
                },
                enabled: {
                    type: "choice",
                    caption: "Access",
                    choices: ["Access DISABLED", "Access ENABLED", "PRIVATE Access Only"],
                    horizontalSpan: 2,
                    value: request.values?.enabled === EnabledState.PrivateOnly ? "PRIVATE Access Only" :
                        request.values?.enabled === EnabledState.Enabled ? "Access ENABLED" : "Access DISABLED",
                    options: [
                        CommonDialogValueOption.Grouped,
                    ],
                },
                requiresAuth: {
                    type: "boolean",
                    caption: "Auth. Required",
                    horizontalSpan: 2,
                    value: (request.values?.requiresAuth ?? true) as boolean,
                    options: [
                        CommonDialogValueOption.Grouped,
                    ],
                },
            },
        };

        // ---------------------------------------------------------------------
        // Add MrsRestObjectFieldEditor
        const customData: IMrsObjectFieldEditorData = {
            servicePath: selectedService?.urlContextRoot ?? "",
            dbSchemaName: selectedSchema?.name ?? "",
            dbSchemaPath: selectedSchema?.requestPath ?? "",
            dbObject: this.requestValue,
            defaultMrsObjectName: convertToPascalCase(selectedService?.urlContextRoot ?? "") +
                convertToPascalCase(selectedSchema?.requestPath ?? "") +
                convertToPascalCase(this.requestValue.name),
            crudOperations: request.values?.crudOperations as string[],
            mrsObjects: [],
            currentlyListedTables: [],
            currentMrsObjectId: undefined,
            currentTreeItems: [],
            createDbObject: this.createDbObject,
        };

        const mrsObjectSection: IDialogSection = {
            caption: (this.requestValue.objectType === MrsDbObjectType.Procedure ||
                this.requestValue.objectType === MrsDbObjectType.Function)
                ? "Parameters/Result Sets" : "Data Mapping",
            groupName: "group1",
            expand: true,
            values: {
                tree: {
                    type: "custom",
                    value: customData,
                    component: <MrsObjectFieldEditor
                        backend={this.backend}
                        dbObjectChange={this.handleDbObjectChange}
                        getCurrentDbObject={this.handleGetCurrentDbObject} />,
                    horizontalSpan: 8,
                },
            },
        };

        const settingsSection: IDialogSection = {
            caption: "Settings",
            groupName: "group1",
            values: {
                crudOperationFormat: {
                    type: "choice",
                    caption: "Result Format",
                    choices: ["FEED", "ITEM", "MEDIA"],
                    value: request.values?.crudOperationFormat as string,
                    horizontalSpan: 2,
                },
                itemsPerPage: {
                    type: "text",
                    caption: "Items per Page",
                    horizontalSpan: 2,
                    value: request.values?.itemsPerPage as string,
                },
                comments: {
                    type: "text",
                    caption: "Comments",
                    value: request.values?.comments as string,
                    horizontalSpan: 4,
                },
                mediaType: {
                    type: "text",
                    caption: "Media Type",
                    horizontalSpan: 4,
                    value: request.values?.mediaType as string,
                    description: "The HTML MIME Type of the result",
                },
                autoDetectMediaType: {
                    type: "boolean",
                    caption: "Automatically Detect Media Type",
                    horizontalSpan: 4,
                    value: (request.values?.autoDetectMediaType ?? false) as boolean,
                },

            },
        };

        const optionsSection: IDialogSection = {
            caption: "Options",
            groupName: "group1",
            values: {
                options: {
                    type: "text",
                    caption: "Options",
                    value: request.values?.options ? JSON.stringify(request.values.options, undefined, 4) : "",
                    horizontalSpan: 8,
                    multiLine: true,
                    multiLineCount: 8,
                    description: "Additional options in JSON format",
                },
                metadata: {
                    type: "text",
                    caption: "Metadata",
                    value: request.values?.metadata ? JSON.stringify(request.values.metadata, undefined, 4) : "",
                    horizontalSpan: 8,
                    multiLine: true,
                    multiLineCount: 8,
                    description: "Metadata settings in JSON format",
                },
            },
        };

        const authorizationSection: IDialogSection = {
            caption: "Authorization",
            groupName: "group1",
            values: {
                authStoredProcedure: {
                    type: "text",
                    caption: "Custom Stored Procedure used for Authorization",
                    horizontalSpan: 8,
                    value: request.values?.authStoredProcedure as string,
                },
            },
        };

        return {
            id: "mainSection",
            sections: new Map<string, IDialogSection>([
                ["mainSection", mainSection],
                ["mrsObject", mrsObjectSection],
                ["settingsSection", settingsSection],
                ["authorizationSection", authorizationSection],
                ["optionsSection", optionsSection],
            ]),
        };
    }