How to use newParameters method in storybook-root

Best JavaScript code snippet using storybook-root

ScheduleParameters.js

Source:ScheduleParameters.js Github

copy

Full Screen

1import React, {useState} from "react";2import {useSnackbar} from "notistack";3// data hub4import dataHub from "ajax/DataHub";5// local components6import DataLoader from "main/DataLoader/DataLoader";7import DesignerSelectField from "main/Main/Development/Designer/DesignerSelectField";8import DesignerTimeField from "main/Main/Development/Designer/DesignerTimeField";9import {10 checkDayError,11 checkDayWeekError,12 checkDifferenceTimeError,13 checkHourError,14 checkMinuteSecondError,15 checkWeekMonthError,16 DAY_END_MONTH,17 days,18 EVERY_DAY,19 EVERY_MONTH,20 EVERY_WEEK,21 getScheduleTypeId,22 getScheduleTypeName,23 getScheduleTypesForSelect,24 initialData,25 MANUAL,26 scheduleTypesInitial,27 WEEK_END_MONTH,28 WEEK_MONTH,29 weekDays,30 weeks31} from "./scheduleUtil";32/**33 *34 * @callback onChangeScheduleParameters35 * @param {Object} parameters36 * @param {Object} errors37 */38/**39 * Компонент редактирования параметров расписания40 * @param {Object} props - свойства компонента41 * @param {String} props.scheduleType - тип расписания42 * @param {Object} props.data - исходные данные43 * @param {Object} props.errors - данные об ошибках44 * @param {onChangeScheduleParameters} props.onChange - callback, вызываемый при изменении полей45 * @return {JSX.Element}46 * @constructor47 */48export default function ScheduleParameters(props) {49 const {enqueueSnackbar} = useSnackbar();50 const data = {...initialData, ...(props.data || {})};51 const errors = props.errors || {};52 const time = new Date(data.year, data.month, data.day,53 data.hour, data.minute, data.second, 0);54 const [scheduleTypes, setScheduleTypes] = useState(scheduleTypesInitial);55 const [serverUTCOffset, setServerUTCOffset] = useState(3);56 let typeId = typeof (data.scheduleTypeId) === "number" ? data.scheduleTypeId57 : getScheduleTypeId(scheduleTypes, props.scheduleType);58 let scheduleTypeName = getScheduleTypeName(scheduleTypes, typeId);59 const scheduleTypeLoadFunc = dataHub.scheduleController.getTypes;60 const serverDateTimeLoadFunc = dataHub.serverSettings.getDateTime;61 if (typeof(typeId) === "number" && typeId !== data.scheduleTypeId) {62 handleChangeScheduleTypeId(typeId);63 }64 function handleScheduleTypesDataLoaded(loadedData) {65 setScheduleTypes(loadedData);66 }67 function handleServerDateTimeDataLoaded(loadedData) {68 loadedData = loadedData.trim().toUpperCase();69 if (loadedData.slice(-1) === "Z") {70 setServerUTCOffset(0);71 return;72 }73 const offsetRegExp = /([-+])(\d{2}):(\d{2})/;74 const offsetString = loadedData.slice(-6);75 if(!offsetRegExp.test(offsetString)) {76 enqueueSnackbar(`Не удалось получить часовой пояс сервера из строки ${loadedData}. Буду использовать значение ${serverUTCOffset}`,77 {variant: "warning"});78 return;79 }80 const [/* skip */, sign, hourOffset, minuteOffset] = loadedData.match(offsetRegExp);81 const newOffset = (sign === "-" ? -1 : 1) * (+hourOffset + (+minuteOffset) / 60);82 setServerUTCOffset(newOffset);83 }84 function handleDataLoadFailed(message) {85 enqueueSnackbar(`При загрузке данных произошла ошибка: ${message}`, {variant: "error"});86 }87 function handleChange(newData) {88 const hasTypeChanged = typeof (newData.scheduleTypeId) === "number";89 if (hasTypeChanged) {90 typeId = newData.scheduleTypeId;91 scheduleTypeName = getScheduleTypeName(scheduleTypes, typeId);92 }93 let newParameters = {scheduleTypeId: typeId};94 let newErrors = {scheduleTypeId: typeof (typeId) !== "number"};95 const oldTimeParameters = {96 hour: data.hour,97 minute: data.minute,98 second: data.second,99 differenceTime: data.differenceTime100 };101 // parameters102 if (scheduleTypeName !== MANUAL) {103 newParameters = {...newParameters, ...oldTimeParameters};104 }105 switch (scheduleTypeName) {106 case EVERY_DAY:107 break;108 case EVERY_WEEK:109 newParameters = {...newParameters, dayWeek: data.dayWeek};110 break;111 case EVERY_MONTH:112 newParameters = {...newParameters, day: data.day};113 break;114 case DAY_END_MONTH:115 newParameters = {...newParameters, dayEndMonth: data.dayEndMonth};116 break;117 case WEEK_MONTH:118 newParameters = {...newParameters, dayWeek: data.dayWeek, weekMonth: data.weekMonth};119 break;120 case WEEK_END_MONTH:121 newParameters = {...newParameters, dayWeek: data.dayWeek, weekEndMonth: data.weekEndMonth};122 break;123 case MANUAL:124 newParameters = {...newParameters, hour: 0, minute: 0, second: 0, differenceTime: 0};125 break;126 default: 127 break;128 }129 newParameters = {...newParameters, ...newData};130 // errors131 if (scheduleTypeName !== MANUAL) {132 newErrors = {133 ...newErrors,134 hour: checkHourError(newParameters.hour),135 minute: checkMinuteSecondError(newParameters.minute),136 second: checkMinuteSecondError(newParameters.second),137 differenceTime: checkDifferenceTimeError(newParameters.differenceTime)138 };139 }140 switch (scheduleTypeName) {141 case EVERY_DAY:142 break;143 case EVERY_WEEK:144 newErrors = {...newErrors, dayWeek: checkDayWeekError(newParameters.dayWeek)};145 break;146 case EVERY_MONTH:147 newErrors = {...newErrors, day: checkDayError(newParameters.day)};148 break;149 case DAY_END_MONTH:150 newErrors = {...newErrors, dayEndMonth: checkDayError(newParameters.dayEndMonth)};151 break;152 case WEEK_MONTH:153 newErrors = {154 ...newErrors,155 dayWeek: checkDayWeekError(newParameters.dayWeek),156 weekMonth: checkWeekMonthError(newParameters.weekMonth)157 };158 break;159 case WEEK_END_MONTH:160 newErrors = {161 ...newErrors,162 dayWeek: checkDayWeekError(newParameters.dayWeek),163 weekEndMonth: checkWeekMonthError(newParameters.weekEndMonth)164 };165 break;166 case MANUAL:167 break;168 default:169 break;170 }171 props.onChange(newParameters, newErrors);172 }173 function handleChangeScheduleTypeId(scheduleTypeId) {174 handleChange({scheduleTypeId});175 }176 function handleChangeDay(day) {177 handleChange({day});178 }179 function handleChangeDayWeek(dayWeek) {180 handleChange({dayWeek});181 }182 function handleChangeDayEndMonth(dayEndMonth) {183 handleChange({dayEndMonth});184 }185 function handleChangeWeekMonth(weekMonth) {186 handleChange({weekMonth});187 }188 function handleChangeTime(value) {189 const parametersData = {190 hour: value.getHours(),191 minute: value.getMinutes(),192 second: value.getSeconds(),193 differenceTime: (-value.getTimezoneOffset() / 60) - serverUTCOffset194 };195 handleChange(parametersData);196 }197 // building component198 const fields = [];199 fields.push(200 <DesignerSelectField201 key={fields.length}202 fullWidth203 label="Тип расписания"204 value={typeId}205 data={getScheduleTypesForSelect(scheduleTypes)}206 error={errors.scheduleTypeId === undefined ? true : errors.scheduleTypeId}207 onChange={handleChangeScheduleTypeId}208 />209 );210 if (scheduleTypeName === EVERY_WEEK ||211 scheduleTypeName === WEEK_MONTH ||212 scheduleTypeName === WEEK_END_MONTH) {213 fields.push(214 <DesignerSelectField215 key={fields.length}216 fullWidth217 label="День недели"218 value={data.dayWeek}219 data={weekDays}220 error={errors.dayWeek}221 onChange={handleChangeDayWeek}222 />223 )224 }225 if (scheduleTypeName === EVERY_MONTH) {226 fields.push(227 <DesignerSelectField228 key={fields.length}229 fullWidth230 label="День месяца"231 value={data.day}232 data={days}233 error={errors.day}234 onChange={handleChangeDay}235 />236 )237 }238 if (scheduleTypeName === DAY_END_MONTH) {239 fields.push(240 <DesignerSelectField241 key={fields.length}242 fullWidth243 label="Дней до конца месяца"244 value={data.dayEndMonth}245 data={days}246 error={errors.dayEndMonth}247 onChange={handleChangeDayEndMonth}248 />249 );250 }251 if (scheduleTypeName === WEEK_MONTH) {252 fields.push(253 <DesignerSelectField254 key={fields.length}255 fullWidth256 label="Порядковый номер от начала месяца"257 value={data.weekMonth}258 data={weeks}259 error={errors.weekMonth}260 onChange={handleChangeWeekMonth}261 />262 );263 }264 if (scheduleTypeName === WEEK_END_MONTH) {265 fields.push(266 <DesignerSelectField267 key={fields.length}268 fullWidth269 label="Порядковый номер от конца месяца"270 value={data.weekEndMonth}271 data={weeks}272 error={errors.weekEndMonth}273 onChange={handleChangeWeekMonth}274 />275 );276 }277 if (scheduleTypeName === MANUAL) {278 // fields.push(279 // <DesignerTextField280 // key={fields.length}281 // fullWidth282 // label="Уникальный идентификатор расписания"283 // value={""}284 // error={true}285 // onChange={f => f}286 // />287 // );288 }289 if (scheduleTypeName && scheduleTypeName !== MANUAL) {290 fields.push(291 <DesignerTimeField292 key={fields.length}293 fullWidth294 label="Время"295 value={time}296 onChange={handleChangeTime}297 />298 );299 }300 return (301 <DataLoader302 loadFunc={serverDateTimeLoadFunc}303 loadParams={[]}304 onDataLoaded={handleServerDateTimeDataLoaded}305 onDataLoadFailed={handleDataLoadFailed}306 >307 <DataLoader308 loadFunc={scheduleTypeLoadFunc}309 loadParams={[]}310 onDataLoaded={handleScheduleTypesDataLoaded}311 onDataLoadFailed={handleDataLoadFailed}312 >313 {fields}314 </DataLoader>315 </DataLoader>316 );...

Full Screen

Full Screen

GoogleAnalyticUtil.js

Source:GoogleAnalyticUtil.js Github

copy

Full Screen

1import analytics from '@react-native-firebase/analytics';2import {ObjectUtil} from './ObjectUtil';3import {PropertyTypeUtil} from './PropertyTypeUtil';4import {SearchPropertyService} from '../services';5import {UserType, LeadSources} from '../constants';6function trackListingSearch({parameters}) {7 /**8 * required to convert it to readable parameters9 * Not tracking all parameters10 * as there is a cap of 25 parameters11 * and cap of 100 characters per parameters12 */13 const newParameters = {};14 if (parameters) {15 const {16 cdResearchSubTypes,17 type,18 searchText,19 searchType,20 selectedAmenitiesIds,21 selectedDistrictIds,22 selectedHdbTownIds,23 isRoomRental,24 startResultIndex,25 isTransacted,26 ...rest27 } = parameters;28 //page29 newParameters['page'] =30 startResultIndex / SearchPropertyService.maxPerCount + 1; //start from 131 newParameters['isTransacted'] = isTransacted;32 //sale or rent33 newParameters['type'] = type;34 if (type === 'R' && isRoomRental) {35 newParameters['isRoomRental'] = isRoomRental;36 }37 //for location38 if (searchType) {39 newParameters['searchType'] = searchType;40 }41 if (searchText) {42 newParameters['searchText'] = searchText;43 }44 if (selectedAmenitiesIds) {45 newParameters['selectedAmenitiesIds'] = selectedAmenitiesIds;46 }47 if (selectedDistrictIds) {48 newParameters['selectedDistrictIds'] = selectedDistrictIds;49 }50 if (selectedHdbTownIds) {51 newParameters['selectedHdbTownIds'] = selectedHdbTownIds;52 }53 //handle property type54 if (!ObjectUtil.isEmpty(cdResearchSubTypes)) {55 const subtypes = cdResearchSubTypes.split(',');56 var containsCondo = false;57 var containsHDB = false;58 var containsLanded = false;59 var containsCommercial = false;60 subtypes.map(item => {61 if (!containsCondo && PropertyTypeUtil.isCondo(item)) {62 containsCondo = true;63 } else if (!containsHDB && PropertyTypeUtil.isHDB(item)) {64 containsHDB = true;65 } else if (!containsLanded && PropertyTypeUtil.isLanded(item)) {66 containsLanded = true;67 } else if (!containsCommercial && PropertyTypeUtil.isCommercial(item)) {68 containsCommercial = true;69 }70 });71 const propertyTypeCollection = [];72 if (containsCondo && containsHDB && containsLanded) {73 propertyTypeCollection.push('Residential');74 } else {75 if (containsCondo) {76 propertyTypeCollection.push('Condominium');77 }78 if (containsHDB) {79 propertyTypeCollection.push('HDB');80 }81 if (containsLanded) {82 propertyTypeCollection.push('Landed');83 }84 }85 if (containsCommercial) {86 propertyTypeCollection.push('Commercial');87 }88 newParameters.propertyType = propertyTypeCollection.join(',');89 newParameters.cdResearchSubTypes = cdResearchSubTypes;90 }91 }92 console.log(newParameters);93 analytics().logEvent('Search_Listings', newParameters);94}95function trackMapListingSearch({parameters}) {96 /**97 * required to convert it to readable parameters98 * Not tracking all parameters99 * as there is a cap of 25 parameters100 * and cap of 100 characters per parameters101 */102 const newParameters = {};103 if (parameters) {104 const {105 cdResearchSubTypes,106 type,107 searchText,108 searchType,109 selectedAmenitiesIds,110 selectedDistrictIds,111 selectedHdbTownIds,112 isRoomRental,113 isTransacted,114 ...rest115 } = parameters;116 newParameters['isTransacted'] = isTransacted;117 //sale or rent118 newParameters['type'] = type;119 if (type === 'R' && isRoomRental) {120 newParameters['isRoomRental'] = isRoomRental;121 }122 //for location123 newParameters['searchType'] = !ObjectUtil.isEmpty(searchText)124 ? 'keyword'125 : 'feature'; //check ListingSearchManager for logic126 if (searchText) {127 newParameters['searchText'] = searchText;128 }129 if (selectedAmenitiesIds) {130 newParameters['selectedAmenitiesIds'] = selectedAmenitiesIds;131 }132 if (selectedDistrictIds) {133 newParameters['selectedDistrictIds'] = selectedDistrictIds;134 }135 if (selectedHdbTownIds) {136 newParameters['selectedHdbTownIds'] = selectedHdbTownIds;137 }138 //handle property type139 if (!ObjectUtil.isEmpty(cdResearchSubTypes)) {140 const subtypes = cdResearchSubTypes.split(',');141 var containsCondo = false;142 var containsHDB = false;143 var containsLanded = false;144 var containsCommercial = false;145 subtypes.map(item => {146 if (!containsCondo && PropertyTypeUtil.isCondo(item)) {147 containsCondo = true;148 } else if (!containsHDB && PropertyTypeUtil.isHDB(item)) {149 containsHDB = true;150 } else if (!containsLanded && PropertyTypeUtil.isLanded(item)) {151 containsLanded = true;152 } else if (!containsCommercial && PropertyTypeUtil.isCommercial(item)) {153 containsCommercial = true;154 }155 });156 const propertyTypeCollection = [];157 if (containsCondo && containsHDB && containsLanded) {158 propertyTypeCollection.push('Residential');159 } else {160 if (containsCondo) {161 propertyTypeCollection.push('Condominium');162 }163 if (containsHDB) {164 propertyTypeCollection.push('HDB');165 }166 if (containsLanded) {167 propertyTypeCollection.push('Landed');168 }169 }170 if (containsCommercial) {171 propertyTypeCollection.push('Commercial');172 }173 newParameters.propertyType = propertyTypeCollection.join(',');174 newParameters.cdResearchSubTypes = cdResearchSubTypes;175 }176 }177 console.log(newParameters);178 analytics().logEvent('Search_Listings_Map', newParameters);179}180function trackListingDetailsUserActions({viewingItem}) {181 //track when viewing the item or expanding the section182 /**183 * viewingItem184 * Use ListingDetailsViewingItems from constant folder185 */186 if (viewingItem) {187 const newParameters = {188 viewingItem,189 };190 console.log(newParameters);191 analytics().logEvent('ListingDetails_ViewingItems', newParameters);192 }193}194function trackLeads({leadType, source}) {195 /**196 * leadType197 * Use LeadTypes from constant folder198 */199 /**200 * source201 * Use LeadSources from constant folder202 */203 if (leadType && source) {204 const newParameters = {205 leadType,206 };207 let eventName;208 if (source === LeadSources.listings) {209 eventName = 'Leads_Listings';210 } else if (source === LeadSources.listingDetails) {211 eventName = 'Leads_ListingDetails';212 } else if (source === LeadSources.agentCV) {213 eventName = 'Leads_AgentCV';214 }215 console.log(eventName);216 console.log(newParameters);217 if (eventName) {218 console.log(eventName);219 console.log(newParameters);220 analytics().logEvent(eventName, newParameters);221 }222 }223}224//Track for concierge form submission225function trackConciergeSubmission({parameters}) {226 /**227 * required to convert it to readable parameters228 * Not tracking all parameters229 * as there is a cap of 25 parameters230 * and cap of 100 characters per parameters231 */232 const newParameters = {};233 if (parameters) {234 const {235 conciergeMenu,236 userType,237 propertyType,238 districtTownId,239 keywords,240 } = parameters;241 //start adding params242 if (conciergeMenu) {243 newParameters['conciergeMenu'] = conciergeMenu;244 }245 newParameters['userType'] = UserType.getUserTypeDescription(userType);246 if (propertyType) {247 newParameters['propertyType'] = propertyType;248 }249 if (districtTownId) {250 newParameters['districtTownId'] = districtTownId;251 }252 if (keywords) {253 newParameters['keywords'] = keywords;254 }255 console.log(newParameters);256 analytics().logEvent('Concierge_Submission', newParameters);257 }258}259function trackShortlisting({parameters}) {260 /**261 * required to convert it to readable parameters262 * Not tracking all parameters263 * as there is a cap of 25 parameters264 * and cap of 100 characters per parameters265 */266 const newParameters = {};267 if (parameters) {268 const {269 cdResearchSubType,270 districtHdbTown,271 postalDistrictId,272 postalHdbTownId,273 propertyType,274 type,275 } = parameters;276 //start adding params277 newParameters['type'] = type; //sale or rent278 if (cdResearchSubType) {279 newParameters['cdResearchSubType'] = cdResearchSubType;280 }281 if (districtHdbTown) {282 newParameters['districtHdbTown'] = districtHdbTown;283 }284 if (postalDistrictId) {285 newParameters['postalDistrictId'] = postalDistrictId;286 }287 if (postalHdbTownId) {288 newParameters['postalHdbTownId'] = postalHdbTownId;289 }290 if (propertyType) {291 newParameters['propertyType'] = propertyType;292 }293 console.log(newParameters);294 analytics().logEvent('Shortlist_Listings', newParameters);295 }296}297function trackXValueRequest({parameters}) {298 /**299 * required to convert it to readable parameters300 * Not tracking all parameters301 * as there is a cap of 25 parameters302 * and cap of 100 characters per parameters303 */304 const newParameters = {};305 if (parameters) {306 const {307 type, //S or R308 subType,309 } = parameters;310 // //start adding params311 newParameters['type'] = type; //sale or rent312 if (PropertyTypeUtil.isHDB(subType)) {313 newParameters['propertyType'] = 'HDB';314 } else if (PropertyTypeUtil.isCondo(subType)) {315 newParameters['propertyType'] = 'Condominium';316 } else if (PropertyTypeUtil.isLanded(subType)) {317 newParameters['propertyType'] = 'Landed';318 } else if (PropertyTypeUtil.isCommercial(subType)) {319 newParameters['propertyType'] = 'Commercial';320 } else {321 newParameters['propertyType'] = 'Unknown';322 }323 console.log(newParameters);324 analytics().logEvent('Request_XValue', newParameters);325 }326}327function trackCommunityActivity({parameters}) {328 /**329 * required to convert it to readable parameters330 * Not tracking all parameters331 * as there is a cap of 25 parameters332 * and cap of 100 characters per parameters333 */334 const newParameters = {};335 if (parameters) {336 const {type} = parameters; //type Like, Dislike, Comment, Share, Post, Detail337 newParameters['type'] = type;338 if(type === "Shiok"){339 newParameters['type'] = "Communities_Like";340 } else if(type ==="Jialat"){341 newParameters['type'] = "Communities_Dislike";342 } else if(type ==="comment"){343 newParameters['type'] = "Communities_Comment";344 }else if(type ==="share"){345 newParameters['type'] = "Communities_Share";346 }else if(type ==="post"){347 newParameters['type'] = "Communities_Post";348 const {hasGIF, hasImage, hasText} = parameters;349 newParameters['hasText'] = hasText;350 newParameters['hasImage'] = hasImage;351 newParameters['hasGIF'] = hasGIF;352 }else if(type === "detail"){353 newParameters['type'] = "Communities_Detail";354 }355 console.log("track community activity");356 console.log(newParameters);357 analytics().logEvent('Communities_Activity', newParameters);358 }359}360const GoogleAnalyticUtil = {361 trackListingSearch,362 trackMapListingSearch,363 trackListingDetailsUserActions,364 trackLeads,365 trackConciergeSubmission,366 trackShortlisting,367 trackXValueRequest,368 trackCommunityActivity,369};...

Full Screen

Full Screen

syncToUrl.js

Source:syncToUrl.js Github

copy

Full Screen

1import { initialState } from '../reducers/mainReducer';2import _ from 'lodash';3import qs from 'query-string';4import fields from '../types/fields';5import { options } from '../components/SortFieldContainer';6const sortOptions = options.map(function(x) {7 return {8 field: JSON.parse(x.id).field,9 direction: JSON.parse(x.id).direction10 }11});12export function filtersToUrl({filters, grouping, sortField, selectedItemId, zoom, mainContentMode = 'card'}) {13 const params = {};14 var fieldNames = _.keys(fields);15 _.each(fieldNames, function(field) {16 addFieldToParams({field: field, filters: filters, params: params});17 });18 addGroupingToParams({grouping: grouping, params: params});19 addSortFieldToParams({sortField: sortField, params: params});20 // addSortDirectionToParams({sortDirection: sortDirection, params: params});21 addSelectedItemIdToParams({selectedItemId: selectedItemId, params: params });22 addMainContentModeToParams({mainContentMode: mainContentMode, params: params});23 addZoomToParams({zoom: zoom, mainContentMode: mainContentMode, params: params});24 if (_.isEmpty(params)) {25 return '/';26 }27 const filtersPart = qs.stringify(params, {encode: false});28 return '/' + filtersPart;29}30export function parseUrl(url) {31 const args = qs.parse(url);32 const newParameters = {33 filters: {34 }35 };36 var fieldNames = _.keys(fields);37 _.each(fieldNames, function(field) {38 setFieldFromParams({39 field: field,40 params: args,41 filters: newParameters.filters42 });43 });44 setGroupingFromParams({newParameters, params: args });45 setSortFieldFromParams({newParameters, params: args });46 // setSortDirectionFromParams({newParameters, params: args });47 if (newParameters.sortField) {48 var sortOption = _.find(sortOptions, {field: newParameters.sortField});49 if (sortOption) {50 newParameters.sortDirection = sortOption.direction;51 }52 }53 setSelectedItemIdFromParams({newParameters, params: args });54 setMainContentModeFromParams({newParameters, params: args });55 setZoomFromParams({newParameters, params: args });56 return newParameters;57}58function addFieldToParams({field, filters, params}) {59 var value = filters[field];60 const fieldInfo = fields[field];61 if (_.isUndefined(value)) {62 return;63 }64 if (JSON.stringify(value) !== JSON.stringify(initialState.filters[field])) {65 if (!_.isArray(value)) {66 value = [value];67 }68 const processedValues = fieldInfo.processValuesBeforeSaving(value);69 const urlValues = processedValues.map(function(v){70 const valueInfo = _.find(fieldInfo.values, {id: v});71 return valueInfo.url72 });73 params[fieldInfo.url] = urlValues.join(',');74 }75}76function addGroupingToParams({grouping, params}) {77 const value = grouping;78 if (_.isUndefined(value)) {79 return;80 }81 if (value !== initialState.grouping) {82 const fieldInfo = fields[value];83 if (grouping === 'no') {84 params['grouping'] = 'no';85 } else {86 params['grouping'] = fieldInfo.url;87 }88 }89}90function addSortFieldToParams({sortField, params}) {91 const value = sortField;92 if (_.isUndefined(value)) {93 return;94 }95 if (value !== initialState.sortField) {96 const fieldInfo = fields[value];97 params['sort'] = fieldInfo.url;98 }99}100function addMainContentModeToParams({mainContentMode, params}) {101 if (mainContentMode !== initialState.mainContentMode) {102 if (mainContentMode === 'landscape') {103 params['format'] = 'landscape';104 }105 if (mainContentMode === 'serverless') {106 params['format'] = 'serverless';107 }108 }109}110function addZoomToParams({zoom, mainContentMode, params}) {111 if (zoom !== initialState.zoom && mainContentMode !== 'card') {112 params['zoom'] = zoom * 100;113 }114}115function addSelectedItemIdToParams({selectedItemId, params}) {116 const value = selectedItemId;117 if (_.isUndefined(value)) {118 return;119 }120 if (value !== initialState.selectedItemId) {121 params['selected'] = value;122 }123}124function setFieldFromParams({field, filters, params}) {125 const fieldInfo = fields[field];126 if (!fieldInfo) {127 return;128 }129 const urlValue = params[fieldInfo.url];130 if (!urlValue) {131 return;132 }133 const parts = urlValue.split(',');134 const values = parts.map(function(part) {135 return _.find(fieldInfo.values, function(x) {136 return x.url.toLowerCase() === part.toLowerCase();137 });138 }).filter(function(x) { return !!x}).map(function(x) {139 return x.id;140 });141 const processedValues = fieldInfo.processValuesBeforeLoading(values);142 const value = fieldInfo.isArray ? processedValues : processedValues[0];143 if (!_.isUndefined(value)) {144 filters[field] = value;145 }146}147function setGroupingFromParams({ newParameters, params}) {148 const urlValue = params.grouping;149 if (!urlValue) {150 return;151 }152 if (urlValue === 'no') {153 newParameters.grouping = 'no'154 } else {155 const fieldInfo = _.find(_.values(fields), function(x) {156 return x.url.toLowerCase() === urlValue.toLowerCase();157 });158 if (!_.isUndefined(fieldInfo)) {159 newParameters.grouping = fieldInfo.id;160 }161 }162}163function setSortFieldFromParams({ newParameters, params}) {164 const urlValue = params.sort;165 if (!urlValue) {166 return;167 }168 const fieldInfo = _.find(_.values(fields), function(x) {169 return x.url.toLowerCase() === urlValue.toLowerCase();170 });171 if (!_.isUndefined(fieldInfo)) {172 newParameters.sortField = fieldInfo.id;173 }174}175function setMainContentModeFromParams({ newParameters, params}) {176 const format = params.format;177 if (!format) {178 newParameters.mainContentMode = 'card';179 } else if (format === 'serverless') {180 newParameters.mainContentMode = 'serverless';181 } else if (format === 'landscape') {182 newParameters.mainContentMode = 'landscape';183 }184}185function setZoomFromParams({ newParameters, params}) {186 const zoom = params.zoom;187 if (!zoom) {188 // newParameters.zoom = 1.0;189 } else {190 const zoomAsValue = Math.trunc(+params.zoom) / 100;191 newParameters.zoom = zoomAsValue;192 }193}194 /*195function setSortDirectionFromParams({ newParameters, params}) {196 const urlValue = params.sortField;197 if (!urlValue) {198 return;199 }200 const options = ['asc', 'desc'];201 const sortDirection = _.find(options, function(x) {202 return x.toLowerCase() === urlValue.toLowerCase();203 });204 if (!_.isUndefined(sortDirection)) {205 newParameters.sortDirection = sortDirection;206 }207}208*/209function setSelectedItemIdFromParams({ newParameters, params}) {210 const urlValue = params.selected;211 if (!urlValue) {212 return;213 }214 newParameters.selectedItemId = urlValue;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { newParameters } from 'storybook-root';2import { storiesOf } from '@storybook/react';3import { withKnobs, text } from '@storybook/addon-knobs';4const stories = storiesOf('Test', module);5stories.addDecorator(withKnobs);6stories.add('Test', () => {7 const name = text('name', 'World');8 return newParameters({ name });9});10I am trying to extend the functionality of storybook by creating a new method for the root storybook object. I have created a new file which I am importing into my storybook config file. I have also added the file to the addons array in the config file. The new file is as follows:11import React from 'react';12export const newParameters = ({ name }) => (13 <div>Hello {name}</div>14);15You can see that I am exporting a new method called newParameters. This method takes a parameter object and returns a react component. I am trying to use this new method in my storybook by importing it into a storybook file and then calling the method. The storybook file is as follows:16import { newParameters } from 'storybook-root';17import { storiesOf } from '@storybook/react';18import { withKnobs, text } from '@storybook/addon-knobs';19const stories = storiesOf('Test', module);20stories.addDecorator(withKnobs);21stories.add('Test', () => {22 const name = text('name', 'World');23 return newParameters({ name });24});25import { configure } from '@storybook/react';26import { setOptions } from '@storybook/addon-options';27import { addParameters } from '@storybook/react';28import { withKnobs } from '@storybook/addon-knobs';29setOptions({

Full Screen

Using AI Code Generation

copy

Full Screen

1const { withRootParameters } = require('storybook-root-parameters')2module.exports = {3 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],4 parameters: withRootParameters({5 }),6}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { newParameters } from 'storybook-root';2newParameters({3 options: {4 },5});6import { configure } from '@storybook/react';7import { addDecorator } from '@storybook/react';8import { withOptions } from '@storybook/addon-options';9import { withThemesProvider } from 'storybook-addon-styled-component-theme';10import { withInfo } from '@storybook/addon-info';11import { withKnobs } from '@storybook/addon-knobs';12import { withA11y } from '@storybook/addon-a11y';13import { withConsole } from '@storybook/addon-console';14import { withViewport } from '@storybook/addon-viewport';15import { withTests } from '@storybook/addon-jest';16import { withContexts } from '@storybook/addon-contexts/react';17import { withRedux } from 'addon-redux/withRedux';18import { withReduxSaga } from 'addon-redux-saga';19import { withPerformance } from 'storybook-addon-performance';20import { withSmartKnobs } from 'storybook-addon-smart-knobs';21import { withStorysource } from '@storybook/addon-storysource';22import { withI18n } from 'storybook-addon-i18n';23import { withDesign } from 'storybook-addon-designs';24import { withFormik } from 'storybook-formik';25import { withPaddings } from 'storybook-addon-paddings';26import { withThemes } from 'storybook-addon-themes';27import { withBackgrounds } from '@storybook/addon-backgrounds';28import { withCSSResources } from '@storybook/addon-cssresources';29import { withCreevey } from 'creevey';30import { withCreeveyConfig } from 'creevey';31import { withCreeveySkip } from 'creevey';32import { withCreeveyOnly } from 'creevey';33import { withCreeveyStories } from 'creevey';34import { addParameters } from '@storybook/react';35import { addReadme } from 'storybook-readme';36import { addDecoratorWithParameter } from 'storybook-addon-decorator';37import { addDecoratorWithTheme } from 'storybook-addon-decorator';38import { addDecoratorWithThemeParameter } from 'storybook-addon-decorator';39import { addDecoratorWithThemeParameter } from 'storybook

Full Screen

Using AI Code Generation

copy

Full Screen

1import { newParameters } from 'storybook-root';2newParameters({3});4module.exports = {5};6import { parameters } from 'storybook-root';7export const decorators = parameters.decorators;8export const globalTypes = parameters.globalTypes;9export const parameters = parameters.parameters;10import { addons } from '@storybook/addons';11import { parameters } from 'storybook-root';12addons.setConfig(parameters.addons);

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