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

feat(ui) - Add a custom error message for bulk edit to add clarity #6775

Merged
merged 6 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Button, DatePicker, Form, Input, message, Modal } from 'antd';
import { useBatchUpdateDeprecationMutation } from '../../../../graphql/mutations.generated';
import { getGraphqlErrorCode } from '../utils';

type Props = {
urns: string[];
Expand Down Expand Up @@ -35,7 +36,15 @@ export const UpdateDeprecationModal = ({ urns, onClose, refetch }: Props) => {
} catch (e: unknown) {
message.destroy();
if (e instanceof Error) {
message.error({ content: `Failed to update Deprecation: \n ${e.message || ''}`, duration: 2 });
if (urns.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to update Deprecation: \n ${e.message || ''}`, duration: 2 });
}
}
}
refetch?.();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { message, Modal } from 'antd';
import React from 'react';
import { useBatchUpdateSoftDeletedMutation } from '../../../../../../../graphql/mutations.generated';
import ActionDropdown from './ActionDropdown';
import { getGraphqlErrorCode } from '../../../../utils';

type Props = {
urns: Array<string>;
Expand Down Expand Up @@ -30,7 +31,15 @@ export default function DeleteDropdown({ urns, disabled = false, refetch }: Prop
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to delete assets: \n ${e.message || ''}`, duration: 3 });
if (urns.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to delete assets: \n ${e.message || ''}`, duration: 3 });
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useState } from 'react';
import { useBatchUpdateDeprecationMutation } from '../../../../../../../graphql/mutations.generated';
import { UpdateDeprecationModal } from '../../../../EntityDropdown/UpdateDeprecationModal';
import ActionDropdown from './ActionDropdown';
import { getGraphqlErrorCode } from '../../../../utils';

type Props = {
urns: Array<string>;
Expand Down Expand Up @@ -32,10 +33,18 @@ export default function DeprecationDropdown({ urns, disabled = false, refetch }:
})
.catch((e) => {
message.destroy();
message.error({
content: `Failed to mark assets as un-deprecated: \n ${e.message || ''}`,
duration: 3,
});
if (urns.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({
content: `Failed to mark assets as un-deprecated: \n ${e.message || ''}`,
duration: 3,
});
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useState } from 'react';
import { useBatchSetDomainMutation } from '../../../../../../../graphql/mutations.generated';
import { SetDomainModal } from '../../../../containers/profile/sidebar/Domain/SetDomainModal';
import ActionDropdown from './ActionDropdown';
import { getGraphqlErrorCode } from '../../../../utils';

type Props = {
urns: Array<string>;
Expand Down Expand Up @@ -31,7 +32,18 @@ export default function DomainsDropdown({ urns, disabled = false, refetch }: Pro
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to remove assets from Domain: \n ${e.message || ''}`, duration: 3 });
if (urns.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({
content: `Failed to remove assets from Domain: \n ${e.message || ''}`,
duration: 3,
});
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useEntityRegistry } from '../../../../../../useEntityRegistry';
import { useEnterKeyListener } from '../../../../../../shared/useEnterKeyListener';
import { useGetRecommendations } from '../../../../../../shared/recommendation';
import { DomainLabel } from '../../../../../../shared/DomainLabel';
import { getGraphqlErrorCode } from '../../../../utils';

type Props = {
urns: string[];
Expand Down Expand Up @@ -135,7 +136,15 @@ export const SetDomainModal = ({ urns, onCloseModal, refetch, defaultValue, onOk
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add assets to Domain: \n ${e.message || ''}`, duration: 3 });
if (urns.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to add assets to Domain: \n ${e.message || ''}`, duration: 3 });
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { useGetSearchResultsLazyQuery } from '../../../../../../../graphql/search.generated';
import { useGetRecommendations } from '../../../../../../shared/recommendation';
import { OwnerLabel } from '../../../../../../shared/OwnerLabel';
import { getGraphqlErrorCode } from '../../../../utils';

const SelectInput = styled(Select)`
width: 480px;
Expand Down Expand Up @@ -244,7 +245,15 @@ export const EditOwnersModal = ({
} catch (e: unknown) {
message.destroy();
if (e instanceof Error) {
message.error({ content: `Failed to add owners: \n ${e.message || ''}`, duration: 3 });
if (urns.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to add owners: \n ${e.message || ''}`, duration: 3 });
}
}
} finally {
refetch?.();
Expand All @@ -267,7 +276,15 @@ export const EditOwnersModal = ({
} catch (e: unknown) {
message.destroy();
if (e instanceof Error) {
message.error({ content: `Failed to remove owners: \n ${e.message || ''}`, duration: 3 });
if (urns.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to remove owners: \n ${e.message || ''}`, duration: 3 });
}
}
} finally {
refetch?.();
Expand Down
21 changes: 19 additions & 2 deletions datahub-web-react/src/app/entity/shared/entity/EntityActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SearchSelectModal } from '../components/styled/search/SearchSelectModal
import { useEntityRegistry } from '../../../useEntityRegistry';
import { EntityCapabilityType } from '../../Entity';
import { useBatchAddTermsMutation, useBatchSetDomainMutation } from '../../../../graphql/mutations.generated';
import { getGraphqlErrorCode } from '../utils';

export enum EntityActionItem {
/**
Expand Down Expand Up @@ -59,7 +60,15 @@ function EntityActions(props: Props) {
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add glossary term: \n ${e.message || ''}`, duration: 3 });
if (entityUrns.length > 0 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to add glossary term: \n ${e.message || ''}`, duration: 3 });
}
});
};

Expand Down Expand Up @@ -90,7 +99,15 @@ function EntityActions(props: Props) {
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add assets to Domain: \n ${e.message || ''}`, duration: 3 });
if (entityUrns.length > 0 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to add assets to Domain: \n ${e.message || ''}`, duration: 3 });
}
});
};

Expand Down
10 changes: 10 additions & 0 deletions datahub-web-react/src/app/entity/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,13 @@ export const getMatchPrioritizingPrimary = (

return fromQueryGetBestMatch(matchesThatShouldBeShownOnFE, query);
};

export const getGraphqlErrorCode = (e) => {
if (e.graphQLErrors && e.graphQLErrors.length) {
const firstError = e.graphQLErrors[0];
const { extensions } = firstError;
const errorCode = extensions && (extensions.code as number);
return errorCode;
}
return undefined;
};
42 changes: 37 additions & 5 deletions datahub-web-react/src/app/shared/tags/AddTagsTermsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import GlossaryBrowser from '../../glossary/GlossaryBrowser/GlossaryBrowser';
import ClickOutside from '../ClickOutside';
import { useEntityRegistry } from '../../useEntityRegistry';
import { useGetRecommendations } from '../recommendation';
import { FORBIDDEN_URN_CHARS_REGEX } from '../../entity/shared/utils';
import { FORBIDDEN_URN_CHARS_REGEX, getGraphqlErrorCode } from '../../entity/shared/utils';
import { TagTermLabel } from './TagTermLabel';
import { ENTER_KEY_CODE } from '../constants';

Expand Down Expand Up @@ -267,7 +267,15 @@ export default function EditTagTermsModal({
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add: \n ${e.message || ''}`, duration: 3 });
if (resources.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to add: \n ${e.message || ''}`, duration: 3 });
}
})
.finally(() => {
setDisableAction(false);
Expand Down Expand Up @@ -295,7 +303,15 @@ export default function EditTagTermsModal({
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add: \n ${e.message || ''}`, duration: 3 });
if (resources.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to add: \n ${e.message || ''}`, duration: 3 });
}
})
.finally(() => {
setDisableAction(false);
Expand Down Expand Up @@ -323,7 +339,15 @@ export default function EditTagTermsModal({
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to remove: \n ${e.message || ''}`, duration: 3 });
if (resources.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to remove: \n ${e.message || ''}`, duration: 3 });
}
})
.finally(() => {
setDisableAction(false);
Expand Down Expand Up @@ -351,7 +375,15 @@ export default function EditTagTermsModal({
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to remove: \n ${e.message || ''}`, duration: 3 });
if (resources.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
mkamalas marked this conversation as resolved.
Show resolved Hide resolved
duration: 3,
});
} else {
message.error({ content: `Failed to remove: \n ${e.message || ''}`, duration: 3 });
}
})
.finally(() => {
setDisableAction(false);
Expand Down
11 changes: 10 additions & 1 deletion datahub-web-react/src/app/shared/tags/CreateTagModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useBatchAddTagsMutation } from '../../../graphql/mutations.generated';
import { useCreateTagMutation } from '../../../graphql/tag.generated';
import { ResourceRefInput } from '../../../types.generated';
import { useEnterKeyListener } from '../useEnterKeyListener';
import { getGraphqlErrorCode } from '../../entity/shared/utils';

type CreateTagModalProps = {
visible: boolean;
Expand Down Expand Up @@ -50,7 +51,15 @@ export default function CreateTagModal({ onClose, onBack, visible, tagName, reso
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add tag: \n ${e.message || ''}`, duration: 3 });
if (resources.length > 1 && getGraphqlErrorCode(e) === 403) {
message.error({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be more than just datasets - I don't think this specific of an error message will do in this place

content:
'Your bulk edit selection included entities that you do not own. The bulk edit being performed will not be saved.',
duration: 3,
});
} else {
message.error({ content: `Failed to add tag: \n ${e.message || ''}`, duration: 3 });
}
onClose();
})
.finally(() => {
Expand Down