Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: visualize jobs (WIP) #9645

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8689306
feat: job visualization plugin
AlessioGr Dec 1, 2024
73c7036
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 1, 2024
0149a55
make it look pretty
AlessioGr Dec 1, 2024
33ddfec
display task errors nicely in task panel
AlessioGr Dec 1, 2024
9b9fea6
improve test tasks, fix lint
AlessioGr Dec 1, 2024
dbb2db9
fix light mode error display
AlessioGr Dec 1, 2024
c28ca5e
simplify selection handling, support multiple selections
AlessioGr Dec 2, 2024
0eadb5c
ensure input and output task data is displayed
AlessioGr Dec 2, 2024
25cfceb
improve node style
AlessioGr Dec 2, 2024
fe28238
use tabs for node panel
AlessioGr Dec 2, 2024
8026b6e
ensure tab index is reset to 0 when switching between nodes
AlessioGr Dec 2, 2024
aa944e3
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 2, 2024
8fc036d
use correct imports
AlessioGr Dec 2, 2024
6300f60
use CodeEditor for input and output
AlessioGr Dec 2, 2024
a417842
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 2, 2024
9a1f8e1
use correct code editor import
AlessioGr Dec 2, 2024
5680753
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 2, 2024
363f315
fix CI tests
AlessioGr Dec 2, 2024
9217d94
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 3, 2024
6302476
update pnpm-lock
AlessioGr Dec 3, 2024
9cc55dc
export importHandlerPath
AlessioGr Dec 3, 2024
4364ab5
export properly
AlessioGr Dec 3, 2024
3e78927
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 3, 2024
20ade34
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 5, 2024
417e3d2
ensure panel content has max height
AlessioGr Dec 5, 2024
78b94b1
remove useless console logs
AlessioGr Dec 5, 2024
bbdf4b1
memoize tabs, fix error when switching between tabs
AlessioGr Dec 5, 2024
b6681a9
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 5, 2024
68fed44
allow customizing min height of code editor
AlessioGr Dec 5, 2024
2a8fa30
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 5, 2024
a2cd308
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 9, 2024
85da7f2
upgrade dependencies
AlessioGr Dec 9, 2024
4044ffb
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 11, 2024
15a5791
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 11, 2024
5e04db9
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 11, 2024
9742de3
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 12, 2024
9067b37
undo diff
AlessioGr Dec 12, 2024
0332a8a
fix: do not crash visualize page if there are no logs
AlessioGr Dec 13, 2024
bde7f89
Merge remote-tracking branch 'origin/main' into feat/visualize-jobs
AlessioGr Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/plugin-visual-jobs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.env
dist
demo/uploads
build
.DS_Store
package-lock.json
12 changes: 12 additions & 0 deletions packages/plugin-visual-jobs/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.tmp
**/.git
**/.hg
**/.pnp.*
**/.svn
**/.yarn/**
**/build
**/dist/**
**/node_modules
**/temp
**/docs/**
tsconfig.json
24 changes: 24 additions & 0 deletions packages/plugin-visual-jobs/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"sourceMaps": true,
"jsc": {
"target": "esnext",
"parser": {
"syntax": "typescript",
"tsx": true,
"dts": true
},
"transform": {
"react": {
"runtime": "automatic",
"pragmaFrag": "React.Fragment",
"throwIfNamespace": true,
"development": false,
"useBuiltins": true
}
}
},
"module": {
"type": "es6"
}
}
1 change: 1 addition & 0 deletions packages/plugin-visual-jobs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Payload Visual Jobs Plugin
18 changes: 18 additions & 0 deletions packages/plugin-visual-jobs/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { rootEslintConfig, rootParserOptions } from '../../eslint.config.js'

/** @typedef {import('eslint').Linter.Config} Config */

/** @type {Config[]} */
export const index = [
...rootEslintConfig,
{
languageOptions: {
parserOptions: {
...rootParserOptions,
tsconfigRootDir: import.meta.dirname,
},
},
},
]

export default index
22 changes: 22 additions & 0 deletions packages/plugin-visual-jobs/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2018-2024 Payload CMS, Inc. <info@payloadcms.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
99 changes: 99 additions & 0 deletions packages/plugin-visual-jobs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"name": "@payloadcms/plugin-visual-jobs",
"version": "3.2.2",
"description": "Visual Jobs plugin for Payload",
"keywords": [
"payload",
"cms",
"plugin",
"typescript",
"react"
],
"repository": {
"type": "git",
"url": "https://github.com/payloadcms/payload.git",
"directory": "packages/plugin-visual-jobs"
},
"license": "MIT",
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
"maintainers": [
{
"name": "Payload",
"email": "info@payloadcms.com",
"url": "https://payloadcms.com"
}
],
"type": "module",
"exports": {
".": {
"import": "./src/index.ts",
"types": "./src/index.ts",
"default": "./src/index.ts"
},
"./client": {
"import": "./src/exports/client.ts",
"types": "./src/exports/client.ts",
"default": "./src/exports/client.ts"
},
"./rsc": {
"import": "./src/exports/rsc.ts",
"types": "./src/exports/rsc.ts",
"default": "./src/exports/rsc.ts"
}
},
"main": "./src/index.ts",
"types": "./src/index.ts",
"files": [
"dist"
],
"scripts": {
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
"build:types": "tsc --emitDeclarationOnly --outDir dist",
"clean": "rimraf {dist,*.tsbuildinfo}",
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepublishOnly": "pnpm clean && pnpm turbo build"
},
"dependencies": {
"@payloadcms/translations": "workspace:*",
"@payloadcms/ui": "workspace:*",
"@xyflow/react": "^12.3.6"
},
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"@payloadcms/next": "workspace:*",
"@types/react": "19.0.1",
"@types/react-dom": "19.0.1",
"payload": "workspace:*"
},
"peerDependencies": {
"payload": "workspace:*",
"react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
"react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020"
},
"publishConfig": {
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./client": {
"import": "./dist/exports/client.js",
"types": "./dist/exports/client.d.ts",
"default": "./dist/exports/client.js"
},
"./rsc": {
"import": "./dist/exports/rsc.js",
"types": "./dist/exports/rsc.d.ts",
"default": "./dist/exports/rsc.js"
}
},
"main": "./dist/index.js",
"registry": "https://registry.npmjs.org/",
"types": "./dist/index.d.ts"
},
"homepage:": "https://payloadcms.com"
}
1 change: 1 addition & 0 deletions packages/plugin-visual-jobs/src/exports/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use client'
1 change: 1 addition & 0 deletions packages/plugin-visual-jobs/src/exports/rsc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { JobsView } from '../ui/JobsView/index.js'
42 changes: 42 additions & 0 deletions packages/plugin-visual-jobs/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Config } from 'payload'

import type { VisualJobsPluginConfig } from './types.js'

export const visualJobsPlugin =
(pluginConfig: VisualJobsPluginConfig) =>
(config: Config): Config => {
return {
...config,
jobs: {
...config.jobs,

jobsCollectionOverrides: ({ defaultJobsCollection }) => {
return {
...defaultJobsCollection,

admin: {
...(defaultJobsCollection.admin || {}),
components: {
...(defaultJobsCollection.admin?.components || {}),
views: {
...(defaultJobsCollection.admin?.components?.views || {}),
edit: {
jobs: {
Component: '@payloadcms/plugin-visual-jobs/rsc#JobsView',
path: '/visualize',
tab: {
href: '/visualize',
label: 'Visualize',
},
},
},
},
},
hidden: false,
},
}
},
tasks: [...(config.jobs?.tasks || [])],
},
}
}
1 change: 1 addition & 0 deletions packages/plugin-visual-jobs/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type VisualJobsPluginConfig = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use client'
import { TabComponent, TabsProvider } from '@payloadcms/ui'
import React, { useEffect, useState } from 'react'

export type PanelTab = {
Content: React.ReactNode
name: string
}
const baseClass = 'tabs-field'

type Props = {
tabs: PanelTab[]
}
export const Tabs: React.FC<Props> = (props) => {
const { tabs } = props
const [activeTabIndex, setActiveTabIndex] = useState<number>(0)

useEffect(() => {
setActiveTabIndex(0)
}, [tabs])

return (
<TabsProvider>
<div className={`${baseClass}__tabs-wrap`}>
<div className={`${baseClass}__tabs`}>
{tabs.map((tab, tabIndex) => {
return (
<TabComponent
isActive={activeTabIndex === tabIndex}
key={tabIndex}
parentPath={''}
setIsActive={() => {
setActiveTabIndex(tabIndex)
}}
tab={{ name: tab.name, fields: [] }}
/>
)
})}
</div>
</div>
<div className={`${baseClass}__content-wrap`}>{tabs[activeTabIndex]?.Content}</div>
</TabsProvider>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
@import '~@payloadcms/ui/scss';

.nodePanel {
display: flex;
flex-direction: column;
padding: base(1);
border: 1px solid var(--theme-elevation-100);
background: var(--theme-input-bg);
width: 400px;

.tabs-field__tabs::before {
content: none;
}

.tabs-field__content-wrap {
padding-left: 0;
padding-right: 0;
max-height: 800px;
overflow-y: auto;
}

.task-details {
display: flex;
flex-direction: column;
gap: 8px;

.detail-row {
display: flex;
align-items: flex-start;

.label {
min-width: 100px;
font-weight: 600;
}

.value {
flex: 1;

&.state {
text-transform: capitalize;
font-weight: 600;

&.succeeded {
color: #2ecc71;
}

&.failed {
color: #e74c3c;
}

&.running {
color: #3498db;
}
}
}
}
}

.error-container {
margin-top: 12px;
padding: 12px;
background: var(--theme-error-300);
color: var(--theme-elevation-1000);
border: 1px solid var(--theme-error-100);
border-radius: 6px;
max-width: 400px;

.error-type {
font-weight: 600;
}

.stack-trace {
margin-top: 8px;

.stack-header {
font-weight: 600;
margin-bottom: 4px;
}

.stack-content {
background: var(--theme-error-200);
border: 1px solid var(--theme-error-400);
border-radius: 4px;
padding: 8px;
font-family: monospace;
font-size: 12px;
max-height: 200px;
overflow-y: auto;

.stack-line {
padding: 2px 0;
white-space: pre-wrap;
word-break: break-all;
}
}
}
}
}
Loading
Loading