ywana-core8 0.0.471 → 0.0.474

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.471",
3
+ "version": "0.0.474",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -25,6 +25,7 @@ export const FORMATS = {
25
25
  TOKENS: 'TOKENS'
26
26
  }
27
27
 
28
+
28
29
  /**
29
30
  * CHECK
30
31
  */
@@ -45,10 +45,9 @@ export const TabbedTablePage = (props) => {
45
45
  }, [])
46
46
 
47
47
  useEffect( async () => {
48
- console.log("TAB", tab)
49
48
  if (tab) {
50
49
  const filter = { [tab.field]: tab.value }
51
- await pageContext.load(filter, false)
50
+ await pageContext.load(filter, [])
52
51
  setPageContext(Object.assign({}, pageContext))
53
52
  }
54
53
  }, [tab])
@@ -102,7 +101,6 @@ export const TabbedTablePage = (props) => {
102
101
  }
103
102
 
104
103
  async function save() {
105
- console.log('saving.....')
106
104
  await pageContext.update(form)
107
105
  setPageContext(Object.assign({}, pageContext))
108
106
  }
@@ -153,7 +151,6 @@ export const TabbedTablePage = (props) => {
153
151
 
154
152
  function renderTabs() {
155
153
  const selected = tab ? tab.value : null
156
- console.log(selected)
157
154
  return (
158
155
  <Tabs selected={selected} onChange={changeTab}>
159
156
  {tabs.map(tab => <Tab id={tab.value} label={tab.label} />)}
@@ -173,9 +170,6 @@ export const TabbedTablePage = (props) => {
173
170
  </MenuIcon>
174
171
  ) : null}
175
172
  {renderActions()}
176
-
177
- {renderTabs()}
178
-
179
173
  </Header>
180
174
  {canQuery || canFilter ? (
181
175
  <menu className="table-page">
@@ -184,7 +178,7 @@ export const TabbedTablePage = (props) => {
184
178
  </menu>
185
179
  ) : null}
186
180
  <main key={id} className="table-page">
187
- <TableEditor icon={icon} title={name} schema={schema} delay={delay} editable={editable} groupBy={groupBy} filter={tableFilter} actions={tableActions} canDelete={canDelete} />
181
+ <TableEditor icon={icon} title={name} tabs={renderTabs()} schema={schema} delay={delay} editable={editable} groupBy={groupBy} filter={tableFilter} actions={tableActions} canDelete={canDelete} />
188
182
  {children ? <article>{children}</article> : null}
189
183
  </main>
190
184
  {renderAside()}
@@ -329,6 +323,14 @@ const TableFilters = (props) => {
329
323
  return filterSchema
330
324
  }, [schema])
331
325
 
326
+ const likes = useMemo(() => {
327
+ const fields = Object.values(schema)
328
+ return fields.reduce((likes, field) => {
329
+ if (field.like === true) likes.push(field.id)
330
+ return likes
331
+ }, [])
332
+ }, [schema])
333
+
332
334
  useEffect(() => {
333
335
  if (filters) setForm(filters)
334
336
  }, [filters])
@@ -342,7 +344,7 @@ const TableFilters = (props) => {
342
344
  }
343
345
 
344
346
  async function reload() {
345
- await pageContext.load(form)
347
+ await pageContext.load(form, likes)
346
348
  setPageContext(Object.assign({}, pageContext))
347
349
  }
348
350
 
@@ -378,7 +380,7 @@ export const TableEditor = (props) => {
378
380
  const site = useContext(SiteContext)
379
381
  const [pageContext, setPageContext] = useContext(PageContext)
380
382
  const { all = [], filters } = pageContext
381
- const { icon, title, schema, editable, canDelete, filter, actions } = props
383
+ const { icon, title, schema, editable, canDelete, filter, actions, tabs } = props
382
384
  const [groupBy, setGroupBy] = useState(props.groupBy)
383
385
 
384
386
  function changeGroup(id, value) {
@@ -505,6 +507,7 @@ export const TableEditor = (props) => {
505
507
  <Fragment>
506
508
  <Header icon={icon} title={<Text>{title}</Text>}>
507
509
  <DropDown id="groupBy" label="Agrupar Por" value={groupBy} options={buildGroupOptions(schema)} onChange={changeGroup} />
510
+ {tabs}
508
511
  </Header>
509
512
  <main className="table-editor">
510
513
  {renderGroups()}
@@ -529,7 +532,7 @@ const TableContext = (url, field, host, urlQuery) => {
529
532
  queries: [],
530
533
  tab: null,
531
534
 
532
- async load(filter, like) {
535
+ async load(filter, like = []) {
533
536
  try {
534
537
  const filters = filter ? Object.keys(filter).reduce((filters, key) => {
535
538
  const field = filter[key];
@@ -583,7 +586,7 @@ const TableContext = (url, field, host, urlQuery) => {
583
586
  async create(form) {
584
587
  try {
585
588
  await API.create(form);
586
- await this.load({}, false);
589
+ await this.load({}, []);
587
590
  } catch (error) {
588
591
  console.log(error)
589
592
  }
@@ -652,7 +655,7 @@ const TableAPI = (url, host) => {
652
655
  const http = HTTPClient(host || window.API || process.env.REACT_APP_API, Session);
653
656
 
654
657
  return {
655
- all(filters, like = true) {
658
+ all(filters, like = []) {
656
659
  let queryParams = "?"
657
660
  if (filters) {
658
661
  const filterQuery = Object.keys(filters).reduce((query, key) => {
@@ -666,7 +669,7 @@ const TableAPI = (url, host) => {
666
669
  }, "")
667
670
  return query.concat(param)
668
671
  } else {
669
- return like ? query.concat(`${key}=%${filters[key]}%&`) : query.concat(`${key}=${filters[key]}&`)
672
+ return like.includes(key) ? query.concat(`${key}=%${filters[key]}%&`) : query.concat(`${key}=${filters[key]}&`)
670
673
  }
671
674
  }, "")
672
675
  queryParams = queryParams.concat(filterQuery)
@@ -115,19 +115,19 @@ const Page2 = (props) => {
115
115
  const Page3 = (props) => {
116
116
 
117
117
  const schema = {
118
- name : { id: "name" , type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: false, column: true , filter: true , label: "Name" },
119
- state : { id: "state" , type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: true , column: true , filter: false, label: "State" , options: [
118
+ name : { id: "name" , type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: false, column: true , filter: true , like: true, label: "Name" },
119
+ state : { id: "state" , type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: true , column: true , filter: false , label: "State" , options: [
120
120
  { label: "Pendiente", value: "NOT_CLASSIFIED" },
121
121
  { label: "Clasificada", value: "CLASSIFIED"},
122
122
  ]},
123
- field1: { id: "field1", type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: false, column: true , filter: true , label: "field1" },
124
- field2: { id: "field2", type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: false, column: true , filter: true , label: "field2" },
125
- field4: { id: "field4", type: TYPES.STRING, format: FORMATS.COLOR, required: true, tab: false, column: true , filter: true , label: "Color" },
123
+ field1: { id: "field1", type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: false, column: true , filter: true , label: "field1" },
124
+ field2: { id: "field2", type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: false, column: true , filter: true , label: "field2" },
125
+ field4: { id: "field4", type: TYPES.STRING, format: FORMATS.COLOR, required: true, tab: false, column: true , filter: true , label: "Color" },
126
126
  }
127
127
 
128
128
  return (
129
129
  <Fragment>
130
- <TabbedTablePage title="Referencias" schema={schema} host="http://localhost:3000" url="/references"/>
130
+ <TabbedTablePage title="Referencias" schema={schema} host="http://localhost:3000" url="/references" canFilter={true} />
131
131
  </Fragment>
132
132
  )
133
133
  }