Best JavaScript code snippet using storybook-root
ui.ts
Source:ui.ts
...117 var that: UIView = this;118 var template = _.template(FMUIAddLayerTemplate);119 var data = {120 "header": FML.getViewUIAddHeader(),121 "name": FMC.getSelectedItem().get("name"),122 "desc": FMC.getSelectedItem().get("desc"),123 "type": FMC.getSelectedItem().get("type"),124 "sort": FMC.getSelectedItem().get("sort"),125 "date": FMC.getSelectedItem().get("date"),126 "lat": FMC.getSelectedItem().get("lat"),127 "lng": FMC.getSelectedItem().get("lng"),128 "sort1": FMM.getLayers().where({ type: 1 }),129 "sort2": FMM.getLayers().where({ type: 2 }),130 "sort3": FMM.getLayers().where({ type: 3 }),131 };132 that.$el.html(template(data));133 // render type selection134 that.$('#item-info-type').selectpicker();135 // remove event listeners136 that.$("#item-info-amount").off("change");137 that.$("#item-info-lat").off("change");138 that.$("#item-info-lng").off("change");139 that.$("#item-info-btn-edit").off("click");140 that.$("#item-info-btn-delete").off("click");141 that.$("#item-info-date-picker").off("dp.change");142 // add event listeners143 that.$("#item-info-lat").on("change", function () {144 FMC.getSelectedItem().set({ lat: parseFloat($(this).val()) });145 FMV.getMapView().getMarkersView().updateMarker(FMC.getSelectedItem());146 });147 that.$("#item-info-lng").on("change", function () {148 FMC.getSelectedItem().set({ lng: parseFloat($(this).val()) });149 FMV.getMapView().getMarkersView().updateMarker(FMC.getSelectedItem());150 });151 that.$('#item-info-type').on("change", function () {152 var optionSelected = $("option:selected", this);153 FMC.getSelectedItem().set({ type: parseInt(optionSelected.attr("data-type")) });154 FMC.getSelectedItem().set({ sort: parseInt(optionSelected.attr("data-sort")) });155 });156 that.$("#item-info-date-picker").datetimepicker({157 format: FMS.getDateTimeFormat(),158 });159 that.$("#item-info-date-picker").on("dp.change", function () {160 FMC.getSelectedItem().set({ date: $(this).data('date') });161 console.log(FMC.getSelectedItem().get("date"));162 });163 that.$("#item-info-btn-edit").on("click", function () {164 if (FMC.getSelectedItem().get("type") == ItemType.None) {165 FMV.getMsgView().renderError(FML.getViewUIAddTypeSelectError());166 } else {167 FMC.getSelectedItem().setIsRemoved(true);168 FMV.getMapView().getMarkersView().removeMarker(FMC.getSelectedItem());169 FMC.getSelectedItem().save(170 {171 name: that.$("#item-info-name").val(),172 desc: that.$("#item-info-desc").val(),173 },174 {175 success: function (model: Item, response: any) {176 FMV.getMapView().getControlView().resetControls();177 if (FMC.hasSelectedItem()) {178 FMV.getUIView().hide();179 FMV.getMapView().resize(false);180 FMC.getSelectedItem().setIsRemoved(false);181 FMV.getMapView().getMarkersView().render();182 FMV.getMsgView().renderSuccess("'" + model.get("name") + "' " + FML.getViewUIInfoSaveSuccessMsg());183 }184 },185 error: function (error) {186 FMV.getMsgView().renderError(FML.getViewUIInfoSaveErrorMsg());187 },188 });189 }190 });191 that.$("#item-info-btn-delete").on("click", function () {192 FMV.getMapView().getControlView().resetControls();193 if (FMC.hasSelectedItem()) {194 var item = FMC.removeItem(FMC.getSelectedItem());195 item.setIsRemoved(true);196 FMV.getMapView().getMarkersView().removeMarker(item);197 FMC.setSelectedItem(null);198 FMV.getUIView().hide();199 FMV.getMapView().resize(false);200 }201 });202 }203 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////204 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////205 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////206 renderUIInfo(): void {207 var that: UIView = this;208 var template = _.template(FMUIInfoLayerTemplate);209 var data = {210 "header": FML.getViewUIInfoHeader(),211 "id": FMC.getSelectedItem().get("id"),212 "name": FMC.getSelectedItem().get("name"),213 "desc": FMC.getSelectedItem().get("desc"),214 "amount": FMC.getSelectedItem().get("amount"),215 "type": FMC.getSelectedItem().get("type"),216 "sort": FMC.getSelectedItem().get("sort"),217 "lat": FMC.getSelectedItem().get("lat"),218 "lng": FMC.getSelectedItem().get("lng"),219 "date": FMC.getSelectedItem().get("date"),220 "update": FMC.getSelectedItem().get("update"),221 "sort1": FMM.getLayers().where({ type: 1 }),222 "sort2": FMM.getLayers().where({ type: 2 }),223 "sort3": FMM.getLayers().where({ type: 3 }),224 };225 that.$el.html(template(data));226 // render type selection227 that.$('#item-info-type').selectpicker();228 that.$('#item-info-type option').each(function () {229 if ((FMC.getSelectedItem().get("type") == $(this).attr("data-type")) && (FMC.getSelectedItem().get("sort") == $(this).attr("data-sort"))) {230 that.$('#item-info-type').selectpicker("val", $(this).val());231 }232 });233 // remove event listeners234 that.$("#item-info-amount").off("change");235 that.$("#item-info-lat").off("change");236 that.$("#item-info-lng").off("change");237 that.$("#item-info-btn-edit").off("click");238 that.$("#item-info-btn-delete").off("click");239 that.$("#item-info-date-picker").off("dp.change");240 // add event listeners241 that.$("#item-info-amount").on("change", function () {242 FMC.getSelectedItem().save(243 {244 amount: parseFloat($(this).val()),245 },246 {247 success: function (model: Item, response: any) {248 FMV.getMapView().getMarkersView().updateMarker(FMC.getSelectedItem());249 FMV.getMsgView().renderSuccess("'" + model.get("name") + "' " + FML.getViewUIInfoSaveSuccessMsg());250 },251 error: function (error) {252 FMV.getMsgView().renderError(FML.getViewUIInfoSaveErrorMsg());253 },254 });255 });256 that.$("#item-info-lat").on("change", function () {257 FMC.getSelectedItem().save(258 {259 lat: parseFloat($(this).val()),260 },261 {262 success: function (model: Item, response: any) {263 FMV.getMapView().getMarkersView().updateMarker(FMC.getSelectedItem());264 FMV.getMsgView().renderSuccess("'" + model.get("name") + "' " + FML.getViewUIInfoSaveSuccessMsg());265 },266 error: function (error) {267 FMV.getMsgView().renderError(FML.getViewUIInfoSaveErrorMsg());268 },269 });270 });271 that.$("#item-info-lng").on("change", function () {272 FMC.getSelectedItem().save(273 {274 lng: parseFloat($(this).val()),275 },276 {277 success: function (model: Item, response: any) {278 FMV.getMapView().getMarkersView().updateMarker(FMC.getSelectedItem());279 FMV.getMsgView().renderSuccess("'" + model.get("name") + "' " + FML.getViewUIInfoSaveSuccessMsg());280 },281 error: function (error) {282 FMV.getMsgView().renderError(FML.getViewUIInfoSaveErrorMsg());283 },284 });285 });286 287 that.$("#item-info-date-picker").datetimepicker({288 format: FMS.getDateTimeFormat(),289 });290 that.$("#item-info-date-picker").on("dp.change", function () {291 FMC.getSelectedItem().set({ date: $(this).data('date') });292 console.log(FMC.getSelectedItem().get("date"));293 });294 295 // save & delete296 that.$("#item-info-btn-edit").on("click", function () {297 var optionSelected = $("option:selected", that.$('#item-info-type'));298 if (parseInt(optionSelected.attr("data-type")) != 0 && parseInt(optionSelected.attr("data-sort")) != 0) {299 FMV.getMapView().getMarkersView().removeMarker(FMC.getSelectedItem());300 FMC.getSelectedItem().save(301 {302 id: that.$("#item-info-id").val(),303 name: that.$("#item-info-name").val(),304 desc: that.$("#item-info-desc").val(),305 type: parseInt(optionSelected.attr("data-type")),306 sort: parseInt(optionSelected.attr("data-sort")),307 amount: that.$("#item-info-amount").val(),308 lat: that.$("#item-info-lat").val(),309 lng: that.$("#item-info-lng").val(),310 },311 {312 success: function (model: Item, response: any) {313 FMV.getMapView().getMarkersView().render();314 FMV.getMsgView().renderSuccess("'" + model.get("name") + "' " + FML.getViewUIInfoSaveSuccessMsg());315 },316 error: function (error) {317 FMV.getMsgView().renderError(FML.getViewUIInfoSaveErrorMsg());318 },319 });320 } else {321 FMV.getMsgView().renderError(FML.getViewUIAddTypeSelectError());322 }323 324 });325 that.$("#item-info-btn-delete").on("click", function () {326 var r = confirm(FML.getViewUIInfoDeleteConfirmMsg());327 if (r == true) {328 FMC.getSelectedItem().destroy({329 wait: true,330 success: function (model: Item, response: any) {331 model.setIsRemoved(true);332 FMM.getItems().remove(model);333 FMV.getMapView().getMarkersView().removeMarker(model);334 FMV.getMapView().getControlView().resetControls();335 FMV.getUIView().hide();336 FMV.getMapView().resize(false);337 FMV.getMapView().getMarkersView().render();338 FMV.getMsgView().renderSuccess("'" + model.get("name") + "' " + FML.getViewUIInfoDeleteSuccessMsg());339 },340 error: function (error) {341 FMV.getMsgView().renderError(FML.getViewUIInfoDeleteErrorMsg());342 },343 });344 }345 });346 }347 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////348 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////349 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////350 renderUIPicture(): void {351 FMC.fetchPictures(parseInt(FMC.getSelectedItem().get('id')));352 var that: UIView = this;353 var template = _.template(FMViewUILayerPictureTemplate);354 var data = {355 "header": FML.getViewUIPictureHeader(),356 };357 that.$el.html(template(data));358 // Grid instance for data359 var gridData = new Backgrid.Grid({360 columns: pictureColumn,361 collection: FMM.getPictures(),362 emptyText: FML.getViewUIDataNoDataMsg(),363 });364 gridData.render();365 gridData.sort("date", "descending");366 that.$(".ui-body").append(gridData.el);367 setTimeout(function () {368 gridData.sort("date", "descending");369 }, 3000);370 // Grid instance for add Picture371 var picture: Picture = new Picture({ pid: parseInt(FMC.getSelectedItem().get("id")), date: moment(new Date()).format(FMS.getDateTimeFormat()), update: moment(new Date()).format(FMS.getDateTimeFormat()) });372 picture.setIsSavable(false);373 var pictures: Pictures = new Pictures();374 pictures.add(picture);375 var gridAddData = new Backgrid.Grid({376 columns: pictureAddColumn,377 collection: pictures,378 emptyText: FML.getViewUIDataNoDataMsg(),379 });380 that.$("#picture-add-panel").append(gridAddData.render().el);381 }382 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////383 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////384 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////385 renderUILayer(): void {386 var that: UIView = this;387 var isIn:string = "";388 if (that.isLayerCollapsedIn) {389 isIn = "in";390 }391 var template = _.template(FMViewLayerTemplate);392 var data = {393 "header": FML.getViewUILayerHeader(),394 "isIn": isIn,395 "sort1": FMM.getLayers().where({ type: 1 }),396 "sort2": FMM.getLayers().where({ type: 2 }),397 "sort3": FMM.getLayers().where({ type: 3 }),398 };399 that.$el.html(template(data));400 that.updateLayerCheckList();401 if (that.layerHeaderList[1]) {402 $("#check-event-layer").prop({ "checked": true });403 } else {404 $("#check-event-layer").prop({ "checked": false });405 }406 if (that.layerHeaderList[2]) {407 $("#check-organization-layer").prop({ "checked": true });408 } else {409 $("#check-organization-layer").prop({ "checked": false });410 }411 if (that.layerHeaderList[3]) {412 $("#check-donor-layer").prop({ "checked": true });413 } else {414 $("#check-donor-layer").prop({ "checked": false });415 }416 417 $("#check-event-layer").click(function () {418 that.layerHeaderList[1] = $(this).prop("checked");419 if ($(this).prop("checked")) {420 $('input[type="checkbox"][data-type="' + 1 + '"]', that.$el).each(function () {421 $(this).prop({ "checked": true });422 that.layerBodyList[parseInt($(this).attr("data-sort"))] = $(this).prop("checked");423 });424 } else {425 $('input[type="checkbox"][data-type="' + 1 + '"]', that.$el).each(function () {426 $(this).prop({ "checked": false });427 that.layerBodyList[parseInt($(this).attr("data-sort"))] = $(this).prop("checked");428 });429 }430 });431 $("#check-organization-layer").click(function () {432 that.layerHeaderList[2] = $(this).prop("checked");433 if ($(this).prop("checked")) {434 $('input[type="checkbox"][data-type="' + 2 + '"]', that.$el).each(function () {435 $(this).prop({ "checked": true });436 that.layerBodyList[parseInt($(this).attr("data-sort"))] = $(this).prop("checked");437 });438 } else {439 $('input[type="checkbox"][data-type="' + 2 + '"]', that.$el).each(function () {440 $(this).prop({ "checked": false });441 that.layerBodyList[parseInt($(this).attr("data-sort"))] = $(this).prop("checked");442 });443 }444 });445 $("#check-donor-layer").click(function () {446 that.layerHeaderList[3] = $(this).prop("checked");447 if ($(this).prop("checked")) {448 $('input[type="checkbox"][data-type="' + 3 + '"]', that.$el).each(function () {449 $(this).prop({ "checked": true });450 that.layerBodyList[parseInt($(this).attr("data-sort"))] = $(this).prop("checked");451 });452 } else {453 $('input[type="checkbox"][data-type="' + 3 + '"]', that.$el).each(function () {454 $(this).prop({ "checked": false });455 that.layerBodyList[parseInt($(this).attr("data-sort"))] = $(this).prop("checked");456 });457 }458 });459 if (that.layerBodyList[0]) {460 $("#check-unassigned-layer").prop({ "checked": true });461 } else {462 $("#check-unassigned-layer").prop({ "checked": false });463 }464 $("#check-unassigned-layer").click(function () {465 that.layerBodyList[parseInt($(this).attr("data-sort"))] = $(this).prop("checked");466 });467 $('input[type="checkbox"]', that.$el).each(function (index: number, element: any) {468 if (that.layerBodyList[parseInt($(this).attr("data-sort"))]) {469 $(this).prop({ "checked": true });470 } else {471 $(this).prop({ "checked": false });472 }473 });474 $('input[type="checkbox"]', that.$el).click(function () {475 that.layerBodyList[parseInt($(this).attr("data-sort"))] = $(this).prop("checked");476 that.updateLayer();477 });478 // collapsed in479 that.$('button[data-target="#layer-add-panel"]').click(function () {480 that.isLayerCollapsedIn = !that.isLayerCollapsedIn;481 });482 // Grid instance for data483 layerColumn[0].cell = Backgrid.SelectCell.extend({484 optionValues: FMM.getTypes().toArray(),485 })486 var gridData = new Backgrid.Grid({487 columns: layerColumn,488 collection: FMM.getLayers(),489 emptyText: FML.getViewUIDataNoDataMsg(),490 });491 gridData.render();492 gridData.sort("name", "ascending");493 that.$(".ui-body #layer-list-grid").append(gridData.el);494 // Grid instance for adding495 layerAddColumn[0].cell = Backgrid.SelectCell.extend({496 optionValues: FMM.getTypes().toArray(),497 })498 var layer: Layer = new Layer({ name: "", desc: "", type: 1 });499 layer.setIsSavable(false);500 var layers: Layers = new Layers();501 layers.add(layer);502 var gridAddData = new Backgrid.Grid({503 columns: layerAddColumn,504 collection: layers,505 emptyText: FML.getViewUIDataNoDataMsg(),506 });507 that.$(".ui-body #layer-add-grid").append(gridAddData.render().el);508 }509 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////510 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////511 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////512 renderUIDataLayer(): void {513 var that: UIView = this;514 515 if (parseInt(FMC.getSelectedItem().get("type")) != 3) {516 var template = _.template(FMViewUIDataTemplate);517 var data = {518 "header": FML.getViewUIDataHeader(),519 };520 that.$el.html(template(data));521 // Grid instance for data522 var items: Items = new Items();523 items.add(FMM.getItems().where({ type: 2 }));524 items.add(FMM.getItems().where({ type: 3 }));525 dataColumn[0].cell = Backgrid.SelectCell.extend({526 optionValues: items.toArray(),527 })528 var gridData = new Backgrid.Grid({529 columns: dataColumn,530 collection: new Gives(FMM.getGives().where({ tid: FMC.getSelectedItem().get("id") })),531 emptyText: FML.getViewUIDataNoDataMsg(),532 });533 gridData.render();534 gridData.sort("date", "descending");535 that.$(".ui-body").append(gridData.el);536 // Grid instance for adding537 dataAddColumn[0].cell = Backgrid.SelectCell.extend({538 optionValues: items.toArray(),539 })540 var give: Give = new Give({ tid: FMC.getSelectedItem().get("id"), gid: 0, name: "", desc: "", amount: 0, date: moment(new Date()).format(FMS.getDateTimeFormat()), update: moment(new Date()).format(FMS.getDateTimeFormat()) });541 give.setIsSavable(false);542 var gives: Gives = new Gives();543 gives.add(give);544 var gridAddData = new Backgrid.Grid({545 columns: dataAddColumn,546 collection: gives,547 emptyText: FML.getViewUIDataNoDataMsg(),548 });549 that.$(".ui-body #data-add-panel").append(gridAddData.render().el);550 } else { // Donor cannot get donation551 var template = _.template(FMViewUIDataTemplateDonor);552 var data = {553 "header": FML.getViewUIDataHeader(),554 };...
formatConfirmedCases.ts
Source:formatConfirmedCases.ts
...61 attr?: string62 value?: number63 children?: ChildData[]64}65function getSelectedItem(data: DataType, key: string) {66 let result: number | undefined67 const recursiveSearch = (data: ChildDataType) => {68 if (result) {69 return70 }71 if (data.attr === key) {72 result = data.value73 } else if (data.children) {74 data.children.forEach((child: ChildDataType) => {75 if (result) {76 return77 }78 recursiveSearch(child)79 })80 }81 }82 recursiveSearch(data)83 return result || 084}85/**86 * Format for *Chart component87 *88 * @param data - Raw data89 */90export default (data: DataType) => {91 return {92 é½æ§è
æ°: getSelectedItem(data, 'é½æ§æ£è
æ°'),93 å
¥é¢ä¸: getSelectedItem(data, 'å
¥é¢ä¸'),94 軽çä¸çç: getSelectedItem(data, '軽çã»ä¸çç'),95 éç: getSelectedItem(data, 'éç'),96 宿æ³çé¤: getSelectedItem(data, '宿æ³çé¤'),97 èªå®
çé¤: getSelectedItem(data, 'èªå®
çé¤'),98 調æ»ä¸: getSelectedItem(data, '調æ»ä¸'),99 æ»äº¡: getSelectedItem(data, 'æ»äº¡'),100 éé¢: getSelectedItem(data, 'éé¢'),101 } as ConfirmedCasesType...
Using AI Code Generation
1import { getSelectedItem } from 'storybook-root';2const selectedItem = getSelectedItem();3export const getSelectedItem = () => {4 return selectedItem;5}6const selectedItem = {id: 1, name: 'test'};
Using AI Code Generation
1const selectedItem = await this.browser.executeScript(function() {2 return document.querySelector('storybook-root').getSelectedItem();3});4await this.browser.executeScript(function() {5 document.querySelector('storybook-root').setItem('item1');6});7const items = await this.browser.executeScript(function() {8 return document.querySelector('storybook-root').getItems();9});10await this.browser.executeScript(function() {11 document.querySelector('storybook-root').setItems(['item1', 'item2']);12});13await this.browser.executeScript(function() {14 document.querySelector('storybook-root').setItems(['item1', 'item2']);15});16await this.browser.executeScript(function() {17 document.querySelector('storybook-root').setItems(['item1', 'item2']);18});19await this.browser.executeScript(function() {20 document.querySelector('storybook-root').setItems(['item1', 'item2']);21});22await this.browser.executeScript(function() {23 document.querySelector('storybook-root').setItems(['item1', 'item2']);24});25await this.browser.executeScript(function() {26 document.querySelector('storybook-root').setItems(['item1', 'item2']);27});28await this.browser.executeScript(function() {29 document.querySelector('storybook-root').setItems(['item1', 'item2']);30});31await this.browser.executeScript(function() {32 document.querySelector('storybook-root').setItems(['item1', 'item2']);33});34await this.browser.executeScript(function() {35 document.querySelector('storybook-root').setItems(['item1', 'item2']);36});37await this.browser.executeScript(function() {38 document.querySelector('storybook-root').setItems(['item1', 'item2']);39});40await this.browser.executeScript(function() {41 document.querySelector('storybook-root').set
Using AI Code Generation
1const elem = await this.driver.findElement(By.css('storybook-root'));2const selectedItem = await elem.getSelectedItem();3console.log(selectedItem);4const elem = await this.driver.findElement(By.css('storybook-root'));5const selectedItem = await elem.getSelectedItem();6console.log(selectedItem);7const elem = await this.driver.findElement(By.css('storybook-root'));8const selectedItem = await elem.getSelectedItem();9console.log(selectedItem);10const elem = await this.driver.findElement(By.css('storybook-root'));11const selectedItem = await elem.getSelectedItem();12console.log(selectedItem);13const elem = await this.driver.findElement(By.css('storybook-root'));14const selectedItem = await elem.getSelectedItem();15console.log(selectedItem);16const elem = await this.driver.findElement(By.css('storybook-root'));17const selectedItem = await elem.getSelectedItem();18console.log(selectedItem);19const elem = await this.driver.findElement(By.css('storybook-root'));20const selectedItem = await elem.getSelectedItem();21console.log(selectedItem);22const elem = await this.driver.findElement(By.css('storybook-root'));23const selectedItem = await elem.getSelectedItem();24console.log(selectedItem);25const elem = await this.driver.findElement(By.css('storybook-root'));26const selectedItem = await elem.getSelectedItem();27console.log(selectedItem);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!