All files / owid-grapher/explorer ExplorerGrammar.ts

100% Statements 17/17
100% Branches 0/0
100% Functions 0/0
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 1621x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                                                                                                                                                                                                                                                                  
import { SubNavId } from "../clientUtils/owidTypes"
import {
    CellDef,
    BooleanCellDef,
    SlugDeclarationCellDef,
    StringCellDef,
    UrlCellDef,
    SubTableHeaderCellDef,
    IntegerCellDef,
    SlugsDeclarationCellDef,
    Grammar,
    EnumCellDef,
    StringDeclarationDef,
} from "../gridLang/GridLangConstants"
import { GrapherGrammar } from "./GrapherGrammar"
import { ColumnGrammar } from "./ColumnGrammar"
 
const ExplorerFormControlCellDeff: CellDef = {
    ...StringDeclarationDef,
    description: "A form input for the user.",
    regex: /^.+ (Dropdown|Radio|Checkbox)$/,
    requirementsDescription: `Must end with 'Dropdown', 'Radio', or 'Checkbox'`,
}
 
export const ExplorerGrammar: Grammar = {
    table: {
        ...UrlCellDef,
        keyword: "table",
        valuePlaceholder: "",
        regex: new RegExp(`(${UrlCellDef.regex?.source ?? ""}|^[\\w -()]+$)`), // URL or OWID dataset name
        description: "A link to a CSV or TSV or the name of an OWID dataset.",
        positionalCellDefs: [
            {
                ...SlugDeclarationCellDef,
                description:
                    "If you have multiple tables, give each one a unique slug.",
            },
        ],
        headerCellDef: {
            ...SlugDeclarationCellDef,
            cssClass: "SubTableHeaderCellDef",
            grammar: {},
            catchAllCellDef: {
                ...SlugDeclarationCellDef,
                description: "A column slug.",
            },
        },
    },
    explorerTitle: {
        ...StringCellDef,
        keyword: "explorerTitle",
        valuePlaceholder: "Life Expectancy Data Explorer",
        description:
            "The title will appear in the top left corner of the Explorer.",
    },
    explorerSubtitle: {
        ...StringCellDef,
        keyword: "explorerSubtitle",
        valuePlaceholder: "All our data from various sources.",
        description: "The subtitle will appear under the explorerTitle.",
    },
    columns: {
        ...SlugDeclarationCellDef,
        keyword: "columns",
        description:
            "Include all your column definitions for one or multiple tables here. If you do not provide a column definition for every column in your table one will be generated for you by the machine (sometimes incorrectly).",
        headerCellDef: {
            ...SubTableHeaderCellDef,
            grammar: ColumnGrammar,
        },
        isHorizontalList: true,
    },
    graphers: {
        ...SlugDeclarationCellDef,
        keyword: "graphers",
        description: "The decision matrix for your Explorer goes here.",
        headerCellDef: {
            ...SubTableHeaderCellDef,
            grammar: GrapherGrammar,
            catchAllCellDef: ExplorerFormControlCellDeff,
        },
    },
    googleSheet: {
        ...UrlCellDef,
        keyword: "googleSheet",
        valuePlaceholder: "https://docs.google.com/spreadsheets/d/1qeX...",
        description:
            "Create a Google Sheet, share it with the OWID Group, then put the link here.",
    },
    downloadDataLink: {
        ...UrlCellDef,
        keyword: "downloadDataLink",
        valuePlaceholder: "https://example.com/data.csv",
        description:
            "An optional URL for the download button in the Download tab. If blank, the Explorer will instead generate a CSV from the data it has available.",
    },
    isPublished: {
        ...BooleanCellDef,
        keyword: "isPublished",
        description: "Set to true to make this Explorer public.",
    },
    wpBlockId: {
        ...IntegerCellDef,
        keyword: "wpBlockId",
        description:
            "If present will show the matching Wordpress block ID beneath the Explorer.",
    },
    hideControls: {
        ...BooleanCellDef,
        keyword: "hideControls",
        description: "Whether to hide the controls. Default is false.",
    },
    subNavId: {
        ...EnumCellDef,
        terminalOptions: Object.values(SubNavId).map((keyword) => ({
            keyword,
            description: "",
            cssClass: "",
        })),
        keyword: "subNavId",
        description: "A subnav to show, if any.",
    },
    subNavCurrentId: {
        // todo: add options here
        ...EnumCellDef,
        keyword: "subNavCurrentId",
        description: "The current page in the subnav.",
    },
    thumbnail: {
        ...UrlCellDef,
        keyword: "thumbnail",
        description: "URL to the social sharing thumbnail.",
    },
    selection: {
        ...StringCellDef,
        keyword: "selection",
        valuePlaceholder: "Canada",
        description: "The default selected entities.",
        isHorizontalList: true,
    },
    entityType: {
        ...StringCellDef,
        keyword: "entityType",
        valuePlaceholder: "region",
        description:
            "Default is 'country', but you can specify a different one such as 'state' or 'region'.",
    },
    pickerColumnSlugs: {
        ...SlugsDeclarationCellDef,
        keyword: "pickerColumnSlugs",
        valuePlaceholder: "gdp population gdp_per_capita",
        description:
            "You can manually set the column slug(s) to show in the entity picker or else they will be automatically chosen.",
    },
    hideAlertBanner: {
        ...BooleanCellDef,
        keyword: "hideAlertBanner",
        description: "Set to true to hide the Covid alert banner.",
    },
    ...GrapherGrammar,
} as const