Unverified Commit 6c4141be authored by Marius van den Beek's avatar Marius van den Beek Committed by GitHub
Browse files

Merge pull request #15981 from guerler/fix_rerun

[23.0] Fix backbone-based data selector to materialize consistent attribute set
parents 995d2d37 001f1403
Loading
Loading
Loading
Loading
+39 −11
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
<script>
import Vue from "vue";
import FormInputs from "./FormInputs";
import { visitInputs, validateInputs, matchErrors } from "./utilities";
import { visitInputs, validateInputs, matchInputs } from "./utilities";
export default {
    components: {
        FormInputs,
@@ -71,6 +71,10 @@ export default {
            type: Object,
            default: null,
        },
        warnings: {
            type: Object,
            default: null,
        },
        workflowBuildingMode: {
            type: Boolean,
            default: false,
@@ -113,17 +117,14 @@ export default {
            this.$emit("onValidation", this.validation);
        },
        errors() {
            this.resetError();
            if (this.errors) {
                const errorMessages = matchErrors(this.formIndex, this.errors);
                for (const inputId in errorMessages) {
                    this.setError(inputId, errorMessages[inputId]);
                }
            }
            this.onErrors();
        },
        replaceParams() {
            this.onReplaceParams();
        },
        warnings() {
            this.onWarnings();
        },
    },
    created() {
        this.onCloneInputs();
@@ -131,6 +132,10 @@ export default {
        this.formData = this.buildFormData();
        // emit back to parent, so that parent has submittable data
        this.$emit("onChange", this.formData);
        // highlight initial warnings
        this.onWarnings();
        // highlight initial errors
        this.onErrors();
    },
    methods: {
        buildFormData() {
@@ -173,11 +178,28 @@ export default {
            const params = this.buildFormData();
            if (JSON.stringify(params) != JSON.stringify(this.formData)) {
                this.formData = params;
                this.resetError();
                this.resetErrors();
                this.$emit("onChange", params, refreshOnChange);
            }
        },
        getOffsetTop(element, padding = 100) {
        onErrors() {
            this.resetErrors();
            if (this.errors) {
                const errorMessages = matchInputs(this.formIndex, this.errors);
                for (const inputId in errorMessages) {
                    this.setError(inputId, errorMessages[inputId]);
                }
            }
        },
        onWarnings() {
            if (this.warnings) {
                const warningMessages = matchInputs(this.formIndex, this.warnings);
                for (const inputId in warningMessages) {
                    this.setWarning(inputId, warningMessages[inputId]);
                }
            }
        },
        getOffsetTop(element, padding = 150) {
            let offsetTop = 0;
            while (element) {
                offsetTop += element.offsetTop;
@@ -207,7 +229,13 @@ export default {
                input.error = message;
            }
        },
        resetError() {
        setWarning(inputId, message) {
            const input = this.formIndex[inputId];
            if (input) {
                input.warning = message;
            }
        },
        resetErrors() {
            Object.values(this.formIndex).forEach((input) => {
                input.error = null;
            });
+5 −4
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ interface FormElementProps {
    refreshOnChange?: boolean;
    help?: string;
    error?: string;
    warning?: string;
    backbonejs?: boolean;
    disabled?: boolean;
    attributes?: FormParameterAttributes;
@@ -120,7 +121,7 @@ function onConnect() {

const isHidden = computed(() => attrs.value["hidden"]);
const elementId = computed(() => `form-element-${props.id}`);
const hasError = computed(() => Boolean(props.error));
const hasAlert = computed(() => Boolean(props.error || props.warning));
const showPreview = computed(() => (collapsed.value && attrs.value["collapsible_preview"]) || props.disabled);
const showField = computed(() => !collapsed.value && !props.disabled);

@@ -174,10 +175,10 @@ const isOptional = computed(() => !isRequired.value && attrs.value["optional"] !
        v-show="!isHidden"
        :id="elementId"
        class="ui-form-element section-row"
        :class="{ alert: hasError, 'alert-info': hasError }">
        <div v-if="hasError" class="ui-form-error">
        :class="{ alert: hasAlert, 'alert-info': hasAlert }">
        <div v-if="hasAlert" class="ui-form-error">
            <FontAwesomeIcon class="mr-1" icon="fa-exclamation" />
            <span class="ui-form-error-text" v-html="props.error" />
            <span class="ui-form-error-text" v-html="props.error || props.warning" />
        </div>

        <div class="ui-form-title">
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@
                :title="input.label || input.name"
                :type="input.type"
                :error="input.error"
                :warning="input.warning"
                :help="input.help"
                :refresh-on-change="input.refresh_on_change"
                :attributes="input.attributes || input"
+3 −3
Original line number Diff line number Diff line
@@ -71,11 +71,11 @@ export function matchCase(input, value) {
    return -1;
}

/** Match server validation response to highlight errors
/** Match server validation response to highlight inputs
 * @param{dict}   index     - Index of input elements
 * @param{dict}   response  - Nested dictionary with error messages
 * @param{dict}   response  - Nested dictionary with error/warning messages
 */
export function matchErrors(index, response) {
export function matchInputs(index, response) {
    var result = {};
    function search(id, head) {
        if (typeof head === "string") {
+2 −2
Original line number Diff line number Diff line
import { visitInputs, validateInputs, matchCase, matchErrors } from "./utilities";
import { visitInputs, validateInputs, matchCase, matchInputs } from "./utilities";
import toolModel from "./test-data/tool";

function visitInputsString(inputs) {
@@ -129,7 +129,7 @@ describe("form component utilities", () => {
            input_b: ["error_b"],
            input_c: { input_d: "error_d" },
        };
        const result = matchErrors(index, values);
        const result = matchInputs(index, values);
        expect(result["input_a"]).toEqual("error_a");
        expect(result["input_b_0"]).toEqual("error_b");
        expect(result["input_c|input_d"]).toEqual("error_d");
Loading