Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Copy to clipboard the record text (#1625)
This PR adds the "copy text" action in the extra actions menu, it also centralizes the "copy to clipboard" function and makes some small changes to the text Closes #1616 (cherry picked from commit 8db56ed)
- Loading branch information
1 parent
bef010c
commit d634a7b
Showing
12 changed files
with
122 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* coding=utf-8 | ||
* Copyright 2021-present, the Recognai S.L. team. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export default (context, inject) => { | ||
const copyToClipboard = function (text) { | ||
if (document.querySelector(".hidden-input")) { | ||
document.querySelector(".hidden-input").remove(); | ||
} | ||
const myTemporaryInputElement = document.createElement("textarea"); | ||
myTemporaryInputElement.className = "hidden-input"; | ||
myTemporaryInputElement.value = text; | ||
document.body.appendChild(myTemporaryInputElement); | ||
myTemporaryInputElement.select(); | ||
document.execCommand("Copy"); | ||
}; | ||
|
||
inject("copyToClipboard", copyToClipboard); | ||
}; |
34 changes: 34 additions & 0 deletions
34
frontend/specs/components/commons/results/RecordExtraAtions.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { mount } from "@vue/test-utils"; | ||
import RecordExtraActions from "@/components/commons/results/RecordExtraActions"; | ||
|
||
function mountRecordExtraActions() { | ||
return mount(RecordExtraActions, { | ||
idState() { | ||
return { | ||
open: true, | ||
}; | ||
}, | ||
propsData: { | ||
record: { | ||
metadata: { | ||
Metadata: "metadata example", | ||
}, | ||
status: "Validated", | ||
}, | ||
allowChangeStatus: true, | ||
dataset: { | ||
name: "Dataset1", | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
describe("RecordExtraActions", () => { | ||
let spy = jest.spyOn(console, "error"); | ||
afterEach(() => spy.mockReset()); | ||
|
||
test("renders properly", () => { | ||
const wrapper = mountRecordExtraActions(); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
frontend/specs/components/commons/results/__snapshots__/RecordExtraAtions.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`RecordExtraActions renders properly 1`] = ` | ||
<div class="record__extra-actions"><a href="#" class="extra-actions__button"><svg version="1.1" viewBox="0 0 41 40" class="svg-icon svg-fill" style="width: 20px; height: 20px;"> | ||
<path fill="#4A4A4A" stroke="none" pid="0" fill-rule="evenodd" clip-rule="evenodd" d="M20.5 5c1.114 0 1.956.297 2.527.89.57.593.855 1.457.855 2.59 0 1.095-.292 1.942-.875 2.542-.584.6-1.42.9-2.507.9-1.048 0-1.873-.304-2.477-.91-.604-.607-.905-1.45-.905-2.531 0-1.108.295-1.965.885-2.571.59-.607 1.423-.91 2.497-.91zm0 11.53c1.114 0 1.956.296 2.527.89.57.592.855 1.463.855 2.61 0 1.094-.292 1.941-.875 2.54-.584.6-1.42.9-2.507.9-1.048 0-1.873-.303-2.477-.909-.604-.607-.905-1.45-.905-2.531 0-1.121.295-1.985.885-2.591.59-.606 1.423-.91 2.497-.91zm0 11.548c1.114 0 1.956.297 2.527.89.57.594.855 1.457.855 2.591 0 1.094-.292 1.941-.875 2.541-.584.6-1.42.9-2.507.9-1.048 0-1.873-.303-2.477-.91-.604-.606-.905-1.45-.905-2.531 0-1.108.295-1.964.885-2.57.59-.607 1.423-.91 2.497-.91z" _fill="#000"></path> | ||
</svg></a> | ||
<div class="extra-actions__content"> | ||
<div><span>View metadata</span></div> | ||
<re-action-tooltip tooltip="Copied"> | ||
<div><span>Copy text</span></div> | ||
</re-action-tooltip> | ||
<div><span>Discard record</span></div> | ||
</div> | ||
</div> | ||
`; |