Way to get additional data on onDragEnd - react-beutiful-dnd - react-beautiful-dnd

The normal response of the onDragEnd is like this.
{
'draggableId': '2',
'type': 'DEFAULT',
'source': {
'index': 0,
'droppableId': '1'
},
'mode': 'FLUID',
'destination': {
'droppableId': '2',
'index': 0
},
'combine': null,
'reason': 'DROP'
};
Is there any way I can pass additional parameter to the draggable component, So that I will be able to get them in the onDragEnd.
{
'draggableId': '2',
'type': 'DEFAULT',
'source': {
'index': 0,
'droppableId': '1'
},
'mode': 'FLUID',
'destination': {
'droppableId': '2',
'index': 0
},
'combine': null,
'reason': 'DROP'
data: {
cardSpecificKey : value
}
};
It will be helpful, so that, I don't have to read the states again to get those required data.

Related

merge nested objects in lodash

I have a nested Object: (Example of the form)
const result = { '1':
{ 'a':
[ { id: '1',
sndid: 'a',
type: 'ios',
value: '55',
weight: 2
},
{ id: '1',
sndid: 'a',
sumvalue: 2 },
{ id: '1',
sndid: 'a'},
{ id: '1',
sndid: 'a',
calcsum: '3' } ],
'2':
[ { id: '1',
sndid: 'b',
type: 'ios',
value: '55',
weight: 3
},
{ id: '1',
sndid: 'b',
sumvalue: 3 },
{ id: '1',
sndid: 'b'},
{ id: '1',
sndid: 'b',
calcsum: '7' } ] },
'3':
{ 'a':
[ { id: '3',
sndid: 'a',
type: 'ios',
value: '55',
weight: 23},
{ id: '3',
sndid: 'a',
sumvalue: 4 },
{ id: '3',
sndid: 'a',
sumvalue_old: '4' },
{ id: '3',
sndid: 'a',
calcsum: '5' } ] },
}
const assignedobject = {};
_.forEach(result, (values) => {
_.forEach(values, (vals) => {
_.forEach(vals, (val) => {
_.assign(assignedobject, val);
});
});
});
console.log(assignedobject)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js"></script>
With the Values in this Object I want to calc multiple values. Before that I want to transforme this Object into a (more readable) Object.
Every "id" have multiple "sndid". So I want to group the Object by "id" and "sndid".
(For example the transformed Object should have this structure)
{ id: '1',
sndid: 'a',
type: 'ios',
values: '22',
sumvalue: 8,
weight: 20,
calcsum: 2
},
{ id: '1',
sndid: 'b',
type: 'ios',
values: '22',
sumvalue: 8,
weight: 20,
calcsum: 2
},
{ id: '2',
sndid: 'a',
type: 'ios',
values: '22',
sumvalue: 8,
weight: 20,
calcsum: 2}
I tried to loop into all nested objects and assign it to a new object. But he just push the last loop into my Object. Also the code looks badly.
The result is like above the example but he only take the last object.
Recursive flatMap variant:
const result = { '1':
{ 'a':
[ { id: '1',
sndid: 'a',
type: 'ios',
value: '55',
weight: 2
},
{ id: '1',
sndid: 'a',
sumvalue: 2 },
{ id: '1',
sndid: 'a'},
{ id: '1',
sndid: 'a',
calcsum: '3' } ],
'2':
[ { id: '1',
sndid: 'b',
type: 'ios',
value: '55',
weight: 3
},
{ id: '1',
sndid: 'b',
sumvalue: 3 },
{ id: '1',
sndid: 'b'},
{ id: '1',
sndid: 'b',
calcsum: '7' } ] },
'3':
{ 'a':
[ { id: '3',
sndid: 'a',
type: 'ios',
value: '55',
weight: 23},
{ id: '3',
sndid: 'a',
sumvalue: 4 },
{ id: '3',
sndid: 'a',
sumvalue_old: '4' },
{ id: '3',
sndid: 'a',
calcsum: '5' } ] },
}
const extractSndid = item => {
if (_.isArray(item)) {
return _.map(item, i => _.assign(...i));
}
return extractSndid(_.values(item))
}
const assignedobject = _.flatMap(result, extractSndid);
console.log(assignedobject)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js"></script>

Typescript dynamic filter array based on value entered

I have a requirement that to filter the arrays of objects based on the value entered in input fields.
Data
data: [{
taskname: 'Test1',
taskId: '1',
status: 'Submitted'
}, {
taskname: 'Test2',
taskId: '2',
status: 'Resolved'
}, {
taskname: 'Test3',
taskId: '4',
status: 'Submitted'
}, {
taskname: 'Test4',
taskId: '5',
status: 'In Progress'
}, {
taskname: 'Test5',
taskId: '6',
status: 'Resolved'
}, {
taskname: 'Test6',
taskId: '7',
status: 'Submitted'
}
}]
in the input field, while entering
R
Then i have filter data based on status value with "R"
Respected o/p
data: [{
taskname: 'Test2',
taskId: '2',
status: 'Resolved'
}, {
taskname: 'Test5',
taskId: '6',
status: 'Resolved'
}
}]
My code
var o/p = data.filter(x => x.status == input filed value);
The above code is not working properly. Thanks in advance.
let filterdData = data.filter(x => x.status.includes(input))
You can use String.prototype.includes() to return the subset of data whose status property includes your input

Batch: Sequencing requests with the dependsOn property

The documentation Combine multiple requests in one HTTP call using JSON batching for sequencing requests with the dependsOn property indicates that not all calls in the sequence needs to be dependent, however, when making the following batch call I receive the error:
BadRequest - Batch should be either fully sequential or fully parallel
'requests': [
{
'id': '1',
'method': 'GET',
'url': '/me/messages?$top=1'
},
{
'id': '2',
'dependsOn': [ '1' ],
'method': 'GET',
'url': '/me/calendar/events?$top=1'
},
{
'id': '3',
'method': 'GET',
'url': 'me/contacts?$top=1'
}
]
You need to add dependsOn to 'id': '3' request too.
Like:
'requests': [
{
'id': '1',
'method': 'GET',
'url': '/me/messages?$top=1'
},
{
'id': '2',
'dependsOn': [ '1' ],
'method': 'GET',
'url': '/me/calendar/events?$top=1'
},
{
'id': '3',
'dependsOn': [ '2' ],
'method': 'GET',
'url': 'me/contacts?$top=1'
}
]

InsertAll failing with templateSuffix

I'm trying to streaming data to tables in BigQuery using templateSuffix.
The payload:
{
'rows': [{
'insertId': u '47669460689243',
'ignoreUnknownValues': True,
'json': {
'city': u 'jarinu',
'cookies': [],
'remote_addr': u '1.1.1.1',
'country': u 'BR',
'region': u 'sp',
'publishTime': u '2016-10-29T00:04:03.280Z',
'publishTimeUTC': u '2016-10-29T00:04:03.280Z',
'cityLatLong': u '-23.103663,-46.728509',
'user_agent': u 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36',
'messageId': u '47669460689243',
'path': u '/hit/ga',
'arguments': []
},
'templateSuffix': '20161029'
}]
}
When I submit this streaming job, I see a errorless response:
{"kind": "bigquery#tableDataInsertAllResponse"}
But the table will never be created :(
The schema I've used to create the template original table:
{
'fields': [{
'name': 'messageId',
'type': 'STRING',
'mode': 'REQUIRED'
}, {
'name': 'publishTimeUTC',
'type': 'TIMESTAMP',
'mode': 'REQUIRED'
}, {
'name': 'publishTime',
'type': 'STRING',
'mode': 'REQUIRED'
}, {
'name': 'remote_addr',
'type': 'STRING',
'mode': 'REQUIRED'
}, {
'name': 'user_agent',
'type': 'STRING',
'mode': 'REQUIRED'
}, {
'name': 'cookies',
'type': 'RECORD',
'mode': 'REPEATED',
'fields': [{
'name': 'name',
'type': 'STRING',
'mode': 'REQUIRED'
}, {
'name': 'value',
'type': 'STRING',
'mode': 'NULLABLE'
}, ]
}, {
'name': 'country',
'type': 'STRING',
'mode': 'NULLABLE'
}, {
'name': 'region',
'type': 'STRING',
'mode': 'NULLABLE'
}, {
'name': 'city',
'type': 'STRING',
'mode': 'NULLABLE'
}, {
'name': 'cityLatLong',
'type': 'STRING',
'mode': 'NULLABLE'
}, {
'name': 'path',
'type': 'STRING',
'mode': 'REQUIRED'
}, {
'name': 'arguments',
'type': 'RECORD',
'mode': 'REPEATED',
'fields': [{
'name': 'name',
'type': 'STRING',
'mode': 'REQUIRED'
}, {
'name': 'value',
'type': 'STRING',
'mode': 'REPEATED'
}, ]
}, ]
}
But when I run this code without the template suffix, feeding a "traditional" table, It happens ok immediately!
Are the any problems with my schema, my payload? Am I'm missing something?
What does your request look like? The template_suffix should be part of the insert request instead of row, check here: https://cloud.google.com/bigquery/streaming-data-into-bigquery#template-tables
To use a template table via the BigQuery API, add a templateSuffix parameter to your insertAll request.
The problem with the "missing" table is probably because you previously deleted a table with the same name.
If I create a table called foobar, then deleted, another table created called foobar doesn't seem to show up. I seem to remember this is documented somewhere but can't find it right now.

map JSON data to jqGrid

the below code creates a javascript object, converts it to JSON, and attempts to load it into a jqGrid. I have been following the wiki examples, and I feel I have followed their lead very precisely, but still am having no luck. Can anyone see what the missing link is here?
jQuery(document).ready(function () {
var gridData = {
total: 2,
page: '1',
records: '12',
rows: [
{ id: '1', col1: 'cell11', col2: 'cell12', col3: 'cell13' },
{ id: '2', col1: 'cell21', col2: 'cell22', col3: 'cell23' }
]
};
gridData = $.toJSON(gridData);
$('#jqgrid').jqGrid({
data: gridData,
datatype: 'json',
colNames: ['Col1', 'Col2', 'Col3'],
colModel: [
{ name: 'col1' },
{ name: 'col2' },
{ name: 'col3' }
],
jsonReader: {
root: 'rows',
total: 'total',
page: 'page',
records: 'records',
repeatitems: false,
id: '0'
}
})
You don't need convert the data to JSON string. jqGrid will have to convert the data back. In the case you should use datatype:'jsonstring' and datastr:gridData.
The best way would be to use just array of item:
var gridData = [
{ id: '1', col1: 'cell11', col2: 'cell12', col3: 'cell13' },
{ id: '2', col1: 'cell21', col2: 'cell22', col3: 'cell23' }
];
$('#jqgrid').jqGrid({
data: gridData,
datatype: 'local',
...
});

Resources