@blaze-cms/plugin-data-ui 0.139.0-alpha.4 → 0.139.0-alpha.6

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 (153) hide show
  1. package/CHANGELOG.md +48 -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 +38 -0
  6. package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -0
  7. package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js +11 -0
  8. package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -0
  9. package/lib/components/EntityManager/Entity/Entity.js +16 -3
  10. package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
  11. package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +43 -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 +44 -0
  16. package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -0
  17. package/lib/components/EntityManager/Entity/SideBarRelations/index.js +12 -2
  18. package/lib/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  19. package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +37 -0
  20. package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -0
  21. package/lib/components/InfoBoxes/InfoBoxes.js +35 -0
  22. package/lib/components/InfoBoxes/InfoBoxes.js.map +1 -0
  23. package/lib/components/InfoBoxes/container/InfoBoxContainer.js +43 -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 +41 -0
  28. package/lib/components/InfoBoxes/hooks/useData.js.map +1 -0
  29. package/lib/components/InfoBoxes/hooks/useInfoBox.js +25 -0
  30. package/lib/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  31. package/lib/components/InfoBoxes/index.js +11 -0
  32. package/lib/components/InfoBoxes/index.js.map +1 -0
  33. package/lib/components/InfoBoxes/presentational/InfoBox.js +45 -0
  34. package/lib/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  35. package/lib/components/ListingTable/ListingTable.js +124 -79
  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 +91 -25
  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/constants.js +9 -1
  44. package/lib/constants.js.map +1 -1
  45. package/lib/icons/ContentIcon.js +90 -0
  46. package/lib/icons/ContentIcon.js.map +1 -0
  47. package/lib/icons/SettingsIcon.js +46 -0
  48. package/lib/icons/SettingsIcon.js.map +1 -0
  49. package/lib/icons/TaxonomyIcon.js +70 -0
  50. package/lib/icons/TaxonomyIcon.js.map +1 -0
  51. package/lib/icons/UsersIcon.js +43 -0
  52. package/lib/icons/UsersIcon.js.map +1 -0
  53. package/lib/icons/index.js +36 -0
  54. package/lib/icons/index.js.map +1 -0
  55. package/lib/index.js +38 -11
  56. package/lib/index.js.map +1 -1
  57. package/lib/utils/add-content-menu-items.js +61 -13
  58. package/lib/utils/add-content-menu-items.js.map +1 -1
  59. package/lib/utils/build-listing-query.js +11 -2
  60. package/lib/utils/build-listing-query.js.map +1 -1
  61. package/lib/utils/get-default-query-params.js +3 -4
  62. package/lib/utils/get-default-query-params.js.map +1 -1
  63. package/lib-es/components/EntityDataListing/EntityDataListing.js +3 -14
  64. package/lib-es/components/EntityDataListing/EntityDataListing.js.map +1 -1
  65. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +30 -0
  66. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -0
  67. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js +3 -0
  68. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -0
  69. package/lib-es/components/EntityManager/Entity/Entity.js +16 -3
  70. package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
  71. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +30 -0
  72. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +1 -0
  73. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +26 -0
  74. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -0
  75. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +39 -0
  76. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -0
  77. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js +12 -2
  78. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  79. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +24 -0
  80. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -0
  81. package/lib-es/components/InfoBoxes/InfoBoxes.js +28 -0
  82. package/lib-es/components/InfoBoxes/InfoBoxes.js.map +1 -0
  83. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js +30 -0
  84. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  85. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  86. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  87. package/lib-es/components/InfoBoxes/hooks/useData.js +37 -0
  88. package/lib-es/components/InfoBoxes/hooks/useData.js.map +1 -0
  89. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js +19 -0
  90. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  91. package/lib-es/components/InfoBoxes/index.js +3 -0
  92. package/lib-es/components/InfoBoxes/index.js.map +1 -0
  93. package/lib-es/components/InfoBoxes/presentational/InfoBox.js +31 -0
  94. package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  95. package/lib-es/components/ListingTable/ListingTable.js +56 -50
  96. package/lib-es/components/ListingTable/ListingTable.js.map +1 -1
  97. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js +11 -19
  98. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
  99. package/lib-es/components/ListingTable/mappers/populate-rows.js +76 -24
  100. package/lib-es/components/ListingTable/mappers/populate-rows.js.map +1 -1
  101. package/lib-es/components/ListingTable/service/index.js +65 -7
  102. package/lib-es/components/ListingTable/service/index.js.map +1 -1
  103. package/lib-es/constants.js +9 -1
  104. package/lib-es/constants.js.map +1 -1
  105. package/lib-es/icons/ContentIcon.js +80 -0
  106. package/lib-es/icons/ContentIcon.js.map +1 -0
  107. package/lib-es/icons/SettingsIcon.js +36 -0
  108. package/lib-es/icons/SettingsIcon.js.map +1 -0
  109. package/lib-es/icons/TaxonomyIcon.js +60 -0
  110. package/lib-es/icons/TaxonomyIcon.js.map +1 -0
  111. package/lib-es/icons/UsersIcon.js +33 -0
  112. package/lib-es/icons/UsersIcon.js.map +1 -0
  113. package/lib-es/icons/index.js +6 -0
  114. package/lib-es/icons/index.js.map +1 -0
  115. package/lib-es/index.js +37 -9
  116. package/lib-es/index.js.map +1 -1
  117. package/lib-es/utils/add-content-menu-items.js +46 -5
  118. package/lib-es/utils/add-content-menu-items.js.map +1 -1
  119. package/lib-es/utils/build-listing-query.js +10 -1
  120. package/lib-es/utils/build-listing-query.js.map +1 -1
  121. package/lib-es/utils/get-default-query-params.js +1 -3
  122. package/lib-es/utils/get-default-query-params.js.map +1 -1
  123. package/package.json +6 -5
  124. package/src/components/EntityDataListing/EntityDataListing.js +3 -12
  125. package/src/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +26 -0
  126. package/src/components/EntityManager/Entity/EntitiyNavLinks/index.js +3 -0
  127. package/src/components/EntityManager/Entity/Entity.js +10 -1
  128. package/src/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +22 -0
  129. package/src/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +33 -0
  130. package/src/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +28 -0
  131. package/src/components/EntityManager/Entity/SideBarRelations/index.js +34 -16
  132. package/src/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +33 -0
  133. package/src/components/InfoBoxes/InfoBoxes.js +24 -0
  134. package/src/components/InfoBoxes/container/InfoBoxContainer.js +22 -0
  135. package/src/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  136. package/src/components/InfoBoxes/hooks/useData.js +20 -0
  137. package/src/components/InfoBoxes/hooks/useInfoBox.js +13 -0
  138. package/src/components/InfoBoxes/index.js +3 -0
  139. package/src/components/InfoBoxes/presentational/InfoBox.js +34 -0
  140. package/src/components/ListingTable/ListingTable.js +73 -39
  141. package/src/components/ListingTable/ListingTableContent/ListingTableContent.js +8 -22
  142. package/src/components/ListingTable/mappers/populate-rows.js +83 -18
  143. package/src/components/ListingTable/service/index.js +42 -5
  144. package/src/constants.js +13 -1
  145. package/src/icons/ContentIcon.js +83 -0
  146. package/src/icons/SettingsIcon.js +41 -0
  147. package/src/icons/TaxonomyIcon.js +62 -0
  148. package/src/icons/UsersIcon.js +37 -0
  149. package/src/icons/index.js +6 -0
  150. package/src/index.js +36 -8
  151. package/src/utils/add-content-menu-items.js +42 -3
  152. package/src/utils/build-listing-query.js +11 -1
  153. package/src/utils/get-default-query-params.js +1 -1
@@ -3,27 +3,28 @@ 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
- import { PageHeader, DeleteAction } from '@blaze-cms/admin';
6
+ import { PageHeader, DeleteAction, CardPrompt } 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
+ const [displayCardPrompt, setDisplayCardPrompt] = useState(true);
27
28
  const client = useApolloClient();
28
29
  const { addToast } = useToasts();
29
30
 
@@ -34,20 +35,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
34
35
  entitySchema.id !== previousSchema.id ||
35
36
  (previousSchema.id === null && entitySchema.id)
36
37
  ) {
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
+ await doQuery();
51
39
  setPreviousSchema({ id: entitySchema.id });
52
40
  }
53
41
  })();
@@ -55,18 +43,33 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
55
43
  [client, entitySchema, match.url, previousSchema.id, queryParams] // eslint-disable-line react-hooks/exhaustive-deps
56
44
  );
57
45
 
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 }]);
46
+ const doQuery = async (filters = listFilters) => {
47
+ const data = await fetchData({
48
+ client,
49
+ querySettings: {
50
+ entitySchema,
51
+ queryParams: queryParamsDefault
52
+ },
53
+ listFilters: filters
54
+ });
55
+
56
+ const populatedTable = populateRows({
57
+ toggleModal,
58
+ url: match.url,
59
+ entitySchema,
60
+ rows: data
61
+ });
62
+
63
+ setTableData(populatedTable);
68
64
  };
69
65
 
66
+ const updateListingFilters = async filters => {
67
+ await doQuery(filters);
68
+ setListFilters(filters);
69
+ };
70
+
71
+ const onCloseCardPrompt = () => null;
72
+
70
73
  const toggleModal = item => {
71
74
  setModalStatus(!!item);
72
75
  setItemToDelete(item || {});
@@ -107,15 +110,22 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
107
110
  querySettings: {
108
111
  entitySchema,
109
112
  queryParams: sortQueryParams
110
- }
113
+ },
114
+ listFilters
111
115
  });
112
- const { columns } = tableData;
116
+ const { columns, isEnquiry } = tableData;
113
117
  const [firstColumn] = columns;
114
118
 
115
119
  setTableData({
116
120
  ...tableData,
117
121
  appliedSort: { [property]: direction },
118
- rows: formatRows({ rows: data, url: match.url, toggleModal, firstColumn })
122
+ rows: formatRows({
123
+ rows: getParsedRowData(data),
124
+ url: match.url,
125
+ toggleModal,
126
+ firstColumn,
127
+ isEnquiry
128
+ })
119
129
  });
120
130
  };
121
131
 
@@ -133,11 +143,17 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
133
143
  querySettings: {
134
144
  entitySchema,
135
145
  queryParams: updatedQueryParams
136
- }
146
+ },
147
+ listFilters
137
148
  });
138
149
  const updatedRows = [
139
150
  ...tableData.rows,
140
- ...formatRows({ rows: data, url: match.url, toggleModal })
151
+ ...formatRows({
152
+ rows: getParsedRowData(data),
153
+ url: match.url,
154
+ toggleModal,
155
+ isEnquiry: tableData.isEnquiry
156
+ })
141
157
  ];
142
158
 
143
159
  setVerifiedRanges([...verifiedRanges, loadIndex]);
@@ -151,6 +167,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
151
167
  };
152
168
 
153
169
  if (!tableData || !tableData.rows) return 'loading';
170
+ const showAddButton = !!tableData.rows.length && !tableData.isEnquiry;
154
171
 
155
172
  return (
156
173
  <div className="page">
@@ -162,7 +179,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
162
179
  />
163
180
  )}
164
181
  <PageHeader title={entitySchema.displayName} subtitle="">
165
- {(!selectedMenuItem.isDisplayedPrompt || !!tableData.rows.length) && (
182
+ {showAddButton && (
166
183
  <Fragment>
167
184
  <Link
168
185
  data-testid="addEntity"
@@ -181,13 +198,31 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
181
198
  </Fragment>
182
199
  )}
183
200
  </PageHeader>
201
+ {displayCardPrompt &&
202
+ !showAddButton && (
203
+ <CardPrompt
204
+ onClose={() => {
205
+ setDisplayCardPrompt(false);
206
+ }}>
207
+ <Link
208
+ className="button button--rounded button--cta"
209
+ to={`${match.url}/create`}
210
+ data-testid="add-button">
211
+ Add
212
+ </Link>
213
+ </CardPrompt>
214
+ )}
215
+ <RenderHook
216
+ hookKey="entity:listing:main:top"
217
+ schema={entitySchema}
218
+ setListFilters={updateListingFilters}
219
+ />
184
220
  <ListingTableContent
185
221
  overScanBuffer={OVER_SCAN_BUFFER}
186
222
  onSort={handleSort}
187
223
  onRenderItems={handleRenderedItems}
188
224
  tableData={tableData}
189
225
  onCloseCardPrompt={onCloseCardPrompt}
190
- selectedMenuItem={selectedMenuItem}
191
226
  scrollToIndex={scrollToIndex}
192
227
  />
193
228
  </div>
@@ -195,8 +230,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
195
230
  };
196
231
  ListingTable.propTypes = {
197
232
  entitySchema: PropTypes.object.isRequired,
198
- match: PropTypes.object.isRequired,
199
- selectedMenuItem: PropTypes.object.isRequired
233
+ match: PropTypes.object.isRequired
200
234
  };
201
235
 
202
236
  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/constants.js CHANGED
@@ -25,6 +25,16 @@ const PAGE_BUILDER_TAB_INDEX = 1;
25
25
  const EDITOR_VIEW_TAB = 'Editor view';
26
26
  const EDITOR_VIEW_TAB_INDEX = 0;
27
27
 
28
+ const ICON_SIZE = {
29
+ WIDTH: '25px',
30
+ HEIGHT: '25px'
31
+ };
32
+
33
+ const ICON_COLOR = {
34
+ STROKE: '#63779C',
35
+ FILL: '#63779C'
36
+ };
37
+
28
38
  export {
29
39
  DATA_LISTING_PREFIX,
30
40
  ENTITY_PUBLISHED,
@@ -49,5 +59,7 @@ export {
49
59
  EDITOR_VIEW_TAB,
50
60
  PAGE_BUILDER_TAB,
51
61
  UNPUBLISHED_WARNING,
52
- SAVE_BEFORE_PUBLISH_MESSAGE
62
+ SAVE_BEFORE_PUBLISH_MESSAGE,
63
+ ICON_SIZE,
64
+ ICON_COLOR
53
65
  };
@@ -0,0 +1,83 @@
1
+ import React from 'react';
2
+ import { ICON_COLOR } from '../constants';
3
+
4
+ function ContentIcon({ fill = ICON_COLOR.FILL, stroke = ICON_COLOR.STROKE }) {
5
+ return (
6
+ <svg
7
+ width="19px"
8
+ height="19px"
9
+ viewBox="0 0 21 21"
10
+ version="1.1"
11
+ xmlns="http://www.w3.org/2000/svg"
12
+ xmlnsXlink="http://www.w3.org/1999/xlink">
13
+ <title>content</title>
14
+ <g id="Page-1" stroke="none" strokeWidth={1} fill="none" fillRule="evenodd">
15
+ <g id="content" transform="translate(1, 1)">
16
+ <g id="Group">
17
+ <path
18
+ d="M0,8.70833334 L5.445875,3.26245834 C6.37331215,2.33530123 7.87668785,2.33530123 8.804125,3.26245834 L14.25,8.70833334"
19
+ id="Shape-path"
20
+ stroke={stroke}
21
+ strokeLinecap="round"
22
+ strokeLinejoin="round"
23
+ />
24
+ <path
25
+ d="M11.875,6.33333334 L13.758375,4.44995834 C14.6858122,3.52280123 16.1891878,3.52280123 17.116625,4.44995834 L19,6.33333334"
26
+ id="Shape-path"
27
+ stroke={stroke}
28
+ strokeLinecap="round"
29
+ strokeLinejoin="round"
30
+ />
31
+ <path
32
+ d="M2.375,19 L16.625,19 C17.9366763,19 19,17.9366763 19,16.625 L19,2.375 C19,1.06332371 17.9366763,0 16.625,0 L2.375,0 C1.06332371,0 0,1.06332371 0,2.375 L0,16.625 C0,17.9366763 1.06332371,19 2.375,19 Z"
33
+ id="Shape-path"
34
+ stroke={stroke}
35
+ strokeLinecap="round"
36
+ strokeLinejoin="round"
37
+ />
38
+ <circle
39
+ id="Oval"
40
+ fill={fill}
41
+ fillRule="nonzero"
42
+ cx="11.4791666"
43
+ cy="2.77083334"
44
+ r="1.1875"
45
+ />
46
+ </g>
47
+ <line
48
+ x1={0}
49
+ y1="9.23611111"
50
+ x2={19}
51
+ y2="9.23611111"
52
+ id="Path"
53
+ stroke={stroke}
54
+ strokeLinecap="round"
55
+ strokeLinejoin="round"
56
+ />
57
+ <line
58
+ x1="3.95833334"
59
+ y1="12.4027778"
60
+ x2="15.3055553"
61
+ y2="12.4027778"
62
+ id="Path"
63
+ stroke={stroke}
64
+ strokeLinecap="round"
65
+ strokeLinejoin="round"
66
+ />
67
+ <line
68
+ x1="3.95833334"
69
+ y1="15.5694445"
70
+ x2="12.1388885"
71
+ y2="15.5694445"
72
+ id="Path"
73
+ stroke={stroke}
74
+ strokeLinecap="round"
75
+ strokeLinejoin="round"
76
+ />
77
+ </g>
78
+ </g>
79
+ </svg>
80
+ );
81
+ }
82
+
83
+ export default ContentIcon;
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { ICON_SIZE, ICON_COLOR } from '../constants';
3
+
4
+ function SettingsIcon({
5
+ width = ICON_SIZE.WIDTH,
6
+ height = ICON_SIZE.HEIGHT,
7
+ stroke = ICON_COLOR.STROKE
8
+ }) {
9
+ return (
10
+ <svg
11
+ width={width}
12
+ height={height}
13
+ viewBox="0 0 22 22"
14
+ version="1.1"
15
+ xmlns="http://www.w3.org/2000/svg"
16
+ xmlnsXlink="http://www.w3.org/1999/xlink">
17
+ <title>setting</title>
18
+ <g
19
+ id="Page-1"
20
+ stroke="none"
21
+ strokeWidth={1}
22
+ fill="none"
23
+ fillRule="evenodd"
24
+ strokeLinecap="round"
25
+ strokeLinejoin="round">
26
+ <g id="Group" transform="translate(1, 1)" stroke={stroke}>
27
+ <path
28
+ d="M8.13888889,1.46333333 C8.61222222,-0.487777777 11.3877778,-0.487777777 11.8611111,1.46333333 C12.0051589,2.05784356 12.4244819,2.54780471 12.9896128,2.78193979 C13.5547438,3.01607487 14.1977123,2.96622362 14.72,2.64777778 C16.4344444,1.60333333 18.3977778,3.56555556 17.3533333,5.28111111 C17.0353472,5.803171 16.9856162,6.44564563 17.2194755,7.0104213 C17.4533348,7.57519696 17.9426987,7.99444609 18.5366667,8.13888889 C20.4877778,8.61222222 20.4877778,11.3877778 18.5366667,11.8611111 C17.9421564,12.0051589 17.4521953,12.4244819 17.2180602,12.9896128 C16.9839251,13.5547438 17.0337764,14.1977123 17.3522222,14.72 C18.3966667,16.4344444 16.4344444,18.3977778 14.7188889,17.3533333 C14.196829,17.0353472 13.5543544,16.9856162 12.9895787,17.2194755 C12.424803,17.4533348 12.0055539,17.9426987 11.8611111,18.5366667 C11.3877778,20.4877778 8.61222222,20.4877778 8.13888889,18.5366667 C7.99484107,17.9421564 7.57551807,17.4521953 7.01038716,17.2180602 C6.44525624,16.9839251 5.80228769,17.0337764 5.28,17.3522222 C3.56555556,18.3966667 1.60222222,16.4344444 2.64666667,14.7188889 C2.96465281,14.196829 3.01438377,13.5543544 2.78052448,12.9895787 C2.5466652,12.424803 2.05730134,12.0055539 1.46333333,11.8611111 C-0.487777777,11.3877778 -0.487777777,8.61222222 1.46333333,8.13888889 C2.05784356,7.99484107 2.54780471,7.57551807 2.78193979,7.01038716 C3.01607487,6.44525624 2.96622362,5.80228769 2.64777778,5.28 C1.60333333,3.56555556 3.56555556,1.60222222 5.28111111,2.64666667 C6.38777778,3.32222222 7.83222222,2.72444444 8.13888889,1.46333333 Z"
29
+ id="Path"
30
+ />
31
+ <path
32
+ d="M13.6666666,10.3333333 C13.6666666,12.1742825 12.1742825,13.6666666 10.3333333,13.6666666 C8.49238416,13.6666666 7,12.1742825 7,10.3333333 C7,8.49238416 8.49238416,7 10.3333333,7 C12.1742825,7 13.6666666,8.49238416 13.6666666,10.3333333 L13.6666666,10.3333333 Z"
33
+ id="Path"
34
+ />
35
+ </g>
36
+ </g>
37
+ </svg>
38
+ );
39
+ }
40
+
41
+ export default SettingsIcon;
@@ -0,0 +1,62 @@
1
+ import React from 'react';
2
+ import { ICON_SIZE, ICON_COLOR } from '../constants';
3
+
4
+ function TaxonomyIcon({
5
+ width = ICON_SIZE.WIDTH,
6
+ height = ICON_SIZE.HEIGHT,
7
+ stroke = ICON_COLOR.STROKE
8
+ }) {
9
+ return (
10
+ <svg
11
+ width={width}
12
+ height={height}
13
+ viewBox="0 0 22 22"
14
+ version="1.1"
15
+ xmlns="http://www.w3.org/2000/svg"
16
+ xmlnsXlink="http://www.w3.org/1999/xlink">
17
+ <title>taxonomy</title>
18
+ <g
19
+ id="Page-1"
20
+ stroke="none"
21
+ strokeWidth="1"
22
+ fill="none"
23
+ fillRule="evenodd"
24
+ strokeLinecap="round"
25
+ strokeLinejoin="round">
26
+ <g id="Group" transform="translate(1, 1)" stroke={stroke}>
27
+ <rect
28
+ id="Rectangle"
29
+ x="0"
30
+ y="13.2173913"
31
+ width="6.78260868"
32
+ height="6.60869564"
33
+ rx="1.5"
34
+ />
35
+ <rect
36
+ id="Rectangle"
37
+ x="13.2173913"
38
+ y="13.2173913"
39
+ width="6.78260868"
40
+ height="6.60869564"
41
+ rx="1.5"
42
+ />
43
+ <rect
44
+ id="Rectangle"
45
+ x="6.60869564"
46
+ y="0"
47
+ width="6.78260868"
48
+ height="6.60869564"
49
+ rx="1.5"
50
+ />
51
+ <path
52
+ d="M3.30434782,13.2173913 L3.30434782,12.115942 C3.30434782,10.8993147 4.2906191,9.91304346 5.50724637,9.91304346 L14.3188405,9.91304346 C15.5354678,9.91304346 16.5217391,10.8993147 16.5217391,12.115942 L16.5217391,13.2173913"
53
+ id="Path"
54
+ />
55
+ <line x1="9.91304346" y1="6.60869564" x2="9.91304346" y2="9.91304346" id="Path" />
56
+ </g>
57
+ </g>
58
+ </svg>
59
+ );
60
+ }
61
+
62
+ export default TaxonomyIcon;