@journeyapps-labs/reactor-mod-data-browser 2.2.0 → 2.4.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 (138) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/@types/actions/schema-model/ViewSchemaModelAsJsonAction.d.ts +9 -0
  3. package/dist/@types/core/AbstractConnection.d.ts +2 -0
  4. package/dist/@types/core/SchemaModelDefinition.d.ts +4 -1
  5. package/dist/@types/core/SchemaModelObject.d.ts +15 -8
  6. package/dist/@types/core/query/AbstractQuery.d.ts +5 -10
  7. package/dist/@types/core/query/AbstractSerializableQuery.d.ts +11 -0
  8. package/dist/@types/core/query/Page.d.ts +2 -7
  9. package/dist/@types/core/query/query-changed/ChangedModelQuery.d.ts +15 -0
  10. package/dist/@types/core/query/query-simple/SimplePage.d.ts +12 -0
  11. package/dist/@types/core/query/{SimpleQuery.d.ts → query-simple/SimpleQuery.d.ts} +8 -8
  12. package/dist/@types/core/query/widgets/BelongsToDisplayWidget.d.ts +1 -3
  13. package/dist/@types/core/query/widgets/CellDisplayWidget.d.ts +1 -2
  14. package/dist/@types/core/query/widgets/ColumnDisplayWidget.d.ts +1 -0
  15. package/dist/@types/core/query/widgets/SmartBelongsToDisplayWidget.d.ts +10 -0
  16. package/dist/@types/core/query/widgets/SmartCellDisplayWidget.d.ts +7 -0
  17. package/dist/@types/core/query/widgets/SmartColumnWidget.d.ts +2 -1
  18. package/dist/@types/entities/QueryEntityDefinition.d.ts +3 -3
  19. package/dist/@types/forms/SchemaModelForm.d.ts +32 -1
  20. package/dist/@types/forms/TypeEngine.d.ts +31 -0
  21. package/dist/@types/forms/inputs/DirtyWrapperInput.d.ts +16 -0
  22. package/dist/@types/index.d.ts +3 -1
  23. package/dist/@types/panels/_shared/SharedModelPanelFactory.d.ts +22 -0
  24. package/dist/@types/panels/model/ModelPanelFactory.d.ts +4 -20
  25. package/dist/@types/panels/model-json/ModelJsonPanelFactory.d.ts +27 -0
  26. package/dist/@types/panels/model-json/ModelJsonPanelWidget.d.ts +6 -0
  27. package/dist/@types/panels/query/QueryPanelFactory.d.ts +2 -1
  28. package/dist/DataBrowserModule.js +6 -0
  29. package/dist/DataBrowserModule.js.map +1 -1
  30. package/dist/actions/schema-definitions/CreateModelAction.js +2 -1
  31. package/dist/actions/schema-definitions/CreateModelAction.js.map +1 -1
  32. package/dist/actions/schema-definitions/QuerySchemaModelAction.js +1 -1
  33. package/dist/actions/schema-definitions/QuerySchemaModelAction.js.map +1 -1
  34. package/dist/actions/schema-model/ViewSchemaModelAsJsonAction.js +46 -0
  35. package/dist/actions/schema-model/ViewSchemaModelAsJsonAction.js.map +1 -0
  36. package/dist/core/AbstractConnection.js +15 -0
  37. package/dist/core/AbstractConnection.js.map +1 -1
  38. package/dist/core/SchemaModelDefinition.js +52 -13
  39. package/dist/core/SchemaModelDefinition.js.map +1 -1
  40. package/dist/core/SchemaModelObject.js +90 -50
  41. package/dist/core/SchemaModelObject.js.map +1 -1
  42. package/dist/core/query/AbstractQuery.js +2 -8
  43. package/dist/core/query/AbstractQuery.js.map +1 -1
  44. package/dist/core/query/AbstractSerializableQuery.js +13 -0
  45. package/dist/core/query/AbstractSerializableQuery.js.map +1 -0
  46. package/dist/core/query/Page.js +6 -15
  47. package/dist/core/query/Page.js.map +1 -1
  48. package/dist/core/query/query-changed/ChangedModelQuery.js +31 -0
  49. package/dist/core/query/query-changed/ChangedModelQuery.js.map +1 -0
  50. package/dist/core/query/query-simple/SimplePage.js +18 -0
  51. package/dist/core/query/query-simple/SimplePage.js.map +1 -0
  52. package/dist/core/query/{SimpleQuery.js → query-simple/SimpleQuery.js} +26 -25
  53. package/dist/core/query/query-simple/SimpleQuery.js.map +1 -0
  54. package/dist/core/query/widgets/BelongsToDisplayWidget.js +5 -16
  55. package/dist/core/query/widgets/BelongsToDisplayWidget.js.map +1 -1
  56. package/dist/core/query/widgets/CellDisplayWidget.js +16 -76
  57. package/dist/core/query/widgets/CellDisplayWidget.js.map +1 -1
  58. package/dist/core/query/widgets/ColumnDisplayWidget.js +3 -3
  59. package/dist/core/query/widgets/ColumnDisplayWidget.js.map +1 -1
  60. package/dist/core/query/widgets/SmartBelongsToDisplayWidget.js +29 -0
  61. package/dist/core/query/widgets/SmartBelongsToDisplayWidget.js.map +1 -0
  62. package/dist/core/query/widgets/SmartCellDisplayWidget.js +20 -0
  63. package/dist/core/query/widgets/SmartCellDisplayWidget.js.map +1 -0
  64. package/dist/core/query/widgets/SmartColumnWidget.js +11 -1
  65. package/dist/core/query/widgets/SmartColumnWidget.js.map +1 -1
  66. package/dist/entities/ConnectionEntityDefinition.js +5 -0
  67. package/dist/entities/ConnectionEntityDefinition.js.map +1 -1
  68. package/dist/entities/QueryEntityDefinition.js +3 -3
  69. package/dist/entities/QueryEntityDefinition.js.map +1 -1
  70. package/dist/entities/SchemaModelDefinitionEntityDefinition.js +3 -1
  71. package/dist/entities/SchemaModelDefinitionEntityDefinition.js.map +1 -1
  72. package/dist/entities/SchemaModelObjectEntityDefinition.js +28 -8
  73. package/dist/entities/SchemaModelObjectEntityDefinition.js.map +1 -1
  74. package/dist/forms/SchemaModelForm.js +153 -74
  75. package/dist/forms/SchemaModelForm.js.map +1 -1
  76. package/dist/forms/TypeEngine.js +353 -0
  77. package/dist/forms/TypeEngine.js.map +1 -0
  78. package/dist/forms/inputs/DirtyWrapperInput.js +86 -0
  79. package/dist/forms/inputs/DirtyWrapperInput.js.map +1 -0
  80. package/dist/forms/inputs/LocationInput.js +13 -7
  81. package/dist/forms/inputs/LocationInput.js.map +1 -1
  82. package/dist/index.js +3 -1
  83. package/dist/index.js.map +1 -1
  84. package/dist/panels/_shared/SharedModelPanelFactory.js +77 -0
  85. package/dist/panels/_shared/SharedModelPanelFactory.js.map +1 -0
  86. package/dist/panels/model/ModelPanelFactory.js +7 -71
  87. package/dist/panels/model/ModelPanelFactory.js.map +1 -1
  88. package/dist/panels/model/ModelPanelWidget.js +21 -4
  89. package/dist/panels/model/ModelPanelWidget.js.map +1 -1
  90. package/dist/panels/model-json/ModelJsonPanelFactory.js +62 -0
  91. package/dist/panels/model-json/ModelJsonPanelFactory.js.map +1 -0
  92. package/dist/panels/model-json/ModelJsonPanelWidget.js +70 -0
  93. package/dist/panels/model-json/ModelJsonPanelWidget.js.map +1 -0
  94. package/dist/panels/query/QueryPanelFactory.js +4 -0
  95. package/dist/panels/query/QueryPanelFactory.js.map +1 -1
  96. package/dist/panels/query/TableControlsWidget.js +42 -9
  97. package/dist/panels/query/TableControlsWidget.js.map +1 -1
  98. package/dist/tsconfig.tsbuildinfo +1 -1
  99. package/dist-module/bundle.js +91 -41
  100. package/dist-module/bundle.js.map +1 -1
  101. package/package.json +13 -10
  102. package/src/DataBrowserModule.ts +6 -0
  103. package/src/actions/schema-definitions/CreateModelAction.ts +2 -1
  104. package/src/actions/schema-definitions/QuerySchemaModelAction.ts +1 -1
  105. package/src/actions/schema-model/ViewSchemaModelAsJsonAction.ts +33 -0
  106. package/src/core/AbstractConnection.ts +18 -1
  107. package/src/core/SchemaModelDefinition.ts +57 -14
  108. package/src/core/SchemaModelObject.ts +62 -46
  109. package/src/core/query/AbstractQuery.ts +10 -21
  110. package/src/core/query/AbstractSerializableQuery.ts +23 -0
  111. package/src/core/query/Page.ts +6 -21
  112. package/src/core/query/query-changed/ChangedModelQuery.ts +35 -0
  113. package/src/core/query/query-simple/SimplePage.ts +29 -0
  114. package/src/core/query/{SimpleQuery.tsx → query-simple/SimpleQuery.tsx} +41 -39
  115. package/src/core/query/widgets/BelongsToDisplayWidget.tsx +6 -19
  116. package/src/core/query/widgets/CellDisplayWidget.tsx +17 -97
  117. package/src/core/query/widgets/ColumnDisplayWidget.tsx +12 -3
  118. package/src/core/query/widgets/SmartBelongsToDisplayWidget.tsx +46 -0
  119. package/src/core/query/widgets/SmartCellDisplayWidget.tsx +29 -0
  120. package/src/core/query/widgets/SmartColumnWidget.tsx +18 -2
  121. package/src/entities/ConnectionEntityDefinition.tsx +5 -0
  122. package/src/entities/QueryEntityDefinition.ts +6 -6
  123. package/src/entities/SchemaModelDefinitionEntityDefinition.ts +4 -0
  124. package/src/entities/SchemaModelObjectEntityDefinition.ts +34 -8
  125. package/src/forms/SchemaModelForm.tsx +145 -96
  126. package/src/forms/TypeEngine.tsx +451 -0
  127. package/src/forms/inputs/DirtyWrapperInput.tsx +95 -0
  128. package/src/forms/inputs/LocationInput.tsx +14 -7
  129. package/src/index.ts +7 -1
  130. package/src/panels/_shared/SharedModelPanelFactory.tsx +54 -0
  131. package/src/panels/model/ModelPanelFactory.tsx +10 -49
  132. package/src/panels/model/ModelPanelWidget.tsx +45 -9
  133. package/src/panels/model-json/ModelJsonPanelFactory.tsx +61 -0
  134. package/src/panels/model-json/ModelJsonPanelWidget.tsx +92 -0
  135. package/src/panels/query/QueryPanelFactory.tsx +5 -0
  136. package/src/panels/query/TableControlsWidget.tsx +85 -17
  137. package/webpack.config.js +9 -2
  138. 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,122 +1,42 @@
1
- import {
2
- CheckboxWidget,
3
- ImageMedia,
4
- MetadataWidget,
5
- SmartDateDisplayWidget,
6
- styled
7
- } from '@journeyapps-labs/reactor-mod';
8
- import { Attachment, Day, Location, Variable } from '@journeyapps/db';
1
+ import { ioc, SmartDateDisplayWidget, styled } from '@journeyapps-labs/reactor-mod';
9
2
  import * as _ from 'lodash';
10
3
  import * as React from 'react';
11
4
  import { PageRow } from '../Page';
5
+ import { TypeEngine } from '../../../forms/TypeEngine';
12
6
 
13
7
  namespace S {
14
8
  export const Empty = styled.div`
15
9
  opacity: 0.2;
16
10
  `;
17
-
18
- export const Preview = styled.img`
19
- max-height: 40px;
20
- max-width: 40px;
21
- cursor: pointer;
22
- `;
23
-
24
- export const pill = styled.div`
25
- padding: 2px 4px;
26
- background: ${(p) => p.theme.table.pills};
27
- border-radius: 3px;
28
- font-size: 12px;
29
- `;
30
-
31
- export const Pills = styled.div`
32
- display: flex;
33
- column-gap: 2px;
34
- row-gap: 2px;
35
- `;
36
-
37
- export const Max = styled.div`
38
- max-width: 500px;
39
- white-space: pre;
40
- display: inline;
41
- overflow: hidden;
42
- text-overflow: ellipsis;
43
- `;
44
11
  }
45
12
 
46
13
  export interface CellDisplayWidgetProps {
47
14
  row: PageRow;
48
15
  cell: any;
49
- variable: Variable;
16
+ name: string;
50
17
  }
51
18
 
52
- const MAX_NUMBER_OF_ARR_ITEMS_TO_DISPLAY = 3;
53
-
54
19
  export const CellDisplayWidget: React.FC<CellDisplayWidgetProps> = (props) => {
55
- const { row, cell, variable } = props;
20
+ const { row, cell, name } = props;
56
21
  if (cell == null) {
57
22
  return <S.Empty>null</S.Empty>;
58
23
  }
59
- if (_.isString(cell)) {
60
- if (cell.trim() === '') {
61
- return <S.Empty>empty</S.Empty>;
62
- }
63
- return <S.Max>{cell}</S.Max>;
64
- }
65
- if (_.isNumber(cell)) {
66
- return cell;
67
- }
68
- if (_.isArray(cell)) {
69
- if (cell.length === 0) {
70
- return <S.Empty>empty array</S.Empty>;
71
- }
72
-
73
- let items = _.slice(cell, 0, MAX_NUMBER_OF_ARR_ITEMS_TO_DISPLAY);
74
24
 
75
- return (
76
- <S.Pills>
77
- {items.map((c) => {
78
- return <S.pill key={c}>{c}</S.pill>;
79
- })}
80
- {items.length !== cell.length ? '...' : null}
81
- </S.Pills>
82
- );
83
- }
84
- if (cell instanceof Date) {
25
+ if (name === 'updated_at') {
85
26
  return <SmartDateDisplayWidget date={cell} />;
86
27
  }
87
- if (cell instanceof Day) {
88
- return <SmartDateDisplayWidget date={cell.toDate()} />;
89
- }
90
- if (_.isBoolean(cell)) {
91
- return <CheckboxWidget checked={cell} onChange={() => {}} />;
92
- }
93
- if (cell instanceof Location) {
94
- return (
95
- <>
96
- <MetadataWidget label={'Lat'} value={`${cell.latitude}`} />
97
- <MetadataWidget label={'Long'} value={`${cell.longitude}`} />
98
- </>
99
- );
100
- }
101
- if (cell instanceof Attachment) {
102
- if (cell.uploaded()) {
103
- return (
104
- <S.Preview
105
- 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
- }}
114
- src={cell.urls['thumbnail']}
115
- />
116
- );
117
- }
118
- return <S.Empty>Not uploaded</S.Empty>;
28
+
29
+ let display = ioc.get(TypeEngine).getHandler(row.definition.definition.attributes[name].type)?.generateDisplay({
30
+ model: row.model,
31
+ value: cell,
32
+ label: row.definition.definition.attributes[name].label,
33
+ name,
34
+ type: row.definition.definition.attributes[name].type
35
+ });
36
+ if (display) {
37
+ return display;
119
38
  }
120
- console.log('unknown type', cell);
39
+
40
+ console.log('unknown type', cell, row.definition.definition.attributes[name].type);
121
41
  return null;
122
42
  };
@@ -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
  }
@@ -50,6 +50,11 @@ export class ConnectionEntityDefinition extends EntityDefinition<AbstractConnect
50
50
  descendantType: DataBrowserEntities.SCHEMA_MODEL_DEFINITION,
51
51
  generateOptions: (parent) => {
52
52
  return {
53
+ category: {
54
+ label: 'Models',
55
+ icon: 'cube',
56
+ openDefault: true
57
+ },
53
58
  descendants: parent.schema_models.items
54
59
  };
55
60
  }
@@ -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
  }
@@ -1,4 +1,5 @@
1
1
  import {
2
+ EntityActionHandlerComponent,
2
3
  EntityDefinition,
3
4
  EntityDescriberComponent,
4
5
  inject,
@@ -10,6 +11,7 @@ import { DataBrowserEntities } from '../entities';
10
11
  import { ConnectionStore } from '../stores/ConnectionStore';
11
12
  import { AbstractConnection } from '../core/AbstractConnection';
12
13
  import { SchemaModelDefinition } from '../core/SchemaModelDefinition';
14
+ import { QuerySchemaModelAction } from '../actions/schema-definitions/QuerySchemaModelAction';
13
15
 
14
16
  export interface SchemaModelDefinitionEntityDefinitionEncoded {
15
17
  connection_id: string;
@@ -68,6 +70,8 @@ export class SchemaModelDefinitionEntityDefinition extends EntityDefinition<Sche
68
70
  }
69
71
  })
70
72
  );
73
+
74
+ this.registerComponent(new EntityActionHandlerComponent(QuerySchemaModelAction.ID));
71
75
  }
72
76
 
73
77
  matchEntity(t: any): boolean {
@@ -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
  );