Skip to content

Commit 11ed050

Browse files
hlomzikniklubnikrobot-ci-heartex
authored
feat: DIA-2214: Add new Pdf object tag (#7460)
Co-authored-by: niklub <[email protected]> Co-authored-by: nik <[email protected]> Co-authored-by: robot-ci-heartex <[email protected]>
1 parent c338d44 commit 11ed050

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ dependencies = [
7373
"djangorestframework-simplejwt[crypto] (>=5.4.0,<6.0.0)",
7474
"tldextract (>=5.1.3)",
7575
## HumanSignal repo dependencies :start
76-
"label-studio-sdk @ https://github.com/HumanSignal/label-studio-sdk/archive/c4ed0b0240c4a5e9f372393f84fdea01abe33141.zip",
76+
"label-studio-sdk @ https://github.com/HumanSignal/label-studio-sdk/archive/856f396d0ad76c201630f086e8cad16ea0d8b568.zip",
7777
## HumanSignal repo dependencies :end
7878
]
7979

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { inject, observer } from "mobx-react";
2+
import { types } from "mobx-state-tree";
3+
4+
import Registry from "../../core/Registry";
5+
import { AnnotationMixin } from "../../mixins/AnnotationMixin";
6+
import ProcessAttrsMixin from "../../mixins/ProcessAttrs";
7+
import Base from "./Base";
8+
import { parseValue } from "../../utils/data";
9+
10+
/**
11+
* The `Pdf` tag is used to display a PDF document from a URL.
12+
* @example
13+
* <View>
14+
* <Pdf name="pdf-1" value="$pdf_url" />
15+
* </View>
16+
* @name Pdf
17+
* @meta_title Pdf Tag to Display PDF Documents
18+
* @meta_description Customize Label Studio by displaying PDF files in tasks for machine learning and data science projects.
19+
* @param {string} value Data field value containing the URL to the PDF
20+
*/
21+
const Model = types
22+
.model({
23+
type: "pdf",
24+
value: types.maybeNull(types.string),
25+
_url: types.maybeNull(types.string),
26+
})
27+
.actions((self) => ({
28+
updateValue(store) {
29+
// @todo check that the value is a valid URL and document exists
30+
self._url = parseValue(self.value, store.task.dataObj);
31+
},
32+
}));
33+
34+
const PdfModel = types.compose("PdfModel", Base, ProcessAttrsMixin, AnnotationMixin, Model);
35+
36+
const HtxPdf = inject("store")(
37+
observer(({ item }) => {
38+
if (!item._url) return null;
39+
return (
40+
<iframe
41+
src={item._url}
42+
title="PDF Document"
43+
style={{ width: "100%", height: "600px", border: "none" }}
44+
allowFullScreen
45+
/>
46+
);
47+
}),
48+
);
49+
50+
Registry.addTag("pdf", PdfModel, HtxPdf);
51+
Registry.addObjectType(PdfModel);
52+
53+
export { HtxPdf, PdfModel };

web/libs/editor/src/tags/object/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AudioModel } from "./AudioNext";
22
import { ImageModel } from "./Image";
33
import { ParagraphsModel } from "./Paragraphs";
4+
import { PdfModel } from "./Pdf";
45
import { RichTextModel } from "./RichText";
56
import { TableModel } from "./Table";
67
import { TimeSeriesModel } from "./TimeSeries";
@@ -22,4 +23,5 @@ export {
2223
TableModel,
2324
PagedViewModel,
2425
ListModel,
26+
PdfModel,
2527
};

web/libs/editor/src/tags/visual/View.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ const Model = types
119119
"pagedview",
120120
"paragraphs",
121121
"paragraphlabels",
122+
"pdf",
122123
"video",
123124
"videorectangle",
124125
"timelinelabels",

0 commit comments

Comments
 (0)