Each Child in a list should have a unique "key" prop
check render method of HomeScreen
Component Stack(<FeaturedRow/>)
here is the featured Row code :
<FeaturedRow
key={category.id}
id={category.id}
title={category.name}
description={category.short_description}
/>;
What can I do to Avoid this error, on my HomeScreen?
I counterchecked my Sanity backend, updated all schemas, the sanity client is running perfectly.
Nor sure if error is in FeaturedRow component/HomeScreen
Here you are trying to map through a list creating multiple FeaturedRow I can see that for every one you have a key and it is equal to category.id but this can happen if you have duplicate ids or some null categories or ids or categories without the property id, otherwise you can use the index of the map function :
list.map((category,index)=>
<FeaturedRow
key={index}
//...
/>)
But verify your list, try to console.log(list) before mapping and see what is the problem
Related
I have 2 tables, evenements and participants, represented by 2 models Evenement and Participant.
Those entities are belongsToMany related, so I have a third table evenement_participant following Laravel's naming conventions, and inside are foreign evenement_id and participant_id columns.
I'm able to retrieve the relationship and I can
dd($evenement->participants)
which gives me a collection of participants.
In my controller, I have this db call:
$evenements = Evenement::withCount(['participants' => function($query) {
$query->where('is_active', 1);
}])
This withCount generates a participants_count attribute for each evenement.
In my blade view, there is a for-each loop on the evenements collection, and somewhere I do this:
$evenement->participants_count
and I face this error:
Property [participants_count] does not exist on this collection
instance.
However, if instead I do the following in the same blade view
#dd($evenement->participants_count)
it dumps me the count.
I dropped all the evenements to keep just one for testing, and I still have the same error.
Sorry, made a typo in a condition inside my blade loop
I am wondering if it is possible to filter content in Sanity Studio according to set criteria. For example, return all published posts or all posts within a particular category, etc.
Here is a short video showing what I mean: https://www.loom.com/share/5af3a9dd79f045458de00e8f5365cf00
Is this possible? If so, is there any documentation on how to do it?
Thanks.
The easiest way I've found to make all kinds of filters is using the Structure Builder. With it you add as many sections you like, name them, and give it your own filter in the form of groq and params.
Se documentation: https://www.sanity.io/docs/structure-builder-introduction
As an example I've added a S.listItem to the deskStructure.js file that gets all articles that are missing the module field.
export default async () =>
S.list()
.title('Content')
.items([
// ...
S.listItem() // <-- New root item for my filters
.title('My article filters')
.icon(FaRegCopyright)
.child(
S.list() // <-- List of filters
.title('My article filters')
.items([
S.listItem() // <-- Item with filter description
.title('Articles without module')
.icon(FaCogs)
.child(
S.documentList() // <-- Filtered list of articles
.title('Articles without module')
.menuItems(S.documentTypeList(menuType).getMenuItems())
.filter('_type == $type && !defined(module)')
.params({ type: 'article' })
),
S.listItem(), // more filters
S.listItem(), // more filters
])
),
// ...
It doesn't make different filters on one list of elements. It's more making different lists that are all ready filtered as you need. And you can give it what ever icon and text you want. Potato/potàto ,'-)
In the sorting list I don't think you can do much other than adding more sorting. And It doesn't work when the list of elements get larger anyways so I wouldn't bother. But it's in the Sort Order section: https://www.sanity.io/docs/sort-orders
I built my own simple REST API with Express and now I'm consuming it from my client (Vue.js)
So in my page I access all the data from this endpoint: GET /api/books, and it works fine
Now I also have a "sort by" button where I want to get the data by the latest entries. I don't know if that's a good way or if I have to handle this in the backend but what I do is calling the same endpoint which is GET /api/books and sorting the data to get them the right way
For ex:
sortByLatest() {
axios
.get("/api/books")
.then(res => {
const books = res.data;
const sortedBooks = books.sort((a, b) => b.createdAt > a.createdAt ? 1 : -1
);
this.books = sortedBooks;
})
// catch block
}
I do that for everything. If I need a limited number of results or a specific property from the data I have to write some logic in the axios .then block to sort or filter what I want. Is this bad practice?
But that's not my actual problem
My problem is, in addition of sorting by the latest entries, I also want to filter the results by a specific property. The problem is when I click the A button it's gonna filter the books by a specific property, and when I click the B button it's gonna sort them buy the latest entries, but not both at the same time!
And what if I want additionnal things like limit the number of results to 10, filter by other properties etc... I want to be able to create requests that ask all those things at once. How can I do that? Do I have to build that in the backend?
I saw some websites using url parameters to filter stuff, like /genre=horror&sort=latest, is that the key of doing it?
Thank you for your time
I am developing a flutter app which shows an order list and it gonna show respective order details onTap, as I have seen a lot of examples showing on how to pass data from the list screen to the screen that shows the details of that object passing in which we can read the data by widget.obj.name. However, in my case, I would like to pass the id of one of the orders and here I was able to get the order id from the previous screen with widget.orderId but I am stuck with retrieving the details by calling the get order details API.
To further explain I will show my codes here:
In orderlist.dart,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrderDetail(
orderId: order.id,
onRefresh: onRefresh,
)),
);
},
In order_detail.dart, I was trying to build the UI and I am getting null for model.orderItem.toString(). It works perfectly fine when I try to run Services().getOrderDetails() API directly but since I have the OrderItem model and I shall use it with provider.
#override
Widget build(BuildContext context) {
return ListenableProvider<OrderItemModel>(
create: (_) => OrderItemModel(),
child: Consumer<OrderItemModel>(
builder: (context, model, child) {
print("orderItem: " + model.orderItem.toString());
},
));
}
I am getting the following error:
Unhandled Exception: Error: Could not find the correct Provider above this OrderDetail Widget. This likely happens because you used a BuildContext that does not include the provider of your choice. There are a few common scenarios:
The provider you are trying to read is in a different route.
Providers are "scoped". So if you insert of provider inside a route, then other routes will not be able to access that provider.
You used a BuildContext that is an ancestor of the provider you are trying to read.
Make sure that OrderDetail is under your MultiProvider/Provider.This usually happen when you are creating a provider and trying to read it immediatly.
I have tried with the solution provided by Flutter but it still gave me the same error. Is there anything need to be done in the orderlist.dart part in order to call OrderItemModel provider in orderdetails.dart? Did i miss out anything?
Summary: move ListeableProvider a level higher (in orderlist.dart), where the route is pushed (OrderDetail should be its child).
I think this may be because the OrderDetail is not a child of OrderList or whichever widget has the onTap action. This happens because you are specifying a route where OrderDetail is the root and it has no idea about the provider of the other widget. You will need to wrap it into a ChangeNotifierProvider (https://flutter.dev/docs/development/data-and-backend/state-mgmt/simple#changenotifierprovider or what you are using, ListeneableProvider) and build Order Detail there. It will look something along the lines of:
....
builder: (_) => ChangeNotifierProvider.value(value: model, child: OrderDetail(...));
The model will be coming from the OrderList which I am assuming is the provider.
And in OrderDetail, you will need a Consumer<OrderItemModel> instead of the ListeneableProvider.
I would like the titles of the screens, as well as the delete confirmation messages, to use a different field to identify the record to the user than the id, since the id format is not very human friendly.
I know how to customise the text of the messages and titles. However, I have no idea how to access other fields than the id param when constructing the text message.
Is this possible, or do I need to anonymise the messages to not include a reference to the actual record?
This is an illustration of the delete message, where I'd like something nicer for the user, like eg. the e-mail of the employee to delete, instead of the random string that is the id value.
In the page headers you can use any field from the record:
https://marmelab.com/react-admin/Show.html#page-title
const PostTitle = ({ record }) => {
return <span>Post {record ? `"${record.title}"` : ''}</span>;
};
export const PostShow = (props) => (
<Show title={<PostTitle />} {...props}>
...
</Show>
);
In the deletion confirmation dialog, now it is impossible to change the id field to another, in my opinion this possibility is only in development:
https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.js