Skip to content

Commit 7819a11

Browse files
Copilothotlong
andcommitted
fix: address code review - simplify fallback logic and add error handling
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 2b1cca3 commit 7819a11

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

packages/plugin-detail/src/DetailView.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,17 @@ export const DetailView: React.FC<DetailViewProps> = ({
9595
setLoading(false);
9696
return;
9797
}
98-
// Fallback: if not found and resourceId starts with objectName prefix,
99-
// retry with the prefix stripped (handles legacy ID conventions)
100-
if (resourceId.startsWith(prefix)) {
101-
const strippedId = resourceId.slice(prefix.length);
102-
return dataSource.findOne(objectName, strippedId).then((fallbackResult) => {
103-
setData(fallbackResult);
104-
setLoading(false);
105-
});
106-
}
107-
// Fallback: if not found and resourceId does NOT have the prefix,
108-
// retry with the prefix prepended (handles bare IDs)
109-
if (!resourceId.startsWith(prefix)) {
110-
return dataSource.findOne(objectName, `${prefix}${resourceId}`).then((fallbackResult) => {
111-
setData(fallbackResult);
112-
setLoading(false);
113-
});
114-
}
115-
setData(null);
116-
setLoading(false);
98+
// Fallback: try alternate ID format for backward compatibility
99+
const altId = resourceId.startsWith(prefix)
100+
? resourceId.slice(prefix.length) // strip prefix
101+
: `${prefix}${resourceId}`; // prepend prefix
102+
return dataSource.findOne(objectName, altId).then((fallbackResult) => {
103+
setData(fallbackResult);
104+
setLoading(false);
105+
}).catch(() => {
106+
setData(null);
107+
setLoading(false);
108+
});
117109
}).catch((err) => {
118110
console.error('Failed to fetch detail data:', err);
119111
setLoading(false);

0 commit comments

Comments
 (0)