Skip to content

Commit

Permalink
Merged in bugfix/SHIBUI-2146-attribute-success-alert (pull request #589)
Browse files Browse the repository at this point in the history
Attribute edit/create/delete success alert

Approved-by: Dmitriy Kopylenko
Approved-by: Bill Smith
Former-commit-id: 795b8ef3b7478e8e707b31072021447313e81fdb
  • Loading branch information
rmathis committed Aug 12, 2022
2 parents 890ddec + fd30694 commit 0db13be
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ui/public/assets/schema/attribute/attribute.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"title": "label.entity-attribute-help",
"description": "tooltip.entity-attribute-help",
"type": "string",
"minLength": 1,
"minLength": 0,
"maxLength": 255
}
},
Expand Down
4 changes: 4 additions & 0 deletions ui/src/app/metadata/hoc/MetadataAttributes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react';
import { createNotificationAction, NotificationTypes, useNotificationDispatcher } from '../../notifications/hoc/Notifications';
import { useMetadataAttribute, useMetadataAttributes } from '../hooks/api';

export function MetadataAttributes ({children}) {

const dispatch = useNotificationDispatcher();

const { get, response } = useMetadataAttributes({
cachePolicy: 'no-cache'
});
Expand All @@ -24,6 +27,7 @@ export function MetadataAttributes ({children}) {
await del(`/${id}`);
if (attrApi.response.ok) {
loadAttributes();
dispatch(createNotificationAction(`Attribute deleted successfully`, NotificationTypes.SUCCESS, 5000));
}
}

Expand Down
9 changes: 7 additions & 2 deletions ui/src/app/metadata/new/NewAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useMetadataAttribute } from '../hooks/api';
import {CustomAttributeDefinition} from '../domain/attribute/CustomAttributeDefinition';
import MetadataSchema from '../hoc/MetadataSchema';
import { MetadataForm } from '../hoc/MetadataFormContext';
import { createNotificationAction, useNotificationDispatcher } from '../../notifications/hoc/Notifications';
import { createNotificationAction, NotificationTypes, useNotificationDispatcher } from '../../notifications/hoc/Notifications';

export function NewAttribute() {
const history = useHistory();
Expand All @@ -25,11 +25,16 @@ export function NewAttribute() {
const [blocking, setBlocking] = React.useState(false);

async function save(metadata) {
let toast;
const resp = await post(``, definition.parser(metadata));
if (response.ok) {
toast = createNotificationAction(`Added attribute successfully.`, NotificationTypes.SUCCESS);
gotoDetail({ refresh: true });
} else {
dispatch(createNotificationAction(`${resp.errorCode}: Unable to create attribute ... ${resp.errorMessage}`, 'danger', 5000));
toast = createNotificationAction(`${resp.errorCode}: Unable to create attribute ... ${resp.errorMessage}`, 'danger', 5000);
}
if (toast) {
dispatch(toast);
}
};

Expand Down
9 changes: 7 additions & 2 deletions ui/src/app/metadata/view/MetadataAttributeEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useMetadataAttribute } from '../hooks/api';
import { CustomAttributeDefinition, CustomAttributeEditor } from '../domain/attribute/CustomAttributeDefinition';
import MetadataSchema from '../hoc/MetadataSchema';
import { MetadataForm } from '../hoc/MetadataFormContext';
import { createNotificationAction, useNotificationDispatcher } from '../../notifications/hoc/Notifications';
import { createNotificationAction, NotificationTypes, useNotificationDispatcher } from '../../notifications/hoc/Notifications';

export function MetadataAttributeEdit() {
const { id } = useParams();
Expand All @@ -35,11 +35,16 @@ export function MetadataAttributeEdit() {
}

async function save(metadata) {
let toast;
const resp = await put(``, definition.parser(metadata));
if (response.ok) {
toast = createNotificationAction(`Updated attribute successfully.`, NotificationTypes.SUCCESS);
gotoDetail({ refresh: true });
} else {
dispatch(createNotificationAction(`${resp.errorCode}: Unable to edit attribute ... ${resp.errorMessage}`, 'danger', 5000));
toast = createNotificationAction(`${resp.errorCode}: Unable to edit attribute ... ${resp.errorMessage}`, 'danger', 5000);
}
if (toast) {
dispatch(toast);
}
};

Expand Down

0 comments on commit 0db13be

Please sign in to comment.