fix frontend
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
import { MachineContextProvider } from "@/components/hooks/useMachines";
|
import { MachineContextProvider } from "@/components/hooks/useMachines";
|
||||||
|
|
||||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||||
return <MachineContextProvider>{children}</MachineContextProvider>;
|
return (
|
||||||
|
// TODO: select flake?
|
||||||
|
<MachineContextProvider flakeName="defaultFlake">
|
||||||
|
{children}
|
||||||
|
</MachineContextProvider>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
import { NodeTable } from "@/components/table";
|
import { NodeTable } from "@/components/table";
|
||||||
|
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return <NodeTable />;
|
||||||
<NodeTable />
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ interface PureCustomConfigProps extends FormStepContentProps {
|
|||||||
}
|
}
|
||||||
export function CustomConfig(props: FormStepContentProps) {
|
export function CustomConfig(props: FormStepContentProps) {
|
||||||
const { formHooks } = props;
|
const { formHooks } = props;
|
||||||
const { data, isLoading, error } = useGetMachineSchema("mama");
|
const { data, isLoading, error } = useGetMachineSchema(
|
||||||
|
"defaultFlake",
|
||||||
|
"mama",
|
||||||
|
);
|
||||||
// const { data, isLoading, error } = { data: {data:{schema: {
|
// const { data, isLoading, error } = { data: {data:{schema: {
|
||||||
// title: 'Test form',
|
// title: 'Test form',
|
||||||
// type: 'object',
|
// type: 'object',
|
||||||
@@ -53,11 +56,11 @@ export function CustomConfig(props: FormStepContentProps) {
|
|||||||
return {};
|
return {};
|
||||||
}, [data, isLoading, error]);
|
}, [data, isLoading, error]);
|
||||||
|
|
||||||
|
type ValueType = { default: any };
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() =>
|
() =>
|
||||||
Object.entries(schema?.properties || {}).reduce((acc, [key, value]) => {
|
Object.entries(schema?.properties || {}).reduce((acc, [key, value]) => {
|
||||||
/*@ts-ignore*/
|
const init: any = (value as ValueType)?.default;
|
||||||
const init: any = value?.default;
|
|
||||||
if (init) {
|
if (init) {
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
@@ -157,7 +160,7 @@ function PureCustomConfig(props: PureCustomConfigProps) {
|
|||||||
// ObjectFieldTemplate:
|
// ObjectFieldTemplate:
|
||||||
ErrorListTemplate: ErrorList,
|
ErrorListTemplate: ErrorList,
|
||||||
ButtonTemplates: {
|
ButtonTemplates: {
|
||||||
SubmitButton: (props) => (
|
SubmitButton: () => (
|
||||||
<div className="flex w-full items-center justify-center">
|
<div className="flex w-full items-center justify-center">
|
||||||
<Button
|
<Button
|
||||||
onClick={validate}
|
onClick={validate}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ export function CreateMachineForm() {
|
|||||||
)}
|
)}
|
||||||
{!isMobile && (
|
{!isMobile && (
|
||||||
<Stepper activeStep={activeStep} color="secondary">
|
<Stepper activeStep={activeStep} color="secondary">
|
||||||
{steps.map(({ label }, index) => {
|
{steps.map(({ label }) => {
|
||||||
const stepProps: { completed?: boolean } = {};
|
const stepProps: { completed?: boolean } = {};
|
||||||
const labelProps: {
|
const labelProps: {
|
||||||
optional?: React.ReactNode;
|
optional?: React.ReactNode;
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import { useListMachines } from "@/api/default/default";
|
|||||||
import { MachinesResponse } from "@/api/model";
|
import { MachinesResponse } from "@/api/model";
|
||||||
import { AxiosError, AxiosResponse } from "axios";
|
import { AxiosError, AxiosResponse } from "axios";
|
||||||
import React, {
|
import React, {
|
||||||
createContext,
|
|
||||||
Dispatch,
|
Dispatch,
|
||||||
ReactNode,
|
ReactNode,
|
||||||
SetStateAction,
|
SetStateAction,
|
||||||
|
createContext,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { KeyedMutator } from "swr";
|
import { KeyedMutator } from "swr";
|
||||||
@@ -38,7 +38,7 @@ interface AppContextProviderProps {
|
|||||||
}
|
}
|
||||||
export const WithAppState = (props: AppContextProviderProps) => {
|
export const WithAppState = (props: AppContextProviderProps) => {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const { isLoading, error, mutate, swrKey } = useListMachines();
|
const { isLoading, error, mutate, swrKey } = useListMachines("defaultFlake");
|
||||||
|
|
||||||
const [data, setAppState] = useState<AppState>({ isJoined: false });
|
const [data, setAppState] = useState<AppState>({ isJoined: false });
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export function useDebounce(value: any, delay: number) {
|
export function useDebounce<T>(value: T, delay: number) {
|
||||||
const [debouncedValue, setDebouncedValue] = useState(value);
|
const [debouncedValue, setDebouncedValue] = useState<T>(value);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handler = setTimeout(() => {
|
const handler = setTimeout(() => {
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ const initialState = {
|
|||||||
data: [],
|
data: [],
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
|
||||||
export function CreateMachineContext(flakeName: string) {
|
export function CreateMachineContext(flakeName: string) {
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
return createContext<MachineContextType>({
|
return createContext<MachineContextType>({
|
||||||
@@ -106,4 +105,5 @@ export const MachineContextProvider = (props: MachineContextProviderProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useMachines = (flakeName: string) => React.useContext(CreateMachineContext(flakeName));
|
export const useMachines = (flakeName: string) =>
|
||||||
|
React.useContext(CreateMachineContext(flakeName));
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { SearchBar } from "./searchBar";
|
|||||||
import { StickySpeedDial } from "./stickySpeedDial";
|
import { StickySpeedDial } from "./stickySpeedDial";
|
||||||
|
|
||||||
export function NodeTable() {
|
export function NodeTable() {
|
||||||
const machines = useMachines();
|
const machines = useMachines("defaultFlake");
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const is_xs = useMediaQuery(theme.breakpoints.only("xs"));
|
const is_xs = useMediaQuery(theme.breakpoints.only("xs"));
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { SetStateAction, Dispatch, useState, useEffect, useMemo } from "react";
|
|
||||||
import IconButton from "@mui/material/IconButton";
|
|
||||||
import SearchIcon from "@mui/icons-material/Search";
|
|
||||||
import { useDebounce } from "../hooks/useDebounce";
|
|
||||||
import { Autocomplete, InputAdornment, TextField } from "@mui/material";
|
|
||||||
import { Machine } from "@/api/model/machine";
|
import { Machine } from "@/api/model/machine";
|
||||||
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
|
import { Autocomplete, InputAdornment, TextField } from "@mui/material";
|
||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";
|
||||||
|
import { useDebounce } from "../hooks/useDebounce";
|
||||||
|
|
||||||
export interface SearchBarProps {
|
export interface SearchBarProps {
|
||||||
tableData: readonly Machine[];
|
tableData: readonly Machine[];
|
||||||
@@ -13,7 +13,7 @@ export interface SearchBarProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function SearchBar(props: SearchBarProps) {
|
export function SearchBar(props: SearchBarProps) {
|
||||||
let { tableData, setFilteredList } = props;
|
const { tableData, setFilteredList } = props;
|
||||||
const [search, setSearch] = useState<string>("");
|
const [search, setSearch] = useState<string>("");
|
||||||
const debouncedSearch = useDebounce(search, 250);
|
const debouncedSearch = useDebounce(search, 250);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ function createData(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var nameNumber = 0;
|
let nameNumber = 0;
|
||||||
|
|
||||||
// A function to generate random names
|
// A function to generate random names
|
||||||
function getRandomName(): string {
|
function getRandomName(): string {
|
||||||
let names = [
|
const names = [
|
||||||
"Alice",
|
"Alice",
|
||||||
"Bob",
|
"Bob",
|
||||||
"Charlie",
|
"Charlie",
|
||||||
@@ -53,7 +53,7 @@ function getRandomName(): string {
|
|||||||
"Wendy",
|
"Wendy",
|
||||||
"Zoe",
|
"Zoe",
|
||||||
];
|
];
|
||||||
let index = Math.floor(Math.random() * names.length);
|
const index = Math.floor(Math.random() * names.length);
|
||||||
return names[index] + nameNumber++;
|
return names[index] + nameNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +75,12 @@ function getRandomName(): string {
|
|||||||
|
|
||||||
// A function to generate random status keys
|
// A function to generate random status keys
|
||||||
function getRandomStatus(): NodeStatusKeys {
|
function getRandomStatus(): NodeStatusKeys {
|
||||||
let statusKeys = [NodeStatus.Online, NodeStatus.Offline, NodeStatus.Pending];
|
const statusKeys = [
|
||||||
let index = Math.floor(Math.random() * statusKeys.length);
|
NodeStatus.Online,
|
||||||
|
NodeStatus.Offline,
|
||||||
|
NodeStatus.Pending,
|
||||||
|
];
|
||||||
|
const index = Math.floor(Math.random() * statusKeys.length);
|
||||||
return statusKeys[index];
|
return statusKeys[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,8 +89,8 @@ function getRandomLastSeen(status: NodeStatusKeys): number {
|
|||||||
if (status === "online") {
|
if (status === "online") {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
let min = 1; // One day ago
|
const min = 1; // One day ago
|
||||||
let max = 360; // One year ago
|
const max = 360; // One year ago
|
||||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,12 +168,12 @@ export const tableData = [
|
|||||||
|
|
||||||
// A function to execute the createData function with dummy data in a loop 100 times and return an array
|
// A function to execute the createData function with dummy data in a loop 100 times and return an array
|
||||||
export function executeCreateData(): TableData[] {
|
export function executeCreateData(): TableData[] {
|
||||||
let result: TableData[] = [];
|
const result: TableData[] = [];
|
||||||
for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
// Generate dummy data
|
// Generate dummy data
|
||||||
let name = getRandomName();
|
const name = getRandomName();
|
||||||
let status = getRandomStatus();
|
const status = getRandomStatus();
|
||||||
let last_seen = getRandomLastSeen(status);
|
const last_seen = getRandomLastSeen(status);
|
||||||
|
|
||||||
// Call the createData function and push the result to the array
|
// Call the createData function and push the result to the array
|
||||||
result.push(createData(name, status, last_seen));
|
result.push(createData(name, status, last_seen));
|
||||||
|
|||||||
@@ -16,15 +16,16 @@ export default function JoinPrequel() {
|
|||||||
const queryParams = useSearchParams();
|
const queryParams = useSearchParams();
|
||||||
const flakeUrl = queryParams.get("flake") || "";
|
const flakeUrl = queryParams.get("flake") || "";
|
||||||
const flakeAttr = queryParams.get("attr") || "default";
|
const flakeAttr = queryParams.get("attr") || "default";
|
||||||
const { handleSubmit, control, formState, getValues, reset } =
|
const { control, formState, getValues, reset } = useForm<FormValues>({
|
||||||
useForm<FormValues>({ defaultValues: { flakeUrl: "" } });
|
defaultValues: { flakeUrl: "" },
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<Suspense fallback="Loading">
|
<Suspense fallback="Loading">
|
||||||
{!formState.isSubmitted && !flakeUrl && (
|
{!formState.isSubmitted && !flakeUrl && (
|
||||||
<form
|
<form
|
||||||
onSubmit={handleSubmit(() => {})}
|
// onSubmit={handleSubmit(() => {})}
|
||||||
className="w-full max-w-2xl justify-self-center"
|
className="w-full max-w-2xl justify-self-center"
|
||||||
>
|
>
|
||||||
<Controller
|
<Controller
|
||||||
|
|||||||
Reference in New Issue
Block a user