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

ENH Change clear text to delete #155

Merged
merged 1 commit into from
Jan 9, 2024
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
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion client/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ if (typeof(ss) === 'undefined' || typeof(ss.i18n) === 'undefined') {
} else {
ss.i18n.addDictionary('en', {
"LinkField.SAVE_SUCCESS": "Saved link",
"LinkField.CONFIRM_ARCHIVE": "Archived link",
"LinkField.CONFIRM_DELETE": "Deleted link",
"LinkField.ARCHIVE_ERROR": "Failed to archive link",
"LinkField.DELETE_ERROR": "Failed to delete link",
"LinkField.ADD_LINK": "Add Link",
"LinkField.CLEAR": "Clear"
"LinkField.ARCHIVE": "Archive",
"LinkField.DELETE": "Delete"
});
}
5 changes: 4 additions & 1 deletion client/lang/src/en.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"LinkField.SAVE_SUCCESS": "Saved link",
"LinkField.CONFIRM_ARCHIVE": "Archived link",
"LinkField.CONFIRM_DELETE": "Deleted link",
"LinkField.ARCHIVE_ERROR": "Failed to archive link",
"LinkField.DELETE_ERROR": "Failed to delete link",
"LinkField.ADD_LINK": "Add Link",
"LinkField.CLEAR": "Clear",
"LinkField.ARCHIVE": "Archive",
"LinkField.DELETE": "Delete",
"LinkField.LINK_DRAFT_TITLE": "Link has draft changes",
"LinkField.LINK_DRAFT_LABEL": "Draft",
"LinkField.LINK_MODIFIED_TITLE": "Link has unpublished changes",
Expand Down
32 changes: 13 additions & 19 deletions client/src/components/LinkField/LinkField.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,34 +108,28 @@ const LinkField = ({
}

/**
* Update the component when the 'Clear' button in the LinkPicker is clicked
* Update the component when the 'Delete' button in the LinkPicker is clicked
*/
const onClear = (linkID) => {
const onDelete = (linkID) => {
let endpoint = `${Config.getSection(section).form.linkForm.deleteUrl}/${linkID}`;
const parsedURL = url.parse(endpoint);
const parsedQs = qs.parse(parsedURL.query);
parsedQs.ownerID = ownerID;
parsedQs.ownerClass = ownerClass;
parsedQs.ownerRelation = ownerRelation;
endpoint = url.format({ ...parsedURL, search: qs.stringify(parsedQs)});
const versionState = data[linkID]?.versionState || '';
const isVersioned = ['draft', 'modified', 'published'].includes(versionState);
const successText = isVersioned
? i18n._t('LinkField.ARCHIVE_SUCCESS', 'Archived link')
: i18n._t('LinkField.DELETE_SUCCESS', 'Deleted link');
const failedText = isVersioned
? i18n._t('LinkField.ARCHIVE_ERROR', 'Failed to archive link')
: i18n._t('LinkField.DELETE_ERROR', 'Failed to delete link');
// CSRF token 'X-SecurityID' headers needs to be present for destructive requests
backend.delete(endpoint, {}, { 'X-SecurityID': Config.get('SecurityID') })
.then(() => {
actions.toasts.success(
i18n._t(
'LinkField.DELETE_SUCCESS',
'Deleted link',
)
);
})
.catch(() => {
actions.toasts.error(
i18n._t(
'LinkField.DELETE_ERROR',
'Failed to delete link',
)
);
});
.then(() => actions.toasts.success(successText))
.catch(() => actions.toasts.error(failedText));

// update component state
const newData = {...data};
Expand Down Expand Up @@ -167,7 +161,7 @@ const LinkField = ({
description={data[linkID]?.description}
versionState={data[linkID]?.versionState}
typeTitle={type.title || ''}
onClear={onClear}
onDelete={onDelete}
onClick={() => { setEditingID(linkID); }}
canDelete={data[linkID]?.canDelete ? true : false}
/>);
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/LinkPicker/LinkPicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
}

&--unsaved::before,
&--unversioned::before,
&--published::before {
display: none;
}
Expand Down Expand Up @@ -126,7 +127,7 @@
padding-left: 3.5rem;
}

.link-picker__clear {
.link-picker__delete {
flex-grow: 0;
}

Expand Down
9 changes: 6 additions & 3 deletions client/src/components/LinkPicker/LinkPickerTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const LinkPickerTitle = ({
description,
versionState,
typeTitle,
onClear,
onDelete,
onClick,
canDelete
}) => {
Expand All @@ -47,6 +47,9 @@ const LinkPickerTitle = ({
classes[` link-picker__link--${versionState}`] = true;
}
const className = classnames(classes);
const deleteText = ['unversioned', 'unsaved'].includes(versionState)
? i18n._t('LinkField.DELETE', 'Delete')
: i18n._t('LinkField.ARCHIVE', 'Archive');
return <div className={className}>
<Button className="link-picker__button font-icon-link" color="secondary" onClick={stopPropagation(onClick)}>
<div className="link-picker__link-detail">
Expand All @@ -61,7 +64,7 @@ const LinkPickerTitle = ({
</div>
</Button>
{canDelete &&
<Button className="link-picker__clear" color="link" onClick={stopPropagation(() => onClear(id))}>{i18n._t('LinkField.CLEAR', 'Clear')}</Button>
<Button className="link-picker__delete" color="link" onClick={stopPropagation(() => onDelete(id))}>{deleteText}</Button>
}
</div>
};
Expand All @@ -72,7 +75,7 @@ LinkPickerTitle.propTypes = {
description: PropTypes.string,
versionState: PropTypes.string,
typeTitle: PropTypes.string.isRequired,
onClear: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
onClick: PropTypes.func.isRequired,
canDelete: PropTypes.bool.isRequired,
};
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/LinkPicker/tests/LinkPicker-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ onSelect.toString = () => 'onSelect';
const onEdit = action('onEdit');
onEdit.toString = () => 'onEdit';

const onClear = action('onClear');
onClear.toString = () => 'onClear';
const onDelete = action('onDelete');
onDelete.toString = () => 'onDelete';

const props = {
types,
onSelect,
onClear,
onDelete,
onEdit
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function makeProps(obj = {}) {
description: 'My description',
versionState: 'draft',
typeTitle: 'Phone',
onClear: () => {},
onDelete: () => {},
onClick: () => {},
...obj
};
Expand All @@ -22,13 +22,13 @@ test('LinkPickerTitle render() should display clear button if can delete', () =>
canDelete: true
})}
/>);
expect(container.querySelectorAll('.link-picker__clear')).toHaveLength(1);
expect(container.querySelectorAll('.link-picker__delete')).toHaveLength(1);
});

test('LinkPickerTitle render() should not display clear button if cannot delete', () => {
const { container } = render(<LinkPickerTitle {...makeProps({
canDelete: false
})}
/>);
expect(container.querySelectorAll('.link-picker__clear')).toHaveLength(0);
expect(container.querySelectorAll('.link-picker__delete')).toHaveLength(0);
});
2 changes: 1 addition & 1 deletion src/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function getVersionedState(): string
}
// Unversioned - links are saved in the modal so there is no 'dirty state' and
// when undversioned saved is the same thing as published
return 'published';
return 'unversioned';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Models/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function testGetVersionedState(): void
$link = Link::create(['Title' => '123']);
$this->assertEquals('unsaved', $link->getVersionedState());
$link->write();
$this->assertEquals('published', $link->getVersionedState());
$this->assertEquals('unversioned', $link->getVersionedState());
}

/**
Expand Down