All files / ext.wikilambda.app/components/widgets/function-evaluator EvaluationResult.vue

96.06% Statements 122/127
75% Branches 3/4
60% Functions 3/5
96.06% Lines 122/127

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 1281x 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 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 28x 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 16x 16x 16x 16x     16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<!--
	WikiLambda Vue component for Z22/Evaluation Result objects.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-app-evaluation-result" data-testid="z-evaluation-result">
		<div class="ext-wikilambda-app-evaluation-result__result">
			<wl-z-object-key-value
				:skip-key="true"
				:row-id="rowId"
				:edit="false"
			></wl-z-object-key-value>
		</div>
 
		<!-- Action Bar -->
		<div class="ext-wikilambda-app-evaluation-result__actions">
			<a
				v-if="hasMetadata"
				class="ext-wikilambda-app-evaluation-result__action-details"
				role="button"
				@click="showMetadata = !showMetadata"
			>{{ $i18n( 'wikilambda-function-evaluator-result-details' ).text() }}</a>
		</div>
		<!-- Function Metadata Dialog -->
		<wl-function-metadata-dialog
			v-if="hasMetadata"
			:open="showMetadata"
			:header-text="implementationName"
			:metadata="getMetadata"
			@close-dialog="showMetadata = false"
		></wl-function-metadata-dialog>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const Constants = require( '../../../Constants.js' ),
	FunctionMetadataDialog = require( './FunctionMetadataDialog.vue' ),
	ZObjectKeyValue = require( '../../default-view-types/ZObjectKeyValue.vue' ),
	{ mapGetters } = require( 'vuex' );
 
module.exports = exports = defineComponent( {
	name: 'wl-evaluation-result',
	components: {
		'wl-function-metadata-dialog': FunctionMetadataDialog,
		'wl-z-object-key-value': ZObjectKeyValue
	},
	props: {
		rowId: {
			type: Number,
			required: false,
			default: undefined
		}
	},
	data: function () {
		return {
			showMetadata: false
		};
	},
	computed: Object.assign( mapGetters( [
		'getMetadata',
		'getCurrentZObjectId',
		'getLabelData',
		'getZPersistentContentRowId',
		'getZObjectTypeByRowId'
	] ), {
 
		/**
		 * Returns whether there's a metadata value
		 *
		 * @return {boolean}
		 */
		hasMetadata: function () {
			return !!this.getMetadata;
		},
 
		/**
		 * Returns the help link from the Metadata dialog
		 *
		 * @return {string}
		 */
		tooltipMetaDataHelpLink: function () {
			return this.$i18n( 'wikilambda-helplink-tooltip' ).text();
		},
 
		/**
		 * Returns the parsed help link from the Metadata dialog
		 *
		 * @return {string}
		 */
		parsedMetaDataHelpLink: function () {
			const unformattedLink = this.$i18n( 'wikilambda-metadata-help-link' ).text();
			return mw.internalWikiUrlencode( unformattedLink );
		},
 
		/**
		 * If we are in an implementation page, return the implementation
		 * label in the user language. Else return undefined
		 *
		 * @return {string|undefined}
		 */
		implementationName: function () {
			const contentRowId = this.getZPersistentContentRowId() || 0;
			const contentType = this.getZObjectTypeByRowId( contentRowId );
			// If the page is an implementation, return implementation label
			if ( contentType === Constants.Z_IMPLEMENTATION ) {
				return this.getLabelData( this.getCurrentZObjectId );
			}
			return undefined;
		}
	} )
} );
 
</script>
 
<style lang="less">
@import '../../../ext.wikilambda.app.variables.less';
 
.ext-wikilambda-app-evaluation-result {
	.ext-wikilambda-app-evaluation-result__actions {
		display: flex;
		gap: @spacing-50;
	}
}
</style>