All files / ext.wikilambda.app/components/widgets/about About.vue

98.74% Statements 706/715
94.84% Branches 92/97
93.33% Functions 28/30
98.74% Lines 706/715

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 7161x 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 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 36x 36x 36x 36x 36x 36x 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 36x 36x 1x 1x 1x 1x 1x 1x 1x 521x 1x 1x 1x 1x 1x 1x 1x 979x 979x 979x 979x 979x 979x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 33x 1x 1x 1x 1x 1x 1x 1x 33x 1x 1x 1x 1x 1x 1x 1x 36x 1x 1x 1x 1x 1x 1x 1x 1x 479x 1x 1x 1x 1x 1x 1x 1x 1x 1x 977x 977x 977x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 2x 2x 2x 2x 2x 3x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 479x 479x 479x 479x 479x 479x 479x 266x 479x 479x 479x 479x 479x 479x 13x 13x 466x 466x 466x 476x 504x 504x     504x 504x 504x 504x 42x 42x 42x 504x 504x 504x 504x 504x 5x 5x 5x 504x 466x 466x 466x 466x 47x 47x 47x 47x 47x 47x 41x 47x 466x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1246x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 550x 550x 223x 223x 223x 223x 223x 223x 223x 223x 223x 223x 223x 550x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 5x 1x 1x 4x 1x 1x 1x 1x 1x 1x 16x 17x 17x 17x 17x 17x 17x 17x 17x 7x 7x 7x 7x 7x 7x 17x 17x 17x 3x 3x 3x 3x 3x 3x 17x 17x 17x 17x 17x 17x 4x 4x 4x 4x 4x 4x 17x 17x 17x 11x 3x 3x 3x 3x 3x 3x 11x 17x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 9x 1x 9x 8x 8x 8x 8x 8x 8x 8x 8x 8x 16x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1031x 1031x 1x 1x 1x 443x 443x 1x 1x 36x 36x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<!--
	WikiLambda Vue component - About Widget.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<wl-widget-base class="ext-wikilambda-app-about" data-testid="about-widget">
		<!-- Widget header -->
		<template #header>
			{{ $i18n( 'wikilambda-about-widget-title' ).text() }}
		</template>
		<template #header-action>
			<cdx-button
				v-if="isEditing && !edit"
				class="ext-wikilambda-app-about__button-cancel"
				action="default"
				@click="resetEditState"
			>
				{{ $i18n( 'wikilambda-cancel' ).text() }}
			</cdx-button>
			<cdx-button
				v-if="isEditing & !edit"
				class="ext-wikilambda-app-about__button-publish"
				action="progressive"
				@click="saveAllChanges"
			>
				{{ $i18n( 'wikilambda-publishnew' ).text() }}
			</cdx-button>
		</template>
 
		<!-- Widget main -->
		<template #main>
			<!-- Language accordion -->
			<cdx-accordion
				v-for="( displayLanguage, index ) in displayLanguages"
				:key="displayLanguage.zid"
				:ref="'block-' + index"
				:action-icon="( canEditObject && !displayLanguage.edit ) ? icons.cdxIconEdit : null"
				:open="displayLanguage.open"
				class="ext-wikilambda-app-about__accordion"
				action-always-visible
				data-testid="about-language-accordion"
				:action-button-label="$i18n( 'wikilambda-about-widget-edit-button' ).text()"
				@action-button-click="initializeEdit( index )"
			>
				<template #title>
					{{ displayLanguageData[ index ].title }}
				</template>
				<template #description>
					<span :class="accordionDescriptionClass( displayLanguageData[ index ].hasName )">
						{{ displayLanguageData[ index ].name }}
					</span>
				</template>
				<wl-about-language-block
					:edit="displayLanguage.edit"
					:language="displayLanguage.zid"
					:is-function="isFunction"
					:view-data="displayLanguageData[ index ].viewData"
					:edit-data="displayLanguage.editData"
					:field-langs="fieldLangs"
					@update-edit-value="updateEditValue"
					@change-value="saveFieldChange"
				></wl-about-language-block>
			</cdx-accordion>
 
			<!-- Dialogs -->
			<wl-about-languages-dialog
				:open="showLanguagesDialog"
				@add-language="addLanguage"
				@close="showLanguagesDialog = false"
			></wl-about-languages-dialog>
			<wl-publish-dialog
				v-if="!edit"
				:show-dialog="showPublishDialog"
				@close-dialog="cancelPublish"
			></wl-publish-dialog>
		</template>
 
		<!-- Widget footer -->
		<template #footer>
			<div class="ext-wikilambda-app-about__button-languages">
				<cdx-button data-testid="languages-button" @click="openLanguagesDialog">
					<cdx-icon :icon="icons.cdxIconLanguage"></cdx-icon>
					{{ $i18n( 'wikilambda-about-widget-language-count-button', languageCount ).text() }}
				</cdx-button>
			</div>
		</template>
	</wl-widget-base>
</template>
 
<script>
const { CdxAccordion, CdxButton, CdxIcon } = require( '@wikimedia/codex' );
const { defineComponent } = require( 'vue' );
const Constants = require( '../../../Constants.js' ),
	pageTitleUtils = require( '../../../mixins/pageTitleUtils.js' ),
	AboutLanguageBlock = require( './AboutLanguageBlock.vue' ),
	AboutLanguagesDialog = require( './AboutLanguagesDialog.vue' ),
	PublishDialog = require( '../publish/PublishDialog.vue' ),
	WidgetBase = require( '../../base/WidgetBase.vue' ),
	icons = require( '../../../../lib/icons.json' ),
	{ mapActions, mapGetters } = require( 'vuex' );
 
module.exports = exports = defineComponent( {
	name: 'wl-about-widget',
	components: {
		'cdx-accordion': CdxAccordion,
		'cdx-button': CdxButton,
		'cdx-icon': CdxIcon,
		'wl-about-language-block': AboutLanguageBlock,
		'wl-about-languages-dialog': AboutLanguagesDialog,
		'wl-publish-dialog': PublishDialog,
		'wl-widget-base': WidgetBase
	},
	mixins: [ pageTitleUtils ],
	props: {
		edit: {
			type: Boolean,
			required: true
		},
		type: {
			type: String,
			required: true
		}
	},
	data: function () {
		return {
			icons: icons,
			displayLanguages: [],
			showLanguagesDialog: false,
			showPublishDialog: false
		};
	},
	computed: Object.assign( mapGetters( [
		'getFallbackLanguageZids',
		'getLabelData',
		'getMultilingualDataLanguages',
		'getRowByKeyPath',
		'getUserLangZid',
		'getZArgumentLabelForLanguage',
		'getZArgumentTypeRowId',
		'getZArgumentKey',
		'getZFunctionInputs',
		'getZFunctionInputLangs',
		'getZMonolingualTextValue',
		'getZMonolingualStringsetValues',
		'getZPersistentName',
		'getZPersistentNameLangs',
		'getZPersistentDescription',
		'getZPersistentDescriptionLangs',
		'getZPersistentAlias',
		'getZPersistentAliasLangs',
		'isCreateNewPage',
		'isDirty',
		'isUserLoggedIn'
	] ), {
		/**
		 * Returns whether the user can edit the function
		 *
		 * @return {boolean}
		 */
		canEditObject: function () {
			// TODO (T301667): restrict to only certain user roles
			return this.isCreateNewPage ? true : this.isUserLoggedIn;
		},
		/**
		 * Returns whether any of the language blocks is being edited
		 *
		 * @return {boolean}
		 */
		isEditing: function () {
			return !!this.displayLanguages.find( ( item ) => item.edit );
		},
		/**
		 * Returns the available languages for each field
		 *
		 * @return {Object}
		 */
		fieldLangs: function () {
			return {
				name: this.getZPersistentNameLangs(),
				description: this.getZPersistentDescriptionLangs(),
				aliases: this.getZPersistentAliasLangs(),
				inputs: this.getZFunctionInputLangs()
			};
		},
		/**
		 * Returns a list of all the language Zids that are present in
		 * the multilingual data collection (must have at least a name,
		 * a description, a set of aliases or an input label in case the
		 * object is a function).
		 *
		 * @return {Array}
		 */
		allLangs: function () {
			return this.getMultilingualDataLanguages();
		},
		/**
		 * Returns the count of the list of unique available languages
		 *
		 * @return {number}
		 */
		languageCount: function () {
			return this.allLangs.length;
		},
		/**
		 * Returns whether the current object is a function
		 *
		 * @return {boolean}
		 */
		isFunction: function () {
			return this.type === Constants.Z_FUNCTION;
		},
		/**
		 * Returns the list of fallback languages in their Zid
		 * representation, excluding the first (user selected language)
		 *
		 * @return {Array}
		 */
		fallbackLanguageZids: function () {
			return this.getFallbackLanguageZids.slice( 1 );
		},
		/**
		 * Returns a computed array of the multilingual data for
		 * the languages selected for display, as per their persisted
		 * state in the global store.
		 *
		 * @return {Array}
		 */
		displayLanguageData: function () {
			return this.displayLanguages
				.map( ( lang ) => this.getMultilingualDataForLanguage( lang.zid ) );
		}
	} ),
	methods: Object.assign( mapActions( [
		'changeType',
		'removeItemFromTypedList',
		'resetMultilingualData',
		'setDirty',
		'setValueByRowIdAndPath'
	] ), {
		/**
		 * Opens the AboutLanguagesDialog
		 */
		openLanguagesDialog: function () {
			this.showLanguagesDialog = true;
		},
		/**
		 * Adds the selected language to the collection
		 * of displayed languages.
		 *
		 * @param {string} newLang
		 */
		addLanguage: function ( newLang ) {
			// Ignore if already displayed
			const found = this.displayLanguages.find( ( lang ) => lang.zid === newLang );
			if ( found ) {
				return;
			}
			this.displayLanguages.push( {
				zid: newLang,
				edit: this.edit,
				open: false,
				editData: this.edit ?
					this.getMultilingualDataForLanguage( newLang ).viewData :
					undefined
			} );
		},
		/**
		 * Initialize the local editable data collection for a given
		 * language block given its index.
		 *
		 * @param {number} index
		 */
		initializeEdit: function ( index ) {
			this.displayLanguages[ index ].edit = true;
			this.displayLanguages[ index ].open = true;
			this.displayLanguages[ index ].editData = JSON.parse( JSON.stringify(
				this.displayLanguageData[ index ].viewData
			) );
			this.$emit( 'edit-multilingual-data' );
		},
		/**
		 * Restores original view state and cancels publish
		 * action. This only happens when we are in a view page
		 * and after editing information, we proceed to publish
		 * and then we cancel.
		 */
		cancelPublish: function () {
			if ( this.isDirty ) {
				this.resetMultilingualData();
			}
			this.showPublishDialog = false;
		},
		/**
		 * Initializes the collection of languages to display in
		 * the About widget, according to the following logic:
		 * * The user language will always be shown first, in an expanded state.
		 * * If the user language doesn't have complete multilingual data, one or
		 *   more fallback languges will be added to the display.
		 * Each item also includes their local state:
		 * * edit state flag
		 * * edit data values
		 */
		initializeDisplayLanguages: function () {
			// 1. Always start with user language
			this.displayLanguages = [ {
				zid: this.getUserLangZid,
				edit: this.edit,
				open: true,
				editData: this.edit ?
					this.getMultilingualDataForLanguage( this.getUserLangZid ).viewData :
					undefined
			} ];
 
			// 2. If important info in main language is complete, exit
			let missingName = !this.fieldLangs.name.includes( this.getUserLangZid );
			let missingInputs = this.fieldLangs.inputs.filter( ( langs ) => !langs.includes( this.getUserLangZid ) );
			if ( !missingName && missingInputs.length === 0 ) {
				return;
			}
 
			// 3. Collect fallback languages to cover up for missing fields
			let addBlocks = [];
			for ( const langZid of this.fallbackLanguageZids ) {
				// 3.1. If everything is complete, exit loop
				if ( !missingName && missingInputs.length === 0 ) {
					break;
				}
 
				// 3.2. If we are still missing a fallback name, check if we have it in this language
				if ( missingName ) {
					if ( this.fieldLangs.name.includes( langZid ) ) {
						addBlocks.push( langZid );
						missingName = false;
					}
				}
 
				// 3.3. For each missing input labels, check if we have it in this language
				const availableInputs = missingInputs.filter( ( input ) => input.includes( langZid ) );
				if ( availableInputs.length > 0 ) {
					addBlocks.push( langZid );
					missingInputs = missingInputs.filter( ( input ) => !input.includes( langZid ) );
				}
			}
 
			// 4. Remove duplicates and add fallback languages to language blocks
			addBlocks = [ ...new Set( addBlocks ) ];
			addBlocks.forEach( ( langZid ) => {
				this.displayLanguages.push( {
					zid: langZid,
					edit: this.edit,
					open: false,
					editData: this.edit ?
						this.getMultilingualDataForLanguage( langZid ).viewData :
						undefined
				} );
			} );
		},
		/**
		 * Returns a collection fo all multilingual data fields and
		 * their values for a given language
		 *
		 * @param {string} langZid
		 * @return {Object}
		 */
		getMultilingualDataForLanguage: function ( langZid ) {
			const nameRow = this.getZPersistentName( langZid );
			const descriptionRow = this.getZPersistentDescription( langZid );
			const aliasesRow = this.getZPersistentAlias( langZid );
			const inputs = this.isFunction ? this.getInputMultilingualData( langZid ) : [];
 
			const data = {
				name: {
					rowId: nameRow ? nameRow.id : undefined,
					value: nameRow ? this.getZMonolingualTextValue( nameRow.id ) : ''
				},
				description: {
					rowId: descriptionRow ? descriptionRow.id : undefined,
					value: descriptionRow ? this.getZMonolingualTextValue( descriptionRow.id ) : ''
				},
				aliases: {
					rowId: aliasesRow ? aliasesRow.id : undefined,
					value: aliasesRow ? this.getZMonolingualStringsetValues( aliasesRow.id ) : []
				},
				inputs
			};
 
			return {
				title: this.getLabelData( langZid ).label,
				hasName: !!data.name.value,
				name: data.name.value || this.$i18n( 'wikilambda-editor-default-name' ).text(),
				viewData: data
			};
		},
		/**
		 * Returns the array of input data: its label for a given language (if any)
		 * and general input information (key, type rowId, etc.). The results are
		 * sorted by the input key.
		 *
		 * @param {string} langZid
		 * @return {Array}
		 */
		getInputMultilingualData: function ( langZid ) {
			const inputs = this.getZFunctionInputs();
			return inputs.map( ( row ) => {
				const typeRowId = this.getZArgumentTypeRowId( row.id );
				const key = this.getZArgumentKey( row.id );
				const labelRow = this.getZArgumentLabelForLanguage( row.id, langZid );
				const label = labelRow ? this.getZMonolingualTextValue( labelRow.id ) : '';
				return {
					key,
					value: label,
					inputRowId: row.id,
					labelRowId: labelRow ? labelRow.id : undefined,
					typeRowId
				};
			} ).sort( ( a, b ) => ( a.key < b.key ) ? -1 : ( b.key < a.key ) ? 1 : 0 );
		},
		/**
		 * Discards all edits and sets all language blocks to view mode.
		 */
		resetEditState: function () {
			this.displayLanguages.forEach( ( lang ) => {
				lang.edit = false;
				lang.editData = undefined;
			} );
		},
		/**
		 * Only in view pages:
		 * Persists all accummulated changes in the store and initiates publish process
		 */
		saveAllChanges: function () {
			if ( this.edit ) {
				return;
			}
			this.persistState();
			this.showPublishDialog = true;
		},
		/**
		 * Only in edit page:
		 * Persists a field change in the store and updates the page title if needed
		 */
		saveFieldChange: function () {
			if ( !this.edit ) {
				return;
			}
			this.persistState();
		},
		/**
		 * For each language being edited, persists all changes
		 * in the store.
		 */
		persistState: function () {
			this.displayLanguages.forEach( ( lang, index ) => {
				// If language block is in edit mode, persist
				// all changes that have a different edit and view value.
				if ( lang.edit ) {
					const viewData = this.displayLanguageData[ index ].viewData;
					const editData = this.displayLanguages[ index ].editData;
 
					// Persist name if it changed
					if ( viewData.name.value !== editData.name.value ) {
						this.persistName(
							viewData.name.rowId,
							editData.name.value,
							lang.zid
						);
					}
 
					// Persist description if it changed
					if ( viewData.description.value !== editData.description.value ) {
						this.persistDescription(
							viewData.description.rowId,
							editData.description.value,
							lang.zid
						);
					}
 
					// Persist aliases if they changed
					if (
						JSON.stringify( viewData.aliases.value ) !==
						JSON.stringify( editData.aliases.value )
					) {
						this.persistAlias(
							viewData.aliases.rowId,
							editData.aliases.value,
							lang.zid
						);
					}
 
					// Persist input labels if they changed
					for ( const input in editData.inputs ) {
						if ( viewData.inputs[ input ].value !== editData.inputs[ input ].value ) {
							this.persistInputLabel(
								viewData.inputs[ input ],
								editData.inputs[ input ].value,
								lang.zid
							);
						}
					}
				}
			} );
		},
		/**
		 * Persist in the global state a new value for name in the given language
		 *
		 * @param {number} rowId
		 * @param {string} value
		 * @param {string} langZid
		 */
		persistName: function ( rowId, value, langZid ) {
			const parentRowId = this.getRowByKeyPath( [
				Constants.Z_PERSISTENTOBJECT_LABEL,
				Constants.Z_MULTILINGUALSTRING_VALUE
			] ).id;
			this.persistZMonolingualString(
				parentRowId,
				rowId,
				value,
				langZid
			);
			// After persisting in the state, update the page title
			this.updatePageTitle();
		},
		/**
		 * Persist in the global state a new value for description in the given language
		 *
		 * @param {number} rowId
		 * @param {string} value
		 * @param {string} langZid
		 */
		persistDescription: function ( rowId, value, langZid ) {
			const parentRowId = this.getRowByKeyPath( [
				Constants.Z_PERSISTENTOBJECT_DESCRIPTION,
				Constants.Z_MULTILINGUALSTRING_VALUE
			] ).id;
			this.persistZMonolingualString(
				parentRowId,
				rowId,
				value,
				langZid
			);
		},
		/**
		 * Persist in the global state a new value for aliases in the given language
		 *
		 * @param {number} rowId
		 * @param {Array} values
		 * @param {string} langZid
		 */
		persistAlias: function ( rowId, values, langZid ) {
			const parentRowId = this.getRowByKeyPath( [
				Constants.Z_PERSISTENTOBJECT_ALIASES,
				Constants.Z_MULTILINGUALSTRINGSET_VALUE
			] ).id;
			this.persistZMonolingualStringset(
				parentRowId,
				rowId,
				values.map( ( a ) => a.value ),
				langZid
			);
		},
		/**
		 * Persist in the global state a new value for an input label in the given language
		 *
		 * @param {Object} inputData
		 * @param {number} inputData.inputRowId
		 * @param {number} inputData.labelRowId
		 * @param {string} value
		 * @param {string} langZid
		 */
		persistInputLabel: function ( inputData, value, langZid ) {
			const parentRowId = this.getRowByKeyPath( [
				Constants.Z_ARGUMENT_LABEL,
				Constants.Z_MULTILINGUALSTRING_VALUE
			], inputData.inputRowId ).id;
			this.persistZMonolingualString(
				parentRowId,
				inputData.labelRowId,
				value,
				langZid
			);
		},
		/**
		 * Persists ZMonolingualString changes in the data store.
		 * These can be changes to the Name/Z2K3 and Description/Z2K5 fields,
		 * as well as the input labels if the object is a function.
		 *
		 * TODO: take out into a mixin and factorize with FunctionEditor components
		 *
		 * @param {number} parentRowId identifies the parent multilingual value row Id
		 * @param {number|undefined} currentRowId identifies the current monolingual value row Id
		 * @param {string} value
		 * @param {string} langZid
		 */
		persistZMonolingualString: function ( parentRowId, currentRowId, value, langZid ) {
			this.setDirty( true );
 
			if ( currentRowId ) {
				if ( value === '' ) {
					this.removeItemFromTypedList( { rowId: currentRowId } );
				} else {
					this.setValueByRowIdAndPath( {
						rowId: currentRowId,
						keyPath: [
							Constants.Z_MONOLINGUALSTRING_VALUE,
							Constants.Z_STRING_VALUE
						],
						value
					} );
				}
			} else {
				// If currentRowId is null, there's no monolingual string
				// for the given language, so we create a new monolingual string
				// with the new value and append to the parent list.
				this.changeType( {
					id: parentRowId,
					type: Constants.Z_MONOLINGUALSTRING,
					lang: langZid,
					value,
					append: true
				} );
			}
		},
		/**
		 * Persists ZMonolingualStringset changes in the data store.
		 * These correspond to the Aliases/Z2K4 field.
		 *
		 * TODO: take out into a mixin and factorize with FunctionEditor components
		 *
		 * @param {number} parentRowId identifies the parent multilingual stringset value row Id
		 * @param {number|undefined} currentRowId current monolingual stringset row Id
		 * @param {Array} values list of alias to persist
		 * @param {string} langZid
		 */
		persistZMonolingualStringset: function ( parentRowId, currentRowId, values, langZid ) {
			this.setDirty( true );
 
			if ( currentRowId ) {
				if ( values.length === 0 ) {
					this.removeItemFromTypedList( { rowId: currentRowId } );
				} else {
					this.setValueByRowIdAndPath( {
						rowId: currentRowId,
						keyPath: [ Constants.Z_MONOLINGUALSTRINGSET_VALUE ],
						value: [ Constants.Z_STRING, ...values ]
					} );
				}
			} else {
				// If currentRowId is undefined, there's no monolingual stringset
				// for the given language, so we create a new monolingual stringset
				// with the new value and append to the parent list.
				this.changeType( {
					id: parentRowId,
					type: Constants.Z_MONOLINGUALSTRINGSET,
					lang: langZid,
					value: values,
					append: true
				} );
			}
		},
		/**
		 * Persists locally all the changes in the Language Block fields
		 *
		 * @param {Object} payload
		 * @param {Object} payload.data
		 * @param {Array|string} payload.value
		 */
		updateEditValue: function ( payload ) {
			payload.data.value = payload.value;
		},
		/**
		 * Returns special class for the accordion description
		 * depending on the availability of the title.
		 *
		 * @param {boolean} hasName
		 * @return {string}
		 */
		accordionDescriptionClass: function ( hasName ) {
			return hasName ? '' : 'ext-wikilambda-app-about__accordion--untitled';
		}
	} ),
	watch: {
		fallbackLanguageZids: function () {
			this.initializeDisplayLanguages();
		}
	},
	mounted: function () {
		this.initializeDisplayLanguages();
	}
} );
</script>
 
<style lang="less">
@import '../../../ext.wikilambda.app.variables.less';
 
.ext-wikilambda-app-about {
	.ext-wikilambda-app-about__accordion--untitled {
		color: @color-placeholder;
	}
 
	.ext-wikilambda-app-about__button-languages {
		margin-top: @spacing-125;
	}
 
	.ext-wikilambda-app-about__button-cancel {
		margin-right: @spacing-50;
	}
 
	.ext-wikilambda-app-about__button-publish {
		margin-right: @spacing-25;
	}
}
</style>