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 all 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 { handleBatchError } from '../utils';

type Props = {
urns: string[];
Expand Down Expand Up @@ -35,7 +36,12 @@ 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 });
message.error(
handleBatchError(urns, e, {
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 { handleBatchError } from '../../../../utils';

type Props = {
urns: Array<string>;
Expand Down Expand Up @@ -30,7 +31,12 @@ 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 });
message.error(
handleBatchError(urns, e, {
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 { handleBatchError } from '../../../../utils';

type Props = {
urns: Array<string>;
Expand Down Expand Up @@ -32,10 +33,12 @@ 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,
});
message.error(
handleBatchError(urns, e, {
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 { handleBatchError } from '../../../../utils';

type Props = {
urns: Array<string>;
Expand Down Expand Up @@ -31,7 +32,12 @@ 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 });
message.error(
handleBatchError(urns, e, {
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 { handleBatchError } from '../../../../utils';

type Props = {
urns: string[];
Expand Down Expand Up @@ -135,7 +136,12 @@ 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 });
message.error(
handleBatchError(urns, e, {
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 { handleBatchError } from '../../../../utils';

const SelectInput = styled(Select)`
width: 480px;
Expand Down Expand Up @@ -244,7 +245,12 @@ export const EditOwnersModal = ({
} catch (e: unknown) {
message.destroy();
if (e instanceof Error) {
message.error({ content: `Failed to add owners: \n ${e.message || ''}`, duration: 3 });
message.error(
handleBatchError(urns, e, {
content: `Failed to add owners: \n ${e.message || ''}`,
duration: 3,
}),
);
}
} finally {
refetch?.();
Expand All @@ -267,7 +273,12 @@ export const EditOwnersModal = ({
} catch (e: unknown) {
message.destroy();
if (e instanceof Error) {
message.error({ content: `Failed to remove owners: \n ${e.message || ''}`, duration: 3 });
message.error(
handleBatchError(urns, e, {
content: `Failed to remove owners: \n ${e.message || ''}`,
duration: 3,
}),
);
}
} finally {
refetch?.();
Expand Down
15 changes: 13 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 { handleBatchError } from '../utils';

export enum EntityActionItem {
/**
Expand Down Expand Up @@ -59,7 +60,12 @@ function EntityActions(props: Props) {
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add glossary term: \n ${e.message || ''}`, duration: 3 });
message.error(
handleBatchError(entityUrns, e, {
content: `Failed to add glossary term: \n ${e.message || ''}`,
duration: 3,
}),
);
});
};

Expand Down Expand Up @@ -90,7 +96,12 @@ function EntityActions(props: Props) {
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add assets to Domain: \n ${e.message || ''}`, duration: 3 });
message.error(
handleBatchError(entityUrns, e, {
content: `Failed to add assets to Domain: \n ${e.message || ''}`,
duration: 3,
}),
);
});
};

Expand Down
21 changes: 21 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,24 @@ export const getMatchPrioritizingPrimary = (

return fromQueryGetBestMatch(matchesThatShouldBeShownOnFE, query);
};

function 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;
}

export const handleBatchError = (urns, e, defaultMessage) => {
if (urns.length > 1 && getGraphqlErrorCode(e) === 403) {
return {
content:
'Your bulk edit selection included entities that you are unauthorized to update. The bulk edit being performed will not be saved.',
duration: 3,
};
}
return defaultMessage;
};
18 changes: 13 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, handleBatchError } from '../../entity/shared/utils';
import { TagTermLabel } from './TagTermLabel';
import { ENTER_KEY_CODE } from '../constants';

Expand Down Expand Up @@ -267,7 +267,9 @@ export default function EditTagTermsModal({
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add: \n ${e.message || ''}`, duration: 3 });
message.error(
handleBatchError(urns, e, { content: `Failed to add: \n ${e.message || ''}`, duration: 3 }),
);
})
.finally(() => {
setDisableAction(false);
Expand Down Expand Up @@ -295,7 +297,9 @@ export default function EditTagTermsModal({
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to add: \n ${e.message || ''}`, duration: 3 });
message.error(
handleBatchError(urns, e, { content: `Failed to add: \n ${e.message || ''}`, duration: 3 }),
);
})
.finally(() => {
setDisableAction(false);
Expand Down Expand Up @@ -323,7 +327,9 @@ export default function EditTagTermsModal({
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to remove: \n ${e.message || ''}`, duration: 3 });
message.error(
handleBatchError(urns, e, { content: `Failed to remove: \n ${e.message || ''}`, duration: 3 }),
);
})
.finally(() => {
setDisableAction(false);
Expand Down Expand Up @@ -351,7 +357,9 @@ export default function EditTagTermsModal({
})
.catch((e) => {
message.destroy();
message.error({ content: `Failed to remove: \n ${e.message || ''}`, duration: 3 });
message.error(
handleBatchError(urns, e, { content: `Failed to remove: \n ${e.message || ''}`, duration: 3 }),
);
})
.finally(() => {
setDisableAction(false);
Expand Down
8 changes: 7 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 { handleBatchError } from '../../entity/shared/utils';

type CreateTagModalProps = {
visible: boolean;
Expand Down Expand Up @@ -50,7 +51,12 @@ 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 });
message.error(
handleBatchError(resources, e, {
content: `Failed to add tag: \n ${e.message || ''}`,
duration: 3,
}),
);
onClose();
})
.finally(() => {
Expand Down