@blaze-cms/plugin-data-ui 0.134.0-project-admin-customisations.0 → 0.134.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 +4 -33
  2. package/README.md +0 -42
  3. package/lib/components/EntityDataListing/EntityDataListing.js +24 -3
  4. package/lib/components/EntityDataListing/EntityDataListing.js.map +1 -1
  5. package/lib/components/EntityManager/Entity/Entity.js +17 -32
  6. package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
  7. package/lib/components/EntityManager/Entity/SideBarRelations/index.js +7 -23
  8. package/lib/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  9. package/lib/components/ListingTable/ListingTable.js +80 -113
  10. package/lib/components/ListingTable/ListingTable.js.map +1 -1
  11. package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js +20 -8
  12. package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
  13. package/lib/components/ListingTable/mappers/populate-rows.js +26 -92
  14. package/lib/components/ListingTable/mappers/populate-rows.js.map +1 -1
  15. package/lib/components/ListingTable/service/index.js +11 -73
  16. package/lib/components/ListingTable/service/index.js.map +1 -1
  17. package/lib/index.js +11 -3
  18. package/lib/index.js.map +1 -1
  19. package/lib/utils/add-content-menu-items.js +13 -64
  20. package/lib/utils/add-content-menu-items.js.map +1 -1
  21. package/lib/utils/build-listing-query.js +2 -11
  22. package/lib/utils/build-listing-query.js.map +1 -1
  23. package/lib/utils/get-default-query-params.js +4 -3
  24. package/lib/utils/get-default-query-params.js.map +1 -1
  25. package/lib-es/components/EntityDataListing/EntityDataListing.js +14 -3
  26. package/lib-es/components/EntityDataListing/EntityDataListing.js.map +1 -1
  27. package/lib-es/components/EntityManager/Entity/Entity.js +17 -32
  28. package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
  29. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js +8 -24
  30. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  31. package/lib-es/components/ListingTable/ListingTable.js +49 -46
  32. package/lib-es/components/ListingTable/ListingTable.js.map +1 -1
  33. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js +19 -11
  34. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
  35. package/lib-es/components/ListingTable/mappers/populate-rows.js +24 -76
  36. package/lib-es/components/ListingTable/mappers/populate-rows.js.map +1 -1
  37. package/lib-es/components/ListingTable/service/index.js +7 -65
  38. package/lib-es/components/ListingTable/service/index.js.map +1 -1
  39. package/lib-es/index.js +9 -1
  40. package/lib-es/index.js.map +1 -1
  41. package/lib-es/utils/add-content-menu-items.js +5 -49
  42. package/lib-es/utils/add-content-menu-items.js.map +1 -1
  43. package/lib-es/utils/build-listing-query.js +1 -10
  44. package/lib-es/utils/build-listing-query.js.map +1 -1
  45. package/lib-es/utils/get-default-query-params.js +3 -1
  46. package/lib-es/utils/get-default-query-params.js.map +1 -1
  47. package/package.json +9 -10
  48. package/src/components/EntityDataListing/EntityDataListing.js +12 -3
  49. package/src/components/EntityManager/Entity/Entity.js +57 -68
  50. package/src/components/EntityManager/Entity/SideBarRelations/index.js +19 -51
  51. package/src/components/ListingTable/ListingTable.js +38 -57
  52. package/src/components/ListingTable/ListingTableContent/ListingTableContent.js +22 -8
  53. package/src/components/ListingTable/mappers/populate-rows.js +18 -83
  54. package/src/components/ListingTable/service/index.js +5 -42
  55. package/src/index.js +8 -1
  56. package/src/utils/add-content-menu-items.js +3 -45
  57. package/src/utils/build-listing-query.js +1 -11
  58. package/src/utils/get-default-query-params.js +1 -1
  59. package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +0 -39
  60. package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +0 -1
  61. package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js +0 -12
  62. package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +0 -1
  63. package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +0 -44
  64. package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +0 -1
  65. package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +0 -32
  66. package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +0 -1
  67. package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +0 -45
  68. package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +0 -1
  69. package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +0 -38
  70. package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +0 -1
  71. package/lib/components/InfoBoxes/InfoBoxes.js +0 -36
  72. package/lib/components/InfoBoxes/InfoBoxes.js.map +0 -1
  73. package/lib/components/InfoBoxes/container/InfoBoxContainer.js +0 -44
  74. package/lib/components/InfoBoxes/container/InfoBoxContainer.js.map +0 -1
  75. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js +0 -25
  76. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js.map +0 -1
  77. package/lib/components/InfoBoxes/hooks/useData.js +0 -42
  78. package/lib/components/InfoBoxes/hooks/useData.js.map +0 -1
  79. package/lib/components/InfoBoxes/hooks/useInfoBox.js +0 -26
  80. package/lib/components/InfoBoxes/hooks/useInfoBox.js.map +0 -1
  81. package/lib/components/InfoBoxes/index.js +0 -12
  82. package/lib/components/InfoBoxes/index.js.map +0 -1
  83. package/lib/components/InfoBoxes/presentational/InfoBox.js +0 -46
  84. package/lib/components/InfoBoxes/presentational/InfoBox.js.map +0 -1
  85. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +0 -30
  86. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +0 -1
  87. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js +0 -3
  88. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +0 -1
  89. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +0 -30
  90. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +0 -1
  91. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +0 -26
  92. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +0 -1
  93. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +0 -39
  94. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +0 -1
  95. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +0 -24
  96. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +0 -1
  97. package/lib-es/components/InfoBoxes/InfoBoxes.js +0 -28
  98. package/lib-es/components/InfoBoxes/InfoBoxes.js.map +0 -1
  99. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js +0 -30
  100. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js.map +0 -1
  101. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js +0 -25
  102. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +0 -1
  103. package/lib-es/components/InfoBoxes/hooks/useData.js +0 -37
  104. package/lib-es/components/InfoBoxes/hooks/useData.js.map +0 -1
  105. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js +0 -19
  106. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js.map +0 -1
  107. package/lib-es/components/InfoBoxes/index.js +0 -3
  108. package/lib-es/components/InfoBoxes/index.js.map +0 -1
  109. package/lib-es/components/InfoBoxes/presentational/InfoBox.js +0 -31
  110. package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +0 -1
  111. package/src/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +0 -26
  112. package/src/components/EntityManager/Entity/EntitiyNavLinks/index.js +0 -3
  113. package/src/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +0 -22
  114. package/src/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +0 -33
  115. package/src/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +0 -28
  116. package/src/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +0 -33
  117. package/src/components/InfoBoxes/InfoBoxes.js +0 -24
  118. package/src/components/InfoBoxes/container/InfoBoxContainer.js +0 -22
  119. package/src/components/InfoBoxes/helpers/build-dynamic-query.js +0 -25
  120. package/src/components/InfoBoxes/hooks/useData.js +0 -20
  121. package/src/components/InfoBoxes/hooks/useInfoBox.js +0 -13
  122. package/src/components/InfoBoxes/index.js +0 -3
  123. package/src/components/InfoBoxes/presentational/InfoBox.js +0 -34
@@ -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';
6
7
  import { PageHeader, DeleteAction } from '@blaze-cms/admin';
7
8
  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, getParsedRowData } from './mappers/populate-rows';
12
+ import { populateRows, formatRows } 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 }) => {
17
+ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
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(entitySchema);
24
+ const queryParamsDefault = getDefaultQueryParams({ schema: entitySchema });
25
25
  const [queryParams, setQueryParams] = useState(queryParamsDefault);
26
- const [listFilters, setListFilters] = useState([]);
26
+ const { menuItems, setMenuItems } = useMainContext(MainContext);
27
27
  const client = useApolloClient();
28
28
  const { addToast } = useToasts();
29
29
 
@@ -34,7 +34,20 @@ const ListingTable = ({ match, entitySchema }) => {
34
34
  entitySchema.id !== previousSchema.id ||
35
35
  (previousSchema.id === null && entitySchema.id)
36
36
  ) {
37
- await doQuery();
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);
38
51
  setPreviousSchema({ id: entitySchema.id });
39
52
  }
40
53
  })();
@@ -42,33 +55,18 @@ const ListingTable = ({ match, entitySchema }) => {
42
55
  [client, entitySchema, match.url, previousSchema.id, queryParams] // eslint-disable-line react-hooks/exhaustive-deps
43
56
  );
44
57
 
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);
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 }]);
68
68
  };
69
69
 
70
- const onCloseCardPrompt = () => null;
71
-
72
70
  const toggleModal = item => {
73
71
  setModalStatus(!!item);
74
72
  setItemToDelete(item || {});
@@ -109,22 +107,15 @@ const ListingTable = ({ match, entitySchema }) => {
109
107
  querySettings: {
110
108
  entitySchema,
111
109
  queryParams: sortQueryParams
112
- },
113
- listFilters
110
+ }
114
111
  });
115
- const { columns, isEnquiry } = tableData;
112
+ const { columns } = tableData;
116
113
  const [firstColumn] = columns;
117
114
 
118
115
  setTableData({
119
116
  ...tableData,
120
117
  appliedSort: { [property]: direction },
121
- rows: formatRows({
122
- rows: getParsedRowData(data),
123
- url: match.url,
124
- toggleModal,
125
- firstColumn,
126
- isEnquiry
127
- })
118
+ rows: formatRows({ rows: data, url: match.url, toggleModal, firstColumn })
128
119
  });
129
120
  };
130
121
 
@@ -142,17 +133,11 @@ const ListingTable = ({ match, entitySchema }) => {
142
133
  querySettings: {
143
134
  entitySchema,
144
135
  queryParams: updatedQueryParams
145
- },
146
- listFilters
136
+ }
147
137
  });
148
138
  const updatedRows = [
149
139
  ...tableData.rows,
150
- ...formatRows({
151
- rows: getParsedRowData(data),
152
- url: match.url,
153
- toggleModal,
154
- isEnquiry: tableData.isEnquiry
155
- })
140
+ ...formatRows({ rows: data, url: match.url, toggleModal })
156
141
  ];
157
142
 
158
143
  setVerifiedRanges([...verifiedRanges, loadIndex]);
@@ -166,7 +151,6 @@ const ListingTable = ({ match, entitySchema }) => {
166
151
  };
167
152
 
168
153
  if (!tableData || !tableData.rows) return 'loading';
169
- const showAddButton = !!tableData.rows.length && !tableData.isEnquiry;
170
154
 
171
155
  return (
172
156
  <div className="page">
@@ -178,7 +162,7 @@ const ListingTable = ({ match, entitySchema }) => {
178
162
  />
179
163
  )}
180
164
  <PageHeader title={entitySchema.displayName} subtitle="">
181
- {showAddButton && (
165
+ {(!selectedMenuItem.isDisplayedPrompt || !!tableData.rows.length) && (
182
166
  <Fragment>
183
167
  <Link
184
168
  data-testid="addEntity"
@@ -197,17 +181,13 @@ const ListingTable = ({ match, entitySchema }) => {
197
181
  </Fragment>
198
182
  )}
199
183
  </PageHeader>
200
- <RenderHook
201
- hookKey="entity:listing:main:top"
202
- schema={entitySchema}
203
- setListFilters={updateListingFilters}
204
- />
205
184
  <ListingTableContent
206
185
  overScanBuffer={OVER_SCAN_BUFFER}
207
186
  onSort={handleSort}
208
187
  onRenderItems={handleRenderedItems}
209
188
  tableData={tableData}
210
189
  onCloseCardPrompt={onCloseCardPrompt}
190
+ selectedMenuItem={selectedMenuItem}
211
191
  scrollToIndex={scrollToIndex}
212
192
  />
213
193
  </div>
@@ -215,7 +195,8 @@ const ListingTable = ({ match, entitySchema }) => {
215
195
  };
216
196
  ListingTable.propTypes = {
217
197
  entitySchema: PropTypes.object.isRequired,
218
- match: PropTypes.object.isRequired
198
+ match: PropTypes.object.isRequired,
199
+ selectedMenuItem: PropTypes.object.isRequired
219
200
  };
220
201
 
221
202
  export default withRouter(ListingTable);
@@ -1,11 +1,15 @@
1
1
  import React from 'react';
2
2
  import Table from '@blaze-react/table';
3
3
  import PropTypes from 'prop-types';
4
- import { withRouter } from 'react-router-dom';
4
+ import { CardPrompt } from '@blaze-cms/admin';
5
+ import { Link, withRouter } from 'react-router-dom';
5
6
 
6
7
  const ListingTableContent = ({
7
8
  tableData,
8
9
  handleSelect,
10
+ onCloseCardPrompt,
11
+ selectedMenuItem,
12
+ match,
9
13
  onSort,
10
14
  onClickRow,
11
15
  overScanBuffer,
@@ -13,14 +17,12 @@ const ListingTableContent = ({
13
17
  scrollToIndex
14
18
  }) => {
15
19
  const displayTable = tableData && tableData.rows && !!tableData.rows.length;
16
- const { isEnquiry } = tableData;
17
- const className = `page__content${isEnquiry ? ' array-table' : ''}`;
18
20
 
19
21
  return (
20
22
  <>
21
- {displayTable && (
23
+ {displayTable ? (
22
24
  <>
23
- <div className={className}>
25
+ <div className="page__content">
24
26
  <Table
25
27
  scrollToIndex={scrollToIndex}
26
28
  onSort={onSort}
@@ -28,12 +30,23 @@ const ListingTableContent = ({
28
30
  overScanBuffer={overScanBuffer}
29
31
  onRenderItems={onRenderItems}
30
32
  data={tableData}
31
- checkboxes={!isEnquiry}
33
+ checkboxes
32
34
  onSelect={handleSelect}
33
35
  data-testid="listing-table-content"
34
36
  />
35
37
  </div>
36
38
  </>
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
+ )
37
50
  )}
38
51
  </>
39
52
  );
@@ -41,6 +54,8 @@ const ListingTableContent = ({
41
54
 
42
55
  ListingTableContent.propTypes = {
43
56
  tableData: PropTypes.object.isRequired,
57
+ onCloseCardPrompt: PropTypes.func.isRequired,
58
+ selectedMenuItem: PropTypes.object.isRequired,
44
59
  match: PropTypes.shape({
45
60
  url: PropTypes.string
46
61
  }).isRequired,
@@ -58,8 +73,7 @@ ListingTableContent.defaultProps = {
58
73
  onClickRow: () => {},
59
74
  overScanBuffer: 0,
60
75
  scrollToIndex: 0,
61
- onRenderItems: () => {},
62
- selectedMenuItem: null
76
+ onRenderItems: () => {}
63
77
  };
64
78
 
65
79
  export default withRouter(ListingTableContent);
@@ -3,22 +3,18 @@ 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', isEnquiry }) =>
6
+ const formatRows = ({ rows, url, toggleModal, label, firstColumn = 'name' }) =>
7
7
  rows.map(data => {
8
8
  const editUrl = `${url}/update/${data.id}`;
9
- const rowProps = {
9
+ return {
10
10
  ...data,
11
11
  [firstColumn]: (
12
12
  <Link to={editUrl} role="button">
13
13
  {data[firstColumn]}
14
14
  </Link>
15
- )
15
+ ),
16
+ actions: <TableActions editUrl={editUrl} data={data} showDeleteModal={toggleModal} />
16
17
  };
17
- if (!isEnquiry)
18
- rowProps.actions = (
19
- <TableActions editUrl={editUrl} data={data} showDeleteModal={toggleModal} />
20
- );
21
- return rowProps;
22
18
  });
23
19
 
24
20
  const getSanitizedColumnLabel = columnProp => {
@@ -32,82 +28,22 @@ const getSanitizedColumnLabel = columnProp => {
32
28
  return sanitizedChar;
33
29
  };
34
30
 
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 };
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
+ }, {});
90
37
  };
91
38
 
92
39
  const populateRows = ({ toggleModal, url, entitySchema, rows }) => {
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
- );
40
+ const { listingProperties, properties, dynamicProperties = {}, formProperties } = entitySchema;
41
+ const columns = [...listingProperties, ACTIONS];
110
42
  const [firstColumn] = columns;
43
+ const labels = {
44
+ ...getColumnLabels(listingProperties, properties, dynamicProperties),
45
+ [ACTIONS]: ACTIONS
46
+ };
111
47
 
112
48
  return {
113
49
  identification: 'id',
@@ -115,9 +51,8 @@ const populateRows = ({ toggleModal, url, entitySchema, rows }) => {
115
51
  columns,
116
52
  labels,
117
53
  orderBy: [...formProperties],
118
- rows: formatRows({ firstColumn, rows: parsedRowData, url, toggleModal, isEnquiry }),
119
- isEnquiry
54
+ rows: formatRows({ firstColumn, rows, url, toggleModal })
120
55
  };
121
56
  };
122
57
 
123
- export { populateRows, formatRows, getParsedRowData };
58
+ export { populateRows, formatRows };
@@ -1,49 +1,12 @@
1
1
  import buildListingQuery from '../../../utils/build-listing-query';
2
2
 
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 }) => {
3
+ const fetchData = async ({ client, querySettings: { entitySchema, queryParams } }) => {
4
+ const query = buildListingQuery(entitySchema);
37
5
  const {
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' });
6
+ data: { listingData }
7
+ } = await client.query({ query, variables: queryParams, fetchPolicy: 'network-only' });
45
8
 
46
- return data.searchResults ? data.searchResults.results : data.listingData;
9
+ return listingData;
47
10
  };
48
11
 
49
12
  export { fetchData };
package/src/index.js CHANGED
@@ -12,7 +12,14 @@ const EntityManager = React.lazy(() =>
12
12
  );
13
13
 
14
14
  export default async function load(app) {
15
- app.events.once('admin:menu:config:load', getAddContentMenuItems(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));
16
23
 
17
24
  app.events.once('load:custom:field:type', addFieldType => {
18
25
  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) {
6
- return async ({ addConfig }) => {
5
+ function getAddContentMenuItems(app, sectionKey) {
6
+ return async addItem => {
7
7
  const client = app.getClient();
8
8
  const {
9
9
  data: { getEntitySchemas }
@@ -14,51 +14,9 @@ function getAddContentMenuItems(app) {
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
-
54
17
  getEntitySchemas.forEach(({ id, displayName }) => {
55
- menuItems[id] = {
56
- label: displayName,
57
- uri: `/data-listing/${id}`
58
- };
18
+ addItem({ name: displayName, uri: `/data-listing/${id}` }, sectionKey);
59
19
  });
60
-
61
- addConfig(menuConfig);
62
20
  };
63
21
  }
64
22
 
@@ -1,23 +1,13 @@
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';
4
3
 
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) {
4
+ function buildListingQuery(entitySchema) {
13
5
  if (!entitySchema.actions || !entitySchema.actions.getAll || !entitySchema.listingProperties) {
14
6
  throw new BlazeError(
15
7
  'Listing query requires getAll action and listingProperties from entity schema'
16
8
  );
17
9
  }
18
10
 
19
- if (isSearchQuery) return buildAdminSearchQuery(entitySchema);
20
-
21
11
  const sortType =
22
12
  entitySchema.actions.getAll[0].toUpperCase() + entitySchema.actions.getAll.substr(1);
23
13
 
@@ -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
 
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.object.define-property.js");
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- require("core-js/modules/es.array.map.js");
11
- require("core-js/modules/es.object.entries.js");
12
- require("core-js/modules/es.string.starts-with.js");
13
- var _reactRouterDom = require("react-router-dom");
14
- var _react = _interopRequireDefault(require("react"));
15
- var EntityNavLinks = function EntityNavLinks(_ref) {
16
- var schema = _ref.schema;
17
- if (!schema) return null;
18
- var adminSectionNavigation = schema.displayProperties.adminSectionNavigation;
19
- if (!adminSectionNavigation) return null;
20
- var links = Object.entries(adminSectionNavigation).map(function (_ref2) {
21
- var _ref3 = (0, _slicedToArray2["default"])(_ref2, 2),
22
- k = _ref3[0],
23
- v = _ref3[1];
24
- var label = v.label,
25
- uri = v.uri;
26
- var Wrapper = uri.startsWith('#') ? 'a' : _reactRouterDom.Link;
27
- return /*#__PURE__*/_react["default"].createElement(Wrapper, {
28
- className: "entity-section-link",
29
- href: uri,
30
- to: uri
31
- }, label);
32
- });
33
- return /*#__PURE__*/_react["default"].createElement("div", {
34
- className: "entity-section-links"
35
- }, links);
36
- };
37
- var _default = EntityNavLinks;
38
- exports["default"] = _default;
39
- //# sourceMappingURL=EntityNavLinks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EntityNavLinks.js","names":["_reactRouterDom","require","_react","_interopRequireDefault","EntityNavLinks","_ref","schema","adminSectionNavigation","displayProperties","links","Object","entries","map","_ref2","_ref3","_slicedToArray2","k","v","label","uri","Wrapper","startsWith","Link","createElement","className","href","to","_default","exports"],"sources":["../../../../../src/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js"],"sourcesContent":["import { Link } from 'react-router-dom';\nimport React from 'react';\n\nconst EntityNavLinks = ({ schema }) => {\n if (!schema) return null;\n\n const {\n displayProperties: { adminSectionNavigation }\n } = schema;\n\n if (!adminSectionNavigation) return null;\n\n const links = Object.entries(adminSectionNavigation).map(([k, v]) => {\n const { label, uri } = v;\n const Wrapper = uri.startsWith('#') ? 'a' : Link;\n return (\n <Wrapper className=\"entity-section-link\" href={uri} to={uri}>\n {label}\n </Wrapper>\n );\n });\n\n return <div className=\"entity-section-links\">{links}</div>;\n};\n\nexport default EntityNavLinks;\n"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAMG,cAAc,GAAG,SAAjBA,cAAcA,CAAAC,IAAA,EAAmB;EAAA,IAAbC,MAAM,GAAAD,IAAA,CAANC,MAAM;EAC9B,IAAI,CAACA,MAAM,EAAE,OAAO,IAAI;EAExB,IACuBC,sBAAsB,GACzCD,MAAM,CADRE,iBAAiB,CAAID,sBAAsB;EAG7C,IAAI,CAACA,sBAAsB,EAAE,OAAO,IAAI;EAExC,IAAME,KAAK,GAAGC,MAAM,CAACC,OAAO,CAACJ,sBAAsB,CAAC,CAACK,GAAG,CAAC,UAAAC,KAAA,EAAY;IAAA,IAAAC,KAAA,OAAAC,eAAA,aAAAF,KAAA;MAAVG,CAAC,GAAAF,KAAA;MAAEG,CAAC,GAAAH,KAAA;IAC7D,IAAQI,KAAK,GAAUD,CAAC,CAAhBC,KAAK;MAAEC,GAAG,GAAKF,CAAC,CAATE,GAAG;IAClB,IAAMC,OAAO,GAAGD,GAAG,CAACE,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,GAAGC,oBAAI;IAChD,oBACEpB,MAAA,YAAAqB,aAAA,CAACH,OAAO;MAACI,SAAS,EAAC,qBAAqB;MAACC,IAAI,EAAEN,GAAI;MAACO,EAAE,EAAEP;IAAI,GACzDD,KACM,CAAC;EAEd,CAAC,CAAC;EAEF,oBAAOhB,MAAA,YAAAqB,aAAA;IAAKC,SAAS,EAAC;EAAsB,GAAEf,KAAW,CAAC;AAC5D,CAAC;AAAC,IAAAkB,QAAA,GAEavB,cAAc;AAAAwB,OAAA,cAAAD,QAAA"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.object.define-property.js");
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
- var _EntityNavLinks = _interopRequireDefault(require("./EntityNavLinks"));
10
- var _default = _EntityNavLinks["default"];
11
- exports["default"] = _default;
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_EntityNavLinks","_interopRequireDefault","require","_default","EntityNavLinks","exports"],"sources":["../../../../../src/components/EntityManager/Entity/EntitiyNavLinks/index.js"],"sourcesContent":["import EntityNavLinks from './EntityNavLinks';\n\nexport default EntityNavLinks;\n"],"mappings":";;;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8C,IAAAC,QAAA,GAE/BC,0BAAc;AAAAC,OAAA,cAAAF,QAAA"}
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.object.define-property.js");
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
- require("core-js/modules/es.object.keys.js");
10
- require("core-js/modules/es.array.flat-map.js");
11
- require("core-js/modules/es.array.unscopables.flat-map.js");
12
- require("core-js/modules/es.object.to-string.js");
13
- require("core-js/modules/es.object.values.js");
14
- var _propTypes = _interopRequireDefault(require("prop-types"));
15
- var _react = _interopRequireDefault(require("react"));
16
- var _useCustomSidebarData2 = _interopRequireDefault(require("../hooks/useCustomSidebarData"));
17
- var _CustomSidebarInfo = _interopRequireDefault(require("../presentational/CustomSidebarInfo"));
18
- var CustomSibebarInfoContainer = function CustomSibebarInfoContainer(_ref) {
19
- var id = _ref.id,
20
- schema = _ref.schema,
21
- displayProperties = _ref.displayProperties;
22
- var _useCustomSidebarData = (0, _useCustomSidebarData2["default"])({
23
- id: id,
24
- schema: schema,
25
- displayProperties: displayProperties
26
- }),
27
- data = _useCustomSidebarData.data;
28
- if (!data || !Object.keys(data) || Object.keys(data).length === 0) return null;
29
- var items = Object.values(data).flatMap(function (item) {
30
- return Object.values(item);
31
- });
32
- return /*#__PURE__*/_react["default"].createElement(_CustomSidebarInfo["default"], {
33
- items: items,
34
- customSidebarInfoKey: displayProperties.key
35
- });
36
- };
37
- var _default = CustomSibebarInfoContainer;
38
- exports["default"] = _default;
39
- CustomSibebarInfoContainer.propTypes = {
40
- id: _propTypes["default"].string.isRequired,
41
- displayProperties: _propTypes["default"].object.isRequired,
42
- schema: _propTypes["default"].object.isRequired
43
- };
44
- //# sourceMappingURL=CustomSidebarInfoContainer.js.map