From c9a84b29aea55edd3387b47acaea898752f3d7ef Mon Sep 17 00:00:00 2001 From: Ane Date: Thu, 12 Sep 2024 15:33:11 +0200 Subject: [PATCH 1/9] cleanup of deskstructure --- studio/schemas/deskStructure.ts | 191 ++++++++++++++++++-------------- 1 file changed, 110 insertions(+), 81 deletions(-) diff --git a/studio/schemas/deskStructure.ts b/studio/schemas/deskStructure.ts index 65e22dbc3..98d25f7b4 100644 --- a/studio/schemas/deskStructure.ts +++ b/studio/schemas/deskStructure.ts @@ -1,15 +1,14 @@ import { StructureBuilder } from "sanity/structure"; import { pageBuilderID } from "./builders/pageBuilder"; -import { blogId } from "./documents/blog"; +//import { blogId } from "./documents/blog"; import { TransferIcon, UsersIcon, CogIcon, - ControlsIcon, ProjectsIcon, - StackCompactIcon, InfoOutlineIcon, HeartIcon, + SparkleIcon, CaseIcon, DoubleChevronRightIcon, PinIcon, @@ -21,86 +20,116 @@ import { compensationsId } from "./documents/compensations"; import { redirectId } from "./documents/redirect"; import { companyLocationID } from "./documents/companyLocation"; +// Admin Section +const adminSection = (S: StructureBuilder) => + S.listItem() + .title("Admin") + .icon(CaseIcon) + .child( + S.list() + .title("Company Details") + .items([ + S.listItem() + .title("Company Information") + .icon(InfoOutlineIcon) + .child( + S.document() + .schemaType(companyInfoID) + .documentId(companyInfoID) + .title("Company Information"), + ), + S.listItem() + .title("Company Locations") + .icon(PinIcon) + .child( + S.documentTypeList(companyLocationID).title("Company Locations"), + ), + S.listItem() + .title("Legal Documents") + .icon(CogIcon) + .child( + S.documentTypeList(legalDocumentID).title("Legal Documents"), + ), + ]), + ); + +// Site Settings Section +const siteSettingSection = (S: StructureBuilder) => + S.listItem() + .title("Site Settings") + .icon(CogIcon) + .child( + S.list() + .title("Site Settings") + .items([ + S.listItem() + .title("Navigation Manager") + .icon(TransferIcon) + .child( + S.document() + .schemaType("navigationManager") + .documentId("navigationManager") + .title("Navigation Manager"), + ), + S.listItem() + .title("Social Media Profiles") + .icon(UsersIcon) + .child( + S.document().schemaType(soMeLinksID).documentId(soMeLinksID), + ), + S.listItem() + .title("SEO Redirects") + .icon(DoubleChevronRightIcon) + .child(S.documentTypeList(redirectId).title("Redirects")), + //TODO: Add SEO Settings + //TODO: Add Language selector + ]), + ); + +// Section for dynamic and customizable Pages +const pagesSection = (S: StructureBuilder) => + S.listItem() + .title("Pages") + .icon(ProjectsIcon) + .child(S.documentTypeList(pageBuilderID).title("Pages")); + +//Section for set pages +const SpecialPagesSection = (S: StructureBuilder) => + S.listItem() + .title("Special Pages") + .icon(SparkleIcon) + .child( + S.list() + .title("Special Pages") + .items([ + // S.listItem() + // .title("Blog Overview & Settings") + // .icon(ControlsIcon) + // .child( + // S.document() + // .schemaType(blogId) + // .documentId(blogId) + // .title("Blog Overview & Settings"), + // ), + S.listItem() + .title("Compensations") + .icon(HeartIcon) + .child( + S.document() + .schemaType(compensationsId) + .documentId(compensationsId) + .title("Compensations"), + ), + ]), + ); + +// Main export export default (S: StructureBuilder) => S.list() .title("Content") .items([ - S.listItem() - .title("Company Details") - .icon(CaseIcon) - .child( - S.list() - .title("Company Details") - .items([ - S.listItem() - .title("Company Information") - .icon(InfoOutlineIcon) - .child( - S.document() - .schemaType(companyInfoID) - .documentId(companyInfoID) - .title("Company Information"), - ), - S.listItem() - .title("Company Locations") - .icon(PinIcon) - .child( - S.documentTypeList(companyLocationID).title( - "Company Locations", - ), - ), - ]), - ), - S.listItem() - .title("Legal Documents") - .icon(CogIcon) - .child(S.documentTypeList(legalDocumentID).title("Legal Documents")), - S.listItem() - .title("Social Media Profiles") - .icon(UsersIcon) - .child(S.document().schemaType(soMeLinksID).documentId(soMeLinksID)), - S.listItem() - .title("Navigation Manager") - .icon(TransferIcon) - .child( - S.document() - .schemaType("navigationManager") - .documentId("navigationManager") - .title("Navigation Manager"), - ), - S.listItem() - .title("Dynamic Pages") - .icon(ProjectsIcon) - .child(S.documentTypeList(pageBuilderID).title("Dynamic Pages")), - S.listItem() - .title("Static Pages") - .icon(StackCompactIcon) - .child( - S.list() - .title("Static Pages") - .items([ - S.listItem() - .title("Blog Overview & Settings") - .icon(ControlsIcon) - .child( - S.document() - .schemaType(blogId) - .documentId(blogId) - .title("Blog Overview & Settings"), - ), - S.listItem() - .title("Compensations") - .icon(HeartIcon) - .child( - S.document() - .schemaType(compensationsId) - .documentId(compensationsId) - .title("Compensations"), - ), - ]), - ), - S.listItem() - .title("Redirects") - .icon(DoubleChevronRightIcon) - .child(S.documentTypeList(redirectId).title("Redirects")), + adminSection(S), + siteSettingSection(S), + pagesSection(S), + SpecialPagesSection(S), ]); From e0ed61c4e0e76c82914b69f8dabe5ff7ad28ddec Mon Sep 17 00:00:00 2001 From: Ane Date: Mon, 16 Sep 2024 09:11:05 +0200 Subject: [PATCH 2/9] language for localization --- languages.ts | 2 +- studio/schema.ts | 2 + studio/schemas/deskStructure.ts | 7 +- studio/schemas/documents/languageDetails.ts | 71 +++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 studio/schemas/documents/languageDetails.ts diff --git a/languages.ts b/languages.ts index eaf9ff349..0bb192609 100644 --- a/languages.ts +++ b/languages.ts @@ -1,4 +1,4 @@ -const languages = [ +export const languages = [ { id: "en", title: "English" }, { id: "se", title: "Swedish" }, { id: "no", title: "Norwegian" }, diff --git a/studio/schema.ts b/studio/schema.ts index fd2d3ad9d..c868672f0 100644 --- a/studio/schema.ts +++ b/studio/schema.ts @@ -15,6 +15,7 @@ import companyLocation from "./schemas/documents/companyLocation"; import compensations from "./schemas/documents/compensations"; import redirect from "./schemas/documents/redirect"; import benefitsByLocation from "./schemas/objects/compensations/benefitsByLocation"; +import languageDetails from "./schemas/documents/languageDetails"; export const schema: { types: SchemaTypeDefinition[] } = { types: [ @@ -34,5 +35,6 @@ export const schema: { types: SchemaTypeDefinition[] } = { redirect, benefitsByLocation, companyLocation, + languageDetails, ], }; diff --git a/studio/schemas/deskStructure.ts b/studio/schemas/deskStructure.ts index 98d25f7b4..7fc879945 100644 --- a/studio/schemas/deskStructure.ts +++ b/studio/schemas/deskStructure.ts @@ -10,6 +10,7 @@ import { HeartIcon, SparkleIcon, CaseIcon, + TranslateIcon, DoubleChevronRightIcon, PinIcon, } from "@sanity/icons"; @@ -19,6 +20,7 @@ import { legalDocumentID } from "./documents/legalDocuments"; import { compensationsId } from "./documents/compensations"; import { redirectId } from "./documents/redirect"; import { companyLocationID } from "./documents/companyLocation"; +import { languageID } from "./documents/languageDetails"; // Admin Section const adminSection = (S: StructureBuilder) => @@ -82,7 +84,10 @@ const siteSettingSection = (S: StructureBuilder) => .icon(DoubleChevronRightIcon) .child(S.documentTypeList(redirectId).title("Redirects")), //TODO: Add SEO Settings - //TODO: Add Language selector + S.listItem() + .title("Languages") + .icon(TranslateIcon) + .child(S.document().schemaType(languageID).title("Languages")), ]), ); diff --git a/studio/schemas/documents/languageDetails.ts b/studio/schemas/documents/languageDetails.ts new file mode 100644 index 000000000..3a4a71468 --- /dev/null +++ b/studio/schemas/documents/languageDetails.ts @@ -0,0 +1,71 @@ +import { defineType } from "sanity"; +import { languages } from "languages"; + +const languageOptions = languages.map((language) => { + return { title: language.title, value: language.id }; +}); + +export const languageID = "languagesDetails"; + +const languageDetails = defineType({ + name: languageID, + type: "document", + fields: [ + { + name: "languages", + type: "array", + description: + "Select languages available for translation and designate one as the default language for the homepage.", + of: [ + { + type: "object", + fields: [ + { + name: "language", + type: "string", + description: "Select the language available for translation", + title: "Language", + options: { + list: languageOptions, + }, + }, + { + name: "isDefault", + type: "boolean", + title: "Default Language", + description: + "Indicate whether the language should be set as the default. Please note that only one default language is allowed.", + }, + ], + preview: { + select: { + title: "language", + }, + prepare(selection) { + const { title } = selection; + const languageOption = languageOptions.find( + (option) => option.value === title, + ); + return { + title: languageOption ? languageOption.title : title, + }; + }, + }, + }, + ], + validation: (Rule) => + Rule.custom((languages: { language: string; isDefault: boolean }[]) => { + const defaultLanguages = languages.filter((lang) => lang.isDefault); + if (defaultLanguages.length > 1) { + return "Only one default language is allowed"; + } + if (defaultLanguages.length === 0 && languages.length > 0) { + return "At least one language must be marked as default"; + } + return true; + }), + }, + ], +}); + +export default languageDetails; From 4add66f986fc853c1f2e234e59e4730a10fef322 Mon Sep 17 00:00:00 2001 From: Ane Date: Mon, 16 Sep 2024 12:58:20 +0200 Subject: [PATCH 3/9] renaming from languagedetails to supportedlanguages --- studio/schema.ts | 2 +- studio/schemas/deskStructure.ts | 10 ++++++---- .../{languageDetails.ts => supportedLanguages.ts} | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) rename studio/schemas/documents/{languageDetails.ts => supportedLanguages.ts} (92%) diff --git a/studio/schema.ts b/studio/schema.ts index a57e483d9..b494ee4c0 100644 --- a/studio/schema.ts +++ b/studio/schema.ts @@ -15,7 +15,7 @@ import companyLocation from "./schemas/documents/companyLocation"; import compensations from "./schemas/documents/compensations"; import redirect from "./schemas/documents/redirect"; import benefitsByLocation from "./schemas/objects/compensations/benefitsByLocation"; -import languageDetails from "./schemas/documents/languageDetails"; +import languageDetails from "./schemas/documents/supportedLanguages"; import seoFallback from "./schemas/documents/admin/fallbackSeo"; export const schema: { types: SchemaTypeDefinition[] } = { diff --git a/studio/schemas/deskStructure.ts b/studio/schemas/deskStructure.ts index 0ebdc5325..cf11064fa 100644 --- a/studio/schemas/deskStructure.ts +++ b/studio/schemas/deskStructure.ts @@ -21,7 +21,7 @@ import { legalDocumentID } from "./documents/legalDocuments"; import { compensationsId } from "./documents/compensations"; import { redirectId } from "./documents/redirect"; import { companyLocationID } from "./documents/companyLocation"; -import { languageID } from "./documents/languageDetails"; +import { supportedLanguageID } from "./documents/supportedLanguages"; import { seoFallbackID } from "./documents/admin/fallbackSeo"; // Admin Section @@ -84,7 +84,11 @@ const siteSettingSection = (S: StructureBuilder) => S.listItem() .title("Languages") .icon(TranslateIcon) - .child(S.document().schemaType(languageID).title("Languages")), + .child( + S.document() + .schemaType(supportedLanguageID) + .title("Supported Languages"), + ), S.listItem() .title("SEO Configurations") .icon(SearchIcon) @@ -106,8 +110,6 @@ const siteSettingSection = (S: StructureBuilder) => .title("Broken Links") .icon(DoubleChevronRightIcon) .child(S.documentTypeList(redirectId).title("Redirects")), - //TODO: Add SEO Settings - //TODO: Add Language selector ]), ); diff --git a/studio/schemas/documents/languageDetails.ts b/studio/schemas/documents/supportedLanguages.ts similarity index 92% rename from studio/schemas/documents/languageDetails.ts rename to studio/schemas/documents/supportedLanguages.ts index 3a4a71468..aad43879b 100644 --- a/studio/schemas/documents/languageDetails.ts +++ b/studio/schemas/documents/supportedLanguages.ts @@ -5,10 +5,10 @@ const languageOptions = languages.map((language) => { return { title: language.title, value: language.id }; }); -export const languageID = "languagesDetails"; +export const supportedLanguageID = "languagesDetails"; -const languageDetails = defineType({ - name: languageID, +const supportedLanguages = defineType({ + name: supportedLanguageID, type: "document", fields: [ { @@ -68,4 +68,4 @@ const languageDetails = defineType({ ], }); -export default languageDetails; +export default supportedLanguages; From 814db57baaa543a8f070444197e40f5f2ca033fb Mon Sep 17 00:00:00 2001 From: Ane Date: Mon, 16 Sep 2024 13:02:44 +0200 Subject: [PATCH 4/9] update schema with supportedLanguage --- studio/schema.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/studio/schema.ts b/studio/schema.ts index b494ee4c0..b00538b06 100644 --- a/studio/schema.ts +++ b/studio/schema.ts @@ -15,7 +15,7 @@ import companyLocation from "./schemas/documents/companyLocation"; import compensations from "./schemas/documents/compensations"; import redirect from "./schemas/documents/redirect"; import benefitsByLocation from "./schemas/objects/compensations/benefitsByLocation"; -import languageDetails from "./schemas/documents/supportedLanguages"; +import supportedLanguages from "./schemas/documents/supportedLanguages"; import seoFallback from "./schemas/documents/admin/fallbackSeo"; export const schema: { types: SchemaTypeDefinition[] } = { @@ -36,7 +36,7 @@ export const schema: { types: SchemaTypeDefinition[] } = { redirect, benefitsByLocation, companyLocation, - languageDetails, + supportedLanguages, seoFallback, ], }; From 3aea417b8a361cca3836c44319f40f7be98750bd Mon Sep 17 00:00:00 2001 From: anemne <63043552+anemne@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:03:43 +0200 Subject: [PATCH 5/9] Update studio/schemas/deskStructure.ts Co-authored-by: christinaroise <54266462+christinaroise@users.noreply.github.com> --- studio/schemas/deskStructure.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/studio/schemas/deskStructure.ts b/studio/schemas/deskStructure.ts index cf11064fa..4c2863fe1 100644 --- a/studio/schemas/deskStructure.ts +++ b/studio/schemas/deskStructure.ts @@ -82,7 +82,7 @@ const siteSettingSection = (S: StructureBuilder) => S.document().schemaType(soMeLinksID).documentId(soMeLinksID), ), S.listItem() - .title("Languages") + .title("Supported Languages") .icon(TranslateIcon) .child( S.document() From 4da5b8c707f2f7f8fa085eac9fd57c6ddf34e8fc Mon Sep 17 00:00:00 2001 From: Ane Date: Mon, 16 Sep 2024 13:19:23 +0200 Subject: [PATCH 6/9] variablename update --- studio/schemas/deskStructure.ts | 6 +++--- studio/schemas/documents/supportedLanguages.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/studio/schemas/deskStructure.ts b/studio/schemas/deskStructure.ts index cf11064fa..064bac7f9 100644 --- a/studio/schemas/deskStructure.ts +++ b/studio/schemas/deskStructure.ts @@ -21,7 +21,7 @@ import { legalDocumentID } from "./documents/legalDocuments"; import { compensationsId } from "./documents/compensations"; import { redirectId } from "./documents/redirect"; import { companyLocationID } from "./documents/companyLocation"; -import { supportedLanguageID } from "./documents/supportedLanguages"; +import { supportedLanguagesID } from "./documents/supportedLanguages"; import { seoFallbackID } from "./documents/admin/fallbackSeo"; // Admin Section @@ -82,11 +82,11 @@ const siteSettingSection = (S: StructureBuilder) => S.document().schemaType(soMeLinksID).documentId(soMeLinksID), ), S.listItem() - .title("Languages") + .title("Supported Languages") .icon(TranslateIcon) .child( S.document() - .schemaType(supportedLanguageID) + .schemaType(supportedLanguagesID) .title("Supported Languages"), ), S.listItem() diff --git a/studio/schemas/documents/supportedLanguages.ts b/studio/schemas/documents/supportedLanguages.ts index aad43879b..39ea1b70f 100644 --- a/studio/schemas/documents/supportedLanguages.ts +++ b/studio/schemas/documents/supportedLanguages.ts @@ -5,10 +5,10 @@ const languageOptions = languages.map((language) => { return { title: language.title, value: language.id }; }); -export const supportedLanguageID = "languagesDetails"; +export const supportedLanguagesID = "supportedLanguage"; const supportedLanguages = defineType({ - name: supportedLanguageID, + name: supportedLanguagesID, type: "document", fields: [ { From 62188d458f7d2b9350b794161528b861c35a7e7d Mon Sep 17 00:00:00 2001 From: anemne <63043552+anemne@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:31:30 +0200 Subject: [PATCH 7/9] Update studio/schemas/deskStructure.ts Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> --- studio/schemas/deskStructure.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/studio/schemas/deskStructure.ts b/studio/schemas/deskStructure.ts index cea41dcc5..733e9966b 100644 --- a/studio/schemas/deskStructure.ts +++ b/studio/schemas/deskStructure.ts @@ -87,6 +87,7 @@ const siteSettingSection = (S: StructureBuilder) => .child( S.document() .schemaType(supportedLanguagesID) + .documentId(supportedLanguagesID) .title("Supported Languages"), ), S.listItem() From 71addb7ca060b9db159ae6ef63f38f93cf99ed78 Mon Sep 17 00:00:00 2001 From: anemne <63043552+anemne@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:31:51 +0200 Subject: [PATCH 8/9] Update studio/schemas/deskStructure.ts Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> --- studio/schemas/deskStructure.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/studio/schemas/deskStructure.ts b/studio/schemas/deskStructure.ts index 733e9966b..186900d1b 100644 --- a/studio/schemas/deskStructure.ts +++ b/studio/schemas/deskStructure.ts @@ -91,7 +91,6 @@ const siteSettingSection = (S: StructureBuilder) => .title("Supported Languages"), ), S.listItem() - .title("SEO Configurations") .title("Default SEO") .icon(SearchIcon) .child( From fd4dea5463993c138bb8191b2015c582fc9660b1 Mon Sep 17 00:00:00 2001 From: Ane Date: Mon, 16 Sep 2024 13:32:47 +0200 Subject: [PATCH 9/9] variable name fix --- studio/schemas/deskStructure.ts | 4 +++- studio/schemas/documents/supportedLanguages.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/studio/schemas/deskStructure.ts b/studio/schemas/deskStructure.ts index cea41dcc5..68c3c2ec8 100644 --- a/studio/schemas/deskStructure.ts +++ b/studio/schemas/deskStructure.ts @@ -144,7 +144,7 @@ const SpecialPagesSection = (S: StructureBuilder) => ); // Main export -export default (S: StructureBuilder) => +const buildDeskStructure = (S: StructureBuilder) => S.list() .title("Content") .items([ @@ -153,3 +153,5 @@ export default (S: StructureBuilder) => pagesSection(S), SpecialPagesSection(S), ]); + +export default buildDeskStructure; diff --git a/studio/schemas/documents/supportedLanguages.ts b/studio/schemas/documents/supportedLanguages.ts index 39ea1b70f..4ab709cf6 100644 --- a/studio/schemas/documents/supportedLanguages.ts +++ b/studio/schemas/documents/supportedLanguages.ts @@ -5,7 +5,7 @@ const languageOptions = languages.map((language) => { return { title: language.title, value: language.id }; }); -export const supportedLanguagesID = "supportedLanguage"; +export const supportedLanguagesID = "supportedLanguages"; const supportedLanguages = defineType({ name: supportedLanguagesID,