diff --git a/contributing/single-sourcing-content.md b/contributing/single-sourcing-content.md index 2b8a82dfb81..537980ebdfb 100644 --- a/contributing/single-sourcing-content.md +++ b/contributing/single-sourcing-content.md @@ -132,94 +132,6 @@ $ dbt test --models [...] --defer --state path/to/artifacts ``` -## Using global variables - ---- - -Global variables can be configured for use throughout the docs. - -Using a global variable requires two steps: - -1. Set the variable in the `website/dbt-global-variables.js` file. -2. Use the **Var** component to add the global variable to a page. - -```jsx -// The dbtCore property is the identifier for the variable, -// while the name property is the value shown on the page. - -exports.dbtVariables = { - dbtCore: { - name: "dbt Core" - } -} -``` - -```markdown -// is converted to dbt Core - -You can install on the command line by using one of these recommended methods: -``` - -### Versioning global variables - -It is possible to version global variables as well. This creates the ability to show different variations of a string based off the current version a visitor has selected. - -To extend our `dbt-global-variables.js` file above, we can add a new variable: *note - these versions are not accurate and only shown for this example.* - -```jsx -// A new variable called dbtCloud is added below -// This variable includes a versions array -// "Sinter" will replace "dbt Cloud" for versions 0.21 or lower - -exports.dbtVariables = { - dbtCore: { - name: "dbt Core" - }, - dbtCloud: { - name: "dbt Cloud", - versions: [ - { - "name": "Sinter", - "version": "0.21" - } - ] - } -} -``` - -```markdown -You can get started with by [Signing up](https://www.getdbt.com/signup/). -``` - -In the above example, the **dbtCloud** property has a default name of “dbt Cloud”. The naming for variables cascade down, meaning “dbt Cloud” will show for all versions, until version **0.21** or lower is selected. At that point “Sinter” will replace “dbt Cloud”. - -### Global variables properties - -**name** (required): Expects the identifier for a global variable. - -### Global variables example - -The global `` component can be used inline, for example: - -```markdown -This piece of markdown content explains why is awesome. -``` - -However, a Var component cannot start a new line of content. Fortunately, a workaround exists to use the Var component at the beginning of a line of content. - -To use the component at the beginning of a sentence, add a non-breaking space character before the component: - -```markdown -// When starting a new line with a global variable, -// a non-breaking space is required - -// Works - is awesome! - -// Does not work - is awesome! -``` - ## Reusing content To reuse content on different pages, you can use some techniques like partial files or snippets. Partial files, a built-in Docusaurus feature, is the recommended method over snippets. diff --git a/website/dbt-global-variables.js b/website/dbt-global-variables.js deleted file mode 100644 index 8ee4499151e..00000000000 --- a/website/dbt-global-variables.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Full Documentation at: - * https://www.notion.so/dbtlabs/Versioning-on-Docusaurus-c6a4a41a66cd4ea2970854cc42cb5b70#1803b9cb666442e5ac8885cf0bba321f - * - */ - -exports.dbtVariables = { - // Example global variable with versioning - // If version 0.21 or lower is selected - // "Old Example String" will replace "Example String" - exampleString: { - name: "Example String", - versions: [ - { - "name": "Old Example String", - "version": "0.21" - } - ] - }, - dbtTheProduct: { - name: "dbt" - }, - dbtCore: { - name: "dbt Core" - }, - dbtCloud: { - name: "dbt Cloud" - }, - dbtIDE: { - name: "dbt Cloud IDE" - }, -} diff --git a/website/dbt-versions.js b/website/dbt-versions.js index 871c3ce601e..60efef64f75 100644 --- a/website/dbt-versions.js +++ b/website/dbt-versions.js @@ -2,15 +2,15 @@ * Sets the available dbt versions available in the navigation * @type {Array.<{ * version: string, - * EOLDate: string, - * isPrerelease: boolean, + * EOLDate: string, + * isPrerelease: boolean, * customDisplay: string, * }>} * @property {string} version The version number * @property {string} EOLDate "End of Life" date which is used to show the EOL banner * @property {boolean} isPrerelease Boolean used for showing the prerelease banner * @property {string} customDisplay Allows setting a custom display name for the current version - * + * * customDisplay for dbt Cloud should be a version ahead of latest dbt Core release (GA or beta). */ exports.versions = [ @@ -30,7 +30,7 @@ exports.versions = [ version: "1.6", EOLDate: "2024-07-31", }, -] +]; /** * Controls doc page visibility in the sidebar based on the current version @@ -43,146 +43,146 @@ exports.versions = [ */ exports.versionedPages = [ { - "page": "/reference/resource-configs/target_database", - "lastVersion": "1.8", + page: "reference/resource-configs/target_database", + lastVersion: "1.8", }, { - "page": "/reference/resource-configs/target_schema", - "lastVersion": "1.8", + page: "reference/resource-configs/target_schema", + lastVersion: "1.8", }, { - "page": "reference/global-configs/indirect-selection", - "firstVersion": "1.8", + page: "reference/global-configs/indirect-selection", + firstVersion: "1.8", }, { - "page": "reference/resource-configs/store_failures_as", - "firstVersion": "1.7", + page: "reference/resource-configs/store_failures_as", + firstVersion: "1.7", }, { - "page": "docs/build/build-metrics-intro", - "firstVersion": "1.6", + page: "docs/build/build-metrics-intro", + firstVersion: "1.6", }, { - "page": "docs/build/sl-getting-started", - "firstVersion": "1.6", + page: "docs/build/sl-getting-started", + firstVersion: "1.6", }, { - "page": "docs/build/about-metricflow", - "firstVersion": "1.6", + page: "docs/build/about-metricflow", + firstVersion: "1.6", }, { - "page": "docs/build/join-logic", - "firstVersion": "1.6", + page: "docs/build/join-logic", + firstVersion: "1.6", }, { - "page": "docs/build/validation", - "firstVersion": "1.6", + page: "docs/build/validation", + firstVersion: "1.6", }, { - "page": "docs/build/semantic-models", - "firstVersion": "1.6", + page: "docs/build/semantic-models", + firstVersion: "1.6", }, { - "page": "docs/build/group-by", - "firstVersion": "1.6", + page: "docs/build/group-by", + firstVersion: "1.6", }, { - "page": "docs/build/entities", - "firstVersion": "1.6", + page: "docs/build/entities", + firstVersion: "1.6", }, { - "page": "docs/build/metrics-overview", - "firstVersion": "1.6", + page: "docs/build/metrics-overview", + firstVersion: "1.6", }, { - "page": "docs/build/cumulative", - "firstVersion": "1.6", + page: "docs/build/cumulative", + firstVersion: "1.6", }, { - "page": "docs/build/derived", - "firstVersion": "1.6", + page: "docs/build/derived", + firstVersion: "1.6", }, { - "page": "docs/build/measure-proxy", - "firstVersion": "1.6", + page: "docs/build/measure-proxy", + firstVersion: "1.6", }, { - "page": "docs/build/ratio", - "firstVersion": "1.6", + page: "docs/build/ratio", + firstVersion: "1.6", }, { - "page": "reference/commands/clone", - "firstVersion": "1.6", + page: "reference/commands/clone", + firstVersion: "1.6", }, { - "page": "docs/collaborate/govern/project-dependencies", - "firstVersion": "1.6", + page: "docs/collaborate/govern/project-dependencies", + firstVersion: "1.6", }, { - "page": "reference/dbt-jinja-functions/thread_id", - "firstVersion": "1.6", + page: "reference/dbt-jinja-functions/thread_id", + firstVersion: "1.6", }, { - "page": "reference/resource-properties/deprecation_date", - "firstVersion": "1.6", + page: "reference/resource-properties/deprecation_date", + firstVersion: "1.6", }, { - "page": "reference/commands/retry", - "firstVersion": "1.6", + page: "reference/commands/retry", + firstVersion: "1.6", }, { - "page": "docs/build/groups", - "firstVersion": "1.5", + page: "docs/build/groups", + firstVersion: "1.5", }, { - "page": "docs/collaborate/govern/model-contracts", - "firstVersion": "1.5", + page: "docs/collaborate/govern/model-contracts", + firstVersion: "1.5", }, { - "page": "reference/commands/show", - "firstVersion": "1.5", + page: "reference/commands/show", + firstVersion: "1.5", }, { - "page": "docs/collaborate/govern/model-access", - "firstVersion": "1.5", + page: "docs/collaborate/govern/model-access", + firstVersion: "1.5", }, { - "page": "docs/collaborate/govern/model-versions", - "firstVersion": "1.5", + page: "docs/collaborate/govern/model-versions", + firstVersion: "1.5", }, { - "page": "reference/programmatic-invocations", - "firstVersion": "1.5", + page: "reference/programmatic-invocations", + firstVersion: "1.5", }, { - "page": "reference/resource-configs/contract", - "firstVersion": "1.5", + page: "reference/resource-configs/contract", + firstVersion: "1.5", }, { - "page": "reference/resource-configs/group", - "firstVersion": "1.5", + page: "reference/resource-configs/group", + firstVersion: "1.5", }, { - "page": "reference/resource-properties/access", - "firstVersion": "1.5", + page: "reference/resource-properties/access", + firstVersion: "1.5", }, { - "page": "reference/resource-properties/constraints", - "firstVersion": "1.5", + page: "reference/resource-properties/constraints", + firstVersion: "1.5", }, { - "page": "reference/resource-properties/latest_version", - "firstVersion": "1.5", + page: "reference/resource-properties/latest_version", + firstVersion: "1.5", }, { - "page": "reference/resource-properties/versions", - "firstVersion": "1.5", + page: "reference/resource-properties/versions", + firstVersion: "1.5", }, { - "page": "reference/resource-configs/on_configuration_change", - "firstVersion": "1.6", - } -] + page: "reference/resource-configs/on_configuration_change", + firstVersion: "1.6", + }, +]; /** * Controls doc category visibility in the sidebar based on the current version @@ -195,11 +195,11 @@ exports.versionedPages = [ */ exports.versionedCategories = [ { - "category": "Model governance", - "firstVersion": "1.5", + category: "Model governance", + firstVersion: "1.5", }, { - "category": "Build your metrics", - "firstVersion": "1.6", - } -] + category: "Build your metrics", + firstVersion: "1.6", + }, +]; diff --git a/website/src/components/variable/index.js b/website/src/components/variable/index.js deleted file mode 100644 index 444f3203327..00000000000 --- a/website/src/components/variable/index.js +++ /dev/null @@ -1,45 +0,0 @@ -import React, { useState, useEffect, useContext } from 'react' -import { dbtVariables } from '../../../dbt-global-variables'; -import VersionContext from '../../stores/VersionContext'; - -export default function Var({ name }) { - if(!name) - return null - - const [variableName, setVariableName] = useState('') - - const { version } = useContext(VersionContext) - - const currentVariable = dbtVariables[name] - if(!currentVariable) - return null - - useEffect(() => { - if(currentVariable?.versions?.length && version) { - {/* - * If versions set for variable - * show correct variable name for current version - * - * Sort by lowest version first - * If this version is greater or equal to the active version - * Show this variable name - * If no match is found, show original variable name - * - */} - const thisVersionVariable = currentVariable.versions - .sort((item1, item2) => (parseFloat(item1.version) > parseFloat(item2.version)) ? 1 : -1) - .find(varVersion => - parseFloat(varVersion.version) >= parseFloat(version) ? true : false - ) - - !thisVersionVariable - ? setVariableName(currentVariable.name) - : setVariableName(thisVersionVariable.name) - - } else { - setVariableName(currentVariable.name) - } - }, [version]) - - return { variableName } -} diff --git a/website/src/components/versionBlock/index.js b/website/src/components/versionBlock/index.js index 01d6381c0e1..f7982d6eacf 100644 --- a/website/src/components/versionBlock/index.js +++ b/website/src/components/versionBlock/index.js @@ -1,39 +1,25 @@ import React, { useState, useEffect, useContext } from 'react' import VersionContext from '../../stores/VersionContext'; +import { availableInCurrentVersion } from '../../utils/available-in-current-version'; -export default function VersionBlock({ firstVersion = 0, lastVersion = undefined, children }) { - const { version } = useContext(VersionContext) +export default function VersionBlock({ firstVersion = "0", lastVersion = undefined, children }) { + const { version } = useContext(VersionContext); - const [loading, setLoading] = useState(true) + const [loading, setLoading] = useState(true); // Hide versionBlock components until version ready useEffect(() => { - version && setLoading(false) - }, [version]) + version && setLoading(false); + }, [version]); // Only check version if current version set - if(version) { - const currentVersionVal = parseFloat(version) - const firstVersionVal = parseFloat(firstVersion) - {/* - * If last version set, check if current version greater than last version - * Or if current version less than first version - * If either is true, hide block - * Else, if current version less than first version, hide block - */} - if(lastVersion) { - if((currentVersionVal > parseFloat(lastVersion)) - || (currentVersionVal < firstVersionVal)) - return null - } else { - if(currentVersionVal < firstVersionVal) { - return null - } - - } + if (version) { + if (!availableInCurrentVersion( + version, + firstVersion, + lastVersion + )) return null; } - return loading - ? null - : <>{children}> + return loading ? null : <>{children}>; } diff --git a/website/src/theme/DocRoot/Layout/Main/index.js b/website/src/theme/DocRoot/Layout/Main/index.js index 458cb9d8716..da6e29265bb 100644 --- a/website/src/theme/DocRoot/Layout/Main/index.js +++ b/website/src/theme/DocRoot/Layout/Main/index.js @@ -43,11 +43,14 @@ export default function DocRootLayoutMain({ latestStableRelease, } = useContext(VersionContext); - const { pageAvailable, firstAvailableVersion } = pageVersionCheck( - dbtVersion, - versionedPages, - currentDocRoute - ); + const { + pageAvailable, + firstAvailableVersion, + lastAvailableVersion + } = pageVersionCheck(dbtVersion, versionedPages, currentDocRoute); + + const hasFirstAvailableVersion = + firstAvailableVersion && firstAvailableVersion !== "0"; // Check whether this version is a isPrerelease, and show banner if so const [PreData, setPreData] = useState({ @@ -116,21 +119,34 @@ export default function DocRootLayoutMain({ hiddenSidebarContainer && styles.docItemWrapperEnhanced )} > - {!pageAvailable && dbtVersion && firstAvailableVersion && ( -
- Unfortunately, this feature is not available in dbt Core version{" "} - {dbtVersion} -
-- {" "} - You should upgrade to {firstAvailableVersion} or later if you - want to use this feature. -
-+ Unfortunately, this feature is not available in dbt Core + version {dbtVersion} +
+ {hasFirstAvailableVersion ? ( ++ {" "} + You should upgrade to {firstAvailableVersion} or later if + you want to use this feature. +
+ ) : null} +