@blaze-cms/plugin-data-ui 0.130.0-admin-updates.2 → 0.130.0-project-admin-customisations.2
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.
- package/CHANGELOG.md +20 -13
- package/README.md +42 -0
- package/lib/components/EntityDataListing/EntityDataListing.js +3 -24
- package/lib/components/EntityDataListing/EntityDataListing.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +39 -0
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -0
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js +12 -0
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -0
- package/lib/components/EntityManager/Entity/Entity.js +15 -2
- package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +44 -0
- package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +1 -0
- package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +32 -0
- package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -0
- package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +45 -0
- package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -0
- package/lib/components/EntityManager/Entity/SideBarRelations/index.js +12 -2
- package/lib/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +38 -0
- package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -0
- package/lib/components/InfoBoxes/InfoBoxes.js +36 -0
- package/lib/components/InfoBoxes/InfoBoxes.js.map +1 -0
- package/lib/components/InfoBoxes/container/InfoBoxContainer.js +44 -0
- package/lib/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
- package/lib/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
- package/lib/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
- package/lib/components/InfoBoxes/hooks/useData.js +42 -0
- package/lib/components/InfoBoxes/hooks/useData.js.map +1 -0
- package/lib/components/InfoBoxes/hooks/useInfoBox.js +26 -0
- package/lib/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
- package/lib/components/InfoBoxes/index.js +12 -0
- package/lib/components/InfoBoxes/index.js.map +1 -0
- package/lib/components/InfoBoxes/presentational/InfoBox.js +46 -0
- package/lib/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
- package/lib/components/ListingTable/ListingTable.js +14 -32
- package/lib/components/ListingTable/ListingTable.js.map +1 -1
- package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js +9 -14
- package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
- package/lib/components/ListingTable/mappers/populate-rows.js +92 -26
- package/lib/components/ListingTable/mappers/populate-rows.js.map +1 -1
- package/lib/index.js +3 -11
- package/lib/index.js.map +1 -1
- package/lib/utils/add-content-menu-items.js +64 -13
- package/lib/utils/add-content-menu-items.js.map +1 -1
- package/lib-es/components/EntityDataListing/EntityDataListing.js +3 -14
- package/lib-es/components/EntityDataListing/EntityDataListing.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +30 -0
- package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -0
- package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js +3 -0
- package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -0
- package/lib-es/components/EntityManager/Entity/Entity.js +15 -2
- package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +30 -0
- package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +1 -0
- package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +26 -0
- package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -0
- package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +39 -0
- package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -0
- package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js +12 -2
- package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +24 -0
- package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -0
- package/lib-es/components/InfoBoxes/InfoBoxes.js +28 -0
- package/lib-es/components/InfoBoxes/InfoBoxes.js.map +1 -0
- package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js +30 -0
- package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
- package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
- package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
- package/lib-es/components/InfoBoxes/hooks/useData.js +37 -0
- package/lib-es/components/InfoBoxes/hooks/useData.js.map +1 -0
- package/lib-es/components/InfoBoxes/hooks/useInfoBox.js +19 -0
- package/lib-es/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
- package/lib-es/components/InfoBoxes/index.js +3 -0
- package/lib-es/components/InfoBoxes/index.js.map +1 -0
- package/lib-es/components/InfoBoxes/presentational/InfoBox.js +31 -0
- package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
- package/lib-es/components/ListingTable/ListingTable.js +14 -31
- package/lib-es/components/ListingTable/ListingTable.js.map +1 -1
- package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js +12 -15
- package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
- package/lib-es/components/ListingTable/mappers/populate-rows.js +76 -24
- package/lib-es/components/ListingTable/mappers/populate-rows.js.map +1 -1
- package/lib-es/index.js +1 -9
- package/lib-es/index.js.map +1 -1
- package/lib-es/utils/add-content-menu-items.js +49 -5
- package/lib-es/utils/add-content-menu-items.js.map +1 -1
- package/package.json +10 -9
- package/src/components/EntityDataListing/EntityDataListing.js +3 -12
- package/src/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +26 -0
- package/src/components/EntityManager/Entity/EntitiyNavLinks/index.js +3 -0
- package/src/components/EntityManager/Entity/Entity.js +9 -0
- package/src/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +22 -0
- package/src/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +33 -0
- package/src/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +28 -0
- package/src/components/EntityManager/Entity/SideBarRelations/index.js +34 -16
- package/src/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +33 -0
- package/src/components/InfoBoxes/InfoBoxes.js +24 -0
- package/src/components/InfoBoxes/container/InfoBoxContainer.js +22 -0
- package/src/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
- package/src/components/InfoBoxes/hooks/useData.js +20 -0
- package/src/components/InfoBoxes/hooks/useInfoBox.js +13 -0
- package/src/components/InfoBoxes/index.js +3 -0
- package/src/components/InfoBoxes/presentational/InfoBox.js +34 -0
- package/src/components/ListingTable/ListingTable.js +21 -22
- package/src/components/ListingTable/ListingTableContent/ListingTableContent.js +9 -18
- package/src/components/ListingTable/mappers/populate-rows.js +83 -18
- package/src/index.js +1 -8
- package/src/utils/add-content-menu-items.js +45 -3
package/src/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
const CustomSidebarInfo = ({ items, customSidebarInfoKey }) => {
|
|
5
|
+
if (!items) return null;
|
|
6
|
+
|
|
7
|
+
const customSidebarInfoItems = items.map(item =>
|
|
8
|
+
Object.values(item)
|
|
9
|
+
.map(info => {
|
|
10
|
+
if (!info.label || !info.value) return null;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<p>
|
|
14
|
+
{info.label}: <span>{info.value}</span>
|
|
15
|
+
</p>
|
|
16
|
+
);
|
|
17
|
+
})
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="custom-sidebar-info" key={customSidebarInfoKey}>
|
|
23
|
+
<div className="custom-sidebar-info--container">{customSidebarInfoItems}</div>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default CustomSidebarInfo;
|
|
29
|
+
|
|
30
|
+
CustomSidebarInfo.propTypes = {
|
|
31
|
+
customSidebarInfoKey: PropTypes.string.isRequired,
|
|
32
|
+
items: PropTypes.array.isRequired
|
|
33
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import InfoBoxContainer from './container/InfoBoxContainer';
|
|
4
|
+
|
|
5
|
+
const InfoBoxes = ({ id, schema }) => {
|
|
6
|
+
const {
|
|
7
|
+
displayProperties: { adminInfoBoxes = [] }
|
|
8
|
+
} = schema;
|
|
9
|
+
|
|
10
|
+
if (adminInfoBoxes.length <= 0) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return adminInfoBoxes.map(infoBox => (
|
|
15
|
+
<InfoBoxContainer id={id} schema={schema} key={infoBox.key} infoBox={infoBox} />
|
|
16
|
+
));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default InfoBoxes;
|
|
20
|
+
|
|
21
|
+
InfoBoxes.propTypes = {
|
|
22
|
+
id: PropTypes.string.isRequired,
|
|
23
|
+
schema: PropTypes.object.isRequired
|
|
24
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import useData from '../hooks/useData';
|
|
4
|
+
import InfoBox from '../presentational/InfoBox';
|
|
5
|
+
|
|
6
|
+
const InfoBoxContainer = ({ id, schema, infoBox }) => {
|
|
7
|
+
const { data } = useData({ id, schema, infoBox });
|
|
8
|
+
|
|
9
|
+
if (!data || !Object.keys(data) || Object.keys(data).length === 0) return null;
|
|
10
|
+
|
|
11
|
+
const items = Object.values(data).flatMap(item => Object.values(item));
|
|
12
|
+
|
|
13
|
+
return <InfoBox items={items} infoBoxKey={infoBox.key} />;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default InfoBoxContainer;
|
|
17
|
+
|
|
18
|
+
InfoBoxContainer.propTypes = {
|
|
19
|
+
id: PropTypes.string.isRequired,
|
|
20
|
+
infoBox: PropTypes.object.isRequired,
|
|
21
|
+
schema: PropTypes.object.isRequired
|
|
22
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { BlazeError } from '@blaze-cms/core-errors';
|
|
3
|
+
|
|
4
|
+
export default function buildDynamicQuery({ id, schema, infoBox }) {
|
|
5
|
+
if (!schema || !schema.actions || !schema.actions.get || !schema.properties) {
|
|
6
|
+
throw new BlazeError(
|
|
7
|
+
'DataEntity query requires get action, properties and fields from entity schema'
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const fields = `${infoBox.property} {
|
|
12
|
+
label
|
|
13
|
+
value
|
|
14
|
+
}`;
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
query: gql`query getInfoBoxData($id: String!){
|
|
18
|
+
${schema.actions.get}( id: $id ) {
|
|
19
|
+
id
|
|
20
|
+
${fields}
|
|
21
|
+
__typename
|
|
22
|
+
}
|
|
23
|
+
}`
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client';
|
|
2
|
+
import useInfoBoxData from './useInfoBox';
|
|
3
|
+
|
|
4
|
+
function useData({ id, schema, infoBox }) {
|
|
5
|
+
const { query } = useInfoBoxData({ id, schema, infoBox });
|
|
6
|
+
|
|
7
|
+
const infoBoxQuery =
|
|
8
|
+
query ||
|
|
9
|
+
gql`
|
|
10
|
+
query {
|
|
11
|
+
__typename
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
const { data = {}, loading, error } = useQuery(infoBoxQuery, { variables: { id }, skip: !query });
|
|
16
|
+
|
|
17
|
+
return { data: data.__typename !== 'Query' ? data : null, loading, error };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default useData;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import buildDynamicQuery from '../helpers/build-dynamic-query';
|
|
2
|
+
|
|
3
|
+
function useInfoBox({ id, schema, infoBox }) {
|
|
4
|
+
const { query } = buildDynamicQuery({
|
|
5
|
+
id,
|
|
6
|
+
schema,
|
|
7
|
+
infoBox
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
return { query: query || null };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default useInfoBox;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
const InfoBox = ({ items, infoBoxKey }) => {
|
|
5
|
+
if (!items) return null;
|
|
6
|
+
|
|
7
|
+
const infoBoxItems = items.map(item =>
|
|
8
|
+
Object.values(item)
|
|
9
|
+
.map(info => {
|
|
10
|
+
if (!info.label || !info.value) return null;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div className="info-box--item" key={`${infoBoxKey}-${info.label.toLowerCase()}`}>
|
|
14
|
+
<div className="info-box--label">{info.label}: </div>
|
|
15
|
+
<div className="info-box--value">{info.value}</div>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
})
|
|
19
|
+
.filter(Boolean)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<div className="info-box" key={infoBoxKey}>
|
|
24
|
+
<div className="info-box--container">{infoBoxItems}</div>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default InfoBox;
|
|
30
|
+
|
|
31
|
+
InfoBox.propTypes = {
|
|
32
|
+
infoBoxKey: PropTypes.string.isRequired,
|
|
33
|
+
items: PropTypes.array.isRequired
|
|
34
|
+
};
|
|
@@ -3,18 +3,17 @@ 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';
|
|
9
8
|
import ListingTableContent from './ListingTableContent';
|
|
10
9
|
import availableActions from '../EntityManager/Entity/actions-handlers';
|
|
11
10
|
import { fetchData } from './service';
|
|
12
|
-
import { populateRows, formatRows } from './mappers/populate-rows';
|
|
11
|
+
import { populateRows, formatRows, getParsedRowData } from './mappers/populate-rows';
|
|
13
12
|
import { getDefaultQueryParams } from '../../utils/get-default-query-params';
|
|
14
13
|
|
|
15
14
|
const OVER_SCAN_BUFFER = 10;
|
|
16
15
|
|
|
17
|
-
const ListingTable = ({ match, entitySchema
|
|
16
|
+
const ListingTable = ({ match, entitySchema }) => {
|
|
18
17
|
const [tableData, setTableData] = useState({});
|
|
19
18
|
const [modalStatus, setModalStatus] = useState(false);
|
|
20
19
|
const [itemToDelete, setItemToDelete] = useState({});
|
|
@@ -23,7 +22,6 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
|
|
|
23
22
|
const [verifiedRanges, setVerifiedRanges] = useState([]);
|
|
24
23
|
const queryParamsDefault = getDefaultQueryParams({ schema: entitySchema });
|
|
25
24
|
const [queryParams, setQueryParams] = useState(queryParamsDefault);
|
|
26
|
-
const { menuItems, setMenuItems } = useMainContext(MainContext);
|
|
27
25
|
const client = useApolloClient();
|
|
28
26
|
const { addToast } = useToasts();
|
|
29
27
|
|
|
@@ -47,6 +45,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
|
|
|
47
45
|
entitySchema,
|
|
48
46
|
rows: data
|
|
49
47
|
});
|
|
48
|
+
|
|
50
49
|
setTableData(populatedTable);
|
|
51
50
|
setPreviousSchema({ id: entitySchema.id });
|
|
52
51
|
}
|
|
@@ -55,17 +54,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
|
|
|
55
54
|
[client, entitySchema, match.url, previousSchema.id, queryParams] // eslint-disable-line react-hooks/exhaustive-deps
|
|
56
55
|
);
|
|
57
56
|
|
|
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
|
-
};
|
|
57
|
+
const onCloseCardPrompt = () => null;
|
|
69
58
|
|
|
70
59
|
const toggleModal = item => {
|
|
71
60
|
setModalStatus(!!item);
|
|
@@ -109,13 +98,19 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
|
|
|
109
98
|
queryParams: sortQueryParams
|
|
110
99
|
}
|
|
111
100
|
});
|
|
112
|
-
const { columns } = tableData;
|
|
101
|
+
const { columns, isEnquiry } = tableData;
|
|
113
102
|
const [firstColumn] = columns;
|
|
114
103
|
|
|
115
104
|
setTableData({
|
|
116
105
|
...tableData,
|
|
117
106
|
appliedSort: { [property]: direction },
|
|
118
|
-
rows: formatRows({
|
|
107
|
+
rows: formatRows({
|
|
108
|
+
rows: getParsedRowData(data),
|
|
109
|
+
url: match.url,
|
|
110
|
+
toggleModal,
|
|
111
|
+
firstColumn,
|
|
112
|
+
isEnquiry
|
|
113
|
+
})
|
|
119
114
|
});
|
|
120
115
|
};
|
|
121
116
|
|
|
@@ -137,7 +132,12 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
|
|
|
137
132
|
});
|
|
138
133
|
const updatedRows = [
|
|
139
134
|
...tableData.rows,
|
|
140
|
-
...formatRows({
|
|
135
|
+
...formatRows({
|
|
136
|
+
rows: getParsedRowData(data),
|
|
137
|
+
url: match.url,
|
|
138
|
+
toggleModal,
|
|
139
|
+
isEnquiry: tableData.isEnquiry
|
|
140
|
+
})
|
|
141
141
|
];
|
|
142
142
|
|
|
143
143
|
setVerifiedRanges([...verifiedRanges, loadIndex]);
|
|
@@ -151,6 +151,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
|
|
|
151
151
|
};
|
|
152
152
|
|
|
153
153
|
if (!tableData || !tableData.rows) return 'loading';
|
|
154
|
+
const showAddButton = !!tableData.rows.length && !tableData.isEnquiry;
|
|
154
155
|
|
|
155
156
|
return (
|
|
156
157
|
<div className="page">
|
|
@@ -162,7 +163,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
|
|
|
162
163
|
/>
|
|
163
164
|
)}
|
|
164
165
|
<PageHeader title={entitySchema.displayName} subtitle="">
|
|
165
|
-
{
|
|
166
|
+
{showAddButton && (
|
|
166
167
|
<Fragment>
|
|
167
168
|
<Link
|
|
168
169
|
data-testid="addEntity"
|
|
@@ -187,7 +188,6 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
|
|
|
187
188
|
onRenderItems={handleRenderedItems}
|
|
188
189
|
tableData={tableData}
|
|
189
190
|
onCloseCardPrompt={onCloseCardPrompt}
|
|
190
|
-
selectedMenuItem={selectedMenuItem}
|
|
191
191
|
scrollToIndex={scrollToIndex}
|
|
192
192
|
/>
|
|
193
193
|
</div>
|
|
@@ -195,8 +195,7 @@ const ListingTable = ({ match, entitySchema, selectedMenuItem }) => {
|
|
|
195
195
|
};
|
|
196
196
|
ListingTable.propTypes = {
|
|
197
197
|
entitySchema: PropTypes.object.isRequired,
|
|
198
|
-
match: PropTypes.object.isRequired
|
|
199
|
-
selectedMenuItem: PropTypes.object.isRequired
|
|
198
|
+
match: PropTypes.object.isRequired
|
|
200
199
|
};
|
|
201
200
|
|
|
202
201
|
export default withRouter(ListingTable);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Table from '@blaze-react/table';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import {
|
|
5
|
-
import { Link, withRouter } from 'react-router-dom';
|
|
4
|
+
import { withRouter } from 'react-router-dom';
|
|
6
5
|
|
|
7
6
|
const ListingTableContent = ({
|
|
8
7
|
tableData,
|
|
@@ -17,12 +16,14 @@ const ListingTableContent = ({
|
|
|
17
16
|
scrollToIndex
|
|
18
17
|
}) => {
|
|
19
18
|
const displayTable = tableData && tableData.rows && !!tableData.rows.length;
|
|
19
|
+
const { isEnquiry } = tableData;
|
|
20
|
+
const className = `page__content${isEnquiry ? ' array-table' : ''}`;
|
|
20
21
|
|
|
21
22
|
return (
|
|
22
23
|
<>
|
|
23
|
-
{displayTable
|
|
24
|
+
{displayTable && (
|
|
24
25
|
<>
|
|
25
|
-
<div className=
|
|
26
|
+
<div className={className}>
|
|
26
27
|
<Table
|
|
27
28
|
scrollToIndex={scrollToIndex}
|
|
28
29
|
onSort={onSort}
|
|
@@ -30,23 +31,12 @@ const ListingTableContent = ({
|
|
|
30
31
|
overScanBuffer={overScanBuffer}
|
|
31
32
|
onRenderItems={onRenderItems}
|
|
32
33
|
data={tableData}
|
|
33
|
-
checkboxes
|
|
34
|
+
checkboxes={!isEnquiry}
|
|
34
35
|
onSelect={handleSelect}
|
|
35
36
|
data-testid="listing-table-content"
|
|
36
37
|
/>
|
|
37
38
|
</div>
|
|
38
39
|
</>
|
|
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
40
|
)}
|
|
51
41
|
</>
|
|
52
42
|
);
|
|
@@ -55,7 +45,7 @@ const ListingTableContent = ({
|
|
|
55
45
|
ListingTableContent.propTypes = {
|
|
56
46
|
tableData: PropTypes.object.isRequired,
|
|
57
47
|
onCloseCardPrompt: PropTypes.func.isRequired,
|
|
58
|
-
selectedMenuItem: PropTypes.object
|
|
48
|
+
selectedMenuItem: PropTypes.object,
|
|
59
49
|
match: PropTypes.shape({
|
|
60
50
|
url: PropTypes.string
|
|
61
51
|
}).isRequired,
|
|
@@ -73,7 +63,8 @@ ListingTableContent.defaultProps = {
|
|
|
73
63
|
onClickRow: () => {},
|
|
74
64
|
overScanBuffer: 0,
|
|
75
65
|
scrollToIndex: 0,
|
|
76
|
-
onRenderItems: () => {}
|
|
66
|
+
onRenderItems: () => {},
|
|
67
|
+
selectedMenuItem: null
|
|
77
68
|
};
|
|
78
69
|
|
|
79
70
|
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
|
-
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 {
|
|
41
|
-
|
|
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 };
|
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
|
-
|
|
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
|
|
6
|
-
return async
|
|
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
|
-
|
|
55
|
+
menuItems[id] = {
|
|
56
|
+
label: displayName,
|
|
57
|
+
uri: `/data-listing/${id}`
|
|
58
|
+
};
|
|
19
59
|
});
|
|
60
|
+
|
|
61
|
+
addConfig(menuConfig);
|
|
20
62
|
};
|
|
21
63
|
}
|
|
22
64
|
|