All files / ext.wikilambda.app/components/function/editor FunctionEditorOutput.vue

100% Statements 182/182
100% Branches 12/12
100% Functions 10/10
100% Lines 182/182

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 1831x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 57x 1x 1x 1x 1x 1x 1x 1x 1x 24x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 9x 9x 9x 1x 1x 1x 1x 1x 1x 1x 10x 1x 1x 1x 1x 1x 1x 1x 10x 1x 1x 1x 1x 1x 1x 1x 9x 1x 1x 1x 1x 1x 1x 1x 10x 10x 1x 1x 1x 1x 1x 1x 1x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<!--
	WikiLambda Vue component for setting the output of a ZFunction in the Function editor.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<wl-function-editor-field
		class="ext-wikilambda-app-function-editor-output"
		:tooltip-message="tooltipMessage"
		:tooltip-icon="tooltipIcon"
		:show-tooltip="tooltipMessage && !canEdit">
		<template #label>
			<label :id="outputFieldId">
				{{ outputLabel }}
			</label>
		</template>
		<template #description>
			{{ outputFieldDescription }}
			<a :href="listObjectsUrl" target="_blank">{{ listObjectsLink }}</a>
		</template>
		<template #body>
			<wl-type-selector
				v-if="!!outputTypeRowId"
				class="ext-wikilambda-app-function-editor-output__field"
				data-testid="function-editor-output-type"
				:aria-labelledby="outputFieldId"
				:row-id="outputTypeRowId"
				:disabled="!canEdit"
				:label-data="outputTypeLabel"
				:placeholder="outputFieldPlaceholder"
				:type="typeZid"
			></wl-type-selector>
		</template>
	</wl-function-editor-field>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const Constants = require( '../../../Constants.js' ),
	LabelData = require( '../../../store/classes/LabelData.js' ),
	FunctionEditorField = require( './FunctionEditorField.vue' ),
	TypeSelector = require( '../../base/TypeSelector.vue' ),
	{ mapGetters } = require( 'vuex' );
 
module.exports = exports = defineComponent( {
	name: 'wl-function-editor-output',
	components: {
		'wl-type-selector': TypeSelector,
		'wl-function-editor-field': FunctionEditorField
	},
	props: {
		/**
		 * if a user has permission to edit a function
		 */
		canEdit: {
			type: Boolean,
			default: false
		},
		/**
		 * icon that will display a tooltip
		 */
		tooltipIcon: {
			type: [ String, Object ],
			default: null,
			required: false
		},
		/**
		 * message the tooltip displays
		 */
		tooltipMessage: {
			type: String,
			default: null
		}
	},
	data: function () {
		return {
			typeZid: Constants.Z_TYPE
		};
	},
	computed: Object.assign( mapGetters( [
		'getUserLangCode',
		'getZFunctionOutput'
	] ), {
		/**
		 * Returns the row object of the output type
		 * of the function, or undefined if not found.
		 *
		 * @return {Object|undefined}
		 */
		outputTypeRow: function () {
			return this.getZFunctionOutput();
		},
		/**
		 * Returns the row id of the output type
		 * of the function, or undefined if not found.
		 *
		 * @return {number|undefined}
		 */
		outputTypeRowId: function () {
			return this.outputTypeRow ? this.outputTypeRow.id : undefined;
		},
		/**
		 * Returns the label for the output field
		 *
		 * @return {string}
		 */
		outputLabel: function () {
			// TODO (T335583): Replace i18n message with key label
			// return this.getLabelData( Constants.Z_FUNCTION_RETURN_TYPE );
			return this.$i18n( 'wikilambda-function-definition-output-label' ).text();
		},
		/**
		 * Returns the title of the "Type" column for the output field
		 *
		 * @return {string}
		 */
		outputTypeLabel: function () {
			return LabelData.fromString(
				this.$i18n( 'wikilambda-function-definition-output-type-label' ).text()
			);
		},
		/**
		 * Returns the id for the output field
		 *
		 * @return {string}
		 */
		outputFieldId: function () {
			return 'ext-wikilambda-app-function-editor-output__label-id';
		},
		/**
		 * Returns the description for the output field
		 *
		 * @return {string}
		 */
		outputFieldDescription: function () {
			return this.$i18n( 'wikilambda-function-definition-output-description' ).text();
		},
		/**
		 * Returns the placeholder for the output field
		 *
		 * @return {string}
		 */
		outputFieldPlaceholder: function () {
			return this.$i18n( 'wikilambda-function-definition-output-selector' ).text();
		},
		/**
		 * Returns the URL to the Special page List Object by Type
		 *
		 * @return {string}
		 */
		listObjectsUrl: function () {
			return new mw.Title( Constants.PATHS.LIST_OBJECTS_BY_TYPE_TYPE )
				.getUrl( { uselang: this.getUserLangCode } );
		},
		/**
		 * Returns the text for the link to the Special page List Object by Type
		 *
		 * @return {string}
		 */
		listObjectsLink: function () {
			return this.$i18n( 'wikilambda-function-definition-output-types' ).text();
		}
	} )
} );
</script>
 
<style lang="less">
@import '../../../ext.wikilambda.app.variables.less';
 
.ext-wikilambda-app-function-editor-output {
	.ext-wikilambda-app-function-editor-output__field {
		border-radius: @border-radius-base;
		border: @border-subtle;
		padding: @spacing-75;
 
		.cdx-label__label__text {
			font-weight: @font-weight-normal;
		}
	}
}
</style>