How to use alias method in storybook-root

Best JavaScript code snippet using storybook-root

alias-controller.ts

Source:alias-controller.ts Github

copy

Full Screen

1///2/// Copyright © 2016-2022 The Thingsboard Authors3///4/// Licensed under the Apache License, Version 2.0 (the "License");5/// you may not use this file except in compliance with the License.6/// You may obtain a copy of the License at7///8/// http://www.apache.org/licenses/LICENSE-2.09///10/// Unless required by applicable law or agreed to in writing, software11/// distributed under the License is distributed on an "AS IS" BASIS,12/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13/// See the License for the specific language governing permissions and14/// limitations under the License.15///16import { AliasInfo, IAliasController, StateControllerHolder, StateEntityInfo } from '@core/api/widget-api.models';17import { forkJoin, Observable, of, ReplaySubject, Subject } from 'rxjs';18import { Datasource, DatasourceType, datasourceTypeTranslationMap } from '@app/shared/models/widget.models';19import { deepClone, isDefinedAndNotNull, isEqual } from '@core/utils';20import { EntityService } from '@core/http/entity.service';21import { UtilsService } from '@core/services/utils.service';22import { AliasFilterType, EntityAliases, SingleEntityFilter } from '@shared/models/alias.models';23import { EntityInfo } from '@shared/models/entity.models';24import { map, mergeMap } from 'rxjs/operators';25import {26 createDefaultEntityDataPageLink,27 Filter, FilterInfo, filterInfoToKeyFilters, Filters, KeyFilter, singleEntityDataPageLink,28 updateDatasourceFromEntityInfo29} from '@shared/models/query/query.models';30import { TranslateService } from '@ngx-translate/core';31export class AliasController implements IAliasController {32 entityAliasesChangedSubject = new Subject<Array<string>>();33 entityAliasesChanged: Observable<Array<string>> = this.entityAliasesChangedSubject.asObservable();34 filtersChangedSubject = new Subject<Array<string>>();35 filtersChanged: Observable<Array<string>> = this.filtersChangedSubject.asObservable();36 private entityAliasResolvedSubject = new Subject<string>();37 entityAliasResolved: Observable<string> = this.entityAliasResolvedSubject.asObservable();38 entityAliases: EntityAliases;39 filters: Filters;40 userFilters: Filters;41 resolvedAliases: {[aliasId: string]: AliasInfo} = {};42 resolvedAliasesObservable: {[aliasId: string]: Observable<AliasInfo>} = {};43 resolvedAliasesToStateEntities: {[aliasId: string]: StateEntityInfo} = {};44 constructor(private utils: UtilsService,45 private entityService: EntityService,46 private translate: TranslateService,47 private stateControllerHolder: StateControllerHolder,48 private origEntityAliases: EntityAliases,49 private origFilters: Filters) {50 this.entityAliases = deepClone(this.origEntityAliases) || {};51 this.filters = deepClone(this.origFilters) || {};52 this.userFilters = {};53 }54 updateEntityAliases(newEntityAliases: EntityAliases) {55 const changedAliasIds: Array<string> = [];56 for (const aliasId of Object.keys(newEntityAliases)) {57 const newEntityAlias = newEntityAliases[aliasId];58 const prevEntityAlias = this.entityAliases[aliasId];59 if (!isEqual(newEntityAlias, prevEntityAlias)) {60 changedAliasIds.push(aliasId);61 this.setAliasUnresolved(aliasId);62 }63 }64 for (const aliasId of Object.keys(this.entityAliases)) {65 if (!newEntityAliases[aliasId]) {66 changedAliasIds.push(aliasId);67 this.setAliasUnresolved(aliasId);68 }69 }70 this.entityAliases = deepClone(newEntityAliases);71 if (changedAliasIds.length) {72 this.entityAliasesChangedSubject.next(changedAliasIds);73 }74 }75 updateFilters(newFilters: Filters) {76 const changedFilterIds: Array<string> = [];77 for (const filterId of Object.keys(newFilters)) {78 const newFilter = newFilters[filterId];79 const prevFilter = this.filters[filterId];80 if (!isEqual(newFilter, prevFilter)) {81 changedFilterIds.push(filterId);82 }83 }84 for (const filterId of Object.keys(this.filters)) {85 if (!newFilters[filterId]) {86 changedFilterIds.push(filterId);87 }88 }89 this.filters = deepClone(newFilters);90 if (changedFilterIds.length) {91 for (const filterId of changedFilterIds) {92 delete this.userFilters[filterId];93 }94 this.filtersChangedSubject.next(changedFilterIds);95 }96 }97 updateAliases(aliasIds?: Array<string>) {98 if (!aliasIds) {99 aliasIds = [];100 for (const aliasId of Object.keys(this.resolvedAliases)) {101 aliasIds.push(aliasId);102 }103 }104 const tasks: Observable<AliasInfo>[] = [];105 for (const aliasId of aliasIds) {106 this.setAliasUnresolved(aliasId);107 tasks.push(this.getAliasInfo(aliasId));108 }109 forkJoin(tasks).subscribe(() => {110 this.entityAliasesChangedSubject.next(aliasIds);111 });112 }113 dashboardStateChanged() {114 const changedAliasIds: Array<string> = [];115 for (const aliasId of Object.keys(this.resolvedAliasesToStateEntities)) {116 const stateEntityInfo = this.resolvedAliasesToStateEntities[aliasId];117 const newEntityId = this.stateControllerHolder().getEntityId(stateEntityInfo.entityParamName);118 const prevEntityId = stateEntityInfo.entityId;119 if (!isEqual(newEntityId, prevEntityId)) {120 changedAliasIds.push(aliasId);121 this.setAliasUnresolved(aliasId);122 }123 }124 if (changedAliasIds.length) {125 this.entityAliasesChangedSubject.next(changedAliasIds);126 }127 }128 setAliasUnresolved(aliasId: string) {129 delete this.resolvedAliases[aliasId];130 delete this.resolvedAliasesObservable[aliasId];131 delete this.resolvedAliasesToStateEntities[aliasId];132 }133 getEntityAliases(): EntityAliases {134 return this.entityAliases;135 }136 getFilters(): Filters {137 return this.filters;138 }139 getFilterInfo(filterId: string): FilterInfo {140 if (this.userFilters[filterId]) {141 return this.userFilters[filterId];142 } else {143 return this.filters[filterId];144 }145 }146 getKeyFilters(filterId: string): Array<KeyFilter> {147 const filter = this.getFilterInfo(filterId);148 if (filter) {149 return filterInfoToKeyFilters(filter);150 } else {151 return [];152 }153 }154 getEntityAliasId(aliasName: string): string {155 for (const aliasId of Object.keys(this.entityAliases)) {156 const alias = this.entityAliases[aliasId];157 if (alias.alias === aliasName) {158 return aliasId;159 }160 }161 return null;162 }163 getAliasInfo(aliasId: string): Observable<AliasInfo> {164 let aliasInfo = this.resolvedAliases[aliasId];165 if (aliasInfo) {166 return of(aliasInfo);167 } else if (this.resolvedAliasesObservable[aliasId]) {168 return this.resolvedAliasesObservable[aliasId];169 } else {170 const resolvedAliasSubject = new ReplaySubject<AliasInfo>();171 this.resolvedAliasesObservable[aliasId] = resolvedAliasSubject.asObservable();172 const entityAlias = this.entityAliases[aliasId];173 if (entityAlias) {174 this.entityService.resolveAlias(entityAlias, this.stateControllerHolder().getStateParams()).subscribe(175 (resolvedAliasInfo) => {176 this.resolvedAliases[aliasId] = resolvedAliasInfo;177 delete this.resolvedAliasesObservable[aliasId];178 if (resolvedAliasInfo.stateEntity) {179 this.resolvedAliasesToStateEntities[aliasId] = {180 entityParamName: resolvedAliasInfo.entityParamName,181 entityId: this.stateControllerHolder().getEntityId(resolvedAliasInfo.entityParamName)182 };183 }184 this.entityAliasResolvedSubject.next(aliasId);185 resolvedAliasSubject.next(resolvedAliasInfo);186 resolvedAliasSubject.complete();187 },188 () => {189 resolvedAliasSubject.error(null);190 delete this.resolvedAliasesObservable[aliasId];191 }192 );193 } else {194 resolvedAliasSubject.error(null);195 const res = this.resolvedAliasesObservable[aliasId];196 delete this.resolvedAliasesObservable[aliasId];197 return res;198 }199 aliasInfo = this.resolvedAliases[aliasId];200 if (aliasInfo) {201 return of(aliasInfo);202 } else {203 return this.resolvedAliasesObservable[aliasId];204 }205 }206 }207 resolveSingleEntityInfo(aliasId: string): Observable<EntityInfo> {208 return this.getAliasInfo(aliasId).pipe(209 mergeMap((aliasInfo) => {210 if (aliasInfo.resolveMultiple) {211 if (aliasInfo.entityFilter) {212 return this.entityService.findSingleEntityInfoByEntityFilter(aliasInfo.entityFilter,213 {ignoreLoading: true, ignoreErrors: true});214 } else {215 return of(null);216 }217 } else {218 return of(aliasInfo.currentEntity);219 }220 })221 );222 }223 private resolveDatasource(datasource: Datasource, forceFilter = false): Observable<Datasource> {224 const newDatasource = deepClone(datasource);225 if (newDatasource.type === DatasourceType.entity || newDatasource.type === DatasourceType.entityCount) {226 if (newDatasource.filterId) {227 newDatasource.keyFilters = this.getKeyFilters(newDatasource.filterId);228 }229 if (newDatasource.entityAliasId) {230 return this.getAliasInfo(newDatasource.entityAliasId).pipe(231 mergeMap((aliasInfo) => {232 newDatasource.aliasName = aliasInfo.alias;233 if (!aliasInfo.entityFilter) {234 newDatasource.unresolvedStateEntity = true;235 newDatasource.name = 'Unresolved';236 newDatasource.entityName = 'Unresolved';237 return of(newDatasource);238 }239 if (aliasInfo.resolveMultiple) {240 newDatasource.entityFilter = aliasInfo.entityFilter;241 if (forceFilter) {242 return this.entityService.findSingleEntityInfoByEntityFilter(aliasInfo.entityFilter,243 {ignoreLoading: true, ignoreErrors: true}).pipe(244 map((entity) => {245 if (entity) {246 updateDatasourceFromEntityInfo(newDatasource, entity, true);247 }248 return newDatasource;249 })250 );251 } else {252 return of(newDatasource);253 }254 } else {255 if (aliasInfo.currentEntity) {256 updateDatasourceFromEntityInfo(newDatasource, aliasInfo.currentEntity, true);257 } else if (aliasInfo.stateEntity) {258 newDatasource.unresolvedStateEntity = true;259 newDatasource.name = 'Unresolved';260 newDatasource.entityName = 'Unresolved';261 }262 return of(newDatasource);263 }264 })265 );266 } else if (newDatasource.entityId && !newDatasource.entityFilter) {267 newDatasource.entityFilter = {268 singleEntity: {269 id: newDatasource.entityId,270 entityType: newDatasource.entityType,271 },272 type: AliasFilterType.singleEntity273 } as SingleEntityFilter;274 return of(newDatasource);275 } else {276 newDatasource.aliasName = newDatasource.entityName;277 newDatasource.name = newDatasource.entityName;278 return of(newDatasource);279 }280 } else {281 return of(newDatasource);282 }283 }284 resolveAlarmSource(alarmSource: Datasource): Observable<Datasource> {285 return this.resolveDatasource(alarmSource).pipe(286 map((datasource) => {287 if (datasource.type === DatasourceType.function) {288 let name: string;289 if (datasource.name && datasource.name.length) {290 name = datasource.name;291 } else {292 name = DatasourceType.function;293 }294 datasource.name = name;295 datasource.aliasName = name;296 datasource.entityName = name;297 }298 return datasource;299 })300 );301 }302 resolveDatasources(datasources: Array<Datasource>, singleEntity?: boolean, pageSize = 1024): Observable<Array<Datasource>> {303 if (!datasources || !datasources.length) {304 return of([]);305 }306 const toResolve = singleEntity ? [datasources[0]] : datasources;307 const observables = new Array<Observable<Datasource>>();308 toResolve.forEach((datasource) => {309 observables.push(this.resolveDatasource(datasource));310 });311 return forkJoin(observables).pipe(312 map((result) => {313 let functionIndex = 0;314 let entityCountIndex = 0;315 result.forEach((datasource) => {316 if (datasource.type === DatasourceType.function || datasource.type === DatasourceType.entityCount) {317 let name: string;318 if (datasource.name && datasource.name.length) {319 name = datasource.name;320 } else {321 if (datasource.type === DatasourceType.function) {322 functionIndex++;323 } else {324 entityCountIndex++;325 }326 name = this.translate.instant(datasourceTypeTranslationMap.get(datasource.type));327 if (datasource.type === DatasourceType.function && functionIndex > 1) {328 name += ' ' + functionIndex;329 } else if (datasource.type === DatasourceType.entityCount && entityCountIndex > 1) {330 name += ' ' + entityCountIndex;331 }332 }333 datasource.name = name;334 datasource.aliasName = name;335 datasource.entityName = name;336 } else {337 if (singleEntity) {338 datasource.pageLink = deepClone(singleEntityDataPageLink);339 } else if (!datasource.pageLink) {340 pageSize = isDefinedAndNotNull(pageSize) && pageSize > 0 ? pageSize : 1024;341 datasource.pageLink = createDefaultEntityDataPageLink(pageSize);342 }343 }344 });345 return result;346 })347 );348 }349 getInstantAliasInfo(aliasId: string): AliasInfo {350 return this.resolvedAliases[aliasId];351 }352 updateCurrentAliasEntity(aliasId: string, currentEntity: EntityInfo) {353 const aliasInfo = this.resolvedAliases[aliasId];354 if (aliasInfo) {355 const prevCurrentEntity = aliasInfo.currentEntity;356 if (!isEqual(currentEntity, prevCurrentEntity)) {357 aliasInfo.currentEntity = currentEntity;358 this.entityAliasesChangedSubject.next([aliasId]);359 }360 }361 }362 updateUserFilter(filter: Filter) {363 let prevUserFilter = this.userFilters[filter.id];364 if (!prevUserFilter) {365 prevUserFilter = this.filters[filter.id];366 }367 if (prevUserFilter && !isEqual(prevUserFilter, filter)) {368 this.userFilters[filter.id] = filter;369 this.filtersChangedSubject.next([filter.id]);370 }371 }...

Full Screen

Full Screen

alias.js

Source:alias.js Github

copy

Full Screen

1/**2 * There are basically two kinds of alias in CLDR:3 * 1. locale alias e.g.4 * in xml, <alias source="locale" path="......"/>,5 * in gernated JSON bunle, xxxx@localeAlias:{'target':'xxx', 'bundle':'xxxx'}6 * 2. other locale alias e.g.7 * in xml, currently only like <alias source="fr" path="//ldml"/>8 * #1 is supported by this 'alias.js',9 * #2 is covered by 'specialLocale.js' and may need enhancement for future CLDR versions.10 */11djConfig={baseUrl: "../../../dojo/", paths: {"dojo/_base/xhr": "../util/buildscripts/cldr/xhr"}};12load("../../../dojo/dojo.js");13load("../jslib/logger.js");14load("../jslib/fileUtil.js");15load("cldrUtil.js");16dojo.require("dojo.i18n");17var dir/*String*/ = arguments[0];// ${dojo}/dojo/cldr/nls18var logDir = arguments[1];19var logStr = "";20//Add new bundles to the list so that they will be aliased according to the ldml spec.21var BUNDLES = ['gregorian','hebrew','islamic','islamic-civil','buddhist','persian'];22var LOCALE_ALIAS_MARK = '@localeAlias';23var LOCALE_ALIAS_SOURCE_PROPERTY = 'source';24var LOCALE_ALIAS_TARGET_PROPERTY = 'target';25var LOCALE_ALIAS_TARGET_BUNDLE = 'bundle';26var localeAliasPaths = [];/**/27var records = {};/*{property : boolean}, record whether a property has been calculated for alias path*/28var updated = false;29print('alias.js...');30for(var i = 0; i < BUNDLES.length; i++){31 var regExp = new RegExp('\/' + BUNDLES[i] + '\.js$'); //e.g. new RegExp('\/gregorian\.js$')32 var fileList = fileUtil.getFilteredFileList(dir, regExp, true);33 34 for(var j = 0; j < fileList.length; j++){35 var jsFileName = new String(fileList[j]); //Java String36 var jsFilePath = jsFileName.split("/");37 var locale = jsFilePath[jsFilePath.length-2];38 if(locale=="nls"){continue;} // no need for root bundle39 try{40// dojo.i18n._requireLocalization('dojo.cldr', BUNDLES[i], locale); //declare bundle41 var bundle = dojo.i18n.getLocalization('dojo.cldr', BUNDLES[i], locale); //get bundle42 var nativeSrcBundle = getNativeBundle(jsFileName);//bundle not flattened43 }catch(e){/*logStr += "alias: an exception occurred: "+e;/* simply ignore if no bundle found*/}44 45 if(!bundle) continue;46 47 updated = false;48 //logStr += locale + ":" + BUNDLES[i] + "=========================================================================\n";49 50 _calculateAliasPath(bundle, BUNDLES[i]);51 //logStr += "all alias paths=" + dojo.toJson(localeAliasPaths) + "\n";52 53 _processLocaleAlias(localeAliasPaths, bundle, nativeSrcBundle,locale);54 55 if(updated){56 fileUtil.saveUtf8File(jsFileName, "(" + dojo.toJson(nativeSrcBundle, true) + ")");57 }58 //logStr += '\n';59 }60 cleanLocaleAlias(fileList);61}62//fileUtil.saveUtf8File(logDir + '/alias.log',logStr+'\n');63//print('CLDR finished, please refer to logs at ' + logDir + ' for more details.');64function _calculateAliasPath(bundle, name/*String*/){65 for(p in bundle){66 var index = p.indexOf(LOCALE_ALIAS_MARK);67 if(index >= 0 /*p like 'xxx@localeAlias6'*/){68 var localeAliasSource/*String*/ = p.substring(0,index);69 if(records[localeAliasSource]/*calculated*/){70 //logStr += p + " has been calculated, ignored\n"71 continue;72 }73 74 var path = [];75 var aliasIndex = new Number(p.substring(index + LOCALE_ALIAS_MARK.length));76 //logStr += "aliasIndex for " + p + " is " + aliasIndex + "\n";77 var i = aliasIndex;78 while(bundle[localeAliasSource + LOCALE_ALIAS_MARK + (--i)]){}79 80 var src = localeAliasSource;81 while(bundle[localeAliasSource + LOCALE_ALIAS_MARK + (++i)]){82 var mapping = {};83 mapping[LOCALE_ALIAS_SOURCE_PROPERTY] = src;84 mapping[LOCALE_ALIAS_TARGET_PROPERTY] = bundle[localeAliasSource + LOCALE_ALIAS_MARK + i][LOCALE_ALIAS_TARGET_PROPERTY];85 mapping[LOCALE_ALIAS_TARGET_BUNDLE] = bundle[localeAliasSource + LOCALE_ALIAS_MARK + i][LOCALE_ALIAS_TARGET_BUNDLE];86 //whether aliased to the bundle itself87 mapping.inSelf = mapping[LOCALE_ALIAS_TARGET_BUNDLE] === name;88 path.push(mapping);89 records[src] = true;90 src = bundle[localeAliasSource + LOCALE_ALIAS_MARK + i][LOCALE_ALIAS_TARGET_PROPERTY];91 }92 path = path.reverse();93 //logStr += "alias path calucated for " + localeAliasSource + "=" + dojo.toJson(path) + "\n";94 localeAliasPaths.push(path);95 }96 }97}98function _processLocaleAlias(localeAliasPaths/*Array*/, bundle/*JSON Obj*/, nativeSrcBundle/*JSON Obj*/,locale/*String*/){99 // summary:100 // Update all properties as defined by 'locale' alias mapping101 // E.g.'months-format-abbr@localeAlias6':{'target':"months-format-wide", 'bundle':"gregorian"},102 // means the array values of 'months-format-abbr' in current bundle should be103 // merged with(inherit or overwrite) that of 'months-format-wide' in 'gregorian' bundle104 //105 // Note: Currently no bundle recognition, always assume 'gregorian'.106 var processed = {};107 for(var i = 0; i < localeAliasPaths.length; i++){108 var path = localeAliasPaths[i];109 for(var j = 0; j < path.length; j++){110 var mapping = path[j];111 if(mapping.inSelf && mapping[LOCALE_ALIAS_SOURCE_PROPERTY] != mapping[LOCALE_ALIAS_TARGET_PROPERTY]112 && bundle[mapping[LOCALE_ALIAS_TARGET_PROPERTY]]/*target existed*/){113 //e.g. {'source':'months-format-abbr','target':"months-format-wide",'bundle':"gregorian"},114 //currently source and target bundles are the same - gregorian115 if(processed[mapping[LOCALE_ALIAS_SOURCE_PROPERTY]]){/*haven't been processed*/116 //logStr += "!" + mapping[LOCALE_ALIAS_SOURCE_PROPERTY] +" has been processed for alias, escaped\n";117 continue;118 }119 _updateLocaleAlias(bundle, mapping[LOCALE_ALIAS_SOURCE_PROPERTY], bundle,120 mapping[LOCALE_ALIAS_TARGET_PROPERTY], nativeSrcBundle);121 processed[mapping[LOCALE_ALIAS_SOURCE_PROPERTY]] = true;122 }else if(!mapping.inSelf){123 //For other non-gregorian calendars. e.g. "hebrew" etc.124 //Get the bundle according to the locale.125 var targetBundle = dojo.i18n.getLocalization('dojo.cldr', mapping[LOCALE_ALIAS_TARGET_BUNDLE], locale);126 if(processed[mapping[LOCALE_ALIAS_SOURCE_PROPERTY]]){//If being processed, continue;127 continue;128 }129 _updateNoneGregAlias(bundle, mapping[LOCALE_ALIAS_SOURCE_PROPERTY], targetBundle,130 mapping[LOCALE_ALIAS_TARGET_PROPERTY], nativeSrcBundle);131 processed[mapping[LOCALE_ALIAS_SOURCE_PROPERTY]] = true;132 }133 }134 }135}136/*137* This function will flatten the source bundle for non-gregorian ones by searching in the bundle files generated from the ldml spec which have terms like:138* "'months-standAlone-abbr@localeAlias131':{'target':"months-format-abbr",'bundle':"hebrew"},".139* Parameters:140* sourceBundle: The bundles which need to be aliased.141* aliasSource: The source mark string. 'months-standAlone-abbr' for example.142* targetBundle: The aliased bundle. 'hebrew' for example.143* aliasTarget: The target mark string. 'months-format-abbr' for example.144* nativeSrcBundle: The final flattened bundle file.145* According to the dojo way of fetching resource bundle, this function will firstly check the bundle under the appointed146* locale. If the wanted calendar bundle is not under the locale, the root calendar bundle will be fetched. If the non-gregorian147* bundle in the root can not be found, dojo will finally get the root gregorian bundle.148*/149function _updateNoneGregAlias(sourceBundle/*JSON Obj*/, aliasSource/*String*/, targetBundle/*JSON Obj*/, aliasTarget/*String*/, nativeSrcBundle/*JSON Obj*/){150 for (var sKey in sourceBundle) {151 var target = targetBundle[sKey],152 source = sourceBundle[sKey],153 nativeSrc = nativeSrcBundle[sKey];154 if (sKey.indexOf(aliasSource) == 0 && !nativeSrc && target && !compare(source, target)) {155 nativeSrcBundle[sKey] = target;156 sourceBundle[sKey] = target;157 updated = true;158 } else {159 if (sKey.indexOf(aliasSource) == 0 && nativeSrc && dojo.isArray(source) && dojo.isArray(target)) {160 for (var i = 0; i < source.length; i++) {161 if (source[i] === undefined) {162 source[i] = target[i];163 updated = true;164 }165 }166 if (source.length < target.length) {167 source = sourceBundle[sKey] = source.concat(target.slice(source.length));168 updated = true;169 }170 if (updated) {171 nativeSrcBundle[sKey] = source;172 }173 }174 }175 }176}177function _updateLocaleAlias(sourceBundle/*JSON Obj*/,aliasSource/*String*/, targetBundle/*JSON Obj*/,178 aliasTarget/*String*/, nativeSrcBundle/*JSON Obj*/){179 //single property180 if(!nativeSrcBundle[aliasSource] && nativeSrcBundle[aliasTarget]//no this property in current locale181 && !compare(sourceBundle[aliasSource], targetBundle[aliasTarget])){182 // then should inherit from alias target (as defined by 'locale' alias)183 //logStr += '1 '+aliasSource + "=" + sourceBundle[aliasSource] + " is replaced with " + aliasTarget + "=" + targetBundle[aliasTarget]+'\n';184 //sourceBundle[aliasSource] = targetBundle[aliasTarget];185 nativeSrcBundle[aliasSource] = targetBundle[aliasTarget];186 sourceBundle[aliasSource] = nativeSrcBundle[aliasSource];187 updated = true;188 }else if(nativeSrcBundle[aliasSource] && dojo.isArray(sourceBundle[aliasSource])189 && dojo.isArray(targetBundle[aliasTarget])){190 if(sourceBundle[aliasSource].length > targetBundle[aliasTarget].length){191 //logStr +="Error:" + aliasSource + ".length > " + aliasTarget + ".length \n";192 }193 //array property, see if need inherit194 for(var i = 0; i < sourceBundle[aliasSource].length; i++){195 if(sourceBundle[aliasSource][i] == undefined){//need inherit196 //logStr += '2 ' + aliasSource + "["+i+"]=" +sourceBundle[aliasSource][i]+" is replaced with " + aliasTarget+"["+i+"]="+targetBundle[aliasTarget][i]+'\n';197 sourceBundle[aliasSource][i] = targetBundle[aliasTarget][i];198 updated = true;199 }// otherwise no change and use current value200 }201 if(sourceBundle[aliasSource].length < targetBundle[aliasTarget].length){202 //logStr +='3 ' + aliasSource +' from ' + sourceBundle[aliasSource].length +' to '203 // + (targetBundle[aliasTarget].length-1) + ' are copied from '204 // +aliasTarget + '='+ targetBundle[aliasTarget] +'\n';205 sourceBundle[aliasSource] = sourceBundle[aliasSource].concat(206 targetBundle[aliasTarget].slice(sourceBundle[aliasSource].length));207 updated = true;208 }209 if(updated){210 nativeSrcBundle[aliasSource] = sourceBundle[aliasSource];211 }212 }213}214function cleanLocaleAlias(fileList/*Array*/){215 for(var i = 0; i < fileList.length; i++){216 var fileName = new String(fileList[i]); //Java String217 try{218 var bundle = getNativeBundle(fileName);//bundle not flattened219 }catch(e){print(e);/* simply ignore if no bundle found*/}220 221 var newBundle = {};222 var needUpdate = false;223 for(p in bundle){224 if(p.indexOf(LOCALE_ALIAS_MARK) < 0){225 newBundle[p] = bundle[p];226 }else{227 needUpdate = true;228 }229 }230 if(needUpdate){231 fileUtil.saveUtf8File(fileName, "(" + dojo.toJson(newBundle, true) + ")");232 //logStr += "cleaned @localAlias for " + fileName + "\n";233 }234 }...

Full Screen

Full Screen

doc-alias.js

Source:doc-alias.js Github

copy

Full Screen

1// exact-check2const QUERY = [3 'StructItem',4 'StructFieldItem',5 'StructMethodItem',6 'ImplTraitItem',7 'ImplAssociatedConstItem',8 'ImplTraitFunction',9 'EnumItem',10 'VariantItem',11 'EnumMethodItem',12 'TypedefItem',13 'TraitItem',14 'TraitTypeItem',15 'AssociatedConstItem',16 'TraitFunctionItem',17 'FunctionItem',18 'ModuleItem',19 'ConstItem',20 'StaticItem',21 'UnionItem',22 'UnionFieldItem',23 'UnionMethodItem',24 'MacroItem',25];26const EXPECTED = [27 {28 'others': [29 {30 'path': 'doc_alias',31 'name': 'Struct',32 'alias': 'StructItem',33 'href': '../doc_alias/struct.Struct.html',34 'is_alias': true35 },36 ],37 },38 {39 'others': [40 {41 'path': 'doc_alias::Struct',42 'name': 'field',43 'alias': 'StructFieldItem',44 'href': '../doc_alias/struct.Struct.html#structfield.field',45 'is_alias': true46 },47 ],48 },49 {50 'others': [51 {52 'path': 'doc_alias::Struct',53 'name': 'method',54 'alias': 'StructMethodItem',55 'href': '../doc_alias/struct.Struct.html#method.method',56 'is_alias': true57 },58 ],59 },60 {61 // ImplTraitItem62 'others': [],63 },64 {65 // ImplAssociatedConstItem66 'others': [],67 },68 {69 'others': [70 {71 'path': 'doc_alias::Struct',72 'name': 'function',73 'alias': 'ImplTraitFunction',74 'href': '../doc_alias/struct.Struct.html#method.function',75 'is_alias': true76 },77 ],78 },79 {80 'others': [81 {82 'path': 'doc_alias',83 'name': 'Enum',84 'alias': 'EnumItem',85 'href': '../doc_alias/enum.Enum.html',86 'is_alias': true87 },88 ],89 },90 {91 'others': [92 {93 'path': 'doc_alias::Enum',94 'name': 'Variant',95 'alias': 'VariantItem',96 'href': '../doc_alias/enum.Enum.html#variant.Variant',97 'is_alias': true98 },99 ],100 },101 {102 'others': [103 {104 'path': 'doc_alias::Enum',105 'name': 'method',106 'alias': 'EnumMethodItem',107 'href': '../doc_alias/enum.Enum.html#method.method',108 'is_alias': true109 },110 ],111 },112 {113 'others': [114 {115 'path': 'doc_alias',116 'name': 'Typedef',117 'alias': 'TypedefItem',118 'href': '../doc_alias/type.Typedef.html',119 'is_alias': true120 },121 ],122 },123 {124 'others': [125 {126 'path': 'doc_alias',127 'name': 'Trait',128 'alias': 'TraitItem',129 'href': '../doc_alias/trait.Trait.html',130 'is_alias': true131 },132 ],133 },134 {135 'others': [136 {137 'path': 'doc_alias::Trait',138 'name': 'Target',139 'alias': 'TraitTypeItem',140 'href': '../doc_alias/trait.Trait.html#associatedtype.Target',141 'is_alias': true142 },143 ],144 },145 {146 'others': [147 {148 'path': 'doc_alias::Trait',149 'name': 'AssociatedConst',150 'alias': 'AssociatedConstItem',151 'href': '../doc_alias/trait.Trait.html#associatedconstant.AssociatedConst',152 'is_alias': true153 },154 ],155 },156 {157 'others': [158 {159 'path': 'doc_alias::Trait',160 'name': 'function',161 'alias': 'TraitFunctionItem',162 'href': '../doc_alias/trait.Trait.html#tymethod.function',163 'is_alias': true164 },165 ],166 },167 {168 'others': [169 {170 'path': 'doc_alias',171 'name': 'function',172 'alias': 'FunctionItem',173 'href': '../doc_alias/fn.function.html',174 'is_alias': true175 },176 ],177 },178 {179 'others': [180 {181 'path': 'doc_alias',182 'name': 'Module',183 'alias': 'ModuleItem',184 'href': '../doc_alias/Module/index.html',185 'is_alias': true186 },187 ],188 },189 {190 'others': [191 {192 'path': 'doc_alias',193 'name': 'Const',194 'alias': 'ConstItem',195 'href': '../doc_alias/constant.Const.html',196 'is_alias': true197 },198 ],199 },200 {201 'others': [202 {203 'path': 'doc_alias',204 'name': 'Static',205 'alias': 'StaticItem',206 'href': '../doc_alias/static.Static.html',207 'is_alias': true208 },209 ],210 },211 {212 'others': [213 {214 'path': 'doc_alias',215 'name': 'Union',216 'alias': 'UnionItem',217 'href': '../doc_alias/union.Union.html',218 'is_alias': true219 },220 // Not an alias!221 {222 'path': 'doc_alias::Union',223 'name': 'union_item',224 'href': '../doc_alias/union.Union.html#structfield.union_item'225 },226 ],227 },228 {229 'others': [230 {231 'path': 'doc_alias::Union',232 'name': 'union_item',233 'alias': 'UnionFieldItem',234 'href': '../doc_alias/union.Union.html#structfield.union_item',235 'is_alias': true236 },237 ],238 },239 {240 'others': [241 {242 'path': 'doc_alias::Union',243 'name': 'method',244 'alias': 'UnionMethodItem',245 'href': '../doc_alias/union.Union.html#method.method',246 'is_alias': true247 },248 ],249 },250 {251 'others': [252 {253 'path': 'doc_alias',254 'name': 'Macro',255 'alias': 'MacroItem',256 'href': '../doc_alias/macro.Macro.html',257 'is_alias': true258 },259 ],260 },...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2import { setOptions } from '@storybook/addon-options';3import { setDefaults, withInfo } from '@storybook/addon-info';4import { withOptions } from '@storybook/addon-options';5import { setDefaults, withInfo } from '@storybook/addon-info';6import { withOptions } from '@storybook/addon-options';7import { setDefaults, withInfo } from '@storybook/addon-info';8import { withOptions } from '@storybook/addon-options';9import { setDefaults, withInfo } from '@storybook/addon-info';10import { withOptions } from '@storybook/addon-options';11import { setDefaults, withInfo } from '@storybook/addon-info';12import { withOptions } from '@storybook/addon-options';13import { setDefaults, withInfo } from '@storybook/addon-info';14import { withOptions } from '@storybook/addon-options';15import { setDefaults, withInfo } from '@storybook/addon-info';16import { withOptions } from '@storybook/addon-options';17import { setDefaults, withInfo } from '@storybook/addon-info';18import { withOptions } from '@storybook/addon-options';19import { setDefaults, withInfo } from '@storybook/addon-info';20import { withOptions } from '@storybook/addon-options';21import { setDefaults, withInfo } from '@storybook/addon-info';22import { withOptions } from '@storybook/addon-options';23import { setDefaults, withInfo } from '@storybook/addon-info';24import { withOptions } from '@storybook/addon-options';25import { setDefaults, withInfo } from '@storybook/addon-info';26import { withOptions } from '@storybook/addon-options';27import { setDefaults, withInfo } from

Full Screen

Using AI Code Generation

copy

Full Screen

1const rootImport = require('storybook-root-import');2rootImport.setRootPath(__dirname);3module.exports = {4 webpackFinal: async config => {5 return config;6 },7};8const path = require('path');9module.exports = ({ config }) => {10 config.module.rules.push({11 include: path.resolve(__dirname, '../'),12 });13 return config;14};15const rootImport = require('storybook-root-import');16rootImport.setRootPath(__dirname);17module.exports = {18 webpackFinal: async config => {19 return config;20 },21};22import { addDecorator } from '@storybook/react';23import { withInfo } from '@storybook/addon-info';24addDecorator(withInfo);25import { addons } from '@storybook/addons';26import { themes } from '@storybook/theming';27addons.setConfig({28});29/>;30import { addDecorator } from '@storybook/react';31import { withInfo } from '@storybook/addon-info';32addDecorator(withInfo);33import { addons } from '@storybook/addons';34import { themes } from '@storybook/theming';35addons.setConfig({36});

Full Screen

Using AI Code Generation

copy

Full Screen

1const rootImportOptions = {2};3module.exports = (baseConfig, env, config) => {4 config.resolve.alias = {5 ...rootImport(rootImportOptions)6 };7 return config;8};9import { configure } from '@storybook/react';10configure(require.context('../src/stories', true, /\.stories\.js$/), module);11const path = require('path');12module.exports = async ({ config, mode }) => {13 config.resolve.alias = {14 '~': path.resolve(__dirname, '../src')15 };16 config.module.rules.push({17 include: path.resolve(__dirname, '../')18 });19 return config;20};21{22 "babel-plugin-root-import",23 {24 }25}26 at Object../node_modules/react-transition-group/esm/TransitionGroup.js (TransitionGroup.js:12)27 at __webpack_require__ (bootstrap:79)28 at fn (bootstrap:45)29 at Object../node_modules/react-transition-group/esm/index.js (index.js:1)30 at __webpack_require__ (bootstrap:79)31 at fn (bootstrap:45)32 at Object../node_modules/material-ui/esm/Zoom/Zoom.js (Zoom.js:1)33 at __webpack_require__ (bootstrap:79)34 at fn (bootstrap:45)35 at Object../node_modules/material-ui/esm/Zoom/index.js (index.js:1)

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2import { setOptions } from '@storybook/addon-options';3import { setDefaults } from '@storybook/addon-info';4setOptions({5});6setDefaults({7});8configure(() => {9 require('./stories');10}, module);11const path = require('path');12module.exports = (baseConfig, env, defaultConfig) => {13 defaultConfig.resolve.alias['storybook-root-import'] = path.resolve(__dirname, '../');14 return defaultConfig;15};

Full Screen

Using AI Code Generation

copy

Full Screen

1const withTM = require('next-transpile-modules')(['@storybook/addon-knobs', '@storybook/addon-actions', '@storybook/addon-links', '@storybook/addon-notes', '@storybook/addon-options', '@storybook/addon-storysource', '@storybook/addon-viewport', '@storybook/addon-backgrounds', '@storybook/addon-a11y', '@storybook/addon-jest', '@storybook/addon-storyshots', '@storybook/addon-console', '@storybook/addon-knobs/register', '@storybook/addon-actions/register', '@storybook/addon-links/register', '@storybook/addon-notes/register', '@storybook/addon-options/register', '@storybook/addon-storysource/register', '@storybook/addon-viewport/register', '@storybook/addon-backgrounds/register', '@storybook/addon-a11y/register', '@storybook/addon-jest/register', '@storybook/addon-storyshots/register', '@storybook/addon-console/register']);2const withCSS = require('@zeit/next-css');3const withSass = require('@zeit/next-sass');4const withLess = require('@zeit/next-less');5const withImages = require('next-images');6const withPlugins = require('next-compose-plugins');7const withBundleAnalyzer = require('@next/bundle-analyzer')({8});9const withOptimizedImages = require('next-optimized-images');10module.exports = withPlugins([11]);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { rootPath } = require('storybook-root-import');2const path = require('path');3module.exports = {4 stories: ['../**/*.stories.(js|mdx)'],5 webpackFinal: async (config) => {6 config.resolve.alias['@'] = rootPath;7 config.resolve.alias['~'] = path.join(__dirname, '../');8 return config;9 },10};11module.exports = {12 stories: ['../**/*.stories.(js|mdx)'],13};14import { addons } from '@storybook/addons';15import { themes } from '@storybook/theming';16addons.setConfig({17});18import { addDecorator } from '@storybook/vue';19import { withA11y } from '@storybook/addon-a11y';20import { withKnobs } from '@storybook/addon-knobs';21import { withTests } from '@storybook/addon-jest';22import results from '../.jest-test-results.json';23addDecorator(withA11y);24addDecorator(withKnobs);25addDecorator(26 withTests({27 })28);29const path = require('path');30const { rootPath } = require('storybook-root

Full Screen

Using AI Code Generation

copy

Full Screen

1const { alias } = require('storybook-root-alias');2const config = alias({3 '@storybook/react': require.resolve('@storybook/react'),4 react: require.resolve('react'),5 'react-dom': require.resolve('react-dom'),6});7 'babel-plugin-root-import',8 {9 },10];11module.exports = config;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful