forked from italia/publiccode-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make country sections configurable at build time
Make country sections displayed by the UI when it first loads configurable via the DEFAULT_COUNTRY_SECTIONS environment variable.
- Loading branch information
Showing
10 changed files
with
72 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
ELASTIC_URL=http://localhost:9200/indicepa_pec/_search | ||
# Comma separated Country-Specific sections (https://yml.publiccode.tools/country.html) | ||
# to display by default when the editor is loaded. | ||
# | ||
# Valid identifiers: "all", "none" or "italy" | ||
# | ||
# (default: "none") | ||
DEFAULT_COUNTRY_SECTIONS=none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const SECTIONS = ["italy", "all", "none"] as const; | ||
export type CountrySpecificSection = typeof SECTIONS[number]; | ||
|
||
export const parse = (input: string): CountrySpecificSection[] => { | ||
const splitted = input?.split(",")?.map(s => s.trim()); | ||
|
||
const sections: CountrySpecificSection[] = []; | ||
splitted.forEach(s => { | ||
if (!SECTIONS.includes(s as CountrySpecificSection)) { | ||
console.warn(`Unknown Country specific section: ${s}`); | ||
return; | ||
} | ||
|
||
sections.push(s as CountrySpecificSection); | ||
}); | ||
|
||
return sections; | ||
} | ||
|
||
export const isVisible = ( | ||
config: CountrySpecificSection[], | ||
country: CountrySpecificSection, | ||
): boolean => { | ||
if (config.includes("all")) return true; | ||
if (config.includes("none")) return false; | ||
|
||
return config.includes(country); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters