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

93.93% Statements 31/33
70% Branches 7/10
83.33% Functions 10/12
93.93% Lines 31/33

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    18x 18x 18x 18x 18x 18x 18x                                                               14x                       70x                 70x                   14x               13x                               14x               13x               28x                   14x       18x   18x     18x 18x 18x     18x     18x     18x     18x 18x       70x 70x 70x 70x                                                   18x                  
<!--
	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>
	<div class="ext-wikilambda-function-definition-output">
		<div class="ext-wikilambda-function-block__label">
			<label id="ext-wikilambda-function-definition-output__label-id">
				{{ outputLabel }}
			</label>
			<wl-tooltip
				v-if="tooltipMessage && !canEdit"
				:content="tooltipMessage"
			>
				<cdx-icon
					v-if="tooltipIcon"
					class="ext-wikilambda-function-block__label__tooltip-icon"
					:icon="tooltipIcon">
				</cdx-icon>
			</wl-tooltip>
			<span class="ext-wikilambda-function-block__label__description">
				{{ outputFieldDescription }}
				<a :href="listObjectsUrl" target="_blank">{{ listObjectsLink }}</a>
			</span>
		</div>
		<div class="ext-wikilambda-function-block__body">
			<wl-type-selector
				v-if="!!outputTypeRowId"
				class="ext-wikilambda-function-definition-output__field"
				data-testid="function-editor-output-type"
				aria-labelledby="ext-wikilambda-function-definition-output__label-id"
				:row-id="outputTypeRowId"
				:disabled="!canEdit"
				:label="outputTypeLabel"
				:placeholder="outputFieldPlaceholder"
				:type="typeZid"
			></wl-type-selector>
		</div>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const Constants = require( '../../../Constants.js' ),
	TypeSelector = require( '../../base/TypeSelector.vue' ),
	Tooltip = require( '../../base/Tooltip.vue' ),
	CdxIcon = require( '@wikimedia/codex' ).CdxIcon,
	mapGetters = require( 'vuex' ).mapGetters;
 
module.exports = exports = defineComponent( {
	name: 'wl-function-editor-output',
	components: {
		'wl-tooltip': Tooltip,
		'wl-type-selector': TypeSelector,
		'cdx-icon': CdxIcon
	},
	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.getLabel( 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 this.$i18n( 'wikilambda-function-definition-output-type-label' ).text();
		},
		/**
		 * Returns the id for the output field
		 *
		 * @return {string}
		 */
		outputFieldId: function () {
			return 'ext-wikilambda-function-definition-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.edit.variables.less';
 
.ext-wikilambda-function-definition-output {
	&__field {
		border-radius: @border-radius-base;
		border: @border-subtle;
		padding: @spacing-75;
 
		.cdx-label__label__text {
			font-weight: @font-weight-normal;
		}
	}
}
</style>