React-Native-Navigation (WIX) : How do I update the badge count for a bottomTab? - react-native-navigation

I am using the Navigation.mergeOptions() function to try to update the badge count of the third tab (tabindex = 2), however, the badge count is not updating. Here's what my original layout object looks like for setRoot:
{
root: {
bottomTabs: {
children: [
{
stack: {
children: [
{
component: {
name: 'navigation.main.Dispensaries',
},
}
],
options: {
topBar,
bottomTab: NavStyles.tab('Dispensaries', dispensariesTabIcon),
}
}
},
{
stack: {
children: [
{
component: {
name: 'navigation.main.Orders',
},
}
],
options: {
bottomTab: NavStyles.tab('My BudBuddy', myBudbuddyTabIcon),
topBar,
}
}
},
{
stack: {
children: [
{
component: {
name: 'navigation.main.Checkout',
},
}
],
options: {
bottomTab: NavStyles.tab('Bag', bagTabIcon, badge),
topBar,
}
}
},
], options: {
//topBar,
bottomTabs: {
currentTabIndex: 0,
},
},
},
}
Then, in one of my components, I did this, but it causes no effect on the badge count:
Navigation.mergeOptions(this.props.componentId, {
bottomTabs: {
children: [
{}, {},
{
stack: {
options: {
bottomTab: {
badge: '31',
},
},
},
},
],
},
});
I'm quite sure that's wrong, and I even tried replicating the original layout object in the first code block above, except with a different badge count, and it doesn't do anything. Any ideas? Thank you!

Updating options for a specific tab
Hope this helps.

Related

Nested object iteration

Fighting with this one for a while now...
I'm trying to modify each image object by adding more keys-values and changing some values.
As the keys are not having the same names, I need to identify the images by .hasOwnProperty('formats')
The object can be even more nested not only with key-values pairs but with arrays as well (this is where it gets complicated)
const object = {
name: "help",
mainImage: {
name: "picture1",
formats: {
small: {
name: "small_picture1",
},
medium: {
name: "medium_picture1",
},
large: {
name: "large_picture1",
},
},
},
carousel: [
{
name: "picture2",
formats: {
small: {
name: "small_picture2",
},
medium: {
name: "medium_picture2",
},
large: {
name: "large_picture2",
},
},
},
{
name: "picture3",
formats: {
small: {
name: "small_picture3",
},
medium: {
name: "medium_picture3",
},
large: {
name: "large_picture3",
},
},
},
],
nestedPage: {
name: "moreHelp",
mainImage: {
name: "picture4",
formats: {
small: {
name: "small_picture4",
},
medium: {
name: "medium_picture4",
},
large: {
name: "large_picture4",
},
},
},
carousel: [
{
name: "picture5",
formats: {
small: {
name: "small_picture5",
},
medium: {
name: "medium_picture5",
},
large: {
name: "large_picture5",
},
},
},
{
name: "picture5",
formats: {
small: {
name: "small_picture5",
},
medium: {
name: "medium_picture5",
},
large: {
name: "large_picture5",
},
},
},
],
},
};
This is what I tried, but it only goes to a certain level.
const customSanitizer = (entity) => {
const isObject = (value) => {
return !!(value && typeof value === "object" && !Array.isArray(value));
};
if (isObject(entity)) {
Object.entries(entity).forEach(([key, value]) => {
if (isObject(entity[key])) {
if (value.hasOwnProperty("formats")) {
entity[key] = formatImageObject(value);
} else {
customSanitizer(entity[key]);
}
} else {
customSanitizer(entity[key]);
}
});
}
if (Array.isArray(entity)) {
entity.forEach((node) => {
customSanitizer(node);
});
}
}

Mongodb sort when a field value correspond

my problem is a bit tricky.
Here is an example of 3 "types" of elements that my database can give me:
First one :
{
_id: 1234,
informations: {
...
},
data_fields: [
{
name: "input",
value: "loremipsum"
},
{
fieldset_name: "label",
value: "loremipsum"
}
]
}
Second One :
{
_id: 2451,
informations: {
...
},
data_fields: [
{
name: "number",
value: "loremipsum"
},
{
fieldset_name: "input",
value: "loremipsum"
},
{
fieldset_name: "button",
value: "loremipsum",
fieldset_data: [
[
{
fieldset.name: "home",
fieldset.value: "loremipsum"
}
]
]
},
]
}
Third one :
{
_id: 4561,
informations: {
...
},
data_fields: [
{
fieldset_name: "button",
value: "loremipsum",
fieldset_data: [
[
{
fieldset.name: "input",
fieldset.value: "loremipsum"
},
{
fieldset.name: "label",
fieldset.value: "loremipsum"
}
],
[
{
fieldset.name: "home",
fieldset.value: "loremipsum"
}
]
]
},
]
}
In this example, let's say I want to check if there is an input.
As you can see, there are different places I need to check:
In all data_fields with name, again but with fieldset_name and in each fieldset_data if they exist in the data_fields.
And I want that if there is at least one input, it gives my element a element field.
So my result would be for example :
{
_id: 1234,
informations: {
...
},
data_fields: [
{
name: "input",
value: "loremipsum"
},
{
fieldset_name: "label",
value: "loremipsum"
}
],
element: "input"
}
Actually, I have done an aggregate and that :
{ $addFields: {
element: { $map: {
input: "$data_fields",
as: "data_field",
in: { $cond: {
if: { $eq: ["$$data_field.name", "input"] },
then: "$$data_field.name",
else: { $cond: {
if: { $eq: ["$$data_field.fieldset_name", "input"] },
then: "$$data_field.fieldset_name",
else: { $map: {
input: "$$data_field.fieldset_data",
as: "fieldsets",
in : { $map: {
input: "$$fieldsets",
as: "fieldset",
in: { $cond: {
if: { $eq: ["$$fieldset.name", "input"] },
then: "$$fieldset.name",
else: "$$REMOVE"
}}
}}
}}
}}
}}
}}
}}
but the result look like that :
{
_id: 1234,
informations: {
...
},
data_fields: [
{
name: "input",
value: "loremipsum"
},
{
fieldset_name: "label",
value: "loremipsum"
}
],
element: [null, "input", [null, null, null], null]
}

How can I create an Elasticsearch Query DSL for finding objects with empty array OR a value in same object

I am searching for objects in Elasticsearch 6.3.
I have 3 objects:
{
identifier: 01,
lineCodes: [],
},
{
identifier: 02,
lineCodes: [
{
link: "brussels",
name: "br"
},
{
link: "antwerp",
name: "an"
},
],
},
{
identifier: 03,
lineCodes: [
{
link: "ghent",
name: "gh"
},
],
}
My lineCodes schema is:
{
"lineCodes": {
"properties": {
"__typename": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"link": {
"type": "keyword"
},
"name": {
"type": "keyword"
}
}
}
}
Can you help me with Query DSL's that find all objects with:
Brussels in lineCodes.link or empty lineCodes
All empty lineCodes
Ghent in lineCodes.link or empty lineCodes
query 1 should result in object 01 and 02
query 2 should result in object 01
query 3 should result in object 01 and 03
I tried this query, but it gives me not the empty LineCodes objects
let query = {
size: 1000,
index: 'catalog',
body: {
query: {
bool: {
must: [
{
bool: {
should: [
{ term: { 'lineCodes.link': lineCode } },
{ terms: { 'lineCodes': [] } },
],
},
}
],
}
}
}
};
You can use the exists query ( doc here ) and negate it with a must_not clause in a bool query
Could you try :
{
size: 1000,
index: 'catalog',
body: {
query: {
bool: {
must: [
{
bool: {
should: [
{ term: { 'lineCodes.link': lineCode } },
{
bool: {
must_not: {
exists: {
field: 'lineCodes'
}
}
}
}
],
},
}
],
}
}
}
}
NB: As you use a term query for linecode.link watch out for case and accents!
Hope it helps !

Actions on Google - Location Permission

How do you request device location using webhook, and actions on google v2.
Previously, I used permission_request field, but that is now deprecated, and not sure where it fits into the response object at.
json response
{
speech: "",
displayText: "",
data: {
google: {
expectUserResponse: true,
noInputPrompts: [
{
textToSpeech: "Hello McFly!"
},
{
textToSpeech: "Good talk, Russ"
},
{
textToSpeech: "Alright, I'm just gonna go over here and hang out. Let me know if there is anything else I can do for you."
}
],
richResponse: {
items: [
{
simpleResponse: {
textToSpeech: "Testing",
ssml: "<speak >Testing</speak>",
displayText: "Testing"
},
basicCard: null
}
],
suggestions: [ ],
linkOutSuggestion: {
destinationName: null,
url: null
}
},
systemIntent: null,
possibleIntents: [
{
intent: "actions.intent.PERMISSION",
inputValueData: {
#type: "type.googleapis.com/google.actions.v2.PermissionValueSpec",
optContext: "To provide weather information for you.",
permissions: [
"DEVICE_COARSE_LOCATION"
]
}
}
]
}
},
contextOut: [ ],
source: "Abbi"
}
so i needed to add the permission request as a system intent, not expected intent, or possible intent.
the below json works now
{
speech: "",
displayText: "",
data: {
google: {
expectUserResponse: true,
noInputPrompts: [
{
textToSpeech: "Hello McFly!"
},
{
textToSpeech: "Good talk, Russ"
},
{
textToSpeech: "Alright, I'm just gonna go over here and hang out. Let me know if there is anything else I can do for you."
}
],
richResponse: {
items: [
{
simpleResponse: {
textToSpeech: "",
ssml: "<speak ></speak>",
displayText: ""
},
basicCard: null
}
],
suggestions: [ ],
linkOutSuggestion: {
destinationName: null,
url: null
}
},
systemIntent: {
intent: "actions.intent.PERMISSION",
data: {
#type: "type.googleapis.com/google.actions.v2.PermissionValueSpec",
optContext: "To provide an accurate experience, ",
permissions: [
"DEVICE_PRECISE_LOCATION"
],
carouselSelect: null
}
}
}
},
contextOut: [ ],
source: "Abbi"
}

how to count the number of documents under nested fields in elasticsearch

I am new to elasticsearch, just started to try out utilize the elasticsearch to do fulltext search on nodejs. Currently I have a problem to find out the count the number of item of the nested field. For example suppose this is my data:
{
user1: {
movies: [
{
title: 'eat'
},
{
title: 'drink'
}
],
books: [
{
author: 'apple'
}
]
},
user2: {
movies: [
{
title: 'jump'
},
{
title: 'punch'
},
{
title: 'sleep'
},
{
title: 'eat'
}
],
books: [
{
author: 'orange'
}
]
}
}
how to do a simple count of how many movies does user1 or user2 have?(2 and 4 in this case).
If it turns out to be surprisingly difficult, I could still fallback to store that number somewhere else.
let users = {
user1: {
movies: [
{
title: 'eat'
},
{
title: 'drink'
}
],
books: [
{
author: 'apple'
}
]
},
user2: {
movies: [
{
title: 'jump'
},
{
title: 'punch'
},
{
title: 'sleep'
},
{
title: 'eat'
}
],
books: [
{
author: 'orange'
}
]
}
}
console.log(`User1 count: ${users.user1.movies.length}`);
console.log(`User2 count: ${users.user2.movies.length}`);

Resources