Skip to content

Commit

Permalink
πŸ› Improve redirects validation #1381
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandolucchesi committed Nov 26, 2022
1 parent a1e96d7 commit c757ab5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions studio/schemas/documents/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ export default {
validation: (Rule: Rule) =>
Rule.custom(async (value: string, context: ValidationContext) => {
const { document } = context
const documentId = document?._id
const query = `*[_type == 'redirect' && from == $value && _id != $documentId && "drafts." + _id != $documentId]`
const documentId = Flags.IS_DEV ? document?._id.replace('drafts.', '') : document?._id
const query = Flags.IS_DEV
? /* groq */ `*[_type == 'redirect' && from == $value && _id != $documentId && !(_id in path('drafts.**'))]`
: `*[_type == 'redirect' && from == $value && _id != $documentId && "drafts." + _id != $documentId]`

const params = { value, documentId }
const redirects = await client.fetch(query, params)

Expand Down

0 comments on commit c757ab5

Please sign in to comment.