mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 18:48:08 +00:00 
			
		
		
		
	 5c18a4e7a4
			
		
	
	5c18a4e7a4
	
	
	
		
			
			* Update add-to-array and remove-from-array helpers * remove search-select-has-many, moved logic directly into mfa-login-enforcement-form (see #16470) * Replace add/remove object in MFA files - All MFA tests pass * Replace in PKI components (pki tests all passing) * Replace in core addon where applicable * glimmerize console service -- console tests pass * more replacements * update string-list, add comment to vertical-bar-chart * Refactor CSP Event service - only used one place (auth-form) so simplified that usage - glimmerize and refactor so that the tests work * small updates * more cleanup * Fix tests * Remove objectAt from console-helpers * Address PR comments * move commandIndex clearing back * Remove extra model set
		
			
				
	
	
		
			35 lines
		
	
	
		
			949 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			949 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /**
 | |
|  * Copyright (c) HashiCorp, Inc.
 | |
|  * SPDX-License-Identifier: BUSL-1.1
 | |
|  */
 | |
| 
 | |
| import { helper as buildHelper } from '@ember/component/helper';
 | |
| import { assert } from '@ember/debug';
 | |
| 
 | |
| function dedupe(items) {
 | |
|   return items.filter((v, i) => items.indexOf(v) === i);
 | |
| }
 | |
| 
 | |
| export function removeManyFromArray(array, toRemove) {
 | |
|   assert(`Both values must be an array`, Array.isArray(array) && Array.isArray(toRemove));
 | |
|   const a = [...(array || [])];
 | |
|   return a.filter((v) => !toRemove.includes(v));
 | |
| }
 | |
| 
 | |
| export function removeFromArray(array, string) {
 | |
|   assert(`Value provided is not an array`, Array.isArray(array));
 | |
|   const newArray = [...array];
 | |
|   const idx = newArray.indexOf(string);
 | |
|   if (idx >= 0) {
 | |
|     newArray.splice(idx, 1);
 | |
|   }
 | |
|   return dedupe(newArray);
 | |
| }
 | |
| 
 | |
| export default buildHelper(function ([array, string]) {
 | |
|   if (Array.isArray(string)) {
 | |
|     return removeManyFromArray(array, string);
 | |
|   }
 | |
|   return removeFromArray(array, string);
 | |
| });
 |