Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support emptyText for missing referenced entity as well on ReferenceField #7688

Closed
archfz opened this issue May 12, 2022 · 0 comments · Fixed by #7851
Closed

Support emptyText for missing referenced entity as well on ReferenceField #7688

archfz opened this issue May 12, 2022 · 0 comments · Fixed by #7851

Comments

@archfz
Copy link

archfz commented May 12, 2022

Is your feature request related to a problem? Please describe.
I want to display empty text in case where reference is set but the referenced entity is missing. This is easily a case in systems where soft deleting is allowed.

Describe the solution you'd like
For now I am using the same emptyText as is used in the same case where the reference is not set. This works for me, but maybe best is to have a separate prop. Here is the patch:

diff --git a/node_modules/ra-ui-materialui/esm/field/ReferenceField.js b/node_modules/ra-ui-materialui/esm/field/ReferenceField.js
index 3dc814e..f44ccae 100644
--- a/node_modules/ra-ui-materialui/esm/field/ReferenceField.js
+++ b/node_modules/ra-ui-materialui/esm/field/ReferenceField.js
@@ -85,7 +85,7 @@ var ReferenceField = function (props) {
     if (!isReferenceDeclared) {
         throw new Error("You must declare a <Resource name=\"" + props.reference + "\"> in order to use a <ReferenceField reference=\"" + props.reference + "\">");
     }
-    return get(record, source) == null ? (emptyText ? (React.createElement(Typography, { component: "span", variant: "body2" }, emptyText)) : null) : (React.createElement(NonEmptyReferenceField, __assign({}, rest, { record: record, source: source })));
+    return get(record, source) == null ? (emptyText ? (React.createElement(Typography, { component: "span", variant: "body2" }, emptyText)) : null) : (React.createElement(NonEmptyReferenceField, __assign({}, rest, { emptyText, record: record, source: source })));
 };
 ReferenceField.propTypes = {
     addLabel: PropTypes.bool,
@@ -157,7 +157,7 @@ export var ReferenceFieldView = function (props) {
         return React.createElement(LinearProgress, null);
     }
     if (!referenceRecord) {
-        return null;
+        return props.emptyText || null;
     }
     if (resourceLinkPath) {
         return (React.createElement(RecordContextProvider, { value: referenceRecord },

Describe alternatives you've considered
N\A

Additional context
N\A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants