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

96.66% Statements 29/30
100% Branches 4/4
87.5% Functions 7/8
96.66% Lines 29/30

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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234    17x 17x 17x 17x 17x 17x 17x 17x 17x 17x                                         21x                     21x                 24x                                     21x                     4x                   21x       17x   17x     17x 17x 17x         24x 24x 24x 24x 24x 24x 24x                                                                           17x                                                                                                                                                                  
<!--
	WikiLambda Vue componen for function editor language block. Contains all
	the function fields for a given input language.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div
		class="ext-wikilambda-function-block"
		data-testid="function-editor-language-block"
	>
		<!-- component that displays the language selector -->
		<wl-function-editor-language
			class="ext-wikilambda-function-block__row"
			data-testid="function-editor-language-selector"
			:z-language="zLanguage"
			@change="changeLanguage"
		></wl-function-editor-language>
		<!-- component that displays name for a language -->
		<wl-function-editor-name
			class="ext-wikilambda-function-block__row"
			data-testid="function-editor-name-input"
			:z-language="zLanguage"
			:is-main-language-block="isMainLanguageBlock"
			@updated-name="updatedLabels"
		></wl-function-editor-name>
		<!-- component that displays the description for a language -->
		<wl-function-editor-description
			class="ext-wikilambda-function-block__row"
			data-testid="function-editor-description-input"
			:z-language="zLanguage"
			@updated-description="updatedLabels"
		></wl-function-editor-description>
		<!-- component that displays aliases for a language -->
		<wl-function-editor-aliases
			class="ext-wikilambda-function-block__row"
			data-testid="function-editor-alias-input"
			:z-language="zLanguage"
			@updated-alias="updatedLabels"
		></wl-function-editor-aliases>
		<!-- component that displays list of inputs for a language -->
		<wl-function-editor-inputs
			class="ext-wikilambda-function-block__row"
			data-testid="function-editor-inputs"
			:z-language="zLanguage"
			:is-main-language-block="isMainLanguageBlock"
			:can-edit="canEditFunction"
			:tooltip-icon="icons.cdxIconLock"
			:tooltip-message="adminTooltipMessage"
			@updated-argument-label="updatedLabels"
		></wl-function-editor-inputs>
		<!-- component that displays output for a language -->
		<wl-function-editor-output
			v-if="isMainLanguageBlock"
			class="ext-wikilambda-function-block__row"
			data-testid="function-editor-output"
			:can-edit="canEditFunction"
			:tooltip-icon="icons.cdxIconLock"
			:tooltip-message="adminTooltipMessage"
		></wl-function-editor-output>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const FunctionEditorLanguage = require( './FunctionEditorLanguage.vue' ),
	FunctionEditorName = require( './FunctionEditorName.vue' ),
	FunctionEditorDescription = require( './FunctionEditorDescription.vue' ),
	FunctionEditorAliases = require( './FunctionEditorAliases.vue' ),
	FunctionEditorInputs = require( './FunctionEditorInputs.vue' ),
	FunctionEditorOutput = require( './FunctionEditorOutput.vue' ),
	icons = require( '../../../../lib/icons.json' ),
	mapGetters = require( 'vuex' ).mapGetters;
 
module.exports = exports = defineComponent( {
	name: 'wl-function-editor-language-block',
	components: {
		'wl-function-editor-language': FunctionEditorLanguage,
		'wl-function-editor-name': FunctionEditorName,
		'wl-function-editor-description': FunctionEditorDescription,
		'wl-function-editor-aliases': FunctionEditorAliases,
		'wl-function-editor-inputs': FunctionEditorInputs,
		'wl-function-editor-output': FunctionEditorOutput
	},
	props: {
		zLanguage: {
			type: String,
			required: true
		},
		index: {
			type: Number,
			default: 0
		}
	},
	data: function () {
		return {
			icons: icons
		};
	},
	computed: Object.assign( mapGetters( [
		'getMetadataLanguages',
		'isCreateNewPage',
		'isUserLoggedIn'
	] ), {
		/**
		 * Returns whether the current language block is the first (main) one
		 *
		 * @return {boolean}
		 */
		isMainLanguageBlock: function () {
			return this.index === 0;
		},
		/**
		 * Returns whether the user can edit the function
		 *
		 * @return {boolean}
		 */
		canEditFunction: function () {
			// TODO (T301667): restrict to only certain user roles
			return this.isCreateNewPage ? true : this.isUserLoggedIn;
		},
		/**
		 * Returns the available languages for the function definition,
		 * which includes Name, Description, Aliases and Input labels.
		 *
		 * @return {Array}
		 */
		functionLanguages: function () {
			return this.getMetadataLanguages( this.rowId );
		},
		/**
		 * Message for admin tooltip to show in both Input and Output components
		 *
		 * @return {string}
		 */
		adminTooltipMessage: function () {
			// TODO (T299604): Instead of just "users with special permissions", once the right exists we should
			// actually check which group has the right, fetch its display name, and display it in this text.
			return this.$i18n( 'wikilambda-editor-fn-edit-definition-tooltip-content' ).text();
		}
	} ),
	methods: {
		/**
		 * Emits a setLanguage event to set the language block
		 * to the given language.
		 *
		 * @param {string} value
		 */
		changeLanguage: function ( value ) {
			this.$emit( 'set-language', {
				language: value,
				index: this.index
			} );
		},
		/**
		 * Emits a updatedLabels event for the root function
		 * definition to track label changes.
		 */
		updatedLabels: function () {
			this.$emit( 'updated-labels' );
		}
	}
} );
</script>
 
<style lang="less">
@import '../../../ext.wikilambda.edit.variables.less';
 
.ext-wikilambda-function-block {
	padding-top: @spacing-150;
	border-bottom: 1px solid @border-color-subtle;
 
	&:first-child {
		border-top: 1px solid @border-color-subtle;
	}
 
	&__row {
		display: flex;
		margin-bottom: @spacing-150;
		gap: @spacing-100;
 
		@media screen and ( max-width: @max-width-breakpoint-mobile ) {
			& {
				flex-direction: column;
			}
		}
	}
 
	&__label {
		width: @wl-field-label-width;
		display: flex;
		flex-direction: column;
 
		& > label {
			line-height: @size-200;
			font-weight: @font-weight-bold;
 
			& > span {
				font-weight: @font-weight-normal;
			}
		}
 
		&__description {
			color: @color-subtle;
			font-size: @font-size-small;
			line-height: @line-height-small;
			display: inline-block;
		}
 
		&__tooltip-icon {
			margin-left: @spacing-50;
			width: @size-100;
			height: @size-100;
		}
 
		@media screen and ( max-width: @max-width-breakpoint-mobile ) {
			& > label {
				line-height: inherit;
				margin-bottom: @spacing-25;
			}
 
			&__description {
				margin-bottom: @spacing-25;
			}
		}
	}
 
	&__body {
		width: @wl-field-body-width;
	}
}
</style>