mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-23 00:18:06 +00:00
Fix UI Error Handling on Topic entity page (#3615)
This commit is contained in:
parent
9c71754b25
commit
6ce65141a2
@ -41,6 +41,7 @@ const jsonData = {
|
|||||||
'fetch-table-details-error': 'Error while fetching table details!',
|
'fetch-table-details-error': 'Error while fetching table details!',
|
||||||
'fetch-table-queries-error': 'Error while fetching table queries!',
|
'fetch-table-queries-error': 'Error while fetching table queries!',
|
||||||
'fetch-tags-error': 'Error while fetching tags!',
|
'fetch-tags-error': 'Error while fetching tags!',
|
||||||
|
'fetch-topic-details-error': 'Error while fetching topic details!',
|
||||||
|
|
||||||
'update-owner-error': 'Error while updating owner',
|
'update-owner-error': 'Error while updating owner',
|
||||||
|
|
||||||
|
@ -585,8 +585,6 @@ const DatasetDetailsPage: FunctionComponent = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: move all the error from below code to en.ts and use handleShowErrorToast to show error.
|
|
||||||
|
|
||||||
const followTable = () => {
|
const followTable = () => {
|
||||||
addFollower(tableId, USERId)
|
addFollower(tableId, USERId)
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
|
@ -44,11 +44,6 @@ import {
|
|||||||
getTopicDetailsPath,
|
getTopicDetailsPath,
|
||||||
getVersionPath,
|
getVersionPath,
|
||||||
} from '../../constants/constants';
|
} from '../../constants/constants';
|
||||||
import {
|
|
||||||
onConfirmText,
|
|
||||||
onErrorText,
|
|
||||||
onUpdatedConversastionError,
|
|
||||||
} from '../../constants/feed.constants';
|
|
||||||
import { EntityType, TabSpecificField } from '../../enums/entity.enum';
|
import { EntityType, TabSpecificField } from '../../enums/entity.enum';
|
||||||
import { ServiceCategory } from '../../enums/service.enum';
|
import { ServiceCategory } from '../../enums/service.enum';
|
||||||
import { CreateThread } from '../../generated/api/feed/createThread';
|
import { CreateThread } from '../../generated/api/feed/createThread';
|
||||||
@ -56,6 +51,7 @@ import { Topic } from '../../generated/entity/data/topic';
|
|||||||
import { User } from '../../generated/entity/teams/user';
|
import { User } from '../../generated/entity/teams/user';
|
||||||
import { TagLabel } from '../../generated/type/tagLabel';
|
import { TagLabel } from '../../generated/type/tagLabel';
|
||||||
import useToastContext from '../../hooks/useToastContext';
|
import useToastContext from '../../hooks/useToastContext';
|
||||||
|
import jsonData from '../../jsons/en';
|
||||||
import {
|
import {
|
||||||
addToRecentViewed,
|
addToRecentViewed,
|
||||||
getCurrentUserId,
|
getCurrentUserId,
|
||||||
@ -121,13 +117,38 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleShowErrorToast = (errMessage: string) => {
|
||||||
|
showToast({
|
||||||
|
variant: 'error',
|
||||||
|
body: errMessage,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleShowSuccessToast = (message: string) => {
|
||||||
|
showToast({
|
||||||
|
variant: 'success',
|
||||||
|
body: message,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const getEntityFeedCount = () => {
|
const getEntityFeedCount = () => {
|
||||||
getFeedCount(getEntityFeedLink(EntityType.TOPIC, topicFQN)).then(
|
getFeedCount(getEntityFeedLink(EntityType.TOPIC, topicFQN))
|
||||||
(res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
|
if (res.data) {
|
||||||
setFeedCount(res.data.totalCount);
|
setFeedCount(res.data.totalCount);
|
||||||
setEntityFieldThreadCount(res.data.counts);
|
setEntityFieldThreadCount(res.data.counts);
|
||||||
}
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['fetch-entity-feed-count-error']
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err: AxiosError) => {
|
||||||
|
const errMsg =
|
||||||
|
err.response?.data?.message ||
|
||||||
|
jsonData['api-error-messages']['fetch-entity-feed-count-error'];
|
||||||
|
handleShowErrorToast(errMsg);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchActivityFeed = () => {
|
const fetchActivityFeed = () => {
|
||||||
@ -135,26 +156,23 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
getAllFeeds(getEntityFeedLink(EntityType.TOPIC, topicFQN))
|
getAllFeeds(getEntityFeedLink(EntityType.TOPIC, topicFQN))
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
const { data } = res.data;
|
const { data } = res.data;
|
||||||
|
if (data) {
|
||||||
setEntityThread(data);
|
setEntityThread(data);
|
||||||
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['fetch-entity-feed-error']
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((err: AxiosError) => {
|
||||||
showToast({
|
const errMsg =
|
||||||
variant: 'error',
|
err.response?.data?.message ||
|
||||||
body: 'Error while fetching entity feeds',
|
jsonData['api-error-messages']['fetch-entity-feed-error'];
|
||||||
});
|
handleShowErrorToast(errMsg);
|
||||||
})
|
})
|
||||||
.finally(() => setIsentityThreadLoading(false));
|
.finally(() => setIsentityThreadLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (topicDetailsTabs[activeTab - 1].path !== tab) {
|
|
||||||
setActiveTab(getCurrentTopicTab(tab));
|
|
||||||
}
|
|
||||||
if (TabSpecificField.ACTIVITY_FEED === tab) {
|
|
||||||
fetchActivityFeed();
|
|
||||||
}
|
|
||||||
}, [tab]);
|
|
||||||
|
|
||||||
const saveUpdatedTopicData = (updatedData: Topic): Promise<AxiosResponse> => {
|
const saveUpdatedTopicData = (updatedData: Topic): Promise<AxiosResponse> => {
|
||||||
const jsonPatch = compare(topicDetails, updatedData);
|
const jsonPatch = compare(topicDetails, updatedData);
|
||||||
|
|
||||||
@ -168,6 +186,7 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
getTopicByFqn(topicFQN, ['owner', 'followers', 'tags'])
|
getTopicByFqn(topicFQN, ['owner', 'followers', 'tags'])
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
|
if (res.data) {
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
deleted,
|
deleted,
|
||||||
@ -229,19 +248,24 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
serviceType: serviceType,
|
serviceType: serviceType,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
});
|
});
|
||||||
setLoading(false);
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['fetch-table-details-error']
|
||||||
|
);
|
||||||
|
setIsError(true);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
if (err.response?.status === 404) {
|
if (err.response?.status === 404) {
|
||||||
setIsError(true);
|
setIsError(true);
|
||||||
} else {
|
} else {
|
||||||
const errMsg = err.message || 'Error while fetching topic details';
|
const errMsg =
|
||||||
showToast({
|
err.response?.data?.message ||
|
||||||
variant: 'error',
|
jsonData['api-error-messages']['fetch-topic-details-error'];
|
||||||
body: errMsg,
|
handleShowErrorToast(errMsg);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -249,54 +273,67 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
const followTopic = () => {
|
const followTopic = () => {
|
||||||
addFollower(topicId, USERId)
|
addFollower(topicId, USERId)
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
|
if (res.data) {
|
||||||
const { newValue } = res.data.changeDescription.fieldsAdded[0];
|
const { newValue } = res.data.changeDescription.fieldsAdded[0];
|
||||||
|
|
||||||
setFollowers([...followers, ...newValue]);
|
setFollowers([...followers, ...newValue]);
|
||||||
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['update-entity-follow-error']
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
const errMsg =
|
const errMsg =
|
||||||
err.response?.data.message || 'Error while following entity.';
|
err.response?.data?.message ||
|
||||||
showToast({
|
jsonData['api-error-messages']['update-entity-follow-error'];
|
||||||
variant: 'error',
|
handleShowErrorToast(errMsg);
|
||||||
body: errMsg,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const unfollowTopic = () => {
|
const unfollowTopic = () => {
|
||||||
removeFollower(topicId, USERId)
|
removeFollower(topicId, USERId)
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
|
if (res.data) {
|
||||||
const { oldValue } = res.data.changeDescription.fieldsDeleted[0];
|
const { oldValue } = res.data.changeDescription.fieldsDeleted[0];
|
||||||
|
|
||||||
setFollowers(
|
setFollowers(
|
||||||
followers.filter((follower) => follower.id !== oldValue[0].id)
|
followers.filter((follower) => follower.id !== oldValue[0].id)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['update-entity-unfollow-error']
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
const errMsg =
|
const errMsg =
|
||||||
err.response?.data.message || 'Error while unfollowing entity.';
|
err.response?.data?.message ||
|
||||||
showToast({
|
jsonData['api-error-messages']['update-entity-unfollow-error'];
|
||||||
variant: 'error',
|
handleShowErrorToast(errMsg);
|
||||||
body: errMsg,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const descriptionUpdateHandler = (updatedTopic: Topic) => {
|
const descriptionUpdateHandler = (updatedTopic: Topic) => {
|
||||||
saveUpdatedTopicData(updatedTopic)
|
saveUpdatedTopicData(updatedTopic)
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
|
if (res.data) {
|
||||||
const { description, version } = res.data;
|
const { description, version } = res.data;
|
||||||
setCurrentVersion(version);
|
setCurrentVersion(version);
|
||||||
setTopicDetails(res.data);
|
setTopicDetails(res.data);
|
||||||
setDescription(description);
|
setDescription(description);
|
||||||
getEntityFeedCount();
|
getEntityFeedCount();
|
||||||
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['update-description-error']
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
const errMsg =
|
const msg =
|
||||||
err.response?.data.message || 'Error while updating description.';
|
err.response?.data?.message ||
|
||||||
showToast({
|
jsonData['api-error-messages']['update-description-error'];
|
||||||
variant: 'error',
|
handleShowErrorToast(msg);
|
||||||
body: errMsg,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -304,21 +341,25 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
saveUpdatedTopicData(updatedTopic)
|
saveUpdatedTopicData(updatedTopic)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
if (res.data) {
|
||||||
setTopicDetails(res.data);
|
setTopicDetails(res.data);
|
||||||
setCurrentVersion(res.data.version);
|
setCurrentVersion(res.data.version);
|
||||||
setOwner(res.data.owner);
|
setOwner(res.data.owner);
|
||||||
setTier(getTierTags(res.data.tags));
|
setTier(getTierTags(res.data.tags));
|
||||||
getEntityFeedCount();
|
getEntityFeedCount();
|
||||||
resolve();
|
resolve();
|
||||||
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['update-entity-error']
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
const errMsg =
|
const msg =
|
||||||
err.response?.data.message || 'Error while updating entity.';
|
err.response?.data?.message ||
|
||||||
|
jsonData['api-error-messages']['update-entity-error'];
|
||||||
|
handleShowErrorToast(msg);
|
||||||
reject();
|
reject();
|
||||||
showToast({
|
|
||||||
variant: 'error',
|
|
||||||
body: errMsg,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -326,18 +367,22 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
const onTagUpdate = (updatedTopic: Topic) => {
|
const onTagUpdate = (updatedTopic: Topic) => {
|
||||||
saveUpdatedTopicData(updatedTopic)
|
saveUpdatedTopicData(updatedTopic)
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
|
if (res.data) {
|
||||||
setTier(getTierTags(res.data.tags));
|
setTier(getTierTags(res.data.tags));
|
||||||
setCurrentVersion(res.data.version);
|
setCurrentVersion(res.data.version);
|
||||||
setTags(getTagsWithoutTier(res.data.tags));
|
setTags(getTagsWithoutTier(res.data.tags));
|
||||||
getEntityFeedCount();
|
getEntityFeedCount();
|
||||||
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['update-tags-error']
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
const errMsg =
|
const errMsg =
|
||||||
err.response?.data.message || 'Error while updating tags.';
|
err.response?.data?.message ||
|
||||||
showToast({
|
jsonData['api-error-messages']['update-tags-error'];
|
||||||
variant: 'error',
|
handleShowErrorToast(errMsg);
|
||||||
body: errMsg,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -367,31 +412,41 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
getEntityFeedCount();
|
||||||
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['add-feed-error']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((err: AxiosError) => {
|
||||||
showToast({
|
const errMsg =
|
||||||
variant: 'error',
|
err.response?.data?.message ||
|
||||||
body: 'Error while posting feed',
|
jsonData['api-error-messages']['add-feed-error'];
|
||||||
});
|
handleShowErrorToast(errMsg);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const createThread = (data: CreateThread) => {
|
const createThread = (data: CreateThread) => {
|
||||||
postThread(data)
|
postThread(data)
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
|
if (res.data) {
|
||||||
setEntityThread((pre) => [...pre, res.data]);
|
setEntityThread((pre) => [...pre, res.data]);
|
||||||
getEntityFeedCount();
|
getEntityFeedCount();
|
||||||
showToast({
|
handleShowSuccessToast(
|
||||||
variant: 'success',
|
jsonData['api-success-messages']['create-conversation']
|
||||||
body: 'Conversation created successfully',
|
);
|
||||||
});
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages']['create-conversation-error']
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((err: AxiosError) => {
|
||||||
showToast({
|
const errMsg =
|
||||||
variant: 'error',
|
err.response?.data?.message ||
|
||||||
body: 'Error while creating the conversation',
|
jsonData['api-error-messages']['create-conversation-error'];
|
||||||
});
|
handleShowErrorToast(errMsg);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -400,6 +455,7 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
getUpdatedThread(threadId)
|
getUpdatedThread(threadId)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
if (data) {
|
||||||
setEntityThread((pre) => {
|
setEntityThread((pre) => {
|
||||||
return pre.map((thread) => {
|
return pre.map((thread) => {
|
||||||
if (thread.id === data.id) {
|
if (thread.id === data.id) {
|
||||||
@ -413,26 +469,44 @@ const TopicDetailsPage: FunctionComponent = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
handleShowErrorToast(
|
||||||
|
jsonData['api-error-messages'][
|
||||||
|
'fetch-updated-conversation-error'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error: AxiosError) => {
|
||||||
const message = error?.message;
|
const message =
|
||||||
showToast({
|
error?.response?.data?.message ||
|
||||||
variant: 'error',
|
jsonData['api-error-messages'][
|
||||||
body: message ?? onUpdatedConversastionError,
|
'fetch-updated-conversation-error'
|
||||||
});
|
];
|
||||||
|
handleShowErrorToast(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
showToast({
|
handleShowSuccessToast(
|
||||||
variant: 'success',
|
jsonData['api-success-messages']['delete-message']
|
||||||
body: onConfirmText,
|
);
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error: AxiosError) => {
|
||||||
const message = error?.message;
|
const message =
|
||||||
showToast({ variant: 'error', body: message ?? onErrorText });
|
error?.response?.data?.message ||
|
||||||
|
jsonData['api-error-messages']['delete-message-error'];
|
||||||
|
handleShowErrorToast(message);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (topicDetailsTabs[activeTab - 1].path !== tab) {
|
||||||
|
setActiveTab(getCurrentTopicTab(tab));
|
||||||
|
}
|
||||||
|
if (TabSpecificField.ACTIVITY_FEED === tab) {
|
||||||
|
fetchActivityFeed();
|
||||||
|
}
|
||||||
|
}, [tab]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getEntityFeedCount();
|
getEntityFeedCount();
|
||||||
}, []);
|
}, []);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user