ywana-core8 0.0.34 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.34",
3
+ "version": "0.0.38",
4
4
  "description": "ywana-core8",
5
5
  "author": "Ernesto Roldan Garcia",
6
6
  "license": "MIT",
@@ -3,7 +3,6 @@
3
3
  }
4
4
 
5
5
  .content-editor>section {
6
-
7
6
  margin-bottom: 1rem;
8
7
  }
9
8
 
@@ -90,14 +89,12 @@
90
89
  background-color: var(--paper-color) !important;
91
90
  }
92
91
 
93
-
94
92
  .collection-adder td.actions {
95
93
  border: solid 0px red;
96
94
  display: flex;
97
95
  align-items: center;
98
96
  }
99
97
 
100
-
101
98
  .field-editor {
102
99
  padding: 0;
103
100
  }
@@ -31,9 +31,10 @@ export const CreateContentDialog = ({ label, type, value = {}, filter, validator
31
31
  site.closeDialog();
32
32
  }
33
33
 
34
- function createFilter(field, content) {
35
- return field.required === true || field.optional === true
36
- // TODO: execute props.filter
34
+ function filterForm(field, content) {
35
+ console.log('------ filterForm------------', field.id, filter)
36
+ const visible = field.required === true || field.optional === true
37
+ return filter ? visible && filter(field, content) : visible
37
38
  }
38
39
 
39
40
  const actions = (
@@ -48,7 +49,7 @@ export const CreateContentDialog = ({ label, type, value = {}, filter, validator
48
49
  const content = new Content(type, form)
49
50
  return (
50
51
  <Dialog title={title} open={true} onAction={onAction} actions={actions}>
51
- <ContentEditor content={content} onChange={change} filter={createFilter} />
52
+ <ContentEditor content={content} onChange={change} filter={filterForm} />
52
53
  {errors.map(error => <Text use="overline" tag="div" className="error">{error}</Text>)}
53
54
  </Dialog>
54
55
  )
@@ -31,6 +31,11 @@ export const EditContentDialog = ({ label, type, value = {}, filter, validator,
31
31
  site.closeDialog();
32
32
  }
33
33
 
34
+ function filterForm(field, content) {
35
+ const visible = field.required === true || field.optional === true
36
+ return filter ? visible && filter(field, content) : visible
37
+ }
38
+
34
39
  const actions = (
35
40
  <Fragment>
36
41
  <Button label="CLOSE" action={() => onAction("CLOSE")} />
@@ -43,7 +48,7 @@ export const EditContentDialog = ({ label, type, value = {}, filter, validator,
43
48
  const content = new Content(type, form)
44
49
  return (
45
50
  <Dialog title={title} open={true} onAction={onAction} actions={actions}>
46
- <ContentEditor content={content} onChange={change} filter={filter} />
51
+ <ContentEditor content={content} onChange={change} filter={filterForm} />
47
52
  {errors.map(error => <Text use="overline" tag="div" className="error">{error}</Text>)}
48
53
  </Dialog>
49
54
  )
@@ -1,11 +1,11 @@
1
1
  import equal from 'deep-equal'
2
2
  import React, { Fragment, useContext, useEffect, useMemo, useRef, useState } from 'react'
3
- import { EditContentDialog } from './EditContentDialog'
4
- import { Content } from './ContentType'
5
- import { ContentEditor } from './ContentEditor'
6
- import { HTTPClient, Session } from '../http'
7
- import { SiteContext, PageContext } from '../site'
8
3
  import { Button, DataTable, DropDown, Header, Icon, MenuIcon, MenuItem, Text } from '../html'
4
+ import { HTTPClient, Session } from '../http'
5
+ import { PageContext, SiteContext } from '../site'
6
+ import { ContentEditor } from './ContentEditor'
7
+ import { Content } from './ContentType'
8
+ import { CreateContentDialog } from './CreateContentDialog'
9
9
  import "./TablePage.css"
10
10
 
11
11
  const http = HTTPClient(window.API || process.env.REACT_APP_API, Session);
@@ -16,7 +16,7 @@ const http = HTTPClient(window.API || process.env.REACT_APP_API, Session);
16
16
  export const TablePage = (props) => {
17
17
 
18
18
  const site = useContext(SiteContext)
19
- const { id = "table", icon, title, name = "table 1", schema, url, field, delay = 1000, actions, editable, canAdd = true, dev = false, autosave = true, groupBy, validator, scenario } = props
19
+ const { id = "table", icon, title, name = "table 1", schema, url, field, delay = 1000, actions, editable, canAdd = true, dev = false, autosave = true, groupBy, validator, scenario, formFilter } = props
20
20
  const [pageContext, setPageContext] = useContext(PageContext)
21
21
  const { selected } = pageContext
22
22
  const timer = useRef(null)
@@ -46,7 +46,8 @@ export const TablePage = (props) => {
46
46
  await pageContext.create(form);
47
47
  setPageContext(Object.assign({}, pageContext))
48
48
  }
49
- site.openDialog(<EditContentDialog label={`Crear ${name}`} type={schema} onOK={onOK} validator={validator} />);
49
+ //site.openDialog(<EditContentDialog label={`Crear ${name}`} type={schema} onOK={onOK} validator={validator} />);
50
+ site.openDialog(<CreateContentDialog label={`Crear ${name}`} type={schema} onOK={onOK} validator={validator} filter={formFilter}/>);
50
51
  }
51
52
 
52
53
  function change(next) {
@@ -59,4 +59,22 @@ const UploadIcon = ({ resumable }) => {
59
59
  <Icon icon="folder_open" clickable/>
60
60
  </div>
61
61
  )
62
+ }
63
+
64
+ /**
65
+ * Upload Button
66
+ */
67
+ export function UploadButton({ resumable, icon="file_upload", label="Upload"}) {
68
+
69
+ const buttonElement = useRef();
70
+
71
+ useEffect(() => {
72
+ if (resumable && buttonElement) resumable.assignBrowse(buttonElement.current);
73
+ }, []);
74
+
75
+ return (
76
+ <div className="upload-button" ref={buttonElement}>
77
+ <Button icon={icon} label={label} outlined/>
78
+ </div>
79
+ )
62
80
  }
@@ -1,6 +1,7 @@
1
1
  .uploader {
2
2
  display: flex;
3
3
  flex-direction: column;
4
+ flex: 1;
4
5
  }
5
6
 
6
7
  .demo-uploader {
@@ -1,68 +1,85 @@
1
1
  import React, { useState, useMemo } from 'react'
2
2
  import ResumableJS from 'resumablejs'
3
- import { UploadArea } from './UploadArea'
3
+ import { UploadArea } from "./UploadArea";
4
+ import { UploadFile } from "./UploadFile";
4
5
  import './uploader.css'
5
6
 
7
+ const STATES = {
8
+ IDLE: 0, RUNNING: 1, SUCCESS: 2, ERROR': 3, COMPLETED: 4 }
6
9
  /**
7
10
  * Uploader
8
11
  */
9
- export const Uploader = ({ label, target, accept, className, onSuccess, onError, onComplete, errors = [] }) => {
12
+ export const Uploader = ({ label, target, accept, simultaneousUploads = 1, className, onSuccess, onError, onComplete, errors = [] }) => {
10
13
 
11
- const STATES = { 'IDLE': 0, 'RUNNING': 1, 'SUCCESS': 2, 'ERROR': 3, 'COMPLETED': 4 }
12
14
 
13
- const resumable = useMemo(() => {
14
- const config = {
15
- target: target,
16
- chunkSize: 1 * 1024 * 1024,
17
- simultaneousUploads: 1,
18
- testChunks: false,
19
- throttleProgressCallbacks: 1,
20
- fileType: accept
21
- }
22
- const resumable = new ResumableJS(config)
23
- resumable.on('fileAdded', onFileAdded)
24
- resumable.on('fileProgress', onFileProgress)
25
- resumable.on('fileSuccess', onFileSuccess)
26
- resumable.on('fileError', onFileError)
27
- resumable.on('complete', onAllComplete)
28
- return resumable
29
- }, [])
15
+ const resumable = useMemo(() => {
16
+ const config = {
17
+ target: target,
18
+ chunkSize: 1 * 1024 * 1024,
19
+ simultaneousUploads,
20
+ testChunks: false,
21
+ throttleProgressCallbacks: 1,
22
+ fileType: accept
23
+ }
24
+ const resumable = new ResumableJS(config)
25
+ resumable.on('fileAdded', onFileAdded)
26
+ resumable.on('fileProgress', onFileProgress)
27
+ resumable.on('fileSuccess', onFileSuccess)
28
+ resumable.on('fileError', onFileError)
29
+ resumable.on('complete', onAllComplete)
30
+ return resumable
31
+ }, [])
30
32
 
31
- const [progress, setProgress] = useState(0)
32
- const [state, setState] = useState(STATES.IDLE)
33
- const [error, setError] = useState()
34
- const [files, setFiles] = useState([])
33
+ const [progress, setProgress] = useState(0)
34
+ const [state, setState] = useState(STATES.IDLE)
35
+ const [error, setError] = useState()
36
+ const [files, setFiles] = useState([])
35
37
 
36
- function onFileAdded(file) {
37
- files.push(file)
38
- setFiles(files)
39
- resumable.upload()
40
- }
38
+ function onFileAdded(file) {
39
+ files.push(file)
40
+ setFiles(files)
41
+ setState(STATES.RUNNING)
42
+ resumable.upload()
43
+ }
41
44
 
42
- function onFileProgress(file) {
43
- const progress = file.progress()
44
- setProgress(progress)
45
- }
45
+ function onFileProgress(file) {
46
+ const progress = file.progress()
47
+ setProgress(progress)
48
+ if (onProgress) onProgress(files);
49
+ }
46
50
 
47
- function onFileSuccess(file, message) {
48
- setState(STATES.SUCCESS)
49
- if (onSuccess) onSuccess(file, message)
50
- }
51
+ function onFileSuccess(file, message) {
52
+ setState(STATES.SUCCESS)
53
+ if (onSuccess) onSuccess(file, message)
54
+ }
51
55
 
52
- function onFileError(file, message) {
53
- setError(message)
54
- setState(STATES.ERROR)
55
- if (onError) onError(file, message)
56
- }
56
+ function onFileError(file, message) {
57
+ setError(message)
58
+ setState(STATES.ERROR)
59
+ if (onError) onError(file, message)
60
+ }
61
+
62
+ function onAllComplete() {
63
+ setState(STATES.IDLE)
64
+ if (onComplete) onComplete(files)
65
+ }
57
66
 
58
- function onAllComplete() {
59
- setState(STATES.IDLE)
60
- if (onComplete) onComplete(files)
67
+ return (
68
+ <div className={`uploader ${className}`}>
69
+ {state === STATES.IDLE ? <UploadArea resumable={resumable} state={state} label={label} error={error} progress={progress} /> : null}
70
+ {state === STATES.RUNNING || STATES.SUCCESS || STATES.ERROR ? <UploadProgress files={files} errors={errors} /> : null}
71
+ </div>
72
+ )
61
73
  }
62
74
 
63
- return (
64
- <div className={`uploader ${className}`}>
65
- <UploadArea resumable={resumable} state={state} label={label} error={error}/>
66
- </div>
67
- )
68
- }
75
+ const UploadProgress = ({ files = [], errors }) => {
76
+ return (
77
+ <div>
78
+ {files.map((file) => {
79
+ const error2 = errors.some((e) => e === file.fileName) ? "Fichero Mal Nombrado" : "";
80
+ const progress = 1
81
+ return <UploadFile file={file} state={STATES.RUNNING} progress={file.progress()} />;
82
+ })}
83
+ </div>
84
+ );
85
+ };