@journeyapps-labs/reactor-mod-data-browser 2.2.0 → 2.3.0

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.
Files changed (112) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/@types/core/AbstractConnection.d.ts +2 -0
  3. package/dist/@types/core/SchemaModelDefinition.d.ts +4 -1
  4. package/dist/@types/core/SchemaModelObject.d.ts +15 -8
  5. package/dist/@types/core/query/AbstractQuery.d.ts +5 -10
  6. package/dist/@types/core/query/AbstractSerializableQuery.d.ts +11 -0
  7. package/dist/@types/core/query/Page.d.ts +2 -7
  8. package/dist/@types/core/query/query-changed/ChangedModelQuery.d.ts +15 -0
  9. package/dist/@types/core/query/query-simple/SimplePage.d.ts +12 -0
  10. package/dist/@types/core/query/{SimpleQuery.d.ts → query-simple/SimpleQuery.d.ts} +8 -8
  11. package/dist/@types/core/query/widgets/BelongsToDisplayWidget.d.ts +1 -3
  12. package/dist/@types/core/query/widgets/CellDisplayWidget.d.ts +1 -2
  13. package/dist/@types/core/query/widgets/ColumnDisplayWidget.d.ts +1 -0
  14. package/dist/@types/core/query/widgets/SmartBelongsToDisplayWidget.d.ts +10 -0
  15. package/dist/@types/core/query/widgets/SmartCellDisplayWidget.d.ts +7 -0
  16. package/dist/@types/core/query/widgets/SmartColumnWidget.d.ts +2 -1
  17. package/dist/@types/entities/QueryEntityDefinition.d.ts +3 -3
  18. package/dist/@types/forms/SchemaModelForm.d.ts +32 -1
  19. package/dist/@types/forms/TypeEngine.d.ts +20 -0
  20. package/dist/@types/forms/inputs/DirtyWrapperInput.d.ts +15 -0
  21. package/dist/@types/index.d.ts +1 -1
  22. package/dist/@types/panels/model/ModelPanelFactory.d.ts +2 -2
  23. package/dist/@types/panels/query/QueryPanelFactory.d.ts +2 -1
  24. package/dist/DataBrowserModule.js +2 -0
  25. package/dist/DataBrowserModule.js.map +1 -1
  26. package/dist/actions/schema-definitions/CreateModelAction.js +2 -1
  27. package/dist/actions/schema-definitions/CreateModelAction.js.map +1 -1
  28. package/dist/actions/schema-definitions/QuerySchemaModelAction.js +1 -1
  29. package/dist/actions/schema-definitions/QuerySchemaModelAction.js.map +1 -1
  30. package/dist/core/AbstractConnection.js +15 -0
  31. package/dist/core/AbstractConnection.js.map +1 -1
  32. package/dist/core/SchemaModelDefinition.js +52 -13
  33. package/dist/core/SchemaModelDefinition.js.map +1 -1
  34. package/dist/core/SchemaModelObject.js +90 -50
  35. package/dist/core/SchemaModelObject.js.map +1 -1
  36. package/dist/core/query/AbstractQuery.js +2 -8
  37. package/dist/core/query/AbstractQuery.js.map +1 -1
  38. package/dist/core/query/AbstractSerializableQuery.js +13 -0
  39. package/dist/core/query/AbstractSerializableQuery.js.map +1 -0
  40. package/dist/core/query/Page.js +6 -15
  41. package/dist/core/query/Page.js.map +1 -1
  42. package/dist/core/query/query-changed/ChangedModelQuery.js +31 -0
  43. package/dist/core/query/query-changed/ChangedModelQuery.js.map +1 -0
  44. package/dist/core/query/query-simple/SimplePage.js +18 -0
  45. package/dist/core/query/query-simple/SimplePage.js.map +1 -0
  46. package/dist/core/query/{SimpleQuery.js → query-simple/SimpleQuery.js} +26 -25
  47. package/dist/core/query/query-simple/SimpleQuery.js.map +1 -0
  48. package/dist/core/query/widgets/BelongsToDisplayWidget.js +5 -16
  49. package/dist/core/query/widgets/BelongsToDisplayWidget.js.map +1 -1
  50. package/dist/core/query/widgets/CellDisplayWidget.js +11 -4
  51. package/dist/core/query/widgets/CellDisplayWidget.js.map +1 -1
  52. package/dist/core/query/widgets/ColumnDisplayWidget.js +3 -3
  53. package/dist/core/query/widgets/ColumnDisplayWidget.js.map +1 -1
  54. package/dist/core/query/widgets/SmartBelongsToDisplayWidget.js +29 -0
  55. package/dist/core/query/widgets/SmartBelongsToDisplayWidget.js.map +1 -0
  56. package/dist/core/query/widgets/SmartCellDisplayWidget.js +20 -0
  57. package/dist/core/query/widgets/SmartCellDisplayWidget.js.map +1 -0
  58. package/dist/core/query/widgets/SmartColumnWidget.js +11 -1
  59. package/dist/core/query/widgets/SmartColumnWidget.js.map +1 -1
  60. package/dist/entities/QueryEntityDefinition.js +3 -3
  61. package/dist/entities/QueryEntityDefinition.js.map +1 -1
  62. package/dist/entities/SchemaModelObjectEntityDefinition.js +28 -8
  63. package/dist/entities/SchemaModelObjectEntityDefinition.js.map +1 -1
  64. package/dist/forms/SchemaModelForm.js +153 -74
  65. package/dist/forms/SchemaModelForm.js.map +1 -1
  66. package/dist/forms/TypeEngine.js +135 -0
  67. package/dist/forms/TypeEngine.js.map +1 -0
  68. package/dist/forms/inputs/DirtyWrapperInput.js +72 -0
  69. package/dist/forms/inputs/DirtyWrapperInput.js.map +1 -0
  70. package/dist/index.js +1 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/panels/model/ModelPanelFactory.js +11 -7
  73. package/dist/panels/model/ModelPanelFactory.js.map +1 -1
  74. package/dist/panels/model/ModelPanelWidget.js +21 -4
  75. package/dist/panels/model/ModelPanelWidget.js.map +1 -1
  76. package/dist/panels/query/QueryPanelFactory.js +4 -0
  77. package/dist/panels/query/QueryPanelFactory.js.map +1 -1
  78. package/dist/panels/query/TableControlsWidget.js +42 -9
  79. package/dist/panels/query/TableControlsWidget.js.map +1 -1
  80. package/dist/tsconfig.tsbuildinfo +1 -1
  81. package/dist-module/bundle.js +64 -35
  82. package/dist-module/bundle.js.map +1 -1
  83. package/package.json +8 -6
  84. package/src/DataBrowserModule.ts +2 -0
  85. package/src/actions/schema-definitions/CreateModelAction.ts +2 -1
  86. package/src/actions/schema-definitions/QuerySchemaModelAction.ts +1 -1
  87. package/src/core/AbstractConnection.ts +18 -1
  88. package/src/core/SchemaModelDefinition.ts +57 -14
  89. package/src/core/SchemaModelObject.ts +62 -46
  90. package/src/core/query/AbstractQuery.ts +10 -21
  91. package/src/core/query/AbstractSerializableQuery.ts +23 -0
  92. package/src/core/query/Page.ts +6 -21
  93. package/src/core/query/query-changed/ChangedModelQuery.ts +35 -0
  94. package/src/core/query/query-simple/SimplePage.ts +29 -0
  95. package/src/core/query/{SimpleQuery.tsx → query-simple/SimpleQuery.tsx} +41 -39
  96. package/src/core/query/widgets/BelongsToDisplayWidget.tsx +6 -19
  97. package/src/core/query/widgets/CellDisplayWidget.tsx +24 -13
  98. package/src/core/query/widgets/ColumnDisplayWidget.tsx +12 -3
  99. package/src/core/query/widgets/SmartBelongsToDisplayWidget.tsx +46 -0
  100. package/src/core/query/widgets/SmartCellDisplayWidget.tsx +29 -0
  101. package/src/core/query/widgets/SmartColumnWidget.tsx +18 -2
  102. package/src/entities/QueryEntityDefinition.ts +6 -6
  103. package/src/entities/SchemaModelObjectEntityDefinition.ts +34 -8
  104. package/src/forms/SchemaModelForm.tsx +145 -96
  105. package/src/forms/TypeEngine.ts +160 -0
  106. package/src/forms/inputs/DirtyWrapperInput.tsx +75 -0
  107. package/src/index.ts +1 -1
  108. package/src/panels/model/ModelPanelFactory.tsx +11 -9
  109. package/src/panels/model/ModelPanelWidget.tsx +45 -9
  110. package/src/panels/query/QueryPanelFactory.tsx +5 -0
  111. package/src/panels/query/TableControlsWidget.tsx +85 -17
  112. package/dist/core/query/SimpleQuery.js.map +0 -1
@@ -1,18 +1,19 @@
1
- import { AbstractQuery, AbstractQueryEncoded } from './AbstractQuery';
2
- import { ActionSource, inject, TableColumn } from '@journeyapps-labs/reactor-mod';
3
- import { ConnectionStore } from '../../stores/ConnectionStore';
4
- import * as db from '@journeyapps/db';
5
- import { Promise, Type, Variable } from '@journeyapps/db';
6
- import { Page, PageRow } from './Page';
7
- import { SchemaModelDefinition } from '../SchemaModelDefinition';
1
+ import { inject, TableColumn } from '@journeyapps-labs/reactor-mod';
2
+ import { ConnectionStore } from '../../../stores/ConnectionStore';
3
+ import { Promise, Variable } from '@journeyapps/db';
4
+ import { Page, PageRow } from '../Page';
5
+ import { SchemaModelDefinition } from '../../SchemaModelDefinition';
8
6
  import * as _ from 'lodash';
9
7
  import * as React from 'react';
10
8
  import { action, observable } from 'mobx';
11
- import { CellDisplayWidget } from './widgets/CellDisplayWidget';
12
- import { BelongsToDisplayWidget } from './widgets/BelongsToDisplayWidget';
13
- import { EditSchemaModelAction } from '../../actions/schema-model/EditSchemaModelAction';
14
- import { SmartColumnWidget } from './widgets/SmartColumnWidget';
15
- import { AbstractFilter, SimpleFilter } from './filters';
9
+ import { CellDisplayWidget } from '../widgets/CellDisplayWidget';
10
+ import { SmartColumnWidget } from '../widgets/SmartColumnWidget';
11
+ import { SimpleFilter } from '../filters';
12
+ import { SmartCellDisplayWidget } from '../widgets/SmartCellDisplayWidget';
13
+ import { SchemaModelObject } from '../../SchemaModelObject';
14
+ import { SimplePage } from './SimplePage';
15
+ import { AbstractQueryEncoded, AbstractSerializableQuery } from '../AbstractSerializableQuery';
16
+ import { SmartBelongsToDisplayWidget } from '../widgets/SmartBelongsToDisplayWidget';
16
17
 
17
18
  export interface SimpleQueryOptions {
18
19
  definition?: SchemaModelDefinition;
@@ -24,7 +25,7 @@ export interface SimpleQueryEncoded extends AbstractQueryEncoded {
24
25
  definition: string;
25
26
  }
26
27
 
27
- export class SimpleQuery extends AbstractQuery<SimpleQueryEncoded> {
28
+ export class SimpleQuery extends AbstractSerializableQuery<SimpleQueryEncoded> {
28
29
  @inject(ConnectionStore)
29
30
  accessor connStore: ConnectionStore;
30
31
 
@@ -43,30 +44,22 @@ export class SimpleQuery extends AbstractQuery<SimpleQueryEncoded> {
43
44
  this.simple_filters = new Map();
44
45
  }
45
46
 
46
- async getCollection() {
47
- let connection = await this.connection.getConnection();
48
- return connection[this.options.definition.definition.name] as db.Collection;
49
- }
50
-
51
47
  @action async load() {
52
48
  this._pages = [];
53
- let collection = await this.getCollection();
54
-
49
+ let collection = await this.options.definition.getCollection();
55
50
  let query = collection.all();
56
51
  this.simple_filters.forEach((f) => {
57
52
  query = f.augment(query);
58
53
  });
59
-
60
54
  let results = await (collection.adapter as any).doApiQuery(query);
61
55
  this._totalPages = Math.ceil(results.total / this.options.limit);
62
56
  }
63
57
 
64
58
  getPage(number: number): Page {
65
59
  if (!this._pages[number]) {
66
- let page = new Page({
60
+ let page = new SimplePage({
67
61
  offset: number * this.options.limit,
68
62
  limit: this.options.limit,
69
- collection: () => this.getCollection(),
70
63
  definition: this.options.definition,
71
64
  index: number,
72
65
  filters: Array.from(this.simple_filters.values())
@@ -103,31 +96,33 @@ export class SimpleQuery extends AbstractQuery<SimpleQueryEncoded> {
103
96
  noWrap: true,
104
97
  shrink: true
105
98
  },
99
+ {
100
+ key: 'updated_at',
101
+ display: 'Updated at',
102
+ noWrap: true,
103
+ shrink: true,
104
+ accessor: (cell, row: PageRow) => {
105
+ return <CellDisplayWidget name="updated_at" cell={row.model.updated_at} row={row} />;
106
+ }
107
+ },
106
108
  ..._.map(this.options.definition.definition.belongsToIdVars, (a) => {
107
109
  return {
108
110
  key: a.name,
109
- display: a.name,
111
+ display: (
112
+ <SmartColumnWidget
113
+ variable={this.options.definition.definition.belongsToVars[a.relationship]}
114
+ type={this.options.definition.definition.belongsTo[a.relationship].foreignType}
115
+ filterChanged={(filter) => {}}
116
+ />
117
+ ),
110
118
  noWrap: true,
111
119
  shrink: true,
112
120
  accessor: (cell, row: PageRow) => {
113
- return (
114
- <BelongsToDisplayWidget
115
- open={(object) => {
116
- EditSchemaModelAction.get().fireAction({
117
- source: ActionSource.BUTTON,
118
- targetEntity: object
119
- });
120
- }}
121
- relationship={row.model.definition.definition.belongsTo[a.relationship]}
122
- connection={this.connection}
123
- id={row.model.model[a.name]}
124
- />
125
- );
121
+ return <SmartBelongsToDisplayWidget variable_id={a} row={row} connection={this.connection} />;
126
122
  }
127
123
  } as TableColumn;
128
124
  }),
129
125
  ..._.map(this.options.definition.definition.attributes, (a) => {
130
- // @ts-ignore FIXME, remove when `display` supports JSX.Element as a type
131
126
  return {
132
127
  key: a.name,
133
128
  display: (
@@ -148,7 +143,7 @@ export class SimpleQuery extends AbstractQuery<SimpleQueryEncoded> {
148
143
  noWrap: true,
149
144
  shrink: true,
150
145
  accessor: (cell, row: PageRow) => {
151
- return <CellDisplayWidget variable={a} cell={cell} row={row} />;
146
+ return <SmartCellDisplayWidget name={a.name} row={row} />;
152
147
  }
153
148
  } as TableColumn;
154
149
  })
@@ -158,4 +153,11 @@ export class SimpleQuery extends AbstractQuery<SimpleQueryEncoded> {
158
153
  getSimpleName(): string {
159
154
  return `Query: ${this.options.definition.definition.label}`;
160
155
  }
156
+
157
+ getDirtyObjects(): SchemaModelObject[] {
158
+ return _.flatMap(
159
+ this._pages.filter((p) => !!p),
160
+ (page) => page.getDirtyObjects()
161
+ );
162
+ }
161
163
  }
@@ -5,15 +5,17 @@ import { AbstractConnection } from '../../AbstractConnection';
5
5
  import { IconWidget, styled, TableButtonWidget } from '@journeyapps-labs/reactor-mod';
6
6
  import { copyTextToClipboard } from '@journeyapps-labs/lib-reactor-utils';
7
7
  import { Relationship } from '@journeyapps/parser-schema';
8
+ import { observer } from 'mobx-react';
8
9
 
9
10
  export interface BelongsToDisplayWidgetProps {
10
11
  relationship: Relationship;
11
12
  id: string;
12
13
  connection: AbstractConnection;
13
14
  open: (object: SchemaModelObject) => any;
15
+ className?: any;
14
16
  }
15
17
 
16
- export const BelongsToDisplayWidget: React.FC<BelongsToDisplayWidgetProps> = (props) => {
18
+ export const BelongsToDisplayWidget: React.FC<BelongsToDisplayWidgetProps> = observer((props) => {
17
19
  const [object, setObject] = useState<SchemaModelObject>(null);
18
20
  const [broken, setBroken] = useState(false);
19
21
 
@@ -55,8 +57,8 @@ export const BelongsToDisplayWidget: React.FC<BelongsToDisplayWidgetProps> = (pr
55
57
  }
56
58
 
57
59
  return (
58
- <S.Container>
59
- <BelongsToStringWidget model={object} />
60
+ <S.Container className={props.className}>
61
+ {object.data.display}
60
62
  <TableButtonWidget
61
63
  icon="arrow-right"
62
64
  action={() => {
@@ -65,22 +67,7 @@ export const BelongsToDisplayWidget: React.FC<BelongsToDisplayWidgetProps> = (pr
65
67
  />
66
68
  </S.Container>
67
69
  );
68
- };
69
-
70
- export const BelongsToStringWidget: React.FC<{ model: SchemaModelObject }> = ({ model }) => {
71
- const [display, setDisplay] = useState<string>();
72
- useEffect(() => {
73
- model.displayValue().then((value) => {
74
- setDisplay(value);
75
- });
76
- }, []);
77
-
78
- if (!display) {
79
- return <S.Spinner spin={true} icon="spinner" />;
80
- }
81
-
82
- return <span>{display}</span>;
83
- };
70
+ });
84
71
 
85
72
  namespace S {
86
73
  export const Warning = styled(TableButtonWidget)`
@@ -1,14 +1,16 @@
1
1
  import {
2
2
  CheckboxWidget,
3
3
  ImageMedia,
4
+ ioc,
4
5
  MetadataWidget,
5
6
  SmartDateDisplayWidget,
6
7
  styled
7
8
  } from '@journeyapps-labs/reactor-mod';
8
- import { Attachment, Day, Location, Variable } from '@journeyapps/db';
9
+ import { Attachment, Day, Location } from '@journeyapps/db';
9
10
  import * as _ from 'lodash';
10
11
  import * as React from 'react';
11
12
  import { PageRow } from '../Page';
13
+ import { TypeEngine } from '../../../forms/TypeEngine';
12
14
 
13
15
  namespace S {
14
16
  export const Empty = styled.div`
@@ -46,13 +48,13 @@ namespace S {
46
48
  export interface CellDisplayWidgetProps {
47
49
  row: PageRow;
48
50
  cell: any;
49
- variable: Variable;
51
+ name: string;
50
52
  }
51
53
 
52
54
  const MAX_NUMBER_OF_ARR_ITEMS_TO_DISPLAY = 3;
53
55
 
54
56
  export const CellDisplayWidget: React.FC<CellDisplayWidgetProps> = (props) => {
55
- const { row, cell, variable } = props;
57
+ const { row, cell, name } = props;
56
58
  if (cell == null) {
57
59
  return <S.Empty>null</S.Empty>;
58
60
  }
@@ -69,9 +71,7 @@ export const CellDisplayWidget: React.FC<CellDisplayWidgetProps> = (props) => {
69
71
  if (cell.length === 0) {
70
72
  return <S.Empty>empty array</S.Empty>;
71
73
  }
72
-
73
74
  let items = _.slice(cell, 0, MAX_NUMBER_OF_ARR_ITEMS_TO_DISPLAY);
74
-
75
75
  return (
76
76
  <S.Pills>
77
77
  {items.map((c) => {
@@ -88,7 +88,14 @@ export const CellDisplayWidget: React.FC<CellDisplayWidgetProps> = (props) => {
88
88
  return <SmartDateDisplayWidget date={cell.toDate()} />;
89
89
  }
90
90
  if (_.isBoolean(cell)) {
91
- return <CheckboxWidget checked={cell} onChange={() => {}} />;
91
+ return (
92
+ <CheckboxWidget
93
+ checked={cell}
94
+ onChange={(checked) => {
95
+ row.model.set(name, checked);
96
+ }}
97
+ />
98
+ );
92
99
  }
93
100
  if (cell instanceof Location) {
94
101
  return (
@@ -103,13 +110,17 @@ export const CellDisplayWidget: React.FC<CellDisplayWidgetProps> = (props) => {
103
110
  return (
104
111
  <S.Preview
105
112
  onClick={() => {
106
- row.model.getMedia(variable.name).then((media) => {
107
- if (media instanceof ImageMedia) {
108
- media.open();
109
- } else {
110
- window.open(cell.url(), '_blank');
111
- }
112
- });
113
+ ioc
114
+ .get(TypeEngine)
115
+ .getHandler(row.definition.definition.attributes[name].type)
116
+ .decode(cell)
117
+ .then((media: ImageMedia) => {
118
+ if (media instanceof ImageMedia) {
119
+ media.open();
120
+ } else {
121
+ window.open(cell.url(), '_blank');
122
+ }
123
+ });
113
124
  }}
114
125
  src={cell.urls['thumbnail']}
115
126
  />
@@ -3,17 +3,26 @@ import styled from '@emotion/styled';
3
3
 
4
4
  export interface ColumnDisplayWidgetProps {
5
5
  label: string;
6
+ className?: any;
6
7
  }
7
8
 
8
9
  export const ColumnDisplayWidget: React.FC<ColumnDisplayWidgetProps> = (props) => {
9
10
  let parts = (props.label || '').split(' ');
10
11
  if (parts.length >= 5) {
11
- return <S.Width length={150}>{props.label}</S.Width>;
12
+ return (
13
+ <S.Width className={props.className} length={150}>
14
+ {props.label}
15
+ </S.Width>
16
+ );
12
17
  }
13
18
  if (parts.length >= 3) {
14
- return <S.Width length={80}>{props.label}</S.Width>;
19
+ return (
20
+ <S.Width className={props.className} length={80}>
21
+ {props.label}
22
+ </S.Width>
23
+ );
15
24
  }
16
- return <S.Span>{props.label}</S.Span>;
25
+ return <S.Span className={props.className}>{props.label}</S.Span>;
17
26
  };
18
27
 
19
28
  namespace S {
@@ -0,0 +1,46 @@
1
+ import * as React from 'react';
2
+ import { EditSchemaModelAction } from '../../../actions/schema-model/EditSchemaModelAction';
3
+ import { BelongsToDisplayWidget } from './BelongsToDisplayWidget';
4
+ import { PageRow } from '../Page';
5
+ import { ActionSource, styled } from '@journeyapps-labs/reactor-mod';
6
+ import { AbstractConnection } from '../../AbstractConnection';
7
+ import { Variable } from '@journeyapps/db';
8
+ import { observer } from 'mobx-react';
9
+
10
+ export interface SmartBelongsToDisplayWidgetProps {
11
+ row: PageRow;
12
+ connection: AbstractConnection;
13
+ variable_id: Variable;
14
+ }
15
+
16
+ export const SmartBelongsToDisplayWidget: React.FC<SmartBelongsToDisplayWidgetProps> = observer((props) => {
17
+ const { row, connection, variable_id } = props;
18
+
19
+ let dirty = false;
20
+ let value = row.model.model[variable_id.name];
21
+ if (row.model.patch.has(variable_id.relationship)) {
22
+ value = row.model.patch.get(variable_id.relationship)?.id;
23
+ dirty = true;
24
+ }
25
+
26
+ return (
27
+ <S.Container
28
+ dirty={dirty}
29
+ open={(object) => {
30
+ EditSchemaModelAction.get().fireAction({
31
+ source: ActionSource.BUTTON,
32
+ targetEntity: object
33
+ });
34
+ }}
35
+ relationship={row.model.definition.definition.belongsTo[variable_id.relationship]}
36
+ connection={connection}
37
+ id={value}
38
+ />
39
+ );
40
+ });
41
+ namespace S {
42
+ export const Container = styled(BelongsToDisplayWidget)<{ dirty: boolean }>`
43
+ border-left: solid 4px ${(p) => (p.dirty ? p.theme.status.success : 'transparent')};
44
+ padding-left: 2px;
45
+ `;
46
+ }
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+ import { observer } from 'mobx-react';
3
+ import { PageRow } from '../Page';
4
+ import { CellDisplayWidget } from './CellDisplayWidget';
5
+ import { styled } from '@journeyapps-labs/reactor-mod';
6
+
7
+ export interface SmartCellDisplayWidgetProps {
8
+ row: PageRow;
9
+ name: string;
10
+ }
11
+
12
+ export const SmartCellDisplayWidget: React.FC<SmartCellDisplayWidgetProps> = observer((props) => {
13
+ let value = props.row.model.model[props.name];
14
+ if (props.row.model.patch.has(props.name)) {
15
+ value = props.row.model.patch.get(props.name);
16
+ }
17
+
18
+ return (
19
+ <S.Container dirty={props.row.model.patch.has(props.name)}>
20
+ <CellDisplayWidget {...props} cell={value} />
21
+ </S.Container>
22
+ );
23
+ });
24
+ namespace S {
25
+ export const Container = styled.div<{ dirty: boolean }>`
26
+ border-left: solid 4px ${(p) => (p.dirty ? p.theme.status.success : 'transparent')};
27
+ padding-left: 2px;
28
+ `;
29
+ }
@@ -1,20 +1,30 @@
1
1
  import * as React from 'react';
2
2
  import styled from '@emotion/styled';
3
- import { Variable } from '@journeyapps/db';
3
+ import { ObjectType, Type, Variable } from '@journeyapps/db';
4
4
  import { ColumnDisplayWidget } from './ColumnDisplayWidget';
5
5
  import { SmartFilterWidget } from './SmartFilterWidget';
6
6
  import { SimpleFilter } from '../filters';
7
7
 
8
8
  export interface SmartColumnWidgetProps {
9
9
  variable: Variable;
10
+ type?: ObjectType;
10
11
  filter?: SimpleFilter;
11
12
  filterChanged: (filter: SimpleFilter | null) => any;
12
13
  }
13
14
 
14
15
  export const SmartColumnWidget: React.FC<SmartColumnWidgetProps> = (props) => {
16
+ let display = <ColumnDisplayWidget label={props.variable.label || props.variable.name} />;
17
+ if (props.type) {
18
+ display = (
19
+ <S.TypeGroup>
20
+ {display}
21
+ <S.Type label={props.type.label} />
22
+ </S.TypeGroup>
23
+ );
24
+ }
15
25
  return (
16
26
  <S.Container>
17
- <ColumnDisplayWidget label={props.variable.label} />
27
+ {display}
18
28
  <SmartFilterWidget filter={props.filter} variable={props.variable} filterChanged={props.filterChanged} />
19
29
  </S.Container>
20
30
  );
@@ -27,4 +37,10 @@ namespace S {
27
37
  align-items: center;
28
38
  column-gap: 5px;
29
39
  `;
40
+
41
+ export const Type = styled(ColumnDisplayWidget)`
42
+ opacity: 0.5;
43
+ `;
44
+
45
+ export const TypeGroup = styled.div``;
30
46
  }
@@ -1,10 +1,10 @@
1
1
  import { EntityDefinition, inject, InlineEntityEncoderComponent } from '@journeyapps-labs/reactor-mod';
2
2
  import { DataBrowserEntities } from '../entities';
3
3
  import { ConnectionStore } from '../stores/ConnectionStore';
4
- import { AbstractQuery, AbstractQueryEncoded } from '../core/query/AbstractQuery';
5
- import { SimpleQuery } from '../core/query/SimpleQuery';
4
+ import { SimpleQuery } from '../core/query/query-simple/SimpleQuery';
5
+ import { AbstractQueryEncoded, AbstractSerializableQuery } from '../core/query/AbstractSerializableQuery';
6
6
 
7
- export class QueryEntityDefinition extends EntityDefinition<AbstractQuery> {
7
+ export class QueryEntityDefinition extends EntityDefinition<AbstractSerializableQuery> {
8
8
  @inject(ConnectionStore)
9
9
  accessor connectionStore: ConnectionStore;
10
10
 
@@ -18,7 +18,7 @@ export class QueryEntityDefinition extends EntityDefinition<AbstractQuery> {
18
18
  });
19
19
 
20
20
  this.registerComponent(
21
- new InlineEntityEncoderComponent<AbstractQuery, AbstractQueryEncoded>({
21
+ new InlineEntityEncoderComponent<AbstractSerializableQuery, AbstractQueryEncoded>({
22
22
  version: 1,
23
23
  encode: (e) => {
24
24
  return e.serialize();
@@ -35,12 +35,12 @@ export class QueryEntityDefinition extends EntityDefinition<AbstractQuery> {
35
35
  }
36
36
 
37
37
  matchEntity(t: any): boolean {
38
- if (t instanceof AbstractQuery) {
38
+ if (t instanceof AbstractSerializableQuery) {
39
39
  return true;
40
40
  }
41
41
  }
42
42
 
43
- getEntityUID(t: AbstractQuery) {
43
+ getEntityUID(t: AbstractSerializableQuery) {
44
44
  return t.id;
45
45
  }
46
46
  }
@@ -3,11 +3,13 @@ import {
3
3
  EntityDescriberComponent,
4
4
  inject,
5
5
  InlineEntityEncoderComponent,
6
- InlineTreePresenterComponent
6
+ InlineTreePresenterComponent,
7
+ SimpleParentEntitySearchEngine
7
8
  } from '@journeyapps-labs/reactor-mod';
8
9
  import { DataBrowserEntities } from '../entities';
9
10
  import { ConnectionStore } from '../stores/ConnectionStore';
10
11
  import { SchemaModelObject } from '../core/SchemaModelObject';
12
+ import { SchemaModelDefinition } from '../core/SchemaModelDefinition';
11
13
 
12
14
  export interface SchemaModelObjectEntityDefinitionEncoded {
13
15
  connection_id: string;
@@ -33,13 +35,42 @@ export class SchemaModelObjectEntityDefinition extends EntityDefinition<SchemaMo
33
35
  label: 'Simple',
34
36
  describe: (entity: SchemaModelObject) => {
35
37
  return {
36
- simpleName: entity.model.id,
38
+ simpleName: entity.data.display,
37
39
  complexName: entity.definition.definition.label
38
40
  };
39
41
  }
40
42
  })
41
43
  );
42
44
 
45
+ // this.registerComponent(
46
+ // new SimpleParentEntitySearchEngine<SchemaModelDefinition,SchemaModelObject>({
47
+ // label: 'ID',
48
+ // filterResultsWithMatcher: false,
49
+ // type: DataBrowserEntities.SCHEMA_MODEL_DEFINITION,
50
+ // getEntities: async (event) => {
51
+ // let object = await event.parameters.parent.resolve(event.value);
52
+ // if(object){
53
+ // return [object]
54
+ // }
55
+ // return []
56
+ // }
57
+ // })
58
+ // );
59
+
60
+ this.registerComponent(
61
+ new SimpleParentEntitySearchEngine<SchemaModelDefinition, SchemaModelObject>({
62
+ label: 'Label',
63
+ type: DataBrowserEntities.SCHEMA_MODEL_DEFINITION,
64
+ filterResultsWithMatcher: false,
65
+ getEntities: async (event) => {
66
+ if (!event.value) {
67
+ return [];
68
+ }
69
+ return await event.parameters.parent.search(event.value);
70
+ }
71
+ })
72
+ );
73
+
43
74
  this.registerComponent(
44
75
  new InlineEntityEncoderComponent<SchemaModelObject, SchemaModelObjectEntityDefinitionEncoded>({
45
76
  version: 1,
@@ -53,12 +84,7 @@ export class SchemaModelObjectEntityDefinition extends EntityDefinition<SchemaMo
53
84
  decode: async (entity) => {
54
85
  let connection = await this.connectionStore.waitForReadyForConnection(entity.connection_id);
55
86
  let definition = await connection.waitForSchemaModelDefinitionByName(entity.type);
56
- let db = await definition.getCollection();
57
- let model = await db.first(entity.id);
58
- return new SchemaModelObject({
59
- model,
60
- definition
61
- });
87
+ return await definition.resolve(entity.id);
62
88
  }
63
89
  })
64
90
  );