React component does not update - jquery-ui

I am using React and Redux for my application. I have a dynamic form when i drag my question of same type my component position does not update.
For dragging i am using JqueryUI Sortable
My question object:
var questions : [
{"name" : "Question Title", "title" : "Question Title", "type" : "text"},
{"name" : "Question Title", "title" : "Question Title", "type" : "text"}
]
React Component
class SingleTextQuestion extends React.Component{
constructor(props){
super(props)
}
componentDidMount(){
let draggableFunction = new utilityFunction();
draggableFunction.addDraggableFeature('divQuestion_container');
}
render(){
//create span or textbox based upon edit mode
let element = Symbol();
element = (<QuestionTitle questionNumber={this.props.questionNumber} data={this.props.data} key={this.props.key} />)
return (
<div id={"div_"+this.props.questionNumber} className="div_commonId" key={this.props.key}>
<div className='icons_parent'>
<DragIcon />
<DeleteButon questionNumber={this.props.questionNumber} />
</div>
<div id={"q_no_title_"+this.props.questionNumber} className="q_no_title_class">
<QuestionNumber questionNumber={this.props.questionNumber}/>
<div id={"title_q"+this.props.questionNumber} className="question-title">
{element}
</div>
</div>
<div id={"typeDiv_"+this.props.questionNumber}>
<input id={"optionTypeElem_0_"+this.props.questionNumber}/>
</div>
</div>
)
}
}
Question Title Component
class QuestionTitle extends React.Component{
constructor(props){
super(props)
this.showTextBox = this.showTextBox.bind(this)
}
showTextBox(content, id, type, choiceIndex){
if(type != 'image'){
this.props.showTextBox(content, id, type, choiceIndex);
}
}
render(){
return(
<span id={"title_"+this.props.questionNumber}
onClick={this.showTextBox.bind(this, this.props.data.title ,
'title_'+this.props.questionNumber, 'question_title', null)} >
{this.props.data.title}
</span>
)
}
}
Now if i change the text of question title, the state gets updated and title is changed. And when i drag the question from 2 to 1. I update my question array too.
var questions : [
{"name" : "Question Title", "title" : "Question Title Changed", "type" : "text"},
{"name" : "Question Title", "title" : "Question Title", "type" : "text"}
]
Question 2 remains at the same position where it was, this happend if i drag question of same type eg: text. The type of question is defined in the question object.

For any list you are rendering, each list item should have a way to identify it (similar to how data is stored in databases, right?). So you can put an id property to each question (doesn't matter how you generate them as long as they are unique for each question). Then you can use that property as a key when rendering them using react.

By adding a key to the component the problem is solved.
When creating an object i appended a key to my data
var questions : [
{"name" : "Question Title", "title" : "Question Title", "type" : "text", "key_rand" : 123},
{"name" : "Question Title", "title" : "Question Title", "type" : "text", "key_rand" : 223}
]
So whenever i update the array index after dragging the key_rand is also changed which renders the component.

Related

How to fix issue regarding pkpass not working after dragging to ios simulator?

I am currently creating a passcard for my app but unfortunately, it is not working. Passcard is not showing in the simulator when dragging it or event downloading it from my email. My pass.json codes are below.
"formatVersion" : 1,
"passTypeIdentifier" : "pass.com.example",
"serialNumber" : "0000000",
"teamIdentifier" : "xxxxxxxx",
"barcode" : {
"message" : "123456789",
"format" : "PKBarcodeFormatPDF417",
"messageEncoding" : "iso-8859-1",
},
"organizationName" : "companyname",
"description" : "companytagline",
"logoText" : "companyname",
"foregroundColor" : "rgb(255,255,255)",
"backgroundColor": "rgb(0,100,0)",
"generic" : {
"auxiliaryFields" : [
{
"key" : "patientName",
"label" : "NAME",
"value" : "Retail Pharmacy 1, Test Patient"
},
{
"key" : "gender",
"label" : "GENDER",
"value" : "Female"
}
],
}
}
This is what I have in my Terminal
hopprlabs-iMac:Desktop developer1$ ./signpass -p healthpass.raw/
2019-02-19 10:10:39.483 signpass[2096:231781] {
".DS_Store" = df2fbeb1400acda0909a32c1cf6bf492f1121e07;
"Icon.png" = 295cb779e5e185efefd6c5e9a2a94c3352e51b2a;
"Icon#2x.png" = 987db966ddc28a72d6bfd15a6565d191be06d0f0;
"pass.json" = 3e66cf17f758939547932654c3394e42470d1c94;
"thumbnail.png" = 2a616d4490d1e12d81ddb0610df6b992ad79aeca;
}
Thanks for emailing that through. Having looked at the package, it seems there is a problem with your icon file.
The iPhone reports this error like this:
Invalid data error reading pass pass.com./0000000. Pass does not contain icon.png/icon#2x.png/icon#3x.png
I suggest making your icon file names lower case, so icon.png instead of Icon.png.
I would also include the #3x size file too.

Adding Implementation Notes and Description to Swagger UI

I am attempting to add Implementation Notes and Description to my Swagger UI. However, neither show up on the UI when implemented as below:
{
"swagger" : "2.0",
"info" : {
"description" : "The definition of the Rest API to service plugin over https on port 9443.",
"version" : "1.0",
"title" : "Plugin Rest API",
"contact" : {
"name" : "John Doe",
"email" : "john.doe#gmail.com"
}
},
"basePath" : "/service",
"tags" : [ {
"name" : "service"
} ],
"schemes" : [ "https" ],
"paths" : {
"/entry" : {
"get" : {
"notes" : "This is a note",
"method" : "get",
"tags" : [ "service" ],
"summary" : "Get an entry by first name and last name",
"description" : "This is a description",
"operationId" : "getEntry",
"produces" : [ "application/xml", "application/json" ],
"parameters" : [ {
"name" : "first",
"in" : "query",
"description" : "The first name",
"required" : true,
"type" : "string"
}, {
"name" : "last",
"in" : "query",
"description" : "The last name",
"required" : true,
"type" : "string"
} ],
"responses" : {
"200" : {
"description" : "Matching entry, or entries, if any, were returned",
"schema" : {
"$ref" : "#/definitions/Service"
}
}
}
},
I am not sure what I am doing wrong in my code. I've tested it on various sample swagger.json files and I cannot seem to get it to work.
notes is not a swagger field. See the documentation
Your description field is written twice, so the first one has been overridden.
you can add implementation notes using notes tag in #ApiOperation annotation as shown below,
#ApiOperation(notes = "Your Implementation Notes will show here[![enter image description here][1]][1]", value = "Add Customer Payment Details and Generate Payment Link through Batch.", nickname = "insertPaymentBatch", tags =
"Insert Payment" )

Firebase query with queryOrderedByKey().queryLimitedToLast(10) does not return one of the last 10 items

I am trying to load the last 10 products that have been added to the all_products table in firebase.
I run the following query with version 3.2.0 of the firebase SDK:
let fbRef = FIRDatabase.database().reference().child("products_all").queryOrderedByKey().queryLimitedToLast(10).observeSingleEventOfType(.Value, withBlock: { snapshot in
for item in snapshot.children {
let keyString = (item as! FIRDataSnapshot).key
However, the items that get returned are not the last 10 items in this table. I have about 1017 products in this table and the first item that gets returned in this query is item 973, while it should be item 1008.
My firebase looks like this (I used childByAutoId to add the products):
{
"products_all" : {
"-KFOiZDrbR4eq4fXSdMZ" : {
"affiliate_url" : "https://some.link.com",
"description" : "product description",
"image_url" : "https://image.url.com/firstImage.jpg",
"images" : [ "https://image.url.com/firstImage.jpg", "https://image.url.com/secondImage.jpg" ],
"merchant" : "merchant.com",
"price_usd" : "100.00",
"title" : "product title"
},
...,
"-KFtOmT_Hq-48chbHh7I" : {
"affiliate_url" : "https://another.link.com",
"description" : "another product description",
"image_url" : "https://image.link.com/anotherImage.jpg",
"images" : [ "https://image.link.com/anotherImage.jpg" ],
"merchant" : "anothermerchant.com",
"original_currency" : "GBP",
"original_price" : "255",
"price_usd" : "364.65",
"product_category" : "Bracelet",
"external_product_id" : "Anothermerchant-123",
"title" : "another product title"
},
...,
"-KFtOmTlcb5-PTQ6kTv8" : {
"affiliate_url" : "https://last.product.com",
"description" : "last product description",
"image_url" : "https://last.product.com/image.jpg",
"images" : [ "https://last.product.com/image.jpg" ],
"merchant" : "anothermerchant.com",
"original_currency" : "GBP",
"original_price" : "179",
"price_usd" : "268.5",
"product_category" : "Bracelet",
"scraped_product_id" : "anothermerchant-493",
"title" : "last product title"
}
}
}
EDIT: Also, the last element in the batch of 10 is number 992 - so the 10 items are neither in the last 10, nor are their all 'neighbours'.
First keys that were included:
-KFtOmT_Hq-48chbHh7I
-KFtOmT_Hq-48chbHh7J
-KFtOmT_Hq-48chbHh7K
Subsequent keys that were skipped:
-KFtOmT0Qj3mrCTlxOfj
-KFtOmT1jouJgm8x_Mi7
-KFtOmT4GUpXtd9Y90sq
-KFtOmT4GUpXtd9Y90sr
-KFtOmT57vidxDl_jpj_
-KFtOmT57vidxDl_jpja
-KFtOmT9yuy-1G8WBrsE
Then some keys were included and others again excluded, the 'coverage' is patchy.

MVC KENDO UI GRID - dynamic columns objects

Hi there im building a grid that have dynamic columns depending on the number of a specific object.. here's a example
public class Team
{
string name {get;set;}
List<members> memberslist {get;set;}
}
public class member{
string name {get;set;}
int goals {get;set;}
}
in the view:
#(Html.Kendo().Grid(Model.TeamList)
.Name("goalslist")
.Columns(columns =>
{
columns.Bound(team => team.name).Title("Team Name");
columns.Bound(team => team.memberslist);
}...
what i would like the result was something like this:
Team Name, John Smith Taylor Fernandez
Ajax       22      1     3
Milan      0      1      2
Any Ideia?! how its done will print object[object], i tried a lot of stufs but without sucess.. thanks
The easiest way to do this is through JSON. Convert your column list into json and pass it to the column, see below. At the very bottom you can see me pushing the columns to the grid. Below that you can see what the JSON itself looks like.
var gridJSON = {
dataSource: {
data: data,
schema: {
model: {} // the model gets filled in by the JSON coming from the database
},
pageSize: 20
},
height: 550,
groupable: false,
sortable: true,
resizable: true,
filterable: {
extra: false,
operators: {
string: {
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to"
}
}
},
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
toolbar: kendo.template($("#template").html())
};
gridJSON.columns = currentReport.JSON.columns;
gridJSON.dataSource.schema.model.fields = currentReport.JSON.fields;
Here is the JSON for the 'currentReport.JSON.columns'
"columns" : [{
"field" : "ReceiverID",
"title" : "Receiver ID"
}, {
"field" : "ReceiverBatchID",
"title" : "Batch ID"
}, {
"field" : "PoNumber",
"title" : "PO Number"
}, {
"field" : "ReceiverTransactionDate",
"title" : "Receiver Trans Date",
"format" : "{0: yyyy-MM-dd}"
}, {
"field" : "PrintingLocation",
"title" : "Location"
}, {
"field" : "VendorID",
"title" : "Vendor ID"
}, {
"field" : "InNemo",
"title" : "InNemo"
}, {
"field" : "Path",
"title" : "Path",
"encoded" : "true",
"template": "#=Path#",
"width" : "50"
}
]

MongoDB/Mongoid: Can one query for ObjectID in embedded documents?

For the record, I'm a bit of a newbie when it comes to Rails and MongoDB.
I'm using Rails+Mongoid+MongoDB to build an app and I've noticed that Mongoid adds ObjectID to embedded documents for some reason.
Is there any way to query all documents in a collection by ObjectID both the main documents and nested ones?
If I run this command
db.programs.findOne( { _id: ObjectId( "4d1a035cfa87b171e9000002" ) } )
I get these results which is normal since I'm querying for the ObjectID at root level.
{
"_id" : ObjectId("4d1a035cfa87b171e9000002"),
"created_at" : "Tue Dec 28 2010 00:00:00 GMT+0000 (GMT)",
"name" : "program",
"routines" : [
{
"name" : "Day 1",
"_id" : ObjectId("4d1a7689fa87b17f50000020")
},
{
"name" : "Day 2",
"_id" : ObjectId("4d1a7695fa87b17f50000022")
},
{
"name" : "Day 3",
"_id" : ObjectId("4d1a76acfa87b17f50000024")
},
{
"name" : "Day 4",
"_id" : ObjectId("4d1a76ecfa87b17f50000026")
},
{
"name" : "Day 5",
"_id" : ObjectId("4d1a7708fa87b17f50000028")
},
{
"name" : "Day 6",
"_id" : ObjectId("4d1a7713fa87b17f5000002a")
},
{
"name" : "Day 7",
"_id" : ObjectId("4d1a7721fa87b17f5000002c")
}
],
"user_id" : ObjectId("4d190cdbfa87b15c2900000a")
}
Now if I try to query with an ObjectID with one of the embedded document (routines) I get null like so.
db.programs.findOne( { _id: ObjectId( "4d1a7689fa87b17f50000020" ) } )
null
I know one can query embedded objects like so
db.postings.find( { "author.name" : "joe" } );
but that seems a bit redundant if you get passed an ObjectID of some sort and want to find in what document that ObjectID resides.
So I guess my question is this...
Is it possible, with some method I'm not familiar with, to query by ObjectID and search the ObjectID's in the embedded documents?
Thanks.
You can't query ObjectIDs globally like that. You would have to do
db.programs.find({"routines._id": ObjectId("4d1a7689fa87b17f50000020")})
no, you can search only by field like { "routines._id" : ObjectId("4d1a7689fa87b17f50000020")}
If you want to get the matched sub-document only you can use $elemMatch with '$' operator like below:
db.programs.find({"_id" : ObjectId("4d1a035cfa87b171e9000002"),
routines:{$elemMatch:{"_id" : ObjectId("4d1a7689fa87b17f50000020")}}},{"routines.$":1})
It will return you only that matched sub-document instead of the complete sub-document.

Resources