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

92.71% Statements 140/151
94.02% Branches 63/67
87.5% Functions 63/72
92.14% Lines 129/140

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 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788    17x 17x 17x 17x 17x 17x 17x 17x                             24x                                                 48x               235x               48x               48x               48x               85x               91x               97x               229x                       60x           4x                                                         272x 272x   730x     730x     730x     730x   730x   248x 248x         482x 482x 234x     234x           730x               9x                                                                         272x               48x               235x               48x               48x               48x               68x               76x               229x                       279x 24x   255x           5x                               255x 754x 754x 726x           255x               286x 286x   524x     524x     524x               7x                                                       524x 1536x 1476x                     524x   286x                   48x                   24x 24x 24x                 24x 24x 24x                   28x 28x 78x 78x                         28x 28x 56x 56x                   5x 2x 2x       2x       2x             5x 2x 2x       2x       2x             4x 2x 2x       2x       2x             6x 3x 3x       2x   1x   3x             24x                           96x 96x 96x 48x 48x 48x 48x 48x   48x   48x                     332x                 9x 22x                                                                               24x 24x         24x 24x     17x   17x     17x 17x 17x     17x     17x         296x 296x 296x                                                                                             17x                                                                                                                                        
<!--
	WikiLambda Vue component for the details tab in the ZFunction Viewer.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<main class="ext-wikilambda-function-details">
		<section class="ext-wikilambda-function-details__tables">
			<wl-function-viewer-details-table
				:type="implementationType"
				:header="implementationsHeader"
				:body="implementationsBody"
				:title="$i18n( 'wikilambda-function-implementation-table-header' ).text()"
				:current-page="implementationsPage"
				:total-pages="implementationsTotalPages"
				:showing-all="implementationsShowAll"
				:can-connect="areProposedImplementationsSelected"
				:can-disconnect="areAvailableImplementationsSelected"
				:empty-text="implementationsFetched ?
					$i18n( 'wikilambda-implementation-none-found' ).text() : $i18n( 'wikilambda-loading' ).text()"
				:is-loading="implementationsLoading"
				:add-link="addImplementationLink"
				data-testid="function-implementations-table"
				@update-page="updateImplementationPage"
				@reset-view="resetImplementationView"
				@connect="connectCheckedImplementations"
				@disconnect="disconnectCheckedImplementations"
			></wl-function-viewer-details-table>
			<wl-function-viewer-details-table
				:type="testType"
				:header="testsHeader"
				:body="testsBody"
				:title="$i18n( 'wikilambda-function-test-cases-table-header' ).text()"
				:current-page="testsPage"
				:total-pages="testsTotalPages"
				:showing-all="testsShowAll"
				:can-connect="areProposedTestersSelected"
				:can-disconnect="areAvailableTestersSelected"
				:empty-text="testsFetched ?
					$i18n( 'wikilambda-tester-none-found' ).text() : $i18n( 'wikilambda-loading' ).text()"
				:is-loading="testsLoading"
				:add-link="addTestLink"
				data-testid="function-testers-table"
				@update-page="updateTestersPage"
				@reset-view="resetTestersView"
				@connect="connectCheckedTests"
				@disconnect="disconnectCheckedTests"
			></wl-function-viewer-details-table>
		</section>
		<div
			v-if="!!currentToast"
			class="ext-wikilambda-toast-message"
		>
			<cdx-message
				:dismiss-button-label="$i18n( 'wikilambda-toast-close' ).text()"
				:fade-in="true"
				type="error"
				@user-dismissed="closeToast"
			>
				{{ currentToast }}
			</cdx-message>
		</div>
	</main>
</template>

<script>
const { defineComponent } = require( 'vue' );
const FunctionViewerDetailsTable = require( './FunctionViewerDetailsTable.vue' ),
	Constants = require( '../../../Constants.js' ),
	typeUtils = require( '../../../mixins/typeUtils.js' ),
	CdxMessage = require( '@wikimedia/codex' ).CdxMessage,
	mapGetters = require( 'vuex' ).mapGetters,
	mapActions = require( 'vuex' ).mapActions;
 
module.exports = exports = defineComponent( {
	name: 'wl-function-viewer-details',
	components: {
		'wl-function-viewer-details-table': FunctionViewerDetailsTable,
		'cdx-message': CdxMessage
	},
	mixins: [ typeUtils ],
	props: {
		rowId: {
			type: Number,
			required: false,
			default: 0
		}
	},
	data: function () {
		return {
			/* Local state for function implementations */
			implementationType: Constants.Z_IMPLEMENTATION,
			implementationsState: {},
			implementationsPage: 1,
			implementationsFetched: false,
			implementationsLoading: false,
			implementationsShowAll: false,
 
			/* Local state for function tests */
			testType: Constants.Z_TYPE,
			testsState: {},
			testsPage: 1,
			testsFetched: false,
			testsLoading: false,
			testsShowAll: false,
 
			currentToast: null
		};
	},
	computed: Object.assign( mapGetters( [
		'getConnectedImplementations',
		'getConnectedTests',
		'getCurrentZObjectId',
		'getLabel',
		'getLanguageOfImplementation',
		'getZTesterPercentage',
		'getTypeOfImplementation',
		'getUserLangCode'
	] ), {
		/**
		 * Zids of all implementations for this function
		 *
		 * @return {Array}
		 */
		allImplementations: function () {
			return Object.keys( this.implementationsState );
		},
		/**
		 * Zids of all implementations already connected to the function
		 *
		 * @return {Array}
		 */
		connectedImplementations: function () {
			return this.getConnectedImplementations( this.rowId );
		},
		/**
		 * Zids of all the implementations visible in the table
		 *
		 * @return {Array}
		 */
		visibleImplementations: function () {
			return this.implementationsShowAll ?
				this.allImplementations :
				this.paginatedImplementations[ this.implementationsPage ];
		},
		/**
		 * Return the implementations structured into pages
		 *
		 * @return {Object}
		 */
		paginatedImplementations: function () {
			return this.paginateList( this.allImplementations );
		},
		/**
		 * Total number of implementation pages
		 *
		 * @return {number}
		 */
		implementationsTotalPages: function () {
			return Object.keys( this.paginatedImplementations ).length;
		},
		/**
		 * Whether any of the available implementations are checked
		 *
		 * @return {boolean}
		 */
		areAnyImplementationsChecked: function () {
			return Object.keys( this.implementationsState ).some( ( zid ) => this.implementationsState[ zid ].checked );
		},
		/**
		 * Whether any of the disconnected implementations are checked
		 *
		 * @return {boolean}
		 */
		areProposedImplementationsSelected: function () {
			return Object.keys( this.implementationsState ).some( ( zid ) =>
				this.implementationsState[ zid ].checked && !this.implementationsState[ zid ].available );
		},
		/**
		 * Whether any of the connected implementations are checked
		 *
		 * @return {boolean}
		 */
		areAvailableImplementationsSelected: function () {
			return Object.keys( this.implementationsState ).some( ( zid ) =>
				this.implementationsState[ zid ].checked && this.implementationsState[ zid ].available );
		},
		/**
		 * Returns the link for add new implementation page
		 *
		 * @return {string}
		 */
		addImplementationLink: function () {
			return new mw.Title( Constants.PATHS.CREATE_OBJECT_TITLE ).getUrl( {
				uselang: this.getUserLangCode,
				zid: Constants.Z_IMPLEMENTATION,
				[ Constants.Z_IMPLEMENTATION_FUNCTION ]: this.getCurrentZObjectId
			} );
		},
		/**
		 * Build the header row for the Implementations table
		 *
		 * @return {Object}
		 */
		implementationsHeader: function () {
			return ( this.visibleImplementations.length === 0 ) ? undefined :
				{
					checkbox: {
						title: '',
						component: 'cdx-checkbox',
						props: {
							modelValue: this.areAllRowsChecked( this.implementationsState ),
							'onUpdate:modelValue': ( value ) => this.checkAllRows( this.implementationsState, value )
						},
						class: 'ext-wikilambda-function-details-table-text'
					},
					name: {
						title: this.$i18n( 'wikilambda-function-implementation-name-label' ),
						class: 'ext-wikilambda-function-details-table-text',
						id: 'implementations-header-checkbox'
					},
					state: {
						title: this.$i18n( 'wikilambda-function-implementation-state-label' ),
						class: 'ext-wikilambda-function-details-table-text'
					},
					language: {
						title: this.$i18n( 'wikilambda-function-implementation-language-label' ),
						class: 'ext-wikilambda-function-details-table-text'
					},
					testsPassed: {
						title: this.$i18n( 'wikilambda-function-implementation-tests-passed-label' ),
						class: 'ext-wikilambda-function-details-table-text'
					}
				};
		},
		/**
		 * Build the content rows for the Implementations table
		 *
		 * @return {Array}
		 */
		implementationsBody: function () {
			const tableData = [];
			for ( const zid of this.visibleImplementations ) {
				// Get implementation name or its zid if unnamed:
				const implementationName = this.getLabel( zid );
 
				// Get implementation connected state:
				const isConnected = this.connectedImplementations.includes( zid );
 
				// Get implementation test results:
				const testResults = this.getZTesterPercentage( zid );
 
				// Get implementation type and language:
				const type = this.getTypeOfImplementation( zid );
				let language;
				switch ( type ) {
					case Constants.Z_IMPLEMENTATION_COMPOSITION:
						language = this.$i18n( 'wikilambda-implementation-selector-composition' ).text();
						break;
					case Constants.Z_IMPLEMENTATION_BUILT_IN:
						language = this.$i18n( 'wikilambda-implementation-selector-built-in' ).text();
						break;
					default:
						language = this.getLanguageOfImplementation( zid );
						if ( this.isValidZidFormat( language ) ) {
							this.fetchZids( { zids: [ language ] } );
							language = this.getLabel( language );
						}
				}
 
				// Build the table data for the implementations table
 
				tableData.push( {
					// Column 1: checkbox
					checkbox: {
						title: '',
						component: 'cdx-checkbox',
						props: {
							modelValue: this.implementationsState[ zid ].checked,
							'onUpdate:modelValue': ( value ) => {
								this.implementationsState[ zid ].checked = value;
							}
						},
						class: 'ext-wikilambda-function-details-table-item',
						id: implementationName
					},
					// Column 2: name
					name: {
						title: implementationName,
						component: 'a',
						props: {
							href: `/view/${ this.getUserLangCode }/${ zid }`
						},
						class: 'ext-wikilambda-function-details-table-item'
					},
					// Column 3: status
					state: {
						component: 'cdx-info-chip',
						title: this.$i18n( isConnected ?
							'wikilambda-function-implementation-state-approved' :
							'wikilambda-function-implementation-state-deactivated'
						).text(),
						props: {
							status: isConnected ? 'success' : 'warning'
						},
						class: 'ext-wikilambda-function-details-table-item'
					},
					// Column 4: language
					language: {
						title: language,
						class: 'ext-wikilambda-function-details-table-item'
					},
					// Column 4: passed tests
					testsPassed: {
						title: testResults.passing + '/' + testResults.total
					},
					// Row class
					class: this.implementationsState[ zid ].checked ? 'ext-wikilambda-function-details-table__row--active' : null
				} );
			}
 
			return tableData;
		},
		/**
		 * Zids of all tests for this function
		 *
		 * @return {Array}
		 */
		allTests: function () {
			return Object.keys( this.testsState );
		},
		/**
		 * Zids of all tests already connected to the function
		 *
		 * @return {Array}
		 */
		connectedTests: function () {
			return this.getConnectedTests( this.rowId );
		},
		/**
		 * Zids of all the tests visible in the table
		 *
		 * @return {Array}
		 */
		visibleTests: function () {
			return this.testsShowAll ?
				this.allTests :
				this.paginatedTests[ this.testsPage ];
		},
		/**
		 * Return the tests structured into pages
		 *
		 * @return {Object}
		 */
		paginatedTests: function () {
			return this.paginateList( this.allTests );
		},
		/**
		 * Total number of tests pages
		 *
		 * @return {number}
		 */
		testsTotalPages: function () {
			return Object.keys( this.paginatedTests ).length;
		},
		/**
		 * Whether any of the disconnected tests are checked
		 *
		 * @return {boolean}
		 */
		areProposedTestersSelected: function () {
			return Object.keys( this.testsState ).some( ( zid ) =>
				this.testsState[ zid ].checked && !this.testsState[ zid ].available );
		},
		/**
		 * Whether any of the connected tests are checked
		 *
		 * @return {boolean}
		 */
		areAvailableTestersSelected: function () {
			return Object.keys( this.testsState ).some( ( zid ) =>
				this.testsState[ zid ].checked && this.testsState[ zid ].available );
		},
		/**
		 * Returns the link for add new test page
		 *
		 * @return {string}
		 */
		addTestLink: function () {
			return new mw.Title( Constants.PATHS.CREATE_OBJECT_TITLE ).getUrl( {
				uselang: this.getUserLangCode,
				zid: Constants.Z_TESTER,
				[ Constants.Z_TESTER_FUNCTION ]: this.getCurrentZObjectId
			} );
		},
		/**
		 * Build the header row for the Implementations table
		 *
		 * @return {Object}
		 */
		testsHeader: function () {
			if ( this.visibleTests.length === 0 ) {
				return undefined;
			}
 
			const headers = {
				checkbox: {
					title: '',
					component: 'cdx-checkbox',
					props: {
						modelValue: this.areAllRowsChecked( this.testsState ),
						'onUpdate:modelValue': ( value ) => this.checkAllRows( this.testsState, value )
					},
					class: 'ext-wikilambda-function-details-table-text'
				},
				name: {
					title: this.$i18n( 'wikilambda-function-implementation-name-label' ),
					class: 'ext-wikilambda-function-details-table-text'
				},
				state: {
					title: this.$i18n( 'wikilambda-function-implementation-state-label' ),
					class: 'ext-wikilambda-function-details-table-text'
				}
			};
 
			// Add one column for each implementation selected,
			// or for all visble implementations if none are selected
			for ( const zid of this.visibleImplementations ) {
				const implementationLabel = this.getLabel( zid );
				if ( this.implementationsState[ zid ].checked || !this.areAnyImplementationsChecked ) {
					headers[ zid ] = {
						title: implementationLabel,
						class: 'ext-wikilambda-function-details-table-text'
					};
				}
			}
 
			return headers;
		},
		/**
		 * Build the content rows for the Tests table
		 *
		 * @return {Array}
		 */
		testsBody: function () {
			const tableData = [];
			for ( const zid of this.visibleTests ) {
				// Get test name or its zid if unnamed:
				const testName = this.getLabel( zid );
 
				// Get test connected state:
				const isConnected = this.connectedTests.includes( zid );
 
				// Build row data with first three columns:
				const rowData = {
					// Column 1: checkbox
					checkbox: {
						title: '',
						component: 'cdx-checkbox',
						props: {
							modelValue: this.testsState[ zid ].checked,
							'onUpdate:modelValue': ( value ) => {
								this.testsState[ zid ].checked = value;
							}
						},
						class: 'ext-wikilambda-function-details-table-item'
					},
					// Column 2: name
					name: {
						title: testName,
						component: 'a',
						props: {
							href: `/view/${ this.getUserLangCode }/${ zid }`
						},
						class: 'ext-wikilambda-function-details-table-item'
					},
					// Column 3: status
					state: {
						component: 'cdx-info-chip',
						title: this.$i18n( isConnected ?
							'wikilambda-function-tester-state-approved' :
							'wikilambda-function-tester-state-deactivated'
						).text(),
						props: {
							status: isConnected ? 'success' : 'warning'
						},
						class: 'ext-wikilambda-function-details-table-item'
					},
					// Row class
					class: this.testsState[ zid ].checked ? 'ext-wikilambda-function-details-table__row--active' : null
				};
 
				// Add a column per implementation selected
				for ( const impZid of this.visibleImplementations ) {
					if ( this.implementationsState[ impZid ].checked || !this.areAnyImplementationsChecked ) {
						rowData[ impZid ] = {
							component: 'wl-function-tester-table',
							props: {
								zFunctionId: this.getCurrentZObjectId,
								zImplementationId: impZid,
								zTesterId: zid
							},
							class: 'ext-wikilambda-function-details-table-item'
						};
					}
				}
 
				tableData.push( rowData );
			}
			return tableData;
		},
		/**
		 * Computed property to watch the value of the
		 * fetch flags. The hook will re-run the tests
		 * every time that a change is observed
		 *
		 * @return {boolean}
		 */
		fetchedObjects: function () {
			return this.implementationsFetched && this.testsFetched;
		}
	} ),
	methods: Object.assign( mapActions( [
		'connectImplementations',
		'connectTests',
		'disconnectImplementations',
		'disconnectTests',
		'fetchImplementations',
		'fetchTests',
		'fetchZids',
		'getTestResults'
	] ), {
		/**
		 * Fetches all the associated implementations and
		 * initializes the local state variables
		 */
		initializeImplementations: function () {
			// Fetch implementations for the current Function Zid
			this.fetchImplementations( this.getCurrentZObjectId ).then( ( zids ) => {
				this.setImplementationsState( zids );
				this.implementationsFetched = true;
			} );
		},
		/**
		 * Fetches all the associated tests and
		 * initializes the local state variables
		 */
		initializeTests: function () {
			// Fetch tests for the current Function Zid
			this.fetchTests( this.getCurrentZObjectId ).then( ( zids ) => {
				this.setTestsState( zids );
				this.testsFetched = true;
			} );
		},
		/**
		 * Sets the local implementations state with the properties
		 * checked (set to false) and available
		 *
		 * @param {Array|null} zids
		 */
		setImplementationsState: function ( zids = null ) {
			const allZids = zids === null ? this.allImplementations : zids;
			for ( const zid of allZids ) {
				const isConnected = this.connectedImplementations.includes( zid );
				this.implementationsState[ zid ] = {
					available: isConnected,
					checked: false
				};
			}
		},
		/**
		 * Sets the local implementations state with the properties
		 * checked (set to false) and available
		 *
		 * @param {Array|null} zids
		 */
		setTestsState: function ( zids = null ) {
			const allZids = zids === null ? this.allTests : zids;
			for ( const zid of allZids ) {
				const isConnected = this.connectedTests.includes( zid );
				this.testsState[ zid ] = {
					available: isConnected,
					checked: false
				};
			}
		},
		/**
		 * Get the set of checked implementations and connect them to the current function
		 */
		connectCheckedImplementations: function () {
			const zids = Object.keys( this.implementationsState ).filter( ( zid ) =>
				this.implementationsState[ zid ].checked && !this.implementationsState[ zid ].available );
 
			this.implementationsLoading = true;
			this.connectImplementations( {
				rowId: this.rowId,
				zids
			} ).then( () => {
				this.setImplementationsState();
			} ).catch( ( error ) => {
				this.currentToast = error.error.message;
			} ).finally( () => {
				this.implementationsLoading = false;
			} );
		},
		/**
		 * Get the set of checked implementations and disconnect them from the current function
		 */
		disconnectCheckedImplementations: function () {
			const zids = Object.keys( this.implementationsState ).filter( ( zid ) =>
				this.implementationsState[ zid ].checked && this.implementationsState[ zid ].available );
 
			this.implementationsLoading = true;
			this.disconnectImplementations( {
				rowId: this.rowId,
				zids
			} ).then( () => {
				this.setImplementationsState();
			} ).catch( ( error ) => {
				this.currentToast = error.error.message;
			} ).finally( () => {
				this.implementationsLoading = false;
			} );
		},
		/**
		 * Get the set of checked tests and connect them to the current function
		 */
		connectCheckedTests: function () {
			const zids = Object.keys( this.testsState ).filter( ( zid ) =>
				this.testsState[ zid ].checked && !this.testsState[ zid ].available );

			this.testsLoading = true;
			this.connectTests( {
				rowId: this.rowId,
				zids
			} ).then( () => {
				this.setTestsState();
			} ).catch( ( error ) => {
				this.currentToast = error.error.message;
			} ).finally( () => {
				this.testsLoading = false;
			} )E;
		},
		/**
		 * Get the set of checked tests and disconnect them from the current function
		 */
		disconnectCheckedTests: function () {
			const zids = Object.keys( this.testsState ).filter( ( zid ) =>
				this.testsState[ zid ].checked && this.testsState[ zid ].available );
 
			this.testsLoading = true;
			this.disconnectTests( {
				rowId: this.rowId,
				zids
			} ).then( () => {
				this.setTestsState();
			} ).catch( ( error ) => {
				this.currentToast = error.error.message;
			} ).finally( () => {
				this.testsLoading = false;
			} );
		},
		/**
		 * Triggers the re-run of all the tests and sets the result
		 */
		runTesters: function () {
			this.getTestResults( {
				zFunctionId: this.getCurrentZObjectId,
				zImplementations: this.allImplementations,
				zTesters: this.allTests,
				clearPreviousResults: true
			} );
		},
		/**
		 * Convert an array into a paginated object structure
		 *
		 * @param {Array} items
		 * @return {Object}
		 */
		paginateList: function ( items ) {
			const paginatedItems = {};
			let pageNum = 1;
			if ( items.length > 0 ) {
				for ( let i = 0; i < items.length; i += Constants.PAGINATION_SIZE ) {
					const endIndex = Math.min( items.length, i + Constants.PAGINATION_SIZE );
					const pageItems = items.slice( i, endIndex );
					paginatedItems[ pageNum ] = pageItems;
					pageNum++;
				}
				return paginatedItems;
			}
			return { 1: items };
		},
		/**
		 * Returns whether all the rows of the given state object are checked
		 *
		 * @param {Object} rows
		 * @return {boolean}
		 */
		areAllRowsChecked: function ( rows ) {
			return Object.keys( rows ).every( ( zid ) => rows[ zid ].checked );
		},
		/**
		 * Modifies the given state object to check or uncheck all the rows
		 *
		 * @param {Object} rows
		 * @param {boolean} value
		 */
		checkAllRows: function ( rows, value ) {
			for ( const zid in rows ) {
				rows[ zid ].checked = value;
			}
		},
		/**
		 * Sets the current page of the implementations table
		 *
		 * @param {number} page
		 */
		updateImplementationPage: function ( page ) {
			this.implementationsPage = page;
		},
		/**
		 * Sets the current page of the tests table
		 *
		 * @param {number} page
		 */
		updateTestersPage: function ( page ) {
			this.testsPage = page;
		},
		/**
		 * Toggle the view all/view less button in the implementations table
		 */
		resetImplementationView: function () {
			this.implementationsShowAll = !this.implementationsShowAll;
		},
		/**
		 * Toggle the view all/view less button in the implementations table
		 */
		resetTestersView: function () {
			this.testsShowAll = !this.testsShowAll;
		},
		/**
		 * Closes the warning toast message
		 */
		closeToast: function () {
			this.currentToast = null;
		}
	} ),
	watch: {
		fetchedObjects: function ( value ) {
			if ( value ) {
				this.runTesters();
			}
		}
	},
	mounted: function () {
		this.initializeImplementations();
		this.initializeTests();
	}
} );
</script>
 
<style lang="less">
@import '../../../ext.wikilambda.edit.variables.less';
 
.ext-wikilambda-function-details {
	display: flex;
	-webkit-flex-flow: row wrap;
	flex-flow: row wrap;
	gap: @spacing-150 @spacing-400;
 
	&__tables {
		flex: 1;
		flex-grow: 1;
		width: calc( 100% - 400px );
	}
 
	@media screen and ( max-width: @max-width-breakpoint-mobile ) {
		flex-flow: column wrap;
 
		&__tables {
			width: @size-full;
		}
	}
}
</style>