Skip to content

Commit 910cb7a

Browse files
Hassan AdamHassan Adam
authored andcommitted
feature: action wramework UI prototype
1 parent b3ece34 commit 910cb7a

File tree

6 files changed

+187
-1
lines changed

6 files changed

+187
-1
lines changed

apps/sensenet/src/components/context-menu/use-context-menu-actions.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,19 @@ export function useContextMenuActions(
196196
},
197197
})
198198
break
199+
/*Az az új hozzáállás, hogy ha nem találja meg az action-t akkor jöjjön be az operation kezelő.
200+
Ezt majd le kell!! cserélni úgy, hogy vizsgálva legyen a Type-ja*/
199201
default:
200-
logger.warning({ message: `${actionName} is not implemented yet. Try to use it from command palette.` })
202+
openDialog({
203+
name: 'operation',
204+
props: {
205+
content,
206+
OperationName: actionName,
207+
},
208+
dialogProps: { classes: { paper: globalClasses.pickerDialog } },
209+
})
210+
break
211+
// logger.warning({ message: `${actionName} is not implemented yet. Try to use it from command palette.` })
201212
}
202213
}
203214

apps/sensenet/src/components/dialogs/dialog-provider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
DateRangePickerProps,
1414
DeleteContentDialogProps,
1515
ExecuteActionDialogProps,
16+
OperationsDialogProps,
1617
PermissionEditorDialogProps,
1718
ReferenceContentListProps,
1819
RestoreProps,
@@ -24,6 +25,7 @@ export type DialogWithProps = (
2425
| { name: 'delete'; props: DeleteContentDialogProps }
2526
| { name: 'error'; props: ErrorBoundaryState }
2627
| { name: 'copy-move'; props: CopyMoveDialogProps }
28+
| { name: 'operation'; props: OperationsDialogProps }
2729
| { name: 'check-in'; props: CheckInProps }
2830
| { name: 'are-you-sure'; props: AreYouSureProps }
2931
| { name: 'approve'; props: ApproveProps }

apps/sensenet/src/components/dialogs/dialogs.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const ChangePasswordDialog = lazy(() => import('./change-password'))
2424
const DateRangePicker = lazy(() => import('./date-range-picker'))
2525
const AddDeleteUserGroups = lazy(() => import('./add-delete-user-groups'))
2626
const ColumnSettings = lazy(() => import('./column-settings'))
27+
const Operations = lazy(() => import('./operations'))
2728

2829
function dialogRenderer(dialog: DialogWithProps) {
2930
switch (dialog.name) {
@@ -69,6 +70,8 @@ function dialogRenderer(dialog: DialogWithProps) {
6970
return <DateRangePicker {...dialog.props} />
7071
case 'column-settings':
7172
return <ColumnSettings {...dialog.props} />
73+
case 'operation':
74+
return <Operations {...dialog.props} />
7275
default:
7376
return null
7477
}

apps/sensenet/src/components/dialogs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export * from './restore'
1919
export * from './save-query'
2020
export * from './add-delete-user-groups'
2121
export * from './column-settings'
22+
export * from './operations'
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
import { Button, createStyles, DialogActions, DialogContent, makeStyles, TextField } from '@material-ui/core'
2+
import { GenericContent } from '@sensenet/default-content-types'
3+
import { useLogger, useRepository } from '@sensenet/hooks-react'
4+
import React, { useEffect, useRef, useState } from 'react'
5+
import { useCurrentUser } from '../../context'
6+
import { useGlobalStyles } from '../../globalStyles'
7+
import { useLocalization } from '../../hooks'
8+
import { Icon } from '../Icon'
9+
import { DialogTitle, useDialog } from '.'
10+
11+
export interface OperationsDialogProps {
12+
content: GenericContent
13+
OperationName: string
14+
}
15+
/*Ezt itt jól ki kell dolgozni!!! nem végleges csak demora van egyszerűsítve
16+
Valószínüleg nem is itt lesz a végleges helye hanem ott ahol a GenericContent van
17+
*/
18+
type UIDescription = {
19+
title?: string
20+
submitTitle?: string
21+
elements: Array<{
22+
name?: string
23+
description?: string
24+
inputProps: React.HTMLProps<HTMLInputElement>
25+
}>
26+
}
27+
const useStyles = makeStyles(() =>
28+
createStyles({
29+
form: {
30+
display: 'flex',
31+
flexDirection: 'column',
32+
alignItems: 'center',
33+
rowGap: '30px',
34+
'& :is(h3,p)': {
35+
margin: '0 0',
36+
fontWeight: 'normal',
37+
},
38+
'& input': {
39+
padding: '0',
40+
},
41+
'& .input-container': {
42+
width: '300px',
43+
},
44+
},
45+
}),
46+
)
47+
48+
export function OperationsDialog(props: OperationsDialogProps) {
49+
const { closeLastDialog } = useDialog()
50+
const currentUser = useCurrentUser()
51+
const classes = useStyles()
52+
const logger = useLogger('Operations')
53+
const formRef = useRef<HTMLFormElement>(null)
54+
const repository = useRepository()
55+
const localization = useLocalization().operations
56+
const globalClasses = useGlobalStyles()
57+
58+
const [UIDescription, setUIDescription] = useState<UIDescription>()
59+
60+
useEffect(() => {
61+
console.log(props.OperationName)
62+
const loadOperation = async () => {
63+
try {
64+
const result = await repository.executeAction<any, UIDescription>({
65+
method: 'GET',
66+
idOrPath: props.content.Path,
67+
name: props.OperationName,
68+
})
69+
setUIDescription(result)
70+
} catch (error) {
71+
logger.error({ message: error.message })
72+
}
73+
}
74+
75+
loadOperation()
76+
}, [logger, props.OperationName, props.content.Path, repository])
77+
78+
const submitAction = async (e: React.FormEvent<HTMLFormElement>) => {
79+
e.preventDefault()
80+
if (!formRef.current) return
81+
82+
const formData = new FormData(formRef.current)
83+
const formJson: Record<string, any> = {}
84+
85+
formData.forEach((value, key) => {
86+
formJson[key] = value
87+
})
88+
89+
try {
90+
await repository.executeAction<any, UIDescription>({
91+
method: 'POST',
92+
idOrPath: props.content.Path,
93+
name: props.OperationName,
94+
body: formJson,
95+
})
96+
97+
closeLastDialog()
98+
} catch (error) {
99+
logger.error({ message: error.message })
100+
}
101+
}
102+
103+
return (
104+
<>
105+
<DialogTitle>
106+
<div className={globalClasses.centered}>
107+
<Icon
108+
style={{
109+
margin: '0 1em 0 0',
110+
transition: 'filter linear 1s, opacity linear 1.5s',
111+
}}
112+
item={currentUser}
113+
/>
114+
{UIDescription?.title || localization.title}
115+
</div>
116+
</DialogTitle>
117+
<>
118+
<DialogContent>
119+
<form
120+
ref={formRef}
121+
className={classes.form}
122+
id="operation-form"
123+
onSubmit={(e) => {
124+
submitAction(e)
125+
}}>
126+
{UIDescription?.elements.map((field, index) => {
127+
const { inputProps, description, name } = field
128+
129+
return (
130+
<div className="input-container" key={index}>
131+
<h3>{name}</h3>
132+
<p>{description}</p>
133+
134+
<TextField
135+
name={inputProps.name}
136+
required={Boolean(inputProps.required)}
137+
fullWidth
138+
inputProps={inputProps}
139+
/>
140+
</div>
141+
)
142+
})}
143+
</form>
144+
</DialogContent>
145+
<DialogActions>
146+
<Button aria-label={localization.cancel} className={globalClasses.cancelButton} onClick={closeLastDialog}>
147+
{localization.cancel}
148+
</Button>
149+
<Button
150+
aria-label={localization.submit}
151+
form="operation-form"
152+
color="primary"
153+
variant="contained"
154+
type="submit"
155+
autoFocus={true}>
156+
{UIDescription?.submitTitle || localization.submit}
157+
</Button>
158+
</DialogActions>
159+
</>
160+
</>
161+
)
162+
}
163+
164+
export default OperationsDialog

apps/sensenet/src/localization/default.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,11 @@ const values = {
685685
trash: 'Trash',
686686
'/Root/ContentTemplates': 'Content Templates',
687687
},
688+
operations: {
689+
title: 'Action Framkework Demo',
690+
submit: 'Upload',
691+
cancel: 'Cancel',
692+
},
688693
}
689694

690695
export default values

0 commit comments

Comments
 (0)