@blaze-cms/plugin-data-ui 0.126.0 → 0.127.0-project-admin-customisations.1

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 (48) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -0
  3. package/lib/components/EntityManager/Entity/Entity.js +24 -18
  4. package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
  5. package/lib/components/EntityManager/Entity/SideBarRelations/index.js +12 -6
  6. package/lib/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  7. package/lib/components/InfoBoxes/InfoBoxes.js +36 -0
  8. package/lib/components/InfoBoxes/InfoBoxes.js.map +1 -0
  9. package/lib/components/InfoBoxes/container/InfoBoxContainer.js +44 -0
  10. package/lib/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  11. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  12. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  13. package/lib/components/InfoBoxes/hooks/useData.js +42 -0
  14. package/lib/components/InfoBoxes/hooks/useData.js.map +1 -0
  15. package/lib/components/InfoBoxes/hooks/useInfoBox.js +26 -0
  16. package/lib/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  17. package/lib/components/InfoBoxes/index.js +12 -0
  18. package/lib/components/InfoBoxes/index.js.map +1 -0
  19. package/lib/components/InfoBoxes/presentational/InfoBox.js +46 -0
  20. package/lib/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  21. package/lib-es/components/EntityManager/Entity/Entity.js +24 -18
  22. package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
  23. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js +13 -7
  24. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  25. package/lib-es/components/InfoBoxes/InfoBoxes.js +28 -0
  26. package/lib-es/components/InfoBoxes/InfoBoxes.js.map +1 -0
  27. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js +30 -0
  28. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  29. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js +24 -0
  30. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  31. package/lib-es/components/InfoBoxes/hooks/useData.js +37 -0
  32. package/lib-es/components/InfoBoxes/hooks/useData.js.map +1 -0
  33. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js +19 -0
  34. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  35. package/lib-es/components/InfoBoxes/index.js +3 -0
  36. package/lib-es/components/InfoBoxes/index.js.map +1 -0
  37. package/lib-es/components/InfoBoxes/presentational/InfoBox.js +31 -0
  38. package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  39. package/package.json +6 -6
  40. package/src/components/EntityManager/Entity/Entity.js +63 -59
  41. package/src/components/EntityManager/Entity/SideBarRelations/index.js +23 -9
  42. package/src/components/InfoBoxes/InfoBoxes.js +24 -0
  43. package/src/components/InfoBoxes/container/InfoBoxContainer.js +22 -0
  44. package/src/components/InfoBoxes/helpers/build-dynamic-query.js +24 -0
  45. package/src/components/InfoBoxes/hooks/useData.js +20 -0
  46. package/src/components/InfoBoxes/hooks/useInfoBox.js +13 -0
  47. package/src/components/InfoBoxes/index.js +3 -0
  48. package/src/components/InfoBoxes/presentational/InfoBox.js +34 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaze-cms/plugin-data-ui",
3
- "version": "0.126.0",
3
+ "version": "0.127.0-project-admin-customisations.1",
4
4
  "description": "Blaze plugin data ui",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-es/index.js",
@@ -27,12 +27,12 @@
27
27
  },
28
28
  "license": "GPL-3.0",
29
29
  "dependencies": {
30
- "@blaze-cms/admin-ui-utils": "^0.125.0",
30
+ "@blaze-cms/admin-ui-utils": "0.127.0-project-admin-customisations.0",
31
31
  "@blaze-cms/core-errors": "^0.118.0",
32
- "@blaze-cms/react-form-builder": "^0.125.0",
33
- "@blaze-cms/react-page-builder": "^0.126.0",
32
+ "@blaze-cms/react-form-builder": "0.127.0-project-admin-customisations.0",
33
+ "@blaze-cms/react-page-builder": "0.127.0-project-admin-customisations.0",
34
34
  "@blaze-cms/setup-ui": "^0.92.0",
35
- "@blaze-cms/versioning-ui": "^0.124.0",
35
+ "@blaze-cms/versioning-ui": "0.127.0-project-admin-customisations.0",
36
36
  "@blaze-react/button": "0.5.19",
37
37
  "@blaze-react/more": "0.5.19",
38
38
  "@blaze-react/multiselect": "0.6.6",
@@ -65,5 +65,5 @@
65
65
  "lib/*",
66
66
  "lib-es/*"
67
67
  ],
68
- "gitHead": "3426eb3c15ca8bf9c601ebfccff00ad695b9a83a"
68
+ "gitHead": "e4b28ef61ef99924bfbd026fd76159d6d5e27e50"
69
69
  }
@@ -34,6 +34,7 @@ import {
34
34
  checkFulfilConditions
35
35
  } from '../utils/entity';
36
36
  import useToggle from '../../../utils/hooks/useToggle';
37
+ import InfoBoxes from '../../InfoBoxes/InfoBoxes';
37
38
 
38
39
  const Entity = ({
39
40
  formData,
@@ -403,68 +404,71 @@ const Entity = ({
403
404
 
404
405
  return (
405
406
  <div className="page">
406
- <Prompt when={hasToDisplayPrompt} message={LEAVE_PAGE_MESSAGE} />
407
- {showModal && (
408
- <DeleteAction
409
- onClose={setModalStatus}
410
- deleteAction={onDelete}
411
- itemName={formData.values.name}
412
- />
413
- )}
414
- {copyModalStatus && (
415
- <CopyDataFromAction
416
- onClose={handleCopyDataFromClose}
417
- copyAction={onCopy}
418
- getFormData={getFormData}
419
- />
420
- )}
421
-
422
- <div className="row row--display-row">
423
- <div className="column column--three-quarters">
424
- <EntityHeader
425
- entityData={entityData}
426
- entityIdentifier={entityIdentifier}
427
- pageTitle={pageTitle}
428
- pageName={pageName}
429
- onSubmit={onSubmit}
430
- handlePublishAndUnpublish={handlePublishAndUnpublish}
431
- isSaveButtonAvailable={isSaveButtonAvailable}
432
- isEnablePublishButton={isEnablePublishButton}
433
- isEnablePreviewButton={isEnablePreviewButton}
434
- toggleCopyModal={setCopyModalStatus}
435
- toggleModal={setModalStatus}
436
- formData={formData}
437
- onViewUrl={onViewUrlHandler}
438
- saveButtonText={saveButtonText}
439
- />
440
-
441
- <div className="page__content">
442
- <div className="content">
443
- <Tabs
444
- enabled={showPageBuilderTabs}
445
- onTabChange={tabId => {
446
- client.writeQuery({
447
- query: GET_CURRENT_TAB_ID,
448
- data: { currentTabId: tabId }
449
- });
450
- setCurrentTabId(tabId);
451
- }}>
452
- <FormBuilder
453
- getIsFormValid={setIsFormValid}
454
- getFormValues={getFormValues}
455
- schema={schema}
456
- data={clonedFormData}
457
- onChange={onChangeFormValues}
458
- shouldCopyData={shouldCopyData}
459
- updateCopyData={updateCopyData}
460
- formValues={formValues}
461
- isNewEntity={isNewEntity}
462
- />
463
- </Tabs>
407
+ <EntityHeader
408
+ entityData={entityData}
409
+ entityIdentifier={entityIdentifier}
410
+ pageTitle={pageTitle}
411
+ pageName={pageName}
412
+ onSubmit={onSubmit}
413
+ handlePublishAndUnpublish={handlePublishAndUnpublish}
414
+ isSaveButtonAvailable={isSaveButtonAvailable}
415
+ isEnablePublishButton={isEnablePublishButton}
416
+ isEnablePreviewButton={isEnablePreviewButton}
417
+ toggleCopyModal={setCopyModalStatus}
418
+ toggleModal={setModalStatus}
419
+ formData={formData}
420
+ onViewUrl={onViewUrlHandler}
421
+ saveButtonText={saveButtonText}
422
+ />
423
+ <div className="page-wrapper__content">
424
+ <div className="tabs-wrapper tabs-wrapper__tab">
425
+ <Prompt when={hasToDisplayPrompt} message={LEAVE_PAGE_MESSAGE} />
426
+ {showModal && (
427
+ <DeleteAction
428
+ onClose={setModalStatus}
429
+ deleteAction={onDelete}
430
+ itemName={formData.values.name}
431
+ />
432
+ )}
433
+ {copyModalStatus && (
434
+ <CopyDataFromAction
435
+ onClose={handleCopyDataFromClose}
436
+ copyAction={onCopy}
437
+ getFormData={getFormData}
438
+ />
439
+ )}
440
+
441
+ <div className="page__content--fixed">
442
+ <div className="page__content">
443
+ <div className="content">
444
+ <InfoBoxes id={entity.id} schema={schema} />
445
+ <Tabs
446
+ enabled={showPageBuilderTabs}
447
+ onTabChange={tabId => {
448
+ client.writeQuery({
449
+ query: GET_CURRENT_TAB_ID,
450
+ data: { currentTabId: tabId }
451
+ });
452
+ setCurrentTabId(tabId);
453
+ }}>
454
+ <FormBuilder
455
+ getIsFormValid={setIsFormValid}
456
+ getFormValues={getFormValues}
457
+ schema={schema}
458
+ data={clonedFormData}
459
+ onChange={onChangeFormValues}
460
+ shouldCopyData={shouldCopyData}
461
+ updateCopyData={updateCopyData}
462
+ formValues={formValues}
463
+ isNewEntity={isNewEntity}
464
+ />
465
+ </Tabs>
466
+ </div>
464
467
  </div>
465
468
  </div>
466
469
  </div>
467
- <div className="column column--one-third">
470
+
471
+ <div className="column column--one-third page-sidebar">
468
472
  {showSideBarRelations && (
469
473
  <SideBarRelations
470
474
  entity={entity}
@@ -4,16 +4,21 @@ import uuidv1 from 'uuid/v1';
4
4
  import { useApolloClient } from '@apollo/client';
5
5
  import { getQuery } from '@blaze-cms/admin-ui-utils';
6
6
  import { formFieldTypes } from '@blaze-cms/react-form-builder';
7
- import Badge from '@blaze-react/badge';
7
+ import classnames from 'classnames';
8
8
  import { VersionsList } from '@blaze-cms/versioning-ui';
9
- import { PUBLISHED } from '../../../../constants';
9
+ import { PUBLISHED, UNPUBLISHED } from '../../../../constants';
10
10
 
11
11
  const SideBarRelations = ({ schema, onChange, formData, entity }) => {
12
12
  const { relation: RelationComponent } = formFieldTypes;
13
- const { formattedStatus, formattedUpdated, formattedCreated, formattedPublished } = formData;
13
+ const {
14
+ formattedStatus,
15
+ formattedUpdated,
16
+ formattedCreated,
17
+ formattedPublished,
18
+ status
19
+ } = formData;
14
20
  const client = useApolloClient();
15
21
  const [relationsComponents, setRelationsComponents] = useState(null);
16
-
17
22
  useEffect(
18
23
  () => {
19
24
  (async () => {
@@ -51,17 +56,26 @@ const SideBarRelations = ({ schema, onChange, formData, entity }) => {
51
56
  const { id: itemId } = entity;
52
57
  const { identifier: itemEntity, interfaces } = schema;
53
58
 
59
+ const statusClassName = classnames('sidebar__status__badge', {
60
+ 'sidebar__status__badge--published': status === PUBLISHED,
61
+ 'sidebar__status__badge--unpublished': status === UNPUBLISHED
62
+ });
63
+
54
64
  return (
55
65
  <div className="sidebar" data-testid="sideBarRelations-main-div">
56
66
  <div className="sidebar__content">
57
67
  {formattedCreated && (
58
68
  <div className="sidebar__status">
59
- {formattedStatus && (
60
- <Badge type="status" modifiers={formattedStatus}>
61
- {formattedStatus}
62
- {formattedStatus === PUBLISHED && `: ${formattedPublished}`}
63
- </Badge>
69
+ <div className="sidebar__status__wrapper">
70
+ <b>Status</b>
71
+ <span className={statusClassName}>{formattedStatus}</span>
72
+ </div>
73
+ {formattedStatus === PUBLISHED && (
74
+ <p>
75
+ {formattedStatus} on: <span> {formattedPublished}</span>
76
+ </p>
64
77
  )}
78
+
65
79
  <p>
66
80
  Created: <span>{formattedCreated}</span>
67
81
  </p>
@@ -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,24 @@
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
+ ${fields}
20
+ __typename
21
+ }
22
+ }`
23
+ };
24
+ }
@@ -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,3 @@
1
+ import InfoBoxes from './InfoBoxes';
2
+
3
+ export default InfoBoxes;
@@ -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
+ };