Display all properties of an array of objects in Sanity.io - schema

In a Sanity project, I've created a schema containing an array of objects.
In Sanity Studio, this appears as a list of those objects' first property, but I really need to see at least 2 properties for it to be meaningful.
I can't find a way to do this. Is it possible?
Below is my schema. It represents a blog article which holds an array of translations. Each translation is defined by a language and a reference to another article.
// sanity\schemas\documents\article.ts
import { defineArrayMember, defineField, defineType } from "sanity"
import translation from "../objects/translation";
export default defineType({
title: 'Article',
name: 'article',
type: 'document',
fields: [
defineField({ title: 'Title', name: 'title', type: 'string' }),
defineField({ title: 'Translations', name: 'translations', type: 'array', of: [defineArrayMember(translation)] }),
// sanity\schemas\objects\translation.ts
import { defineField, defineType } from "sanity"
export default defineType({
title: 'Translation',
name: 'translation',
type: 'object',
fields: [
defineField({ title: 'Language', name: 'language', type: 'string' }),
defineField({ title: 'Article', name: 'article', type: 'reference', to: [{ type: 'article' }] }),
]
});
This is how it shows up:
I would like to see "fr - title of the article in french".
Note that I'd like to do this for other fields too, so I'm not looking for a package to handle internationalisation. Is it doable?

Found the answer: sanity.io/docs/previews-list-views
I hadn't realised this applies to lists within fields too, not just lists of documents. Adding the "preview" property at the root of my schema did the trick:
preview: {
select: {
title: 'field1',
subtitle: 'field2'
}
}

Related

Sanity.io field-level localisation

I need to have proper localisation for my Sanity CMS.
I found the official information here, but it doesn't get into details. I tried to apply the same approach for block type:
export default {
title: 'Localised block',
name: 'localeBlock',
type: 'object',
fieldsets: [
{
title: 'Translations',
name: 'translations',
options: {
collapsible: true,
},
},
],
fields: supportedLanguages.map(lang => ({
title: lang.title,
name: lang.id,
type: 'block',
fieldset: lang.isDefault ? null : 'translations',
})),
}
But I got the following error:
Object type "localeBlock"
localeBlock:object → fields → block:block
Found unknown properties for block declaration: "fieldset"
How do I implement block localisation? Is there a deeper documentation on localisation than the official one?

How to store Array of multipe types with realm in react native

When using realm, if i need to store filed with value like [783, "Name of"],
This is my code, when i use mixed i got null,
export const Schema = {
name: 'Schema',
primaryKey: 'id',
properties: {
id: 'int',
name: {type: 'string', indexed: true},
field: 'string[]', // mixed[] not work too
}
}
Any help please !!!

Realm-js schema with nested objects

I want to easily query such results:
[{
name: 'john_doe',
info: {
age: 24,
notes: 'custom text',
phoneNumbers: {
home: 112345678,
work: 1234567,
},
},
}, {...}, {...}...]
... by such query:
contacts.filtered("info.age = 24 AND info.notes CONTAINS 'custom'");
How should i create such schema? docs are very confusing about data types and nested properties:
https://realm.io/docs/react-native/0.14.0/api/Realm.html#~PropertyType
https://realm.io/docs/react-native/latest/#nested-objects
I do not need to retrieve any parts of this data separately - only complete object with all nested objects at once.
You could put all fields into a single object:
var ContactSchema = {
name: 'Contact',
properties: {
name: 'string',
age: 'int',
notes: 'string',
homePhone: 'string',
workPhone: 'string'
}
};
Alternatively you could create child objects for info and phoneNumbers but if you are not sharing this data across multiple contacts then this probably isn't needed.

keystoneJS relationship to self

I want to create a Category model that can hold another category, but having a problem with reference field that I can set my current category to it self
Any suggestions how to achieve hierarchical categories?
Does KeystoneJS have filter like 'not equal'?
In other hand, maybe I can set default reference field to it self and it will be like a root...
My current code below:
var keystone = require('keystone'),
Types = keystone.Field.Types;
var PageCategory = keystone.List('PageCategory', {
map: { name: 'name' },
autokey : { from: 'name', path: 'key'}
});
PageCategory.add({
name: { type: String, required: true, unique: true},
image: { type: Types.CloudinaryImage, label: "Category Image"},
description : { type: Types.Html, wysiwyg: true},
parent: { type: Types.Relationship, ref: "PageCategory", label: "Parent category"}
});
PageCategory.relationship({ ref: "PageCategory", path: "parent"});
PageCategory.register();
I think you have misunderstood how Model.relationship() works.
It has three options:
path, this is the "virtual" field name that will hold the values
ref, this is the model that we reference
refPath, this is the field in the referenced model that we populate path with
I think something in line with this will work for you
PageCategory.relationship({ ref: "PageCategory", path: "children", refPath: "parent"});

sencha touch insert data to localstorage

Hi i have found a lot of examples about loading data from a db in sencha.
i try to make a list with notes and on second step i want to be able to add(save) a note to my db. i try that on localstorage.
for now i load data from a array in my Arraystore.
where shall i set my proxy? (in store or in model?)
how could i insert data in my store?
i have tried something like that on my current arraystore but with no luck:
(this is the code run by pressing a code):
MyArrayStore.add({title:"newnote",narrative:"bla bla bla",date:now,id:noteid});
MyArrayStore.sync();
the browser console gets an error:
Uncaught ReferenceError: MyArrayStore is not defined
shall i make an instance of my store or something?
my model is this:
thanx for the answer. i try that on architect.
my model is this:
Ext.define('MyApp.model.NoteModel', {
extend: 'Ext.data.Model',
alias: 'model.NoteModel',
config: {
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'date',
type: 'date'
},
{
name: 'title',
type: 'string'
},
{
name: 'narrative',
type: 'string'
}
],
proxy: {
type: 'localstorage',
id: 'local'
}
}
});
and my store is this:
Ext.define('MyApp.store.MyArrayStore', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.NoteModel'
],
config: {
data: [
{
title: 'Note 1',
narrative: 'test1 1'
},
{
title: 'Note 2',
narrative: 'narrative 2'
},
{
title: '3 ertyyh',
narrative: 'narrative 3'
},
{
title: '4 asdf',
narrative: 'narrative 4'
},
{
title: 'Note 5',
narrative: 'narrative 5'
},
{
title: 'weadf',
narrative: 'narrative 6'
}
],
model: 'MyApp.model.NoteModel',
storeId: 'MyArrayStore'
}
});
You should set your proxy in your model OR in your store.
Here's how to do it within your model.
Ext.define('MyModel', {
extend: 'Ext.data.Model',
config: {
fields: ['field1'],
proxy: {
type: 'localstorage',
id : 'my-model-localstorage-id'
}
});
The same can alternatively be done in your store.
After that, given that 'MyArrayStore' is an instance of such a store, the code you propose should work just fine.
Hope this helps.
If you want to access your store (the one you updated in your question), then you can use:
Ext.StoreManager.get('MyArrayStore')
So, for instance, the operations you wanted to perform could be done in the following way:
var store=Ext.StoreManager.get('MyArrayStore');
store.add({title:"newnote",narrative:"bla bla bla",date:now,id:noteid});
store.sync();