-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add introspection, styles, react-table
- Loading branch information
Showing
21 changed files
with
718 additions
and
82 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 |
---|---|---|
|
@@ -37,6 +37,7 @@ yarn-error.log* | |
.DS_Store | ||
*.pem | ||
cache | ||
logs | ||
|
||
# Orama | ||
orama_bump_*.json |
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from "./bulk.mjs" | ||
export * from "./introspection.mjs" | ||
export * from "./persist.mjs" | ||
export * from "./search.mjs" | ||
export * from "./styles.mjs" |
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,16 @@ | ||
import type { FastifyInstance } from "fastify" | ||
|
||
export async function introspectionRoute(fastify: FastifyInstance) { | ||
fastify.route({ | ||
url: "/introspection", | ||
method: "get", | ||
handler: async () => { | ||
const { dbSchema, ui } = fastify.pinoramaOpts | ||
|
||
return { | ||
dbSchema, | ||
ui | ||
} | ||
} | ||
}) | ||
} |
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,19 @@ | ||
import type { FastifyInstance } from "fastify" | ||
import { generateCSS } from "../utils/styles.mjs" | ||
|
||
export async function stylesRoute(fastify: FastifyInstance) { | ||
fastify.route({ | ||
url: "/styles.css", | ||
method: "get", | ||
handler: async (req, res) => { | ||
const columns = fastify.pinoramaOpts?.ui?.columns | ||
|
||
if (!columns || columns?.length === 0) { | ||
res.type("text/css").send("") | ||
} | ||
|
||
const css = generateCSS(columns) | ||
res.type("text/css").send(css) | ||
} | ||
}) | ||
} |
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,45 @@ | ||
import { kebabCase } from "change-case" | ||
|
||
type StyleConfig = { | ||
base?: Record<string, string> | ||
conditions?: Record<string | number, Record<string, string>> | ||
} | ||
|
||
type ColumnnDefinition = | ||
| [string, { style: StyleConfig; formatter?: string }] | ||
| string | ||
|
||
export function generateCSS(columns: ColumnnDefinition[]) { | ||
let css = "" | ||
|
||
const generateCSSProps = (styles: Record<string, string>) => { | ||
let props = "" | ||
for (const [prop, value] of Object.entries(styles)) { | ||
props += `${kebabCase(prop)}: ${value};` | ||
} | ||
return props | ||
} | ||
|
||
for (const column of columns) { | ||
if (typeof column === "string") continue | ||
|
||
const prefix = "pinorama-col" | ||
const [className, config] = column | ||
const baseStyles = config.style?.base ?? {} | ||
const conditions = config.style?.conditions ?? {} | ||
|
||
// Generate base style | ||
css += `.${prefix}-${kebabCase(className)} {` | ||
css += generateCSSProps(baseStyles) | ||
css += "}\n" | ||
|
||
// Generate conditional style | ||
for (const [condition, conditionStyles] of Object.entries(conditions)) { | ||
css += `.${prefix}-${kebabCase(className)}-${condition} {` | ||
css += generateCSSProps(conditionStyles) | ||
css += "}\n" | ||
} | ||
} | ||
|
||
return css | ||
} |
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.