@blaze-cms/plugin-data-ui 0.133.0 → 0.134.0-project-admin-customisations.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 (123) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +42 -0
  3. package/lib/components/EntityDataListing/EntityDataListing.js +3 -24
  4. package/lib/components/EntityDataListing/EntityDataListing.js.map +1 -1
  5. package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +39 -0
  6. package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -0
  7. package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js +12 -0
  8. package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -0
  9. package/lib/components/EntityManager/Entity/Entity.js +32 -17
  10. package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
  11. package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +44 -0
  12. package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +1 -0
  13. package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +32 -0
  14. package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -0
  15. package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +45 -0
  16. package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -0
  17. package/lib/components/EntityManager/Entity/SideBarRelations/index.js +23 -7
  18. package/lib/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  19. package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +38 -0
  20. package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -0
  21. package/lib/components/InfoBoxes/InfoBoxes.js +36 -0
  22. package/lib/components/InfoBoxes/InfoBoxes.js.map +1 -0
  23. package/lib/components/InfoBoxes/container/InfoBoxContainer.js +44 -0
  24. package/lib/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  25. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  26. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  27. package/lib/components/InfoBoxes/hooks/useData.js +42 -0
  28. package/lib/components/InfoBoxes/hooks/useData.js.map +1 -0
  29. package/lib/components/InfoBoxes/hooks/useInfoBox.js +26 -0
  30. package/lib/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  31. package/lib/components/InfoBoxes/index.js +12 -0
  32. package/lib/components/InfoBoxes/index.js.map +1 -0
  33. package/lib/components/InfoBoxes/presentational/InfoBox.js +46 -0
  34. package/lib/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  35. package/lib/components/ListingTable/ListingTable.js +113 -80
  36. package/lib/components/ListingTable/ListingTable.js.map +1 -1
  37. package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js +8 -20
  38. package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
  39. package/lib/components/ListingTable/mappers/populate-rows.js +92 -26
  40. package/lib/components/ListingTable/mappers/populate-rows.js.map +1 -1
  41. package/lib/components/ListingTable/service/index.js +73 -11
  42. package/lib/components/ListingTable/service/index.js.map +1 -1
  43. package/lib/index.js +3 -11
  44. package/lib/index.js.map +1 -1
  45. package/lib/utils/add-content-menu-items.js +64 -13
  46. package/lib/utils/add-content-menu-items.js.map +1 -1
  47. package/lib/utils/build-listing-query.js +11 -2
  48. package/lib/utils/build-listing-query.js.map +1 -1
  49. package/lib/utils/get-default-query-params.js +3 -4
  50. package/lib/utils/get-default-query-params.js.map +1 -1
  51. package/lib-es/components/EntityDataListing/EntityDataListing.js +3 -14
  52. package/lib-es/components/EntityDataListing/EntityDataListing.js.map +1 -1
  53. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +30 -0
  54. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -0
  55. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js +3 -0
  56. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -0
  57. package/lib-es/components/EntityManager/Entity/Entity.js +32 -17
  58. package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
  59. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +30 -0
  60. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +1 -0
  61. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +26 -0
  62. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -0
  63. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +39 -0
  64. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -0
  65. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js +24 -8
  66. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  67. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +24 -0
  68. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -0
  69. package/lib-es/components/InfoBoxes/InfoBoxes.js +28 -0
  70. package/lib-es/components/InfoBoxes/InfoBoxes.js.map +1 -0
  71. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js +30 -0
  72. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  73. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  74. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  75. package/lib-es/components/InfoBoxes/hooks/useData.js +37 -0
  76. package/lib-es/components/InfoBoxes/hooks/useData.js.map +1 -0
  77. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js +19 -0
  78. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  79. package/lib-es/components/InfoBoxes/index.js +3 -0
  80. package/lib-es/components/InfoBoxes/index.js.map +1 -0
  81. package/lib-es/components/InfoBoxes/presentational/InfoBox.js +31 -0
  82. package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  83. package/lib-es/components/ListingTable/ListingTable.js +46 -49
  84. package/lib-es/components/ListingTable/ListingTable.js.map +1 -1
  85. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js +11 -19
  86. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
  87. package/lib-es/components/ListingTable/mappers/populate-rows.js +76 -24
  88. package/lib-es/components/ListingTable/mappers/populate-rows.js.map +1 -1
  89. package/lib-es/components/ListingTable/service/index.js +65 -7
  90. package/lib-es/components/ListingTable/service/index.js.map +1 -1
  91. package/lib-es/index.js +1 -9
  92. package/lib-es/index.js.map +1 -1
  93. package/lib-es/utils/add-content-menu-items.js +49 -5
  94. package/lib-es/utils/add-content-menu-items.js.map +1 -1
  95. package/lib-es/utils/build-listing-query.js +10 -1
  96. package/lib-es/utils/build-listing-query.js.map +1 -1
  97. package/lib-es/utils/get-default-query-params.js +1 -3
  98. package/lib-es/utils/get-default-query-params.js.map +1 -1
  99. package/package.json +10 -9
  100. package/src/components/EntityDataListing/EntityDataListing.js +3 -12
  101. package/src/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +26 -0
  102. package/src/components/EntityManager/Entity/EntitiyNavLinks/index.js +3 -0
  103. package/src/components/EntityManager/Entity/Entity.js +68 -57
  104. package/src/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +22 -0
  105. package/src/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +33 -0
  106. package/src/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +28 -0
  107. package/src/components/EntityManager/Entity/SideBarRelations/index.js +51 -19
  108. package/src/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +33 -0
  109. package/src/components/InfoBoxes/InfoBoxes.js +24 -0
  110. package/src/components/InfoBoxes/container/InfoBoxContainer.js +22 -0
  111. package/src/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  112. package/src/components/InfoBoxes/hooks/useData.js +20 -0
  113. package/src/components/InfoBoxes/hooks/useInfoBox.js +13 -0
  114. package/src/components/InfoBoxes/index.js +3 -0
  115. package/src/components/InfoBoxes/presentational/InfoBox.js +34 -0
  116. package/src/components/ListingTable/ListingTable.js +57 -38
  117. package/src/components/ListingTable/ListingTableContent/ListingTableContent.js +8 -22
  118. package/src/components/ListingTable/mappers/populate-rows.js +83 -18
  119. package/src/components/ListingTable/service/index.js +42 -5
  120. package/src/index.js +1 -8
  121. package/src/utils/add-content-menu-items.js +45 -3
  122. package/src/utils/build-listing-query.js +11 -1
  123. package/src/utils/get-default-query-params.js +1 -1
@@ -3,27 +3,27 @@ import React, { useEffect, useState, Fragment } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { withRouter, Link } from 'react-router-dom';
5
5
  import More from '@blaze-react/more';
6
- import { MainContext, useMainContext } from '@blaze-cms/admin-ui-utils';
7
6
  import { PageHeader, DeleteAction } from '@blaze-cms/admin';
8
7
  import { useToasts } from '@blaze-react/toaster';
8
+ import { RenderHook } from '@blaze-cms/plugin-render-hooks-ui';
9
9
  import ListingTableContent from './ListingTableContent';
10
10
  import availableActions from '../EntityManager/Entity/actions-handlers';
11
11
  import { fetchData } from './service';
12
- import { populateRows, formatRows } from './mappers/populate-rows';
12
+ import { populateRows, formatRows, getParsedRowData } from './mappers/populate-rows';
13
13
  import { getDefaultQueryParams } from '../../utils/get-default-query-params';
14
14
 
15
15
  const OVER_SCAN_BUFFER = 10;
16
16
 
17
- const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
17
+ const ListingTable = ({ match, entitySchema }) => {
18
18
  const [tableData, setTableData] = useState({});
19
19
  const [modalStatus, setModalStatus] = useState(false);
20
20
  const [itemToDelete, setItemToDelete] = useState({});
21
21
  const [previousSchema, setPreviousSchema] = useState({ id: null });
22
22
  const [scrollToIndex, setScrollToIndex] = useState(0);
23
23
  const [verifiedRanges, setVerifiedRanges] = useState([]);
24
- const queryParamsDefault = getDefaultQueryParams({ schema: entitySchema });
24
+ const queryParamsDefault = getDefaultQueryParams(entitySchema);
25
25
  const [queryParams, setQueryParams] = useState(queryParamsDefault);
26
- const { menuItems, setMenuItems } = useMainContext(MainContext);
26
+ const [listFilters, setListFilters] = useState([]);
27
27
  const client = useApolloClient();
28
28
  const { addToast } = useToasts();
29
29
 
@@ -34,20 +34,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
34
34
  entitySchema.id !== previousSchema.id ||
35
35
  (previousSchema.id === null && entitySchema.id)
36
36
  ) {
37
- const data = await fetchData({
38
- client,
39
- querySettings: {
40
- entitySchema,
41
- queryParams: queryParamsDefault
42
- }
43
- });
44
- const populatedTable = populateRows({
45
- toggleModal,
46
- url: match.url,
47
- entitySchema,
48
- rows: data
49
- });
50
- setTableData(populatedTable);
37
+ await doQuery();
51
38
  setPreviousSchema({ id: entitySchema.id });
52
39
  }
53
40
  })();
@@ -55,18 +42,33 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
55
42
  [client, entitySchema, match.url, previousSchema.id, queryParams] // eslint-disable-line react-hooks/exhaustive-deps
56
43
  );
57
44
 
58
- const onCloseCardPrompt = () => {
59
- const updatedSelectedMenuItem = {
60
- ...selectedMenuItem,
61
- isDisplayedPrompt: false
62
- };
63
- const [{ header, items }] = menuItems;
64
- const updatedItems = items.map(
65
- item => (item.name === selectedMenuItem.name ? updatedSelectedMenuItem : item)
66
- );
67
- setMenuItems([{ header, items: updatedItems }]);
45
+ const doQuery = async (filters = listFilters) => {
46
+ const data = await fetchData({
47
+ client,
48
+ querySettings: {
49
+ entitySchema,
50
+ queryParams: queryParamsDefault
51
+ },
52
+ listFilters: filters
53
+ });
54
+
55
+ const populatedTable = populateRows({
56
+ toggleModal,
57
+ url: match.url,
58
+ entitySchema,
59
+ rows: data
60
+ });
61
+
62
+ setTableData(populatedTable);
63
+ };
64
+
65
+ const updateListingFilters = async filters => {
66
+ await doQuery(filters);
67
+ setListFilters(filters);
68
68
  };
69
69
 
70
+ const onCloseCardPrompt = () => null;
71
+
70
72
  const toggleModal = item => {
71
73
  setModalStatus(!!item);
72
74
  setItemToDelete(item || {});
@@ -107,15 +109,22 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
107
109
  querySettings: {
108
110
  entitySchema,
109
111
  queryParams: sortQueryParams
110
- }
112
+ },
113
+ listFilters
111
114
  });
112
- const { columns } = tableData;
115
+ const { columns, isEnquiry } = tableData;
113
116
  const [firstColumn] = columns;
114
117
 
115
118
  setTableData({
116
119
  ...tableData,
117
120
  appliedSort: { [property]: direction },
118
- rows: formatRows({ rows: data, url: match.url, toggleModal, firstColumn })
121
+ rows: formatRows({
122
+ rows: getParsedRowData(data),
123
+ url: match.url,
124
+ toggleModal,
125
+ firstColumn,
126
+ isEnquiry
127
+ })
119
128
  });
120
129
  };
121
130
 
@@ -133,11 +142,17 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
133
142
  querySettings: {
134
143
  entitySchema,
135
144
  queryParams: updatedQueryParams
136
- }
145
+ },
146
+ listFilters
137
147
  });
138
148
  const updatedRows = [
139
149
  ...tableData.rows,
140
- ...formatRows({ rows: data, url: match.url, toggleModal })
150
+ ...formatRows({
151
+ rows: getParsedRowData(data),
152
+ url: match.url,
153
+ toggleModal,
154
+ isEnquiry: tableData.isEnquiry
155
+ })
141
156
  ];
142
157
 
143
158
  setVerifiedRanges([...verifiedRanges, loadIndex]);
@@ -151,6 +166,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
151
166
  };
152
167
 
153
168
  if (!tableData || !tableData.rows) return 'loading';
169
+ const showAddButton = !!tableData.rows.length && !tableData.isEnquiry;
154
170
 
155
171
  return (
156
172
  <div className="page">
@@ -162,7 +178,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
162
178
  />
163
179
  )}
164
180
  <PageHeader title={entitySchema.displayName} subtitle="">
165
- {(!selectedMenuItem.isDisplayedPrompt || !!tableData.rows.length) && (
181
+ {showAddButton && (
166
182
  <Fragment>
167
183
  <Link
168
184
  data-testid="addEntity"
@@ -181,13 +197,17 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
181
197
  </Fragment>
182
198
  )}
183
199
  </PageHeader>
200
+ <RenderHook
201
+ hookKey="entity:listing:main:top"
202
+ schema={entitySchema}
203
+ setListFilters={updateListingFilters}
204
+ />
184
205
  <ListingTableContent
185
206
  overScanBuffer={OVER_SCAN_BUFFER}
186
207
  onSort={handleSort}
187
208
  onRenderItems={handleRenderedItems}
188
209
  tableData={tableData}
189
210
  onCloseCardPrompt={onCloseCardPrompt}
190
- selectedMenuItem={selectedMenuItem}
191
211
  scrollToIndex={scrollToIndex}
192
212
  />
193
213
  </div>
@@ -195,8 +215,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
195
215
  };
196
216
  ListingTable.propTypes = {
197
217
  entitySchema: PropTypes.object.isRequired,
198
- match: PropTypes.object.isRequired,
199
- selectedMenuItem: PropTypes.object.isRequired
218
+ match: PropTypes.object.isRequired
200
219
  };
201
220
 
202
221
  export default withRouter(ListingTable);
@@ -1,15 +1,11 @@
1
1
  import React from 'react';
2
2
  import Table from '@blaze-react/table';
3
3
  import PropTypes from 'prop-types';
4
- import { CardPrompt } from '@blaze-cms/admin';
5
- import { Link, withRouter } from 'react-router-dom';
4
+ import { withRouter } from 'react-router-dom';
6
5
 
7
6
  const ListingTableContent = ({
8
7
  tableData,
9
8
  handleSelect,
10
- onCloseCardPrompt,
11
- selectedMenuItem,
12
- match,
13
9
  onSort,
14
10
  onClickRow,
15
11
  overScanBuffer,
@@ -17,12 +13,14 @@ const ListingTableContent = ({
17
13
  scrollToIndex
18
14
  }) => {
19
15
  const displayTable = tableData && tableData.rows && !!tableData.rows.length;
16
+ const { isEnquiry } = tableData;
17
+ const className = `page__content${isEnquiry ? ' array-table' : ''}`;
20
18
 
21
19
  return (
22
20
  <>
23
- {displayTable ? (
21
+ {displayTable && (
24
22
  <>
25
- <div className="page__content">
23
+ <div className={className}>
26
24
  <Table
27
25
  scrollToIndex={scrollToIndex}
28
26
  onSort={onSort}
@@ -30,23 +28,12 @@ const ListingTableContent = ({
30
28
  overScanBuffer={overScanBuffer}
31
29
  onRenderItems={onRenderItems}
32
30
  data={tableData}
33
- checkboxes
31
+ checkboxes={!isEnquiry}
34
32
  onSelect={handleSelect}
35
33
  data-testid="listing-table-content"
36
34
  />
37
35
  </div>
38
36
  </>
39
- ) : (
40
- selectedMenuItem.isDisplayedPrompt && (
41
- <CardPrompt onClose={onCloseCardPrompt} data-testid="card-prompt">
42
- <Link
43
- className="button button--rounded button--cta"
44
- to={`${match.url}/create`}
45
- data-testid="add-button">
46
- Add
47
- </Link>
48
- </CardPrompt>
49
- )
50
37
  )}
51
38
  </>
52
39
  );
@@ -54,8 +41,6 @@ const ListingTableContent = ({
54
41
 
55
42
  ListingTableContent.propTypes = {
56
43
  tableData: PropTypes.object.isRequired,
57
- onCloseCardPrompt: PropTypes.func.isRequired,
58
- selectedMenuItem: PropTypes.object.isRequired,
59
44
  match: PropTypes.shape({
60
45
  url: PropTypes.string
61
46
  }).isRequired,
@@ -73,7 +58,8 @@ ListingTableContent.defaultProps = {
73
58
  onClickRow: () => {},
74
59
  overScanBuffer: 0,
75
60
  scrollToIndex: 0,
76
- onRenderItems: () => {}
61
+ onRenderItems: () => {},
62
+ selectedMenuItem: null
77
63
  };
78
64
 
79
65
  export default withRouter(ListingTableContent);
@@ -3,18 +3,22 @@ import { Link } from 'react-router-dom';
3
3
  import TableActions from '../TableActions';
4
4
  import { ACTIONS } from '../../../constants';
5
5
 
6
- const formatRows = ({ rows, url, toggleModal, label, firstColumn = 'name' }) =>
6
+ const formatRows = ({ rows, url, toggleModal, label, firstColumn = 'name', isEnquiry }) =>
7
7
  rows.map(data => {
8
8
  const editUrl = `${url}/update/${data.id}`;
9
- return {
9
+ const rowProps = {
10
10
  ...data,
11
11
  [firstColumn]: (
12
12
  <Link to={editUrl} role="button">
13
13
  {data[firstColumn]}
14
14
  </Link>
15
- ),
16
- actions: <TableActions editUrl={editUrl} data={data} showDeleteModal={toggleModal} />
15
+ )
17
16
  };
17
+ if (!isEnquiry)
18
+ rowProps.actions = (
19
+ <TableActions editUrl={editUrl} data={data} showDeleteModal={toggleModal} />
20
+ );
21
+ return rowProps;
18
22
  });
19
23
 
20
24
  const getSanitizedColumnLabel = columnProp => {
@@ -28,22 +32,82 @@ const getSanitizedColumnLabel = columnProp => {
28
32
  return sanitizedChar;
29
33
  };
30
34
 
31
- const getColumnLabels = (listingProperties, properties, dynamicProperties) => {
32
- const allProperties = { ...properties, ...dynamicProperties };
33
- return listingProperties.reduce((acc, listingProperty) => {
34
- const label = allProperties[listingProperty].label || getSanitizedColumnLabel(listingProperty);
35
- return { ...acc, ...{ [listingProperty]: label } };
36
- }, {});
35
+ const buildArrayRowContent = rowData => (
36
+ <div className="table-row-list">
37
+ {rowData.map(rowGroup => (
38
+ <div className="table-row-list__group">
39
+ {rowGroup.map(({ label, value, url }) => (
40
+ <div className="table-row-list__group__item">
41
+ <span className="table-row-list__group__item__label"> {label}:</span>
42
+ {url ? (
43
+ <Link to={url} role="button" className="table-row-list__group__item__value">
44
+ {value}
45
+ </Link>
46
+ ) : (
47
+ <span className="table-row-list__group__item__value"> {value}</span>
48
+ )}
49
+ </div>
50
+ ))}
51
+ </div>
52
+ ))}
53
+ </div>
54
+ );
55
+
56
+ const buildArrayRowData = rowData => {
57
+ const dataGroups = [];
58
+ const groups = Math.ceil(rowData.length / 3) || 1;
59
+ for (let index = 0; index < groups; index += 1) {
60
+ const currentStart = index * groups;
61
+ dataGroups[index] = rowData.slice(currentStart, currentStart + 3);
62
+ }
63
+
64
+ return buildArrayRowContent(dataGroups);
65
+ };
66
+
67
+ const getParsedRowData = rows =>
68
+ rows.map(rowData =>
69
+ Object.keys(rowData).reduce((acc, key) => {
70
+ const parsedData = Array.isArray(rowData[key])
71
+ ? buildArrayRowData(rowData[key])
72
+ : rowData[key];
73
+ return { ...acc, [key]: parsedData };
74
+ }, {})
75
+ );
76
+
77
+ const getColumnsAndLabels = (listingProperties, allProperties, rows) => {
78
+ const columns = [];
79
+ const labels = {};
80
+
81
+ listingProperties.forEach(listingProperty => {
82
+ const propKey = listingProperty.includes(' ') ? listingProperty.split(' ')[0] : listingProperty;
83
+ const { label } = allProperties[propKey] || {};
84
+ columns.push(propKey);
85
+ labels[propKey] = label || getSanitizedColumnLabel(propKey);
86
+ });
87
+ const parsedRowData = getParsedRowData(rows);
88
+
89
+ return { columns, labels, parsedRowData };
37
90
  };
38
91
 
39
92
  const populateRows = ({ toggleModal, url, entitySchema, rows }) => {
40
- const { listingProperties, properties, dynamicProperties = {}, formProperties } = entitySchema;
41
- const columns = [...listingProperties, ACTIONS];
93
+ const {
94
+ id: schemaId,
95
+ listingProperties,
96
+ properties,
97
+ dynamicProperties = {},
98
+ formProperties
99
+ } = entitySchema;
100
+
101
+ const isEnquiry = schemaId === 'enquiry';
102
+ const columnOptions = !isEnquiry ? [...listingProperties, ACTIONS] : [...listingProperties];
103
+
104
+ const allProperties = { ...properties, ...dynamicProperties };
105
+ const { columns, labels, parsedRowData } = getColumnsAndLabels(
106
+ columnOptions,
107
+ allProperties,
108
+ rows
109
+ );
42
110
  const [firstColumn] = columns;
43
- const labels = {
44
- ...getColumnLabels(listingProperties, properties, dynamicProperties),
45
- [ACTIONS]: ACTIONS
46
- };
47
111
 
48
112
  return {
49
113
  identification: 'id',
@@ -51,8 +115,9 @@ const populateRows = ({ toggleModal, url, entitySchema, rows }) => {
51
115
  columns,
52
116
  labels,
53
117
  orderBy: [...formProperties],
54
- rows: formatRows({ firstColumn, rows, url, toggleModal })
118
+ rows: formatRows({ firstColumn, rows: parsedRowData, url, toggleModal, isEnquiry }),
119
+ isEnquiry
55
120
  };
56
121
  };
57
122
 
58
- export { populateRows, formatRows };
123
+ export { populateRows, formatRows, getParsedRowData };
@@ -1,12 +1,49 @@
1
1
  import buildListingQuery from '../../../utils/build-listing-query';
2
2
 
3
- const fetchData = async ({ client, querySettings: { entitySchema, queryParams } }) => {
4
- const query = buildListingQuery(entitySchema);
3
+ function buildVariables({ entitySchema, isSearchQuery, listFilters = [], queryParams = {} }) {
4
+ const { identifier } = entitySchema;
5
+ const { sort, offset, limit, where } = queryParams;
6
+ const [{ property, direction }] = sort;
7
+ const parsedOffset = `${property}:${direction}`;
8
+
9
+ if (!isSearchQuery)
10
+ return {
11
+ ...queryParams,
12
+ where: !Array.isArray(listFilters) ? listFilters : where
13
+ };
14
+
15
+ const rawQuery = {
16
+ bool: {
17
+ must: listFilters || [],
18
+ filter: [
19
+ {
20
+ term: {
21
+ entityIdentifier: identifier
22
+ }
23
+ }
24
+ ]
25
+ }
26
+ };
27
+
28
+ return {
29
+ limit,
30
+ offset,
31
+ sort: parsedOffset,
32
+ where: JSON.stringify(rawQuery)
33
+ };
34
+ }
35
+
36
+ const fetchData = async ({ client, querySettings: { entitySchema, queryParams }, listFilters }) => {
5
37
  const {
6
- data: { listingData }
7
- } = await client.query({ query, variables: queryParams, fetchPolicy: 'network-only' });
38
+ displayProperties: { adminListings: { dataSource: { source } = {} } = {} } = {}
39
+ } = entitySchema;
40
+
41
+ const isSearchQuery = source === 'search';
42
+ const query = buildListingQuery(entitySchema, isSearchQuery);
43
+ const variables = buildVariables({ entitySchema, listFilters, queryParams, isSearchQuery });
44
+ const { data = {} } = await client.query({ query, variables, fetchPolicy: 'network-only' });
8
45
 
9
- return listingData;
46
+ return data.searchResults ? data.searchResults.results : data.listingData;
10
47
  };
11
48
 
12
49
  export { fetchData };
package/src/index.js CHANGED
@@ -12,14 +12,7 @@ const EntityManager = React.lazy(() =>
12
12
  );
13
13
 
14
14
  export default async function load(app) {
15
- // To load different plugin information into menu
16
- const sectionKey = 'content';
17
-
18
- app.events.once('load:menu-section', addSection => {
19
- addSection(sectionKey, { header: 'content', order: 100 });
20
- });
21
-
22
- app.events.once('load:menu-items', getAddContentMenuItems(app, sectionKey));
15
+ app.events.once('admin:menu:config:load', getAddContentMenuItems(app));
23
16
 
24
17
  app.events.once('load:custom:field:type', addFieldType => {
25
18
  Object.keys(formFieldTypes).forEach(type => {
@@ -2,8 +2,8 @@ import { getQuery } from '@blaze-cms/admin-ui-utils';
2
2
 
3
3
  const { MENU_PERMISSIONS } = require('../constants');
4
4
 
5
- function getAddContentMenuItems(app, sectionKey) {
6
- return async addItem => {
5
+ function getAddContentMenuItems(app) {
6
+ return async ({ addConfig }) => {
7
7
  const client = app.getClient();
8
8
  const {
9
9
  data: { getEntitySchemas }
@@ -14,9 +14,51 @@ function getAddContentMenuItems(app, sectionKey) {
14
14
  canDoActions: MENU_PERMISSIONS
15
15
  }
16
16
  });
17
+
18
+ if (!getEntitySchemas || !getEntitySchemas.length) return; // no items so don't add section
19
+
20
+ const menuItems = {};
21
+ const sectionMenuItems = { content: {} };
22
+
23
+ getEntitySchemas.forEach(({ id, displayName, displayProperties }) => {
24
+ if (!displayProperties) return null;
25
+
26
+ const { adminMenu: { sectionKey = 'content' } = {} } = displayProperties;
27
+ const sectionItems = sectionMenuItems[sectionKey] || {};
28
+ sectionItems[id] = {
29
+ label: displayName,
30
+ uri: `/data-listing/${id}`
31
+ };
32
+ sectionMenuItems[sectionKey] = sectionItems;
33
+ });
34
+
35
+ const menuConfig = {
36
+ main: {
37
+ items: {
38
+ content: {
39
+ label: 'Content',
40
+ loadOpen: true,
41
+ order: 10,
42
+ items: menuItems
43
+ }
44
+ }
45
+ }
46
+ };
47
+
48
+ Object.entries(sectionMenuItems).forEach(([sectionKey, sectionItems]) => {
49
+ const sectionConfig = menuConfig.main.items[sectionKey] || {};
50
+ sectionConfig.items = sectionItems;
51
+ menuConfig.main.items[sectionKey] = sectionConfig;
52
+ });
53
+
17
54
  getEntitySchemas.forEach(({ id, displayName }) => {
18
- addItem({ name: displayName, uri: `/data-listing/${id}` }, sectionKey);
55
+ menuItems[id] = {
56
+ label: displayName,
57
+ uri: `/data-listing/${id}`
58
+ };
19
59
  });
60
+
61
+ addConfig(menuConfig);
20
62
  };
21
63
  }
22
64
 
@@ -1,13 +1,23 @@
1
1
  import { gql } from '@apollo/client';
2
2
  import { BlazeError } from '@blaze-cms/core-errors';
3
+ import { getDynamicQuery } from '@blaze-cms/admin-ui-utils';
3
4
 
4
- function buildListingQuery(entitySchema) {
5
+ const buildAdminSearchQuery = entitySchema => {
6
+ const { listingProperties = [] } = entitySchema || {};
7
+ const parsedProperties = `id, ${listingProperties.join(' ') || 'id name'}`;
8
+
9
+ return getDynamicQuery('ADMIN_SEARCH')([entitySchema], parsedProperties, true);
10
+ };
11
+
12
+ function buildListingQuery(entitySchema, isSearchQuery) {
5
13
  if (!entitySchema.actions || !entitySchema.actions.getAll || !entitySchema.listingProperties) {
6
14
  throw new BlazeError(
7
15
  'Listing query requires getAll action and listingProperties from entity schema'
8
16
  );
9
17
  }
10
18
 
19
+ if (isSearchQuery) return buildAdminSearchQuery(entitySchema);
20
+
11
21
  const sortType =
12
22
  entitySchema.actions.getAll[0].toUpperCase() + entitySchema.actions.getAll.substr(1);
13
23
 
@@ -1,4 +1,4 @@
1
- const getDefaultQueryParams = ({ schema }) => {
1
+ const getDefaultQueryParams = schema => {
2
2
  const updated = schema.properties && schema.properties.updated;
3
3
  const { adminDefaultListingFilter: where } = schema.displayProperties || {};
4
4