Skip to content

Commit e449f8d

Browse files
committed
fix: fixed bug in generation of the xml
Refs: #7
1 parent b1adbff commit e449f8d

File tree

5 files changed

+95
-230
lines changed

5 files changed

+95
-230
lines changed

example/src/App.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React, {useState, useMemo, memo} from "react";
2-
import {useDymoCheckService, useDymoFetchPrinters, useDymoOpenLabel} from "react-dymo-hooks";
1+
import React, { useState, useMemo, memo } from "react";
2+
import { useDymoCheckService, useDymoFetchPrinters, useDymoOpenLabel } from "react-dymo-hooks";
33

4-
import {generateXmlExample} from "./utils";
4+
import { generateXmlExample } from "./utils";
55

6-
const DymoLabelPreview = memo(({xml, statusDymoService, loadingComponent, errorComponent}) => {
7-
const {label, statusOpenLabel} = useDymoOpenLabel(statusDymoService, xml);
8-
const style = {background: "hsla(0, 0%, 50%, 0.66)", padding: 7};
6+
7+
const DymoLabelPreview = memo(({ xml, statusDymoService, loadingComponent, errorComponent }) => {
8+
const { label, statusOpenLabel } = useDymoOpenLabel(statusDymoService, xml);
9+
const style = { background: "hsla(0, 0%, 50%, 0.66)", padding: 7 };
910
if (statusOpenLabel === "loading") {
1011
return loadingComponent;
1112
} else if (statusOpenLabel === "error") {
@@ -22,21 +23,19 @@ const DymoLabelPreview = memo(({xml, statusDymoService, loadingComponent, errorC
2223
export default function App() {
2324
const statusDymoService = useDymoCheckService();
2425
const [name, setName] = useState("Antonio Peña Batista");
25-
const [address, setAddress] = useState("Headquarters 1120 N Street Sacramento");
26-
const {statusFetchPrinters, printers} = useDymoFetchPrinters(statusDymoService);
26+
const { statusFetchPrinters, printers } = useDymoFetchPrinters(statusDymoService);
2727

28-
const xmlMemo = useMemo(() => generateXmlExample(name, address), [address, name]);
28+
const xmlMemo = useMemo(() => generateXmlExample(name), [name]);
2929
return (
3030
<div>
3131
{statusDymoService === "loading" && <h1>Checking dymo web service...</h1>}
3232
{statusDymoService === "error" && <h1>Error</h1>}
3333
{statusDymoService === "success" && (
3434
<React.Fragment>
35-
<h3 style={{color: "green"}}>DYMO service is running in your PC.</h3>
35+
<h3 style={{ color: "green" }}>DYMO service is running in your PC.</h3>
3636
<input value={name} title="Name" onChange={(e) => setName(e.target.value)} />
3737
<br />
3838
<br />
39-
<input value={address} title="Address" onChange={(e) => setAddress(e.target.value)} />
4039
<br />
4140
<br />
4241
</React.Fragment>

example/src/utils.js

Lines changed: 38 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,41 @@
1-
export function generateXmlExample(dymoName = "Prueba", dymoAddress = "Prueba") {
1+
export function generateXmlExample(dymoName = "Your name") {
22
var labelXml = `<?xml version="1.0" encoding="utf-8"?>
3-
<DieCutLabel Version="8.0" Units="twips" MediaType="Default">
4-
<PaperOrientation>Landscape</PaperOrientation>
5-
<Id>Storage</Id>
6-
<PaperName>30258 Diskette</PaperName>
7-
<DrawCommands>
8-
<RoundRectangle X="0" Y="0" Width="3060" Height="3960" Rx="370" Ry="370"/>
9-
</DrawCommands>
10-
<ObjectInfo>
11-
<TextObject>
12-
<Name>Practice name (label)</Name>
13-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
14-
<BackColor Alpha="0" Red="255" Green="255" Blue="255"/>
15-
<LinkedObjectName></LinkedObjectName>
16-
<Rotation>Rotation0</Rotation>
17-
<IsMirrored>False</IsMirrored>
18-
<IsVariable>False</IsVariable>
19-
<HorizontalAlignment>Left</HorizontalAlignment>
20-
<VerticalAlignment>Top</VerticalAlignment>
21-
<TextFitMode>None</TextFitMode>
22-
<UseFullFontHeight>False</UseFullFontHeight>
23-
<Verticalized>False</Verticalized>
24-
<StyledText>
25-
<Element>
26-
<String>${dymoName}</String>
27-
<Attributes>
28-
<Font Family="Courier" Size="9" Bold="False" Italic="False" Underline="False" Strikeout="False"/>
29-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
30-
</Attributes>
31-
</Element>
32-
</StyledText>
33-
</TextObject>
34-
<Bounds X="316.7999" Y="129.6" Width="3484.8" Height="230.4"/>
35-
</ObjectInfo>
36-
<ObjectInfo>
37-
<TextObject>
38-
<Name>Office address where visit happened</Name>
39-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
40-
<BackColor Alpha="0" Red="255" Green="255" Blue="255"/>
41-
<LinkedObjectName></LinkedObjectName>
42-
<Rotation>Rotation0</Rotation>
43-
<IsMirrored>False</IsMirrored>
44-
<IsVariable>False</IsVariable>
45-
<HorizontalAlignment>Left</HorizontalAlignment>
46-
<VerticalAlignment>Top</VerticalAlignment>
47-
<TextFitMode>None</TextFitMode>
48-
<UseFullFontHeight>False</UseFullFontHeight>
49-
<Verticalized>False</Verticalized>
50-
<StyledText>
51-
<Element>
52-
<String>${dymoAddress}</String>
53-
<Attributes>
54-
<Font Family="Courier" Size="9" Bold="False" Italic="False" Underline="False" Strikeout="False"/>
55-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
56-
</Attributes>
57-
</Element>
58-
</StyledText>
59-
</TextObject>
60-
<Bounds X="316.7999" Y="360" Width="3484.8" Height="230.4"/>
61-
</ObjectInfo>
62-
<ObjectInfo>
63-
<TextObject>
64-
<Name>Patient Name</Name>
65-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
66-
<BackColor Alpha="0" Red="255" Green="255" Blue="255"/>
67-
<LinkedObjectName></LinkedObjectName>
68-
<Rotation>Rotation0</Rotation>
69-
<IsMirrored>False</IsMirrored>
70-
<IsVariable>False</IsVariable>
71-
<HorizontalAlignment>Left</HorizontalAlignment>
72-
<VerticalAlignment>Top</VerticalAlignment>
73-
<TextFitMode>None</TextFitMode>
74-
<UseFullFontHeight>False</UseFullFontHeight>
75-
<Verticalized>False</Verticalized>
76-
<StyledText>
77-
<Element>
78-
<String>Jesse I. Fernandez</String>
79-
<Attributes>
80-
<Font Family="Courier" Size="10" Bold="True" Italic="False" Underline="False" Strikeout="False"/>
81-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
82-
</Attributes>
83-
</Element>
84-
</StyledText>
85-
</TextObject>
86-
<Bounds X="316.7999" Y="1046.278" Width="3484.8" Height="259.2"/>
87-
</ObjectInfo>
88-
<ObjectInfo>
89-
<ShapeObject>
90-
<Name>SHAPE</Name>
91-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
92-
<BackColor Alpha="0" Red="255" Green="255" Blue="255"/>
93-
<LinkedObjectName></LinkedObjectName>
94-
<Rotation>Rotation0</Rotation>
95-
<IsMirrored>False</IsMirrored>
96-
<IsVariable>False</IsVariable>
97-
<ShapeType>HorizontalLine</ShapeType>
98-
<LineWidth>20</LineWidth>
99-
<LineAlignment>LeftOrTop</LineAlignment>
100-
<FillColor Alpha="0" Red="0" Green="0" Blue="0"/>
101-
</ShapeObject>
102-
<Bounds X="317.8156" Y="2148.055" Width="3384" Height="144"/>
103-
</ObjectInfo>
104-
<ObjectInfo>
105-
<TextObject>
106-
<Name>User Dosage Instructions</Name>
107-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
108-
<BackColor Alpha="0" Red="255" Green="255" Blue="255"/>
109-
<LinkedObjectName></LinkedObjectName>
110-
<Rotation>Rotation0</Rotation>
111-
<IsMirrored>False</IsMirrored>
112-
<IsVariable>False</IsVariable>
113-
<HorizontalAlignment>Left</HorizontalAlignment>
114-
<VerticalAlignment>Top</VerticalAlignment>
115-
<TextFitMode>None</TextFitMode>
116-
<UseFullFontHeight>False</UseFullFontHeight>
117-
<Verticalized>False</Verticalized>
118-
<StyledText>
119-
<Element>
120-
<String>This is a test note generated
121-
for the preview of the labe
122-
</String>
123-
<Attributes>
124-
<Font Family="Courier" Size="9" Bold="False" Italic="False" Underline="False" Strikeout="False"/>
125-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
126-
</Attributes>
127-
</Element>
128-
</StyledText>
129-
</TextObject>
130-
<Bounds X="316.7999" Y="2447.37" Width="3484.8" Height="432"/>
131-
</ObjectInfo>
132-
<ObjectInfo>
133-
<TextObject>
134-
<Name>Office Phone Number</Name>
135-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
136-
<BackColor Alpha="0" Red="255" Green="255" Blue="255"/>
137-
<LinkedObjectName></LinkedObjectName>
138-
<Rotation>Rotation0</Rotation>
139-
<IsMirrored>False</IsMirrored>
140-
<IsVariable>False</IsVariable>
141-
<HorizontalAlignment>Left</HorizontalAlignment>
142-
<VerticalAlignment>Top</VerticalAlignment>
143-
<TextFitMode>None</TextFitMode>
144-
<UseFullFontHeight>False</UseFullFontHeight>
145-
<Verticalized>False</Verticalized>
146-
<StyledText>
147-
<Element>
148-
<String>(456) 839-7392</String>
149-
<Attributes>
150-
<Font Family="Courier" Size="9" Bold="False" Italic="False" Underline="False" Strikeout="False"/>
151-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
152-
</Attributes>
153-
</Element>
154-
</StyledText>
155-
</TextObject>
156-
<Bounds X="310.7999" Y="576" Width="1487.977" Height="201.6"/>
157-
</ObjectInfo>
158-
<ObjectInfo>
159-
<TextObject>
160-
<Name>Filled by practitioner</Name>
161-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
162-
<BackColor Alpha="0" Red="255" Green="255" Blue="255"/>
163-
<LinkedObjectName></LinkedObjectName>
164-
<Rotation>Rotation0</Rotation>
165-
<IsMirrored>False</IsMirrored>
166-
<IsVariable>False</IsVariable>
167-
<HorizontalAlignment>Left</HorizontalAlignment>
168-
<VerticalAlignment>Top</VerticalAlignment>
169-
<TextFitMode>None</TextFitMode>
170-
<UseFullFontHeight>False</UseFullFontHeight>
171-
<Verticalized>False</Verticalized>
172-
<StyledText>
173-
<Element>
174-
<String>Filled: 25/04/19</String>
175-
<Attributes>
176-
<Font Family="Courier" Size="9" Bold="False" Italic="False" Underline="False" Strikeout="False"/>
177-
<ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
178-
</Attributes>
179-
</Element>
180-
</StyledText>
181-
</TextObject>
182-
<Bounds X="1915.2" Y="576" Width="1872" Height="201.6"/>
183-
</ObjectInfo>
184-
</DieCutLabel>`;
3+
<DieCutLabel Version="8.0" Units="twips">
4+
<PaperOrientation>Landscape</PaperOrientation>
5+
<Id>Small30336</Id>
6+
<IsOutlined>false</IsOutlined>
7+
<PaperName>30336 1 in x 2-1/8 in</PaperName>
8+
<DrawCommands>
9+
<RoundRectangle X="0" Y="0" Width="1440" Height="3060" Rx="180" Ry="180" />
10+
</DrawCommands>
11+
<ObjectInfo>
12+
<TextObject>
13+
<Name>TEXT</Name>
14+
<ForeColor Alpha="255" Red="0" Green="0" Blue="0" />
15+
<BackColor Alpha="0" Red="255" Green="255" Blue="255" />
16+
<LinkedObjectName />
17+
<Rotation>Rotation0</Rotation>
18+
<IsMirrored>False</IsMirrored>
19+
<IsVariable>False</IsVariable>
20+
<GroupID>-1</GroupID>
21+
<IsOutlined>False</IsOutlined>
22+
<HorizontalAlignment>Center</HorizontalAlignment>
23+
<VerticalAlignment>Middle</VerticalAlignment>
24+
<TextFitMode>ShrinkToFit</TextFitMode>
25+
<UseFullFontHeight>True</UseFullFontHeight>
26+
<Verticalized>False</Verticalized>
27+
<StyledText>
28+
<Element>
29+
<String xml:space="preserve">${dymoName}</String>
30+
<Attributes>
31+
<Font Family="Arial" Size="12" Bold="False" Italic="False" Underline="False" Strikeout="False" />
32+
<ForeColor Alpha="255" Red="0" Green="0" Blue="0" HueScale="100" />
33+
</Attributes>
34+
</Element>
35+
</StyledText>
36+
</TextObject>
37+
<Bounds X="130" Y="300" Width="2846" Height="720" />
38+
</ObjectInfo>
39+
</DieCutLabel>`;
18540
return labelXml;
18641
}

example/yarn.lock

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,12 +2108,12 @@ aws4@^1.8.0:
21082108
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.10.0.tgz#a17b3a8ea811060e74d47d306122400ad4497ae2"
21092109
integrity sha512-3YDiu347mtVtjpyV3u5kVqQLP242c06zwDOgpeRnybmXlYYsLbtTrUBUm8i8srONt+FWobl5aibnU1030PeeuA==
21102110

2111-
axios@^0.19.2:
2112-
version "0.19.2"
2113-
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
2114-
integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==
2111+
axios@^0.21.1:
2112+
version "0.21.4"
2113+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
2114+
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
21152115
dependencies:
2116-
follow-redirects "1.5.10"
2116+
follow-redirects "^1.14.0"
21172117

21182118
axobject-query@^2.0.2:
21192119
version "2.1.2"
@@ -3444,13 +3444,6 @@ [email protected], debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9:
34443444
dependencies:
34453445
ms "2.0.0"
34463446

3447-
debug@=3.1.0:
3448-
version "3.1.0"
3449-
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
3450-
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
3451-
dependencies:
3452-
ms "2.0.0"
3453-
34543447
debug@^3.0.0, debug@^3.1.1, debug@^3.2.5:
34553448
version "3.2.6"
34563449
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
@@ -4513,20 +4506,18 @@ flush-write-stream@^1.0.0:
45134506
inherits "^2.0.3"
45144507
readable-stream "^2.3.6"
45154508

4516-
4517-
version "1.5.10"
4518-
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
4519-
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
4520-
dependencies:
4521-
debug "=3.1.0"
4522-
45234509
follow-redirects@^1.0.0:
45244510
version "1.11.0"
45254511
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.11.0.tgz#afa14f08ba12a52963140fe43212658897bc0ecb"
45264512
integrity sha512-KZm0V+ll8PfBrKwMzdo5D13b1bur9Iq9Zd/RMmAoQQcl2PxxFml8cxXPaaPYVbV0RjNjq1CU7zIzAOqtUPudmA==
45274513
dependencies:
45284514
debug "^3.0.0"
45294515

4516+
follow-redirects@^1.14.0:
4517+
version "1.14.8"
4518+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
4519+
integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==
4520+
45304521
for-in@^0.1.3:
45314522
version "0.1.8"
45324523
resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"
@@ -8510,6 +8501,16 @@ react-dev-utils@^10.2.1:
85108501
strip-ansi "6.0.0"
85118502
text-table "0.2.0"
85128503

8504+
react-dom@^16.13.1:
8505+
version "16.14.0"
8506+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.14.0.tgz#7ad838ec29a777fb3c75c3a190f661cf92ab8b89"
8507+
integrity sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==
8508+
dependencies:
8509+
loose-envify "^1.1.0"
8510+
object-assign "^4.1.1"
8511+
prop-types "^15.6.2"
8512+
scheduler "^0.19.1"
8513+
85138514
"react-dom@link:../node_modules/react-dom":
85148515
version "0.0.0"
85158516
uid ""
@@ -8537,6 +8538,15 @@ react-xml-parser@^1.1.6:
85378538
resolved "https://registry.yarnpkg.com/react-xml-parser/-/react-xml-parser-1.1.8.tgz#e0fd3a5aa3c6e50197eed72a05fe110a5df64307"
85388539
integrity sha512-yX9k9LNCRzzNnFWoyo9cWEjtor6n6VD0Uh7z1ww5rIP6h5vdhJKEmowsm9RumEJMRdr7akcT4mMBScpsz573qQ==
85398540

8541+
react@^16.13.1:
8542+
version "16.14.0"
8543+
resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d"
8544+
integrity sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==
8545+
dependencies:
8546+
loose-envify "^1.1.0"
8547+
object-assign "^4.1.1"
8548+
prop-types "^15.6.2"
8549+
85408550
"react@link:../node_modules/react":
85418551
version "0.0.0"
85428552
uid ""

src/dymo_utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
WS_SVC_PATH,
1111
WS_ACTIONS,
1212
} from "./constants";
13-
import {localRetrieve, localStore} from "./storage";
13+
import { localRetrieve, localStore } from "./storage";
1414

1515
async function storeDymoRequestParams() {
1616
let activeHost, activePort;
@@ -30,9 +30,9 @@ async function storeDymoRequestParams() {
3030
dymoUrlBuilder(WS_PROTOCOL, hostList[currentHostIndex], currentPort, WS_SVC_PATH, "status")
3131
);
3232
const [successRequestHost, successRequestPort] = response.config.url.split("/")[2].split(":");
33-
localStore("dymo-ws-request-params", {activeHost: successRequestHost, activePort: successRequestPort});
33+
localStore("dymo-ws-request-params", { activeHost: successRequestHost, activePort: successRequestPort });
3434
break loop1;
35-
} catch (error) {}
35+
} catch (error) { }
3636
}
3737
}
3838
}
@@ -48,7 +48,7 @@ export async function dymoRequestBuilder({
4848
if (!localRetrieve("dymo-ws-request-params")) {
4949
await storeDymoRequestParams();
5050
}
51-
const {activeHost, activePort} = localRetrieve("dymo-ws-request-params");
51+
const { activeHost, activePort } = localRetrieve("dymo-ws-request-params");
5252

5353
const dymoAxiosInstance = axios.create();
5454
dymoAxiosInstance.interceptors.response.use(
@@ -64,7 +64,7 @@ export async function dymoRequestBuilder({
6464
return Promise.reject(error);
6565
}
6666
try {
67-
const {activeHost, activePort} = localRetrieve("dymo-ws-request-params");
67+
const { activeHost, activePort } = localRetrieve("dymo-ws-request-params");
6868
const response = await axios.request({
6969
url: dymoUrlBuilder(wsProtocol, activeHost, activePort, wsPath, wsAction),
7070
method,

0 commit comments

Comments
 (0)