@blaze-cms/plugin-data-ui 0.146.0-rc-eagle-3.10 → 0.146.0-rc-eagle-3.11
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/lib/components/EntityManager/Entity/Entity.js +26 -1
- package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntityHeader/EntityHeader.js +14 -1
- package/lib/components/EntityManager/Entity/EntityHeader/EntityHeader.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js +16 -2
- package/lib/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js.map +1 -1
- package/lib/components/EntityManager/utils/entity.js +22 -1
- package/lib/components/EntityManager/utils/entity.js.map +1 -1
- package/lib/constants.js +3 -1
- package/lib/constants.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/Entity.js +29 -4
- package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/EntityHeader/EntityHeader.js +14 -1
- package/lib-es/components/EntityManager/Entity/EntityHeader/EntityHeader.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js +16 -2
- package/lib-es/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js.map +1 -1
- package/lib-es/components/EntityManager/utils/entity.js +23 -3
- package/lib-es/components/EntityManager/utils/entity.js.map +1 -1
- package/lib-es/constants.js +3 -1
- package/lib-es/constants.js.map +1 -1
- package/package.json +3 -3
- package/src/components/EntityManager/Entity/Entity.js +31 -5
- package/src/components/EntityManager/Entity/EntityHeader/EntityHeader.js +17 -1
- package/src/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js +19 -2
- package/src/components/EntityManager/utils/entity.js +28 -8
- package/src/constants.js +4 -0
|
@@ -5,7 +5,7 @@ import { useApolloClient } from '@apollo/client';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { RenderHook } from '@blaze-cms/plugin-render-hooks-ui';
|
|
7
7
|
import { getQuery } from '@blaze-cms/admin-ui-utils';
|
|
8
|
-
import { FormBuilder, parseFormValues } from '@blaze-cms/react-form-builder';
|
|
8
|
+
import { FormBuilder, parseFormValues, validate } from '@blaze-cms/react-form-builder';
|
|
9
9
|
import { DeleteAction, CopyDataFromAction } from '@blaze-cms/admin';
|
|
10
10
|
import { useToasts } from '@blaze-react/toaster';
|
|
11
11
|
import cloneDeep from 'lodash.clonedeep';
|
|
@@ -23,13 +23,17 @@ import {
|
|
|
23
23
|
PAGE_BUILDER_TEMPLATE_FIELD_ID,
|
|
24
24
|
ERROR,
|
|
25
25
|
SAVE_BUTTON_TEXTS,
|
|
26
|
-
UNPUBLISHED_WARNING
|
|
26
|
+
UNPUBLISHED_WARNING,
|
|
27
|
+
VIEW_UNPUBLISHED_REASON,
|
|
28
|
+
TITLE_FIELD_ID
|
|
27
29
|
} from '../../../constants';
|
|
28
30
|
import EntityHeader from './EntityHeader';
|
|
29
31
|
|
|
30
32
|
import {
|
|
31
33
|
validateSideBarRelations,
|
|
34
|
+
canEditTitle,
|
|
32
35
|
canViewPage,
|
|
36
|
+
hasViewableUrl,
|
|
33
37
|
onViewUrlClick,
|
|
34
38
|
getUpdatedFormValues,
|
|
35
39
|
checkFulfilConditions
|
|
@@ -407,9 +411,29 @@ const Entity = ({
|
|
|
407
411
|
|
|
408
412
|
const showModal = checkFulfilConditions(formData, modalStatus);
|
|
409
413
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
414
|
+
// Unpublished keeps the button, disabled with a reason, rather than hiding it.
|
|
415
|
+
const isViewable = canViewPage(entity, schema, entityIsPublished);
|
|
416
|
+
const onViewUrlHandler = isViewable ? () => onViewUrlClick(getFullUrl) : onViewUrl;
|
|
417
|
+
const viewUrlDisabledReason =
|
|
418
|
+
!isViewable && hasViewableUrl(entity, schema) ? VIEW_UNPUBLISHED_REASON : null;
|
|
419
|
+
|
|
420
|
+
const onTitleChange = value => {
|
|
421
|
+
if (!componentIsMounted.current) return;
|
|
422
|
+
const updatedFormValues = getUpdatedFormValues({ id: TITLE_FIELD_ID, value, formValues });
|
|
423
|
+
const [isValid, valuesChecked] = validate({
|
|
424
|
+
values: updatedFormValues,
|
|
425
|
+
schema,
|
|
426
|
+
currentField: TITLE_FIELD_ID
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
setFormValues(valuesChecked);
|
|
430
|
+
setPageTitle(value);
|
|
431
|
+
setIsFormValid(isValid);
|
|
432
|
+
setIsSaveButtonAvailable(isValid);
|
|
433
|
+
isValid && setSaveButtonText(SAVE_BUTTON_TEXTS.save);
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const onTitleChangeHandler = canEditTitle(schema, formValues) ? onTitleChange : null;
|
|
413
437
|
|
|
414
438
|
const pageName = formData && formData.values && formData.values.name;
|
|
415
439
|
|
|
@@ -434,6 +458,8 @@ const Entity = ({
|
|
|
434
458
|
toggleModal={setModalStatus}
|
|
435
459
|
formData={formData}
|
|
436
460
|
onViewUrl={onViewUrlHandler}
|
|
461
|
+
viewUrlDisabledReason={viewUrlDisabledReason}
|
|
462
|
+
onTitleChange={onTitleChangeHandler}
|
|
437
463
|
saveButtonText={saveButtonText}
|
|
438
464
|
saveOnChange={saveOnChange}
|
|
439
465
|
entitySchema={entitySchema}
|
|
@@ -22,6 +22,8 @@ const EntityHeader = ({
|
|
|
22
22
|
formData,
|
|
23
23
|
pageName,
|
|
24
24
|
onViewUrl,
|
|
25
|
+
viewUrlDisabledReason,
|
|
26
|
+
onTitleChange,
|
|
25
27
|
saveOnChange
|
|
26
28
|
}) => {
|
|
27
29
|
const SaveButtonModifiers = isSaveButtonAvailable ? ['small'] : ['small', 'disabled'];
|
|
@@ -36,7 +38,17 @@ const EntityHeader = ({
|
|
|
36
38
|
deleteAction.active && formData && Object.keys(formData.values).length !== 0;
|
|
37
39
|
|
|
38
40
|
return (
|
|
39
|
-
<PageHeader
|
|
41
|
+
<PageHeader
|
|
42
|
+
title={pageTitle}
|
|
43
|
+
pageName={pageName}
|
|
44
|
+
onViewUrl={onViewUrl}
|
|
45
|
+
viewUrlDisabledReason={viewUrlDisabledReason}
|
|
46
|
+
onTitleChange={onTitleChange}
|
|
47
|
+
titleActions={
|
|
48
|
+
showPreviewButton ? (
|
|
49
|
+
<HeaderPreviewButton itemId={entityData.id} itemEntity={entityIdentifier} iconOnly />
|
|
50
|
+
) : null
|
|
51
|
+
}>
|
|
40
52
|
<PageHeader.Actions>
|
|
41
53
|
{!saveOnChange && (
|
|
42
54
|
<Button onClick={onSubmit} modifiers={SaveButtonModifiers} data-testid="button-save">
|
|
@@ -96,6 +108,8 @@ EntityHeader.propTypes = {
|
|
|
96
108
|
toggleModal: PropTypes.func.isRequired,
|
|
97
109
|
formData: PropTypes.object,
|
|
98
110
|
onViewUrl: PropTypes.func.isRequired,
|
|
111
|
+
viewUrlDisabledReason: PropTypes.string,
|
|
112
|
+
onTitleChange: PropTypes.func,
|
|
99
113
|
saveButtonText: PropTypes.string,
|
|
100
114
|
saveOnChange: PropTypes.bool.isRequired
|
|
101
115
|
};
|
|
@@ -105,6 +119,8 @@ EntityHeader.defaultProps = {
|
|
|
105
119
|
entityIdentifier: '',
|
|
106
120
|
formData: null,
|
|
107
121
|
pageName: '',
|
|
122
|
+
viewUrlDisabledReason: null,
|
|
123
|
+
onTitleChange: null,
|
|
108
124
|
saveButtonText: 'save'
|
|
109
125
|
};
|
|
110
126
|
|
package/src/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import Button from '@blaze-react/button';
|
|
4
|
+
import { PageHeader } from '@blaze-cms/admin';
|
|
4
5
|
import { useMutation } from '@apollo/client';
|
|
5
6
|
import { getMutation } from '@blaze-cms/admin-ui-utils';
|
|
6
7
|
import { DEBUG_PARAM } from '../../../../../constants';
|
|
7
8
|
|
|
8
|
-
const HeaderPreviewButton = ({ itemId, itemEntity }) => {
|
|
9
|
+
const HeaderPreviewButton = ({ itemId, itemEntity, iconOnly }) => {
|
|
9
10
|
const [createPreviewToken] = useMutation(getMutation('PREVIEW_TOKEN_MUTATION'));
|
|
10
11
|
if (process.env.BLAZE_DISABLE_PREVIEW) return null;
|
|
11
12
|
|
|
@@ -35,6 +36,17 @@ const HeaderPreviewButton = ({ itemId, itemEntity }) => {
|
|
|
35
36
|
} catch (err) {}
|
|
36
37
|
};
|
|
37
38
|
|
|
39
|
+
if (iconOnly) {
|
|
40
|
+
return (
|
|
41
|
+
<PageHeader.IconButton
|
|
42
|
+
icon="visibility"
|
|
43
|
+
label="Preview"
|
|
44
|
+
onClick={onViewPreview}
|
|
45
|
+
data-testid="page-header-preview"
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
38
50
|
return (
|
|
39
51
|
<Button className="more-menu__link" onClick={onViewPreview}>
|
|
40
52
|
Preview
|
|
@@ -44,7 +56,12 @@ const HeaderPreviewButton = ({ itemId, itemEntity }) => {
|
|
|
44
56
|
|
|
45
57
|
HeaderPreviewButton.propTypes = {
|
|
46
58
|
itemId: PropTypes.string.isRequired,
|
|
47
|
-
itemEntity: PropTypes.string.isRequired
|
|
59
|
+
itemEntity: PropTypes.string.isRequired,
|
|
60
|
+
iconOnly: PropTypes.bool
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
HeaderPreviewButton.defaultProps = {
|
|
64
|
+
iconOnly: false
|
|
48
65
|
};
|
|
49
66
|
|
|
50
67
|
export default HeaderPreviewButton;
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEBUG_PARAM,
|
|
3
|
+
ENTITY_PUBLISHED,
|
|
4
|
+
SELECT_DEFAULT_VALUE,
|
|
5
|
+
TITLE_FIELD_ID
|
|
6
|
+
} from '../../../constants';
|
|
7
|
+
|
|
8
|
+
// Whether this record has a front end url at all, publish state aside.
|
|
9
|
+
function hasViewableUrl(entity, schema) {
|
|
10
|
+
return !!(entity && entity.id && schema && schema.id && schema.properties.slug);
|
|
11
|
+
}
|
|
2
12
|
|
|
3
13
|
function canViewPage(entity, schema, entityIsPublished) {
|
|
4
|
-
return (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
return hasViewableUrl(entity, schema) && entityIsPublished === ENTITY_PUBLISHED;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// The header title is only editable inline when it is the record's name field.
|
|
18
|
+
function canEditTitle(schema, formValues) {
|
|
19
|
+
const { properties = {}, displayProperties = {} } = schema || {};
|
|
20
|
+
const { adminHeader } = displayProperties || {};
|
|
21
|
+
const isTitleFromName =
|
|
22
|
+
!adminHeader || (adminHeader.length === 1 && adminHeader[0] === TITLE_FIELD_ID);
|
|
23
|
+
|
|
24
|
+
return !!(
|
|
25
|
+
isTitleFromName &&
|
|
26
|
+
properties[TITLE_FIELD_ID] &&
|
|
27
|
+
Array.isArray(formValues) &&
|
|
28
|
+
formValues.some(({ id }) => id === TITLE_FIELD_ID)
|
|
11
29
|
);
|
|
12
30
|
}
|
|
13
31
|
|
|
@@ -71,7 +89,9 @@ function checkFulfilConditions(...args) {
|
|
|
71
89
|
}
|
|
72
90
|
|
|
73
91
|
export {
|
|
92
|
+
canEditTitle,
|
|
74
93
|
canViewPage,
|
|
94
|
+
hasViewableUrl,
|
|
75
95
|
validateSideBarRelations,
|
|
76
96
|
onViewUrlClick,
|
|
77
97
|
getUpdatedFormValues,
|
package/src/constants.js
CHANGED
|
@@ -6,6 +6,7 @@ const ENTITY_PUBLISHED = 'published';
|
|
|
6
6
|
const SELECT_DEFAULT_VALUE = 'Please Choose...';
|
|
7
7
|
const LEAVE_PAGE_MESSAGE = 'You are going to leave without saving. Are you sure you want to leave?';
|
|
8
8
|
const KEY_TO_CHECK = 'values.slug';
|
|
9
|
+
const TITLE_FIELD_ID = 'name';
|
|
9
10
|
const MENU_PERMISSIONS = ['update:any', 'update:own', 'create:any', 'create:own'];
|
|
10
11
|
const PREVIEW_INTERFACE = 'preview/can-preview';
|
|
11
12
|
const PAGE_BUILDER_FIELD_ID = 'pageBuilder';
|
|
@@ -18,6 +19,7 @@ const SAVE_BUTTON_TEXTS = { save: 'save', saved: 'saved', saving: 'saving' };
|
|
|
18
19
|
const ACTIONS = 'actions';
|
|
19
20
|
const UNPUBLISHED_WARNING = 'Page already unpublished';
|
|
20
21
|
const PAGE_NOT_FOUND = 'Page not found';
|
|
22
|
+
const VIEW_UNPUBLISHED_REASON = 'Not published yet - publish to view it on the site';
|
|
21
23
|
const SAVE_BEFORE_PUBLISH_MESSAGE =
|
|
22
24
|
'You have to click save to create the record before you can publish';
|
|
23
25
|
|
|
@@ -46,6 +48,7 @@ export {
|
|
|
46
48
|
DEBUG_PARAM,
|
|
47
49
|
ENTITY_PUBLISHED,
|
|
48
50
|
KEY_TO_CHECK,
|
|
51
|
+
TITLE_FIELD_ID,
|
|
49
52
|
LEAVE_PAGE_MESSAGE,
|
|
50
53
|
MENU_PERMISSIONS,
|
|
51
54
|
PAGE_BUILDER,
|
|
@@ -70,6 +73,7 @@ export {
|
|
|
70
73
|
ICON_SIZE,
|
|
71
74
|
ICON_COLOR,
|
|
72
75
|
PAGE_NOT_FOUND,
|
|
76
|
+
VIEW_UNPUBLISHED_REASON,
|
|
73
77
|
ENTER_KEY,
|
|
74
78
|
DEFAULT_FILTER_OPTION_LABEL
|
|
75
79
|
};
|