-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved the app to more appropriate folder and optimised the code
- Loading branch information
Showing
179 changed files
with
3,191 additions
and
2,659 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,146 @@ | ||
import {BrowserRouter as Router, Route, Routes} from "react-router-dom"; | ||
import Components from "@/pages/components"; | ||
import CreateComponent from "@/pages/components/create"; | ||
import {APIs} from "@/pages/api"; | ||
import CreateAPI from "@/pages/api/create"; | ||
import APIDetails from "@/pages/api/details"; | ||
import APISettings from "@/pages/api/details/settings"; | ||
import CreateRoute from "@/pages/api/details/createRoute.tsx"; | ||
import Deployments from "@/pages/deployment"; | ||
import {ComponentDetails} from "@/pages/components/details"; | ||
import {PluginList} from "@/pages/plugin"; | ||
import ComponentSettings from "@/pages/components/details/settings"; | ||
import ComponentInfo from "@/pages/components/details/info"; | ||
import Exports from "@/pages/components/details/export"; | ||
import ComponentUpdate from "@/pages/components/details/update"; | ||
import WorkerList from "@/pages/workers"; | ||
import {ThemeProvider} from "@/components/theme-provider.tsx"; | ||
import Navbar from "@/components/navbar.tsx"; | ||
import APINewVersion from "./pages/api/details/newVersion"; | ||
import {Dashboard} from "@/pages/dashboard"; | ||
import CreateWorker from "@/pages/workers/create"; | ||
import WorkerDetails from "@/pages/workers/details"; | ||
import ErrorBoundary from "@/components/errorBoundary"; | ||
import WorkerEnvironments from "@/pages/workers/details/environments"; | ||
import WorkerManage from "@/pages/workers/details/manage"; | ||
import WorkerInvoke from "@/pages/workers/details/invoke"; | ||
import WorkerLive from "@/pages/workers/details/live"; | ||
import CreatePlugin from "@/pages/plugin/create.tsx"; | ||
import {PluginView} from "@/pages/plugin/view.tsx"; | ||
import {ApiRoute} from "@/pages/api/details/viewRoute"; | ||
import CreateDeployment from "@/pages/deployment/create"; | ||
import {ApiLayout} from "./pages/api/details/api-layout"; | ||
|
||
function App() { | ||
return ( | ||
<ThemeProvider defaultTheme="system" storageKey="golem-theme"> | ||
<Router> | ||
<div className="min-h-screen"> | ||
<ErrorBoundary> | ||
<Navbar/> | ||
</ErrorBoundary> | ||
<Routes> | ||
<Route path="/" element={<Dashboard/>}/> | ||
<Route path="/components" element={<Components/>}/> | ||
<Route path="/components/create" element={<CreateComponent/>}/> | ||
<Route | ||
path="/components/:componentId" | ||
element={<ComponentDetails/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/settings" | ||
element={<ComponentSettings/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/update" | ||
element={<ComponentUpdate/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/info" | ||
element={<ComponentInfo/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/exports" | ||
element={<Exports/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/workers" | ||
element={<WorkerList/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/workers/create" | ||
element={<CreateWorker/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/workers/:workerName" | ||
element={<WorkerDetails/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/workers/:workerName/environments" | ||
element={<WorkerEnvironments/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/workers/:workerName/manage" | ||
element={<WorkerManage/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/workers/:workerName/invoke" | ||
element={<WorkerInvoke/>} | ||
/> | ||
<Route | ||
path="/components/:componentId/workers/:workerName/live" | ||
element={<WorkerLive/>} | ||
/> | ||
<Route path="/apis" element={<APIs/>}/> | ||
<Route path="/apis/create" element={<CreateAPI/>}/> | ||
<Route | ||
path="/apis/:apiName/version/:version" | ||
element={<ApiLayout/>} | ||
> | ||
<Route path="" element={<APIDetails/>}/> | ||
<Route path="settings" element={<APISettings/>}/> | ||
<Route path="routes/edit" element={<CreateRoute/>}/> | ||
<Route path="newversion" element={<APINewVersion/>}/> | ||
<Route path="routes" element={<ApiRoute/>}/> | ||
</Route> | ||
{/* <Route | ||
path="/apis/:apiName/version/:version/" | ||
element={<APIDetails />} | ||
/> | ||
<Route | ||
path="/apis/:apiName/version/:version/settings" | ||
element={<APISettings />} | ||
/> | ||
<Route | ||
path="/apis/:apiName/version/:version/route/:routeId" | ||
element={<ApiRoute />} | ||
/> | ||
<Route | ||
path="/apis/:apiName/version/:version/newversion" | ||
element={<APINewVersion />} | ||
/> | ||
<Route | ||
path="/apis/:apiName/version/:version/routes/new" | ||
element={<CreateRoute />} | ||
/> */} | ||
<Route path="/deployments" element={<Deployments/>}/> | ||
<Route path="/plugins" element={<PluginList/>}/> | ||
<Route path="/plugins/create" element={<CreatePlugin/>}/> | ||
<Route path="/apis/:apiName/routes/new" element={<CreateRoute/>}/> | ||
<Route path="/deployments" element={<Deployments/>}/> | ||
<Route path="/deployments/create" element={<CreateDeployment/>}/> | ||
<Route path="/plugins" element={<PluginList/>}/> | ||
<Route path="/plugins/create" element={<CreatePlugin/>}/> | ||
<Route path="/plugins/:pluginId" element={<PluginView/>}/> | ||
<Route | ||
path="/plugins/:pluginId/:version" | ||
element={<PluginView/>} | ||
/> | ||
</Routes> | ||
</div> | ||
</Router> | ||
</ThemeProvider> | ||
); | ||
} | ||
|
||
export default App; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,104 @@ | ||
import { Api } from "@/types/api"; | ||
import { clsx, type ClassValue } from "clsx"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)); | ||
} | ||
|
||
export function formatRelativeTime(dateString: string | number | Date) { | ||
const date = new Date(dateString).getTime(); | ||
const now = new Date().getTime(); | ||
const diffInSeconds = Math.floor((now - date) / 1000); | ||
|
||
const units = [ | ||
{ name: "year", seconds: 60 * 60 * 24 * 365 }, | ||
{ name: "month", seconds: 60 * 60 * 24 * 30 }, | ||
{ name: "week", seconds: 60 * 60 * 24 * 7 }, | ||
{ name: "day", seconds: 60 * 60 * 24 }, | ||
{ name: "hour", seconds: 60 * 60 }, | ||
{ name: "minute", seconds: 60 }, | ||
{ name: "second", seconds: 1 }, | ||
]; | ||
|
||
for (const unit of units) { | ||
if (diffInSeconds >= unit.seconds) { | ||
const value = Math.floor(diffInSeconds / unit.seconds); | ||
return `${value} ${unit.name}${value > 1 ? "s" : ""} ago`; | ||
} | ||
} | ||
|
||
return "just now"; | ||
} | ||
|
||
export const sanitizeInput = (input: string): string => { | ||
return input.replace(/\u201c|\u201d/g, '"').replace(/'/g, '"'); | ||
}; | ||
|
||
export function formatTimestampInDateTimeFormat(timestamp: string) { | ||
const date = new Date(timestamp); | ||
|
||
// Get date components | ||
const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero-indexed | ||
const day = String(date.getDate()).padStart(2, "0"); | ||
|
||
// Get time components | ||
const hours = String(date.getHours()).padStart(2, "0"); | ||
const minutes = String(date.getMinutes()).padStart(2, "0"); | ||
const seconds = String(date.getSeconds()).padStart(2, "0"); | ||
const milliseconds = String(date.getMilliseconds()).padStart(3, "0"); | ||
|
||
// Combine into the desired format | ||
return `${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`; | ||
} | ||
|
||
/// compare semver version | ||
export const compareSemver = (version1: string, version2: string) => { | ||
const semverRegex = | ||
/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/; | ||
|
||
if (!semverRegex.test(version1) || !semverRegex.test(version2)) { | ||
throw new Error("Invalid semver version format"); | ||
} | ||
|
||
const v1Parts = version1.split("."); | ||
const v2Parts = version2.split("."); | ||
|
||
// Compare major version | ||
const major1 = parseInt(v1Parts[0]); | ||
const major2 = parseInt(v2Parts[0]); | ||
if (major1 !== major2) return major1 > major2; | ||
|
||
const minor1 = parseInt(v1Parts[1]); | ||
const minor2 = parseInt(v2Parts[1]); | ||
if (minor1 !== minor2) return minor1 > minor2; | ||
|
||
// Compare patch version | ||
const patch1 = parseInt(v1Parts[2]); | ||
const patch2 = parseInt(v2Parts[2]); | ||
return patch1 > patch2; | ||
|
||
return false; | ||
}; | ||
|
||
/// Remove the duplicate api and keep the latest one by comparing the semver version | ||
export const removeDuplicateApis = (data: Api[]) => { | ||
const uniqueEntries = {} as Record<string, Api>; | ||
|
||
data.forEach((item) => { | ||
if (!uniqueEntries[item.id]) { | ||
uniqueEntries[item.id] = item; | ||
} else { | ||
// check semver for latest version | ||
const uniqueEntriesVersion = uniqueEntries[item.id].version; | ||
const count = (uniqueEntries[item.id].count || 1) + 1; | ||
const itemVersion = item.version; | ||
if (compareSemver(itemVersion, uniqueEntriesVersion)) { | ||
uniqueEntries[item.id] = { ...item, count: count + 1 }; | ||
} else { | ||
uniqueEntries[item.id].count = count; | ||
} | ||
} | ||
}); | ||
return Object.values(uniqueEntries); | ||
}; |
File renamed without changes.
Oops, something went wrong.