All files / ext.wikilambda.edit/components/function/editor FunctionEditorFooter.vue

84.61% Statements 22/26
71.42% Branches 10/14
100% Functions 4/4
84.61% Lines 22/26

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112    17x 17x 17x 17x 17x 17x                                                           21x                   2x   2x 2x                           6x 3x         3x 2x                 17x   17x     17x 17x 17x       28x 28x         17x                            
<!--
	WikiLambda Vue component footer for the Function Editor, including publish, cancel and implement buttons.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-function-definition-footer">
		<wl-publish-widget
			:is-dirty="isFunctionDirty"
			:function-signature-changed="functionSignatureChanged"
			@start-publish="raiseFunctionWarnings"
		></wl-publish-widget>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const PublishWidget = require( '../../widgets/Publish.vue' ),
	Constants = require( '../../../Constants.js' ),
	mapGetters = require( 'vuex' ).mapGetters,
	mapActions = require( 'vuex' ).mapActions;
 
module.exports = exports = defineComponent( {
	name: 'wl-function-editor-footer',
	components: {
		'wl-publish-widget': PublishWidget
	},
	props: {
		functionInputChanged: {
			type: Boolean,
			required: false,
			default: false
		},
		functionOutputChanged: {
			type: Boolean,
			required: false,
			default: false
		},
		isFunctionDirty: {
			type: Boolean,
			required: false,
			default: false
		}
	},
	computed: Object.assign( mapGetters( [
		'isCreateNewPage'
	] ), I{
		/**
		 * Returns whether the function type signature (input types
		 * and output type) has changed from its initial value.
		 *E
		 * @return {boolean}
		 */
		functionSignatureChanged: function () {
			return this.functionInputChanged || this.functionOutputChanged;
		},
		/**
		 * Returns the error code for the type of function
		 * signature warning to be shown to the user, depending on
		 * whether the inputs have changed, the output, or both.
		 *
		 * @return {string}
		 */
		signatureWarningCode: function () {
			if ( this.functionInputChanged && this.functionOutputChanged ) {
				return Constants.errorCodes.FUNCTION_INPUT_OUTPUT_CHANGED;
			} else if ( this.functionInputChanged ) {
				return Constants.errorCodes.FUNCTION_INPUT_CHANGED;
			} else if ( this.functionOutputChanged ) {
				return Constants.errorCodes.FUNCTION_OUTPUT_CHANGED;
			}
			return '';
		}
	} ),
	methods: Object.assign( mapActions( [
		'setError'
	] ), {
		/**
		 * Set warnings when there are changes in the function signature
		 * to announce that
		 */
		raiseFunctionWarnings: function () {
			// Only warn of changes if we are editing an existing function
			if ( this.isCreateNewPage ) {
				return;
			}
 
			// If there's changes in the function signature, warn that
			// implementations and testers will be detached
			if ( this.functionSignatureChanged ) {
				this.setError( {
					rowId: 0,
					errorType: Constants.errorTypes.WARNING,
					errorCode: this.signatureWarningCode
				} );
			}
		}
	} )
} );
 
</script>
 
<style lang="less">
@import '../../../ext.wikilambda.edit.variables.less';
 
.ext-wikilambda-function-definition-footer {
	padding: 0;
	margin-top: @spacing-150;
}
</style>