Deleting pages in Sanity and resolving related reference issues
48 replies
Last updated: Apr 9, 2021
R
Hello there, how can i delete these Home and About pages from sanity, i am unable to do it, due to this error
Apr 9, 2021, 7:49 AM
R
https://www.sanity.io/docs/documents can delete them from the cli
Apr 9, 2021, 7:52 AM
R
Hi
user R
, you could temporarily re-create a pagedocument type to interact with these documents or remove them via the command line instead:
sanity documents delete <_id1> <_id2>
Apr 9, 2021, 7:52 AM
R
Hi
user M
am trying to delete by id but this error occuring,Apr 9, 2021, 7:57 AM
R
even though doc exist
Apr 9, 2021, 7:58 AM
R
is you cli looking at the prod dataset?
Apr 9, 2021, 7:58 AM
R
well, it is on prod dataset but how wil iknow that cli is hittin the right dataset?
Apr 9, 2021, 7:59 AM
R
Looks like you may be getting the
FYI it's also available as
idfrom Gatsby's GraphiQL, which is not precisely the same as the
_idin Sanity. Sorry about the confusion there š Could you try using the
_id(notice the underscore) from the first screenshot you shared, so inside of the studio?
FYI it's also available as
_idin GraphiQL if you prefer that approach.
Apr 9, 2021, 8:02 AM
R
tried with
_idbut now facing this error,
user M
Apr 9, 2021, 8:04 AM
R
ohh i was missing parantheses, in command, now deleted successfully,
Apr 9, 2021, 8:07 AM
R
Thanks
user M
Apr 9, 2021, 8:08 AM
R
Looks like it has a so-called "strong" reference to it, which prevents it from being deleted here as a measure to not end up with broken references. There are several ways around this, but the easiest is probably to open up the relevant doc and unset the reference. You could copy the second ID in the studio search to find the doc.
Apr 9, 2021, 8:08 AM
R
Ah, alright, if that does the trick that's great I guess š Glad to hear!
Apr 9, 2021, 8:08 AM
M
Ohh, the other one was deleted succesfully, but first one which is home page has same issue occuring, now i am not sure where this is referencing, as i have't create any ref.
Apr 9, 2021, 8:11 AM
R
Are you getting the ID in the error message? If so, you could paste it into the studio search bar to find the document that references it. Alternatively, you could run a query like:
*[references("<idOfDocumentYouAreTryingToDelete>")]
Apr 9, 2021, 8:12 AM
R
In your CLI:
sanity documents query '*[references("<idOfDocumentYouAreTryingToDelete>")]'
Apr 9, 2021, 8:14 AM
R
user M
ive ran the above query and this is the result i got.[
{
"_createdAt": "2021-04-07T06:00:07Z",
"_id": "94e1b8ef-ac28-4ead-ba44-6d9d716799fa",
"_rev": "p5oiLzuoOfR9bp21r89iBt",
"_type": "route",
"_updatedAt": "2021-04-07T06:00:40Z",
"page": {
"_ref": "a4921de5-35b0-42e6-9505-c975ff2375c7",
"_type": "reference"
},
"slug": {
"_type": "slug",
"current": "home-page"
},
"useSiteTitle": false
}
]
Apr 9, 2021, 8:17 AM
R
tried to delete with both _ref & _id but no success
Apr 9, 2021, 8:19 AM
P
Are you using
routedocuments in your setup? For example under "Navigations" in your studio? If so, you should be able to unset the reference there and then proceed to delete the page document.
Apr 9, 2021, 8:20 AM
R
Alternatively, you could first delete
94e1b8ef-ac28-4ead-ba44-6d9d716799fa(the route doc) and then the page document. However, you may have to re-create the
home-pageroute afterwards if it your web front-end relies on it š
Apr 9, 2021, 8:22 AM
R
No, i didn't create any
and got this result,
routedoc, but i think its coming from draft,like i ran
sanity documents query '*[references("94e1b8ef-ac28-4ead-ba44-6d9d716799fa")]'
[
{
"_createdAt": "2021-04-07T05:58:28Z",
"_id": "drafts.6ab68685-c225-4ddb-b362-00b5b0c8e6a0",
"_rev": "vwwzyg-8pq-7eo-hhv-uufhdc7m6",
"_type": "navigationMenu",
"_updatedAt": "2021-04-07T06:27:50Z",
"items": [
{
"_key": "6ef39e263942",
"_type": "cta",
"kind": "link",
"route": "/about",
"title": "about page"
},
{
"_key": "b9b73e0ac76d",
"_type": "cta",
"kind": "link",
"landingPageRoute": {
"_ref": "94e1b8ef-ac28-4ead-ba44-6d9d716799fa",
"_type": "reference"
},
"route": "/",
"title": "home page"
}
],
"title": "Nav menu"
}
]
Apr 9, 2021, 8:22 AM
R
yes ,i tried to delete
94e1b8ef-ac28-4ead-ba44-6d9d716799fabut it itself ref to some thing, probably this,
drafts.6ab68685-c225-4ddb-b362-00b5b0c8e6a0
Apr 9, 2021, 8:24 AM
P
Sorry about all the references here š Can be quite confusing. Are you able to see this
navigationMenudoc in the studio itself?
Apr 9, 2021, 8:25 AM
R
No, Peter i can't
navigationMenusee anywhere on studio, not even sure where it comes from
Apr 9, 2021, 8:27 AM
R
What's under "Navigations" in your studio?
Apr 9, 2021, 8:27 AM
R
Btw, let me clarify you, there is another branch, in which this
Navigationsdoc, doesn't exist but still facing this issue,
Apr 9, 2021, 8:29 AM
R
Ah, I'm suspecting you kicked off this project from a starter project on sanity.io/create and then restructured it to fit your needs? But there's some left-over data that you'd like to get rid of?
Apr 9, 2021, 8:30 AM
R
And you're not using the actual
navigationMenuand
routesetup yourself at this point on the front-end side?
Apr 9, 2021, 8:30 AM
R
the problem is that i didn't created this project myself, and this issue started occuring from yesterday. So is there anyway to cleaned this up?
Apr 9, 2021, 8:31 AM
R
Could you try running these in this order:ā¢
ā¢
ā¢
sanity documents delete drafts.6ab68685-c225-4ddb-b362-00b5b0c8e6a0 6ab68685-c225-4ddb-b362-00b5b0c8e6a0
sanity documents delete 94e1b8ef-ac28-4ead-ba44-6d9d716799fa
sanity documents delete a4921de5-35b0-42e6-9505-c975ff2375c7
Apr 9, 2021, 8:32 AM
R
Hi
user M
i ve deleted all docuents, but now i am unable to create a new one, š„Apr 9, 2021, 9:13 AM
R
Could you check your dev tools console for extra details on that error? Also, have you double-checked that the
pagedocument type is included in your
schema.jsfile?
Apr 9, 2021, 9:27 AM
R
yes, page schema is added correctly on
schema.jsand this is the error i got,
Apr 9, 2021, 9:42 AM
R
Could you share your
page.jsschema definitions? There may be an issue with the
initialValuesetup in there.
Apr 9, 2021, 9:46 AM
R
// pages.js
export default {
name: "page",
type: "document",
title: "Pages",
fields: [
{
name: "title",
title: "Title",
type: "string",
description: "An internal description of the page",
},
{
name: "metaTitle",
title: "Meta Title",
type: "string",
description: "Text for the title tag",
},
{
name: "metaDescription",
title: "Meta Description, as used as summary text for story cards",
type: "string",
},
{
name: "slug",
title: "Slug",
type: "slug",
options: {
source: "metaTitle",
slugify: async (_value_, _type_) => {
const { default: slugify } = await import("slugify");
return slugify(_value_, {
lower: true,
});
},
},
validation: (_Rule_) => {
return _Rule_.required().custom((_slug_) => {
if (_slug_ && _slug_.current.indexOf(" ") > -1) {
return "Slugs cannot have spaces";
}
// if (slug && slug.current.indexOf("/") > -1) {
// return "Slugs cannot have slashes";
// }
return true;
});
},
},
],
};
Apr 9, 2021, 9:52 AM
R
// deskStructure.js
import S from "@sanity/desk-tool/structure-builder";
import { GoListUnordered } from "react-icons/go";
import { GiBookshelf, GiBookCover, GiFootTrip } from "react-icons/gi";
import { FiNavigation, FiSettings } from "react-icons/fi";
import { FaTags } from "react-icons/fa";
import {
RiPagesLine,
RiNavigationLine,
RiFootprintLine,
RiPagesFill,
} from "react-icons/ri";
import { AiFillAlert } from "react-icons/ai";
export default () =>
S.list()
.title("Content")
.items([
S.listItem()
.title("Site Settings")
.icon(FiSettings)
.child(
S.list()
.title("Settings")
.items([
...S.documentTypeListItems().filter((_item_) => {
const id = _item_.getId();
return ["siteSettings"].some((_type_) => _type_ === id);
}),
S.divider(),
S.documentTypeListItem("headerLink").title("Header Link"),
S.documentTypeListItem("footerLink").title("Footer Link"),
S.documentTypeListItem("sideMenuLink").title("sideMenuLink"),
])
),
S.listItem()
.title("Pages")
.icon(RiPagesLine)
.child(
S.documentList("page")
.title("Pages")
.menuItems(S.documentTypeList("page").getMenuItems())
.filter('_type == "page"')
.child((_documentId_) =>
S.document()
.documentId(_documentId_)
.schemaType(" ")
.views([S.view.form()])
)
),
S.listItem()
.title("Navigations")
.icon(FiNavigation)
.child(
S.list()
.title("Navigations")
.items([
...S.documentTypeListItems().filter((_item_) =>
["topNav"].some((_type_) => _type_ === _item_.getId())
),
S.divider(),
...S.documentTypeListItems().filter((_item_) =>
["navigation"].some((_type_) => _type_ === _item_.getId())
),
S.divider(),
// S.documentTypeListItem("topNav").title("Top Navigations Links"),
// S.documentTypeListItem("navigation").title("Navigation Links"),
])
),
]);
Apr 9, 2021, 9:53 AM
R
// schema.js
// First, we must import the schema creator
import createSchema from 'part:@sanity/base/schema-creator'
// Then import schema types from any plugins that might expose them
import schemaTypes from 'all:part:@sanity/base/schema-type'
// document schemas
import siteSettings from './documents/siteSettings'
import pages from './documents/pages';
import navigation from './documents/navigations/navigation';
import topNavigations from './documents/navigations/topNavigations';
import footerLink from './footerLink';
import sideMenuLink from './sideMenuLink';
import headerLink from './headerLink';
import selectFooter from './selectFooter';
import selectSideMenu from './selectSideMenu';
import selectHeader from './selectHeader';
// Object types
import link from './objects/link';
import navItem from './objects/navItem';
import reserveBtn from './objects/reserveBtn';
// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
// We name our schema
name: 'default',
// Then proceed to concatenate our document type
// to the ones provided by any plugins that are installed
types: schemaTypes.concat([
/* Your types here! */
footerLink,
sideMenuLink,
headerLink,
selectFooter,
selectSideMenu,
selectHeader,
siteSettings,
pages,
topNavigations,
navigation,
navItem,
link,
]),
})
Apr 9, 2021, 9:54 AM
R
Thanks
With this instead:
user R
. Could you try replacing this part of your deskStructure.jsfile:
S.listItem() .title("Pages") .icon(RiPagesLine) .child( S.documentList("page") .title("Pages") .menuItems(S.documentTypeList("page").getMenuItems()) .filter('_type == "page"') .child((documentId) => S.document() .documentId(documentId) .schemaType(" ") .views([S.view.form()]) ) ),
S.listItem() .title("Pages") .icon(RiPagesLine) .child( S.documentList("page") .title('Pages') .menuItems(S.documentTypeList('page').getMenuItems()) .filter('_type == "page"') .canHandleIntent(S.documentTypeList('page').getCanHandleIntent()) ),
Apr 9, 2021, 10:01 AM
R
ok, let me try with it,
Apr 9, 2021, 10:03 AM
R
wait, now it's working,
Apr 9, 2021, 10:05 AM
P
Thanks
user M
but what excatly is ths issue, and what was the fix? can you tell me a bit about it?Apr 9, 2021, 10:05 AM
R
There was an empty
.schemaType(" ")in the original - it might also have worked if you left it intact like it was but with the added
.schemaType("page")instead. The above is a bit shorter as you don't necessarily need the extra child unless you want to customise views for example.
Apr 9, 2021, 10:10 AM
R
ok and what's this line of code for?
.canHandleIntent(S.documentTypeList('page').getCanHandleIntent())
Apr 9, 2021, 10:11 AM
R
That line ensures that you can use the "compose" icon to create a new document right inside the custom desk structure you define in
deskStructure.js. So it won't collapse the panes but instead opens the new document in the right place.
Apr 9, 2021, 10:13 AM
R
It says: "this item in my desk structure can handle the intents [e.g. create or edit] for the page document type, so these intents will now open here"
Apr 9, 2021, 10:14 AM
R
Thanks Very much
user M
, ok another thing i want to ask is that i was exploring kitchen sink studio and could not get what's the difference between normal and kitchen sink studio? an how can i make this studio to kitchen sink studio?Apr 9, 2021, 10:22 AM
R
The kitchen sink is a normal studio but just has a lot of stuff built into it. It serves as an example of some of the things you can do with the Sanity studio, in the same way as other starters do on sanity.io/create . You can run a starter as an example project or look at the GitHub repositories for hints on how to build parts of it into your own studio.
Apr 9, 2021, 10:30 AM
R
fine
user M
thank you very much for your time.Apr 9, 2021, 10:34 AM
R
Very welcome - looking forward to seeing what you'll build! š
Apr 9, 2021, 10:35 AM
Sanityā build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.