-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP(api): JavaScript module refactor, API stylesheets and theme switc…
…hing - Use js.Build in asset pipeline to transpile and tree-shake ESM modules - Reorganize JS from HTML sections into modular ESM (benefts: testing, intellisense, package management, explicit dependencies (imports) - Move some code into Reactish functional components - Light/dark theme switching for Rapidoc - Basic light/dark SCSS setup - Inherits the user's preferred server URL and sets it as the API server URL
- Loading branch information
1 parent
6f20d7f
commit deeb945
Showing
53 changed files
with
1,257 additions
and
1,045 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { groupData } from './flux-group-keys.js'; | ||
|
||
export default function FluxGroupKeys() { | ||
// Group and render tables on load | ||
document.querySelector(tablesElement).addEventListener('load', groupData()); | ||
}; |
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,5 @@ | ||
import { setSidebarState } from './sidebar-toggle.js'; | ||
|
||
export default function Sidebar() { | ||
setSidebarState(); | ||
} |
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,5 @@ | ||
import { setStyleFromCookie } from './docs-themes.js'; | ||
|
||
export default function ThemeStyle() { | ||
setStyleFromCookie(); | ||
} |
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,15 @@ | ||
import { setStyles, setServerUrl, onPreferenceChanged } from './index.js'; | ||
|
||
export default function ApiReferencePage() { | ||
const rapidocEl = document.getElementById('api-doc'); | ||
if(rapidocEl === null) return; | ||
setStyles(rapidocEl); | ||
setServerUrl(rapidocEl); | ||
rapidocEl.loadSpec(JSON.parse(rapidocEl.dataset.openapiSpec)); | ||
rapidocEl.addEventListener('spec-loaded', (e) => {}); | ||
cookieStore.addEventListener('change', (e) => { | ||
if(e.changed) { | ||
onPreferenceChanged(e, rapidocEl); | ||
} | ||
}); | ||
} |
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,21 +1,58 @@ | ||
import 'rapidoc'; | ||
import { getPreference } from '../cookies.js'; | ||
import { getUrls } from '../influxdb-url.js'; | ||
|
||
function getUserPreferredUrl() { | ||
const urlName = window.getPreference && window.getPreference('influxdb_url'); | ||
return getUrls()[urlName] || (window.placeholderUrls && window.placeholderUrls['oss']); | ||
const urlName = getPreference('influxdb_url'); | ||
return getUrls()[urlName]; | ||
} | ||
|
||
export function apiDocComponent() { | ||
window.addEventListener('DOMContentLoaded', (event) => { | ||
const rapidocEl = document.getElementById('api-doc'); | ||
if(rapidocEl === null) return; | ||
const apiServer = getUserPreferredUrl(); | ||
rapidocEl.addEventListener('spec-loaded', (e) => { | ||
rapidocEl.setApiServer(apiServer); | ||
}); | ||
const spec = JSON.parse(rapidocEl.dataset.openapiSpec); | ||
rapidocEl.loadSpec(spec); | ||
}); | ||
|
||
export function setServerUrl(el) { | ||
const baseUrl = getUserPreferredUrl(); | ||
el.setAttribute('server-url', baseUrl); | ||
el.setApiServer(baseUrl); | ||
} | ||
|
||
apiDocComponent(); | ||
const darkThemeAttributes = { | ||
'theme': 'dark', | ||
}; | ||
|
||
const lightThemeAttributes = { | ||
'theme': 'light', | ||
}; | ||
|
||
export function setStyles(el) { | ||
let theme = getPreference('theme') || 'light'; | ||
theme = theme.replace(/-theme/, ''); | ||
let themeAttributes = { | ||
'nav-accent-color': "", | ||
'nav-bg-color': "", | ||
'nav-hover-bg-color': "", | ||
'nav-hover-text-color': "", | ||
'nav-text-color': "", | ||
'primary-color': "#F63C41", | ||
'render-style': 'view', | ||
'show-header': 'false', | ||
'show-info': 'false', | ||
'style': 'height:100vh; width:100%', | ||
} | ||
switch (theme) { | ||
case 'light': | ||
themeAttributes = { ...themeAttributes, ...lightThemeAttributes }; | ||
break; | ||
case 'dark': | ||
themeAttributes = { ...themeAttributes, ...darkThemeAttributes }; | ||
break; | ||
} | ||
|
||
for (const [key, value] of Object.entries(themeAttributes)) { | ||
el.setAttribute(key, value); | ||
} | ||
} | ||
|
||
export function onPreferenceChanged(e) { | ||
const rapidocEl = document.getElementById('api-doc'); | ||
if(rapidocEl === null) return; | ||
setStyles(rapidocEl); | ||
setServerUrl(rapidocEl); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import $ from 'jquery'; | ||
|
||
var codeBlockSelector = ".article--content pre"; | ||
var codeBlocks = $(codeBlockSelector); | ||
|
||
|
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
Oops, something went wrong.