Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
iberdinsky-skilld committed Jun 25, 2024
1 parent 3ae4ab7 commit 471b8ce
Show file tree
Hide file tree
Showing 23 changed files with 1,103 additions and 272 deletions.
1 change: 1 addition & 0 deletions client/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = {
],
'unicorn/no-null': 0,
'unicorn/prevent-abbreviations': 0,
'unicorn/prefer-add-event-listener': 0,
'unicorn/prefer-query-selector': 0,
'import/no-unresolved': [
2,
Expand Down
4 changes: 3 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@
"react-hook-form": "^7.51.5",
"react-i18next": "^14.1.2",
"react-router-dom": "^6.23.1",
"reactflow": "^11.11.3"
"reactflow": "^11.11.3",
"websocket": "^1.0.35"
},
"devDependencies": {
"@types/lodash": "^4",
"@types/node": "^18.19.34",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/websocket": "^1.0.10",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^7.12.0",
"@vitejs/plugin-react": "^4.3.0",
Expand Down
126 changes: 62 additions & 64 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import routerBindings, {
NavigateToResource,
UnsavedChangesNotifier,
} from '@refinedev/react-router-v6'
import * as React from 'react'
import { BrowserRouter, Outlet, Route, Routes } from 'react-router-dom'

import { ThemedLayoutV2 } from './components/layout'
import { ThemedHeaderV2 } from './components/layout/Header'
import { ThemedSiderV2 } from './components/layout/Sider'
import { ThemedTitleV2 } from './components/layout/Title'
import { ActionProvider } from './context/ActionContext'
import AppProvider from './context/AppContext'
import { liveProvider } from './live-provider'
import { ActionList, ActionShow } from './pages/actions'
import { FlowShow } from './pages/flow'
import { dataProvider as launchrDataProvider } from './rest-data-provider'
Expand All @@ -23,73 +24,70 @@ const apiUrl = import.meta.env.VITE_API_URL

export function App() {
return (
<BrowserRouter>
<RefineKbarProvider>
<ThemeProvider>
<Refine
dataProvider={{
default: launchrDataProvider(apiUrl),
}}
notificationProvider={useNotificationProvider}
routerProvider={routerBindings}
resources={[
{
name: 'actions',
list: '/actions',
show: '/actions/:id/show',
// edit: "/actions/:id/edit",
meta: {
canDelete: false,
},
},
]}
options={{
// syncWithLocation: true,
warnWhenUnsavedChanges: true,
}}
>
<Routes>
<Route
element={
<ThemedLayoutV2
Header={ThemedHeaderV2}
Sider={ThemedSiderV2}
Title={ThemedTitleV2}
>
<Outlet />
</ThemedLayoutV2>
}
<AppProvider>
<ActionProvider>
<BrowserRouter>
<RefineKbarProvider>
<ThemeProvider>
<Refine
dataProvider={{
default: launchrDataProvider(apiUrl),
}}
liveProvider={liveProvider}
notificationProvider={useNotificationProvider}
routerProvider={routerBindings}
resources={[
{
name: 'actions',
list: '/actions',
show: '/actions/:id/show',
// edit: "/actions/:id/edit",
meta: {
canDelete: false,
},
},
]}
options={{
liveMode: 'manual',
}}
>
<Route
index
element={<NavigateToResource resource="actions" />}
/>
<Route path="/actions">
<Route index element={<ActionList />} />
<Route path=":id/show" element={<ActionShow />} />
{/*<Route path=":id/running/:runId" element={<ActionAttach />} />*/}
{/*<Route path=":id/edit" element={<ActionEdit />} />*/}
</Route>
<Route path="/flow">
<Routes>
<Route
index
element={
<ActionProvider>
<FlowShow />
</ActionProvider>
<ThemedLayoutV2
Header={ThemedHeaderV2}
Sider={ThemedSiderV2}
Title={ThemedTitleV2}
>
<Outlet />
</ThemedLayoutV2>
}
/>
</Route>
<Route path="*" element={<ErrorComponent />} />
</Route>
</Routes>
>
<Route
index
element={<NavigateToResource resource="actions" />}
/>
<Route path="/actions">
<Route index element={<ActionList />} />
<Route path=":id/show" element={<ActionShow />} />
{/*<Route path=":id/running/:runId" element={<ActionAttach />} />*/}
{/*<Route path=":id/edit" element={<ActionEdit />} />*/}
</Route>
<Route path="/flow">
<Route index element={<FlowShow />} />
</Route>
<Route path="*" element={<ErrorComponent />} />
</Route>
</Routes>

<RefineKbar />
<UnsavedChangesNotifier />
<DocumentTitleHandler />
</Refine>
</ThemeProvider>
</RefineKbarProvider>
</BrowserRouter>
<RefineKbar />
<UnsavedChangesNotifier />
<DocumentTitleHandler />
</Refine>
</ThemeProvider>
</RefineKbarProvider>
</BrowserRouter>
</ActionProvider>
</AppProvider>
)
}
99 changes: 67 additions & 32 deletions client/src/components/FormFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import Box from '@mui/material/Box'
import Button from '@mui/material/Button'
import Divider from '@mui/material/Divider'
import Typography from '@mui/material/Typography'
import { useApiUrl, useCustomMutation, useOne } from '@refinedev/core'
import {
useApiUrl,
useCustomMutation,
useNotification,
useOne,
usePublish,
} from '@refinedev/core'
import type { IChangeEvent } from '@rjsf/core'
import { withTheme } from '@rjsf/core'
import { Theme } from '@rjsf/mui'
Expand All @@ -13,10 +19,12 @@ import {
TitleFieldProps,
} from '@rjsf/utils'
import validator from '@rjsf/validator-ajv8'
import { type FC, useState } from 'react'
import merge from 'lodash/merge'
import { type FC, useContext, useEffect, useState } from 'react'

import { useStartAction } from '../hooks/ActionHooks'
import { AppContext } from '../context/AppContext'
import type { IActionData, IFormValues } from '../types'
import { customizeUiSchema } from '../utils/helpers'

const Form = withTheme(Theme)

Expand All @@ -37,70 +45,97 @@ function TitleFieldTemplate<

export const FormFlow: FC<{ actionId: string }> = ({ actionId }) => {
const [actionRunning, setActionRunning] = useState(false)
const startAction = useStartAction()
const apiUrl = useApiUrl()
const publish = usePublish()
const { addAction } = useContext(AppContext)
const { mutateAsync } = useCustomMutation()
const { open } = useNotification()

const queryResult = useOne<IActionData>({
resource: 'actions',
id: actionId,
})
const { isFetching, data } = queryResult

const { isFetching } = queryResult

const jsonschema = queryResult?.data?.data?.jsonschema || {}

const uischema = queryResult?.data?.data?.uischema?.uiSchema || {}
// Fetch schema and customize uiSchema
const jsonschema = data?.data?.jsonschema
let uischema = { ...data?.data?.uischema?.uiSchema }

if (jsonschema) {
// @todo I actually don't know for the moment how to overcome error
// "no schema with key or ref" produced when schema is defined.
// Maybe it's because the server returns "2020-12" and default is "draft-07"
// @see https://ajv.js.org/json-schema.html
delete jsonschema.$schema
uischema = merge({}, uischema, customizeUiSchema(jsonschema))
}

const onSubmit = async (
{ formData }: IChangeEvent<IFormValues>
// e: FormEvent<IFormValues>,
) => {
if (!formData) {
return
useEffect(() => {
if (!jsonschema && !isFetching && open) {
open({
type: 'error',
message: 'Schema not found',
description: 'The action schema could not be retrieved.',
})
}
}, [jsonschema, isFetching, open])

setActionRunning(true)
const onSubmit = async ({ formData }: IChangeEvent<IFormValues>) => {
if (!formData) return

startAction(actionId)
setActionRunning(true)
publish?.({
channel: 'processes',
type: 'get-processes',
payload: { action: actionId },
date: new Date(),
})

await mutateAsync(
{
try {
const result = await mutateAsync({
url: `${apiUrl}/actions/${actionId}`,
method: 'post',
values: formData,
},
{
onError: () => {
console.log('error')
successNotification: {
message: 'Action successfully created.',
description: 'Success with no errors',
type: 'success',
},
onSuccess: (data) => {
console.log(data)
errorNotification: {
message: 'Error.',
description: 'Something went wrong',
type: 'error',
},
})

if (result && actionId) {
addAction({
id: actionId.toString(),
title: jsonschema?.title,
description: jsonschema?.description,
})
publish?.({
channel: 'process',
type: 'get-process',
payload: { action: result.data.id },
date: new Date(),
})
}
)
} catch (error) {
console.error('Error creating action:', error)
} finally {
setActionRunning(false)
}
}

return (
<>
{!isFetching && (
<Form
schema={jsonschema}
schema={jsonschema || {}}
uiSchema={uischema}
validator={validator}
onSubmit={onSubmit}
templates={{ TitleFieldTemplate }}
>
<Button variant="contained" type="submit" disabled={actionRunning}>
Form not working yet
Submit
</Button>
<Button type="button" href={`/actions/${actionId}/show`}>
Go to form
Expand Down
Loading

0 comments on commit 471b8ce

Please sign in to comment.