Skip to content

Commit 6eff288

Browse files
[NUI-202] Config import from cli context (#33)
2 parents 34c8238 + e62f95d commit 6eff288

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1302
-91
lines changed

frontend/docs/entities/connection/def/connection.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Nui connection that manages one or more underlying NATS servers connections
44

5-
```typescript
6-
75
```typescript
86
Connection {
97
id?: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## CLI IMPORT
2+
3+
Nui connection that manages one or more underlying NATS servers connections
4+
5+
```typescript
6+
CliImport
7+
{
8+
name: string
9+
path: string
10+
error: string
11+
importedContext: { [key: string]: any }
12+
}
13+
```
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
## IMPORT FROM CLI
3+
4+
### URL
5+
6+
```
7+
POST /api/connection/import/nats-cli
8+
```
9+
10+
11+
### BODY
12+
13+
```typescript
14+
{
15+
path: string
16+
}
17+
```
18+
19+
### RESPONSE
20+
21+
```typescript
22+
{
23+
connections: Connection[]
24+
imports: CliImport[]
25+
}
26+
connection
27+
```
28+
29+
[CONNECTION](./def/connection.md)
30+
31+
[CLI IMPORT](./def/nats-cli-import.md)

frontend/package-lock.json

+60-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@fontsource/darker-grotesque": "^5.0.8",
1919
"@monaco-editor/react": "^4.6.0",
2020
"@priolo/jon": "^0.7.7",
21-
"@priolo/jack": "0.1.9",
21+
"@priolo/jack": "^0.1.11",
2222
"cross-env": "^7.0.3",
2323
"dayjs": "^1.11.12",
2424
"monaco-editor": "^0.50.0",

frontend/src/api/connection.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
import ajax, { CallOptions } from "@/plugins/AjaxService"
2-
import { Connection } from "@/types/Connection"
2+
import { CliImport, Connection } from "@/types/Connection"
33

44

55
/** INDEX
6-
* Recupera tutte le CONNECTION
6+
* Get all the CONNECTIONs
77
*/
88
function index(opt?: CallOptions): Promise<Connection[]> {
99
return ajax.get(`connection`, null, opt)
1010
}
1111

1212
/** UPDATE
13-
* Modifica/crea un CONNECTION
13+
* Update a CONNECTION
1414
*/
1515
function save(cnn: Connection, opt?: CallOptions): Promise<Connection> {
1616
const blockId = cnn.id ? `/${cnn.id}` : ""
1717
return ajax.post(`connection${blockId}`, cnn, opt)
1818
}
1919

2020
/** DELETE
21-
* Rimuove un CONNECTION
21+
* delete a CONNECTION
2222
*/
2323
function remove(id: string, opt?: CallOptions): Promise<void> {
2424
if (!id) return
2525
return ajax.delete(`connection/${id}`, null, opt)
2626
}
2727

28-
const api = {
28+
function importFromNatsCli(path: string, opt?: CallOptions): Promise<{ connections: Connection[], imports: CliImport[]}> {
29+
return ajax.post(`connection/import/nats-cli`, {path: path}, opt)
30+
}
31+
32+
const connectionApi = {
2933
index,
3034
remove,
3135
save,
36+
importFromNatsCli,
3237
}
33-
export default api
38+
export default connectionApi

frontend/src/components/cards/CardIcon.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const CardIcon: FunctionComponent<Props> = ({
3636
return <ConnectionsIcon className={className} style={style} />
3737
case DOC_TYPE.CONNECTION:
3838
return <ConnectionIcon className={className} style={style} />
39+
case DOC_TYPE.CNN_LOADER:
40+
return <ConnectionIcon className={className} style={style} />
41+
3942
case DOC_TYPE.MESSAGES:
4043
return <MessagesIcon className={className} style={style} />
4144
case DOC_TYPE.MESSAGE:

frontend/src/components/cards/PolymorphicCard.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import StreamMessagesView from "../stacks/streams/messages/View"
3939
import SyncView from "../stacks/sync/View"
4040
import JsonConfigView from "../stacks/jsonconfig/View"
4141
import { JsonConfigStore } from "../../stores/stacks/jsonconfig"
42+
import { CnnImportStore } from "../../stores/stacks/cnnImport"
43+
import CnnLoaderView from "../stacks/cnnImport/View"
4244

4345

4446

@@ -57,6 +59,9 @@ const PolymorphicCard: FunctionComponent<DocCmpProps> = ({
5759
return <CnnListView store={view as CnnListStore} />
5860
case DOC_TYPE.CONNECTION:
5961
return <CnnDetailView store={view as CnnDetailStore} />
62+
case DOC_TYPE.CNN_LOADER:
63+
return <CnnLoaderView store={view as CnnImportStore} />
64+
6065
case DOC_TYPE.MESSAGES:
6166
return <MessagesView store={view as MessagesStore} />
6267
case DOC_TYPE.MESSAGE:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Button } from "@priolo/jack"
2+
import { useStore } from "@priolo/jon"
3+
import { FunctionComponent } from "react"
4+
import { CnnImportStore, IMPORT_STATUS } from "../../../stores/stacks/cnnImport"
5+
6+
7+
8+
interface Props {
9+
store?: CnnImportStore
10+
}
11+
12+
const ActionsCmp: FunctionComponent<Props> = ({
13+
store,
14+
}) => {
15+
16+
// STORE
17+
useStore(store)
18+
19+
// HOOKs
20+
21+
// HANDLER
22+
const handleImportClick = async () => {
23+
if (store.state.status == IMPORT_STATUS.LOADING ) return
24+
store.import()
25+
}
26+
27+
// RENDER
28+
if (store.state.status == IMPORT_STATUS.DONE) return null
29+
const clsRoot = store.state.status == IMPORT_STATUS.LOADING ? "jack-ani-loading" : ""
30+
const styRoot = store.state.status == IMPORT_STATUS.LOADING ? { color: "var(--cmp-select-fg)"} : null
31+
32+
return <>
33+
<Button
34+
className={clsRoot} style={styRoot}
35+
children="IMPORT"
36+
onClick={handleImportClick}
37+
/>
38+
</>
39+
}
40+
41+
export default ActionsCmp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.root {
2+
display: flex;
3+
flex-direction: column;
4+
}
5+
.header {
6+
display: flex;
7+
font-size: 12px;
8+
gap: 5px;
9+
}
10+
.header .key {
11+
font-weight: 600;
12+
}
13+
.header .row {
14+
flex: 1;
15+
display: flex;
16+
flex-direction: column;
17+
}
18+
.header .values {
19+
font-weight: 300;
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { FunctionComponent } from "react"
2+
import cls from "./HeadersCmp.module.css"
3+
import { CopyButton } from "@priolo/jack"
4+
5+
6+
7+
interface Props {
8+
headers?: { [key: string]: string[] }
9+
}
10+
11+
/** dettaglio di un messaggio */
12+
const HeadersCmp: FunctionComponent<Props> = ({
13+
headers,
14+
}) => {
15+
16+
// STORE
17+
18+
// HOOKs
19+
20+
// HANDLER
21+
22+
// RENDER
23+
// const headers: [string, string][] = useMemo(() => {
24+
// if (!msgSa.message.headers) return []
25+
// return Object
26+
// .entries(msgSa.message.headers)
27+
// .reduce<[string, string][]>((acc, [key, values]) => {
28+
// return acc.concat(values.map(v => [key, v]))
29+
// }, [])
30+
// }, [msgSa.message.headers])
31+
if ( !headers ) return null
32+
33+
return <div className={cls.root}>
34+
{Object.entries(headers).map(([key, values]) => <div className={cls.header}>
35+
<div className={cls.key}>{key}</div>
36+
<div>:</div>
37+
<div className={cls.row}>
38+
{values.map(value => <div className={`${cls.header} jack-hover-container`}>
39+
<div className={cls.values}>{value}</div>
40+
<CopyButton absolute value={value} />
41+
</div>)}
42+
</div>
43+
</div>)}
44+
</div>
45+
}
46+
47+
export default HeadersCmp
48+
49+

0 commit comments

Comments
 (0)