All files / ext.wikilambda.edit/components/function/viewer FunctionViewerDetailsTable.vue

95.12% Statements 39/41
64.28% Branches 9/14
85.71% Functions 12/14
95.12% Lines 39/41

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 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306    18x 18x 18x 18x 18x 18x 18x 18x 18x 18x                                           1x                                                                                   9x 9x         9x                     4x                                               2x           2x       18x   18x     18x 18x 18x     18x     18x 18x       18x     18x 18x       45x 45x 45x 45x 45x                 44x                   8x                   8x                     24x               8x                     18x                                                                                                                                                                                    
<!--
	WikiLambda Vue component for the implementation table in the ZFunction Viewer Details tab.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-function-details-table">
		<wl-table
			:header="header"
			:hide-header="!header"
			:body="body"
			:is-loading="isLoading"
			:aria-labelledby="'ext-wikilambda-function-details-table__title__text-' + type"
			class="ext-wikilambda-function-details-table__body"
		>
			<template #table-title>
				<div class="ext-wikilambda-function-details-table__title">
					<span
						:id="'ext-wikilambda-function-details-table__title__text-' + type"
						class="ext-wikilambda-function-details-table__title__text">
						{{ title }}
					</span>
					<div
						v-if="canConnect || canDisconnect"
						class="ext-wikilambda-function-details-table__title__buttons"
					>
						<cdx-button
							v-if="!( isMobile && !canConnect )"
							:disabled="!canConnect"
							data-testid="connect"
							@click="connect"
						>
							<label> {{ $i18n( 'wikilambda-function-details-table-approve' ).text() }} </label>
						</cdx-button>
						<cdx-button
							v-if="!( isMobile && !canDisconnect )"
							:disabled="!canDisconnect"
							data-testid="disconnect"
							@click="disconnect"
						>
							<label> {{ $i18n( 'wikilambda-function-details-table-deactivate' ).text() }} </label>
						</cdx-button>
					</div>
					<div v-else>
						<a :href="addLink" data-testid="add-link">
							<cdx-button weight="quiet" aria-label="Add">
								<cdx-icon :icon="icons.cdxIconAdd"></cdx-icon>
							</cdx-button>
						</a>
					</div>
				</div>
			</template>
			<template #table-empty-text>
				<div class="ext-wikilambda-function-details-table__empty">
					<span>{{ emptyText }}</span>
				</div>
			</template>
		</wl-table>
		<wl-pagination
			v-if="totalPages > 1"
			:total-pages="totalPages"
			:current-page="currentPage"
			:showing-all="showingAll"
			@update-page="updateCurrentPage"
			@reset-view="resetView"
		></wl-pagination>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const CdxButton = require( '@wikimedia/codex' ).CdxButton,
	CdxIcon = require( '@wikimedia/codex' ).CdxIcon,
	icons = require( '../../../../lib/icons.json' ),
	TableContainer = require( '../../base/Table.vue' ),
	Pagination = require( '../../base/Pagination.vue' ),
	typeUtils = require( '../../../mixins/typeUtils.js' ),
	Constants = require( '../../../Constants.js' ),
	useBreakpoints = require( '../../../composables/useBreakpoints.js' );
 
module.exports = exports = defineComponent( {
	name: 'wl-function-viewer-details-table',
	components: {
		'cdx-button': CdxButton,
		'cdx-icon': CdxIcon,
		'wl-table': TableContainer,
		'wl-pagination': Pagination
	},
	mixins: [ typeUtils ],
	props: {
		type: {
			type: String,
			required: true
		},
		header: {
			type: Object,
			required: false,
			default: null
		},
		body: {
			type: Array,
			default: function () {
				return [];
			}
		},
		title: {
			type: String,
			required: false,
			default: ''
		},
		emptyText: {
			type: String,
			default: ''
		},
		currentPage: {
			type: Number,
			default: 1
		},
		totalPages: {
			type: Number,
			default: 0
		},
		showingAll: {
			type: Boolean,
			defualt: false
		},
		canConnect: {
			type: Boolean,
			required: true
		},
		canDisconnect: {
			type: Boolean,
			required: true
		},
		isLoading: {
			type: Boolean,
			default: false
		},
		addLink: {
			type: String,
			required: true
		}
	},
	setup: function () {
		const breakpoint = useBreakpoints( Constants.breakpoints );
		return {
			breakpoint
		};
	},
	data: function () {
		return {
			icons: icons
		};
	},
	computed: {
		/**
		 * Whether the display is of the size of a mobile screen
		 *
		 * @return {boolean}
		 */
		isMobile: function () {
			return this.breakpoint.current.value === Constants.breakpointsTypes.MOBILE;
		}
	},
	methods: {
		/**
		 * Emits the event update-page when selecting
		 * a page number to display
		 *
		 * @param {number} newPage
		 */
		updateCurrentPage: function ( newPage ) {
			this.$emit( 'update-page', newPage );
		},
		/**
		 * Emits the event reset-view when switching
		 * the view all/view less toggle button
		 */
		resetView: function () {
			this.$emit( 'reset-view' );
		},
		/**
		 * Emits an event when the connect button is clicked
		 */
		connect: function () {
			this.$emit( 'connect' );
		},
		/**
		 * Emits an event when the disconnect button is clicked
		 */
		disconnect: function () {
			this.$emit( 'disconnect' );
		}
	}
} );
</script>
 
<style lang="less">
@import '../../../ext.wikilambda.edit.variables.less';
 
.ext-wikilambda-function-details-table {
	margin-bottom: @spacing-200;
 
	&__body {
		&-link {
			color: @color-progressive;
		}
	}
 
	&__row--active {
		background: @background-color-progressive-subtle;
	}
 
	&__empty {
		padding: 0 12px;
		font-weight: @font-weight-normal;
		color: @color-placeholder;
		white-space: pre-wrap;
	}
 
	&__title {
		font-weight: @font-weight-bold;
		color: @color-base;
		overflow-wrap: break-word;
		background: @background-color-base;
		padding: 6px 6px 0 12px;
		display: flex;
		align-items: center;
 
		&__text {
			display: block;
			width: 100%;
			margin-right: @spacing-50;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			font-size: @font-size-large;
			padding-top: 6px;
		}
 
		&__buttons {
			margin-left: auto;
			display: flex;
			column-gap: @spacing-75;
		}
	}
 
	&-text {
		padding-right: @spacing-200;
		font-weight: @font-weight-bold;
		color: @color-base;
		overflow-wrap: break-word;
 
		&:first-child {
			width: @size-125;
			padding-left: 12px;
			padding-right: 12px;
		}
 
		.cdx-checkbox {
			display: flex;
			flex-direction: column;
			justify-content: center;
		}
	}
 
	&-item {
		padding-right: 12px;
 
		a {
			display: block; /* Fallback for non-webkit */
			display: -webkit-box;
			width: max-content;
			max-width: 244px;
			max-height: 44.78px; /* Fallback for non-webkit */
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
			overflow-wrap: break-word;
			overflow: hidden;
			text-overflow: ellipsis;
		}
 
		.cdx-checkbox {
			width: 22.85px;
			display: flex;
			flex-direction: column;
			justify-content: center;
		}
 
		&:first-child {
			padding-left: 12px;
		}
	}
 
	@media screen and ( max-width: @max-width-breakpoint-mobile ) {
		&-item {
			a {
				-webkit-line-clamp: 1;
				height: 22.39px;
			}
		}
	}
}
</style>