Skip to content

Commit

Permalink
feat: APP-475 add language subfolders and custom new doc options (#73)
Browse files Browse the repository at this point in the history
* feat: add language subfolders and custom new doc options

* chore: lint

* fix: newDocumentOptions filter

* fix: uniqueDocuments filtering
  • Loading branch information
blushi authored Nov 21, 2024
1 parent 75f5975 commit c07936e
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 184 deletions.
214 changes: 38 additions & 176 deletions deskStructure.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import manyDocumentListItem from './utils/manyDocumentListItem';

export default S =>
S.list()
.title('Content')
Expand Down Expand Up @@ -48,14 +50,8 @@ export default S =>
.title('Bridge Page')
.schemaType('bridgePage')
.child(S.document().schemaType('bridgePage')),
S.listItem()
.title('Methodologies')
.schemaType('methodology')
.child(S.documentTypeList('methodology').title('Methodologies')),
S.listItem()
.title('Credit Classes')
.schemaType('creditClass')
.child(S.documentTypeList('creditClass').title('Credit Classes')),
manyDocumentListItem(S, 'Methodologies', 'methodology'),
manyDocumentListItem(S, 'Credit Classes', 'creditClass'),
S.listItem()
.title('Basket Details Page')
.schemaType('basketDetailsPage')
Expand Down Expand Up @@ -106,10 +102,7 @@ export default S =>
.title('Case Studies Page')
.schemaType('caseStudiesPage')
.child(S.document().schemaType('caseStudiesPage')),
S.listItem()
.title('Case Study Pages')
.schemaType('caseStudyPage')
.child(S.documentTypeList('caseStudyPage').title('case study page')),
manyDocumentListItem(S, 'Case Study Pages', 'caseStudyPage'),
S.listItem()
.title('Community Page')
.schemaType('communityPage')
Expand Down Expand Up @@ -171,166 +164,38 @@ export default S =>
S.list()
.title('Shared')
.items([
S.listItem()
.title('FAQ')
.schemaType('faq')
.child(S.documentTypeList('faq').title('FAQ')),
S.listItem()
.title('Documents')
.schemaType('doc')
.child(S.documentTypeList('doc').title('Documents')),
S.listItem()
.title('Resources')
.schemaType('resource')
.child(S.documentTypeList('resource').title('Resources')),
S.listItem()
.title('Media')
.schemaType('media')
.child(S.documentTypeList('media').title('Media')),
S.listItem()
.title('Ecological Impact')
.schemaType('ecologicalImpact')
.child(S.documentTypeList('ecologicalImpact').title('Ecological Impact')),
S.listItem()
.title('Ecological Outcomes')
.schemaType('ecologicalOutcome')
.child(
S.documentTypeList('ecologicalOutcome').title('Ecological Outcomes'),
),
S.listItem()
.title('Land Management Practices')
.schemaType('landManagementPractice')
.child(
S.documentTypeList('landManagementPractice').title(
'Land Management Practices',
),
),
S.listItem()
.title('SDGs')
.schemaType('sdg')
.child(S.documentTypeList('sdg').title('SDGs')),
S.listItem()
.title('Tags')
.schemaType('tag')
.child(S.documentTypeList('tag').title('Tags')),
S.listItem()
.title('Featured Sections')
.schemaType('featuredSection')
.child(S.documentTypeList('featuredSection').title('Featured Sections')),
S.listItem()
.title('Team Members')
.schemaType('regenTeamMember')
.child(S.documentTypeList('regenTeamMember').title('Team Members')),
S.listItem()
.title('Resources for Getting Started Sections')
.schemaType('gettingStartedResourcesSection')
.child(
S.documentTypeList('gettingStartedResourcesSection').title(
'Resources for Getting Started Sections',
),
),
S.listItem()
.title('Resource for Getting Started Cards')
.schemaType('gettingStartedResourcesCard')
.child(
S.documentTypeList('gettingStartedResourcesCard').title(
'Resource for Getting Started Cards',
),
),
S.listItem()
.title('Sold out projects')
.schemaType('soldOutProjects')
.child(S.documentTypeList('soldOutProjects').title('Sold out projects')),
S.listItem()
.title('Credit Category')
.schemaType('creditCategory')
.child(S.documentTypeList('creditCategory').title('Credit Category')),
S.listItem()
.title('Credit Type')
.schemaType('creditType')
.child(S.documentTypeList('creditType').title('Credit Type')),
S.listItem()
.title('Credit Certification')
.schemaType('creditCertification')
.child(
S.documentTypeList('creditCertification').title('Credit Certification'),
),
S.listItem()
.title('Ecological Credit Card')
.schemaType('ecologicalCreditCard')
.child(
S.documentTypeList('ecologicalCreditCard').title(
'Ecological Credit Card',
),
),
S.listItem()
.title('Offset Method')
.schemaType('offsetMethod')
.child(S.documentTypeList('offsetMethod').title('Offset Method')),
S.listItem()
.title('Project Activity')
.schemaType('projectActivity')
.child(S.documentTypeList('projectActivity').title('Project Activity')),
S.listItem()
.title('Project Ecosystem')
.schemaType('projectEcosystem')
.child(S.documentTypeList('projectEcosystem').title('Project Ecosystem')),
S.listItem()
.title('Project Rating')
.schemaType('projectRating')
.child(S.documentTypeList('projectRating').title('Project Rating')),
S.listItem()
.title('Project')
.schemaType('project')
.child(S.documentTypeList('project').title('Project')),
S.listItem()
.title('Credit Class Prefinance Timeline Status')
.schemaType('classPrefinanceTimelineStatus')
.child(
S.documentTypeList('classPrefinanceTimelineStatus').title(
'Credit Class Prefinance Timeline Status',
),
),
S.listItem()
.title('Project Class Prefinance Timeline Status')
.schemaType('projectPrefinanceTimelineStatus')
.child(
S.documentTypeList('projectPrefinanceTimelineStatus').title(
'Project Class Prefinance Timeline Status',
),
),
S.listItem()
.title('Featured Project Card')
.schemaType('featuredProjectCard')
.child(
S.documentTypeList('featuredProjectCard').title(
'Featured Project Card',
),
),
S.listItem()
.title('Partner')
.schemaType('partner')
.child(S.documentTypeList('partner').title('Partner')),
S.listItem()
.title('Stat Card')
.schemaType('statCard')
.child(S.documentTypeList('statCard').title('Stat Card')),
S.listItem()
.title('Claim')
.schemaType('claim')
.child(S.documentTypeList('claim').title('Claim')),
S.listItem()
.title('Credibility Card')
.schemaType('credibilityCard')
.child(S.documentTypeList('credibilityCard').title('Credibility Card')),
S.listItem()
.title('Person')
.schemaType('person')
.child(S.documentTypeList('person').title('Person')),
S.listItem()
.title('Program')
.schemaType('program')
.child(S.documentTypeList('program').title('Program')),
manyDocumentListItem(S, 'FAQs', 'faq'),
manyDocumentListItem(S, 'Documents', 'doc'),
manyDocumentListItem(S, 'Resources', 'resource'),
manyDocumentListItem(S, 'Media', 'media'),
manyDocumentListItem(S, 'Ecological Impact', 'ecologicalImpact'),
manyDocumentListItem(S, 'Ecological Outcomes', 'ecologicalOutcome'),
manyDocumentListItem(S, 'Land Management Practices', 'landManagementPractice'),
manyDocumentListItem(S, 'SDGs', 'sdg'),
manyDocumentListItem(S, 'Tags', 'tag'),
manyDocumentListItem(S, 'Featured Sections', 'featuredSection'),
manyDocumentListItem(S, 'Team Members', 'regenTeamMember'),
manyDocumentListItem(S, 'Resources for Getting Started Sections', 'gettingStartedResourcesSection'),
manyDocumentListItem(S, 'Resources for Getting Started Cards', 'gettingStartedResourcesCard'),
manyDocumentListItem(S, 'Sold out projects', 'soldOutProjects'),
manyDocumentListItem(S, 'Credit Categories', 'creditCategory'),
manyDocumentListItem(S, 'Credit Types', 'creditType'),
manyDocumentListItem(S, 'Credit Certifications', 'creditCertification'),
manyDocumentListItem(S, 'Ecological Credit Cards', 'ecologicalCreditCard'),
manyDocumentListItem(S, 'Offset Methods', 'offsetMethod'),
manyDocumentListItem(S, 'Project Activities', 'projectActivity'),
manyDocumentListItem(S, 'Project Ecosystems', 'projectEcosystem'),
manyDocumentListItem(S, 'Project Ratings', 'projectRating'),
manyDocumentListItem(S, 'Projects', 'project'),
manyDocumentListItem(S, 'Credit Class Prefinance Timeline Statuses', 'classPrefinanceTimelineStatus'),
manyDocumentListItem(S, 'Project Prefinance Timeline Statuses', 'projectPrefinanceTimelineStatus'),
manyDocumentListItem(S, 'Featured Project Cards', 'featuredProjectCard'),
manyDocumentListItem(S, 'Partners', 'partner'),
manyDocumentListItem(S, 'Stat Cards', 'statCard'),
manyDocumentListItem(S, 'Claims', 'claim'),
manyDocumentListItem(S, 'Credibility Cards', 'credibilityCard'),
manyDocumentListItem(S, 'Persons', 'person'),
manyDocumentListItem(S, 'Programs', 'program'),
]),
),
// Terrasos
Expand All @@ -344,10 +209,7 @@ export default S =>
.title('Tebu Banner')
.schemaType('tebuBanner')
.child(S.document().schemaType('tebuBanner')),
S.listItem()
.title('Terrasos Project')
.schemaType('terrasosProject')
.child(S.documentTypeList('terrasosProject').title('Terrasos Project')),
manyDocumentListItem(S, 'Terrasos Projects', 'terrasosProject'),
S.listItem()
.title('Compliance Info')
.schemaType('complianceInfo')
Expand Down
33 changes: 26 additions & 7 deletions sanity.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,33 @@ const config = {
types: schemas,
},
document: {
// Removes certain document types from the global “create new” menu in the top left navigation bar
newDocumentOptions: (prev, { creationContext }) => {
if (creationContext.type === 'global') {
return prev.filter(
templateItem => !uniqueDocuments.includes(templateItem.templateId),
);
}
return prev;
console.log( prev)
return (
prev
.filter(templateItem =>
// Removes certain document types from the global “create new” menu in the top left navigation bar
creationContext.type === 'global'
? !uniqueDocuments.includes(templateItem.templateId.replace(/-es$|-en$/, ''))
: true,
)
.filter(templateItem =>
// Only allows to create either English or Spanish documents
templateItem.templateId.endsWith('-en') ||
templateItem.templateId.endsWith('-es'),
)
// eg Update title from "English Example Doc" to "Example Doc (EN)"
.map(templateItem => ({
...templateItem,
title: templateItem.title.replace(
/^(English|Spanish) (.+)/,
(_, language, rest) => {
const languageCode = language === 'English' ? 'EN' : 'ES';
return `${rest} (${languageCode})`;
},
),
}))
);
},
// Disable unpublish, delete, and duplicate actions in the documents actions menu
actions: (prev, { schemaType }) => {
Expand Down
1 change: 0 additions & 1 deletion uniqueDocuments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const uniqueDocuments = [
'buyersPage',
'buyModal',
'buyModalOptions',
'caseStudiesPage',
'createCreditClassPage',
'createMethodologyPage',
'createCreditClassPage',
Expand Down
7 changes: 7 additions & 0 deletions utils/filterLanguage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function filterSpanish(docType) {
return `_type == "${docType}" && language == "es"`
}

export function filterEnglish(docType) {
return `_type == "${docType}" && (!defined(language) || language == "en")`
}
23 changes: 23 additions & 0 deletions utils/manyDocumentListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { filterSpanish, filterEnglish } from './filterLanguage';

// Show English and Spanish subfolders for document types with many instances
export default function manyDocumentListItem(S, title, docType) {
return S.listItem()
.title(title)
.child(
S.list()
.title(title)
.items([
S.listItem()
.title('English')
.schemaType(docType)
.child(S.documentTypeList(docType).title(`${title} (EN)`)
.filter(filterEnglish(docType))),
S.listItem()
.title('Spanish')
.schemaType(docType)
.child(S.documentTypeList(docType).title(`${title} (SP)`)
.filter(filterSpanish(docType)))
]),
);
}

0 comments on commit c07936e

Please sign in to comment.