Skip to content

Commit 3440cf4

Browse files
committed
fix(platform): element assemble: fix custom: now if new name exist, warn and not dispatch
1 parent d46dff9 commit 3440cf4

23 files changed

+4305
-6
lines changed

doc/1.3.0.org

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,11 @@ TODO update:
749749
# TODO editor loop will increase
750750

751751

752-
* TODO perf(editor): optimize editor loading
752+
# * TODO perf(editor): optimize editor loading
753753

754754

755755

756-
* TODO fix(platform): create input->set name to exist name->change name to other name: will create dupliate one
756+
* DONE fix(platform): create input->set name to exist name->change name to other name: will create dupliate one
757757

758758
* TODO perf(platform): code edit: if change code, not create monaco
759759

platform/frontend/src/external_layer/ui/app/assemble_space/components/element_assemble/utils/CustomCodeEditUtils.res

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,36 @@ open Antd
33
open AssembleSpaceType
44

55
module Method = {
6+
let _isNameExist = (name, customs) => {
7+
customs
8+
->Meta3dCommonlib.ListSt.find((custom: CommonType.custom) => {
9+
custom.name == name
10+
})
11+
->Meta3dCommonlib.OptionSt.isSome
12+
}
13+
614
let getNewCode = (
15+
service: service,
716
dispatch,
817
getNameFunc,
918
setCurrentCustomNameToGlobalFunc,
1019
buildUpdateActionFunc,
1120
name,
1221
newOriginCode,
1322
newTranspiledCode,
23+
customs,
1424
) => {
1525
let newTranspiledCode = newTranspiledCode->CodeEditUtils.convertTranspliedCodeToUMDCode
1626

1727
let newName = newTranspiledCode->getNameFunc->Meta3dCommonlib.OptionSt.getWithDefault(name)
1828

19-
setCurrentCustomNameToGlobalFunc(newName)
29+
_isNameExist(newName, customs)
30+
? service.console.warn(. {j`name:${newName}已经存在,请换个name`}, None)
31+
: {
32+
setCurrentCustomNameToGlobalFunc(newName)
2033

21-
dispatch(buildUpdateActionFunc(name, newName, newOriginCode, newTranspiledCode->Some))
34+
dispatch(buildUpdateActionFunc(name, newName, newOriginCode, newTranspiledCode->Some))
35+
}
2236
}
2337

2438
let getCode = (name, customs) => {
@@ -61,6 +75,7 @@ let make = (
6175
code={code}
6276
getNewCodeFunc={(newOriginCode, newTranspiledCode) =>
6377
Method.getNewCode(
78+
service,
6479
dispatch,
6580
getNameFunc,
6681
setCurrentCustomNameToGlobalFunc,
@@ -69,6 +84,7 @@ let make = (
6984
getCurrentCustomNameFromGlobalFunc()->Meta3dCommonlib.NullableSt.getExn,
7085
newOriginCode,
7186
newTranspiledCode,
87+
customs,
7288
)}
7389
/>
7490
}

platform/frontend/src/external_layer/ui/app/components/App.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ let make = (~service: FrontendType.service, ~env: EnvType.env) => {
198198
getNeedConfigData: (. configLib) => Meta3d.Main.getNeedConfigData(configLib),
199199
},
200200
console: {
201+
warn: (. warnMessage, durationOpt) => MessageUtils.warn(warnMessage, durationOpt),
201202
error: (. errorMessage, durationOpt) => MessageUtils.error(errorMessage, durationOpt),
202203
errorWithExn: (. error, durationOpt) => MessageUtils.errorWithExn(error, durationOpt),
203204
},

platform/frontend/src/external_layer/ui/app/utils/utils/assemble_space/AssembleSpaceType.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type useDispatch = unit => dispatch
2222

2323
// type errorFunc = Js.Exn.t => unit
2424

25+
type warn = (. string, option<int>) => unit
26+
2527
// type error = (. Antd__Message.error, errorFunc, Js.Exn.t, option<int>) => unit
2628
type error = (. string, option<int>) => unit
2729

@@ -62,7 +64,7 @@ type reactService = {
6264
useEffectOnceAsync: (unit => (Js.Promise.t<unit>, option<unit => unit>)) => unit,
6365
}
6466

65-
type consoleService = {error: error, errorWithExn: errorWithExn}
67+
type consoleService = {warn: warn, error: error, errorWithExn: errorWithExn}
6668

6769
type convertAllFileDataForApp = (
6870
. array<Meta3d.ExtensionFileType.contributeFileData>,

platform/frontend/test/features/customInputCodeEdit.feature

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ Feature: CustomInputCodeEdit
1313
When get new code
1414
Then should convert new code to umd
1515
And get new input name from it
16-
# dispatch UpdateCustomInputFileStr with converted new code and generate input name and default file str
16+
# dispatch UpdateCustomInputFileStr with converted new code and generate input name and default file str
17+
18+
Scenario: if input name exist, warn and not dispatch
19+
Given add exist input with name as n1
20+
And build input name as n1 and new code
21+
When get new code
22+
Then shouldn't dispatch
1723

1824

1925
Rule: getCode
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Contributes show contributes list 1`] = `
4+
<div
5+
className="ant-list ant-list-split ant-list-grid css-dev-only-do-not-override-p7e5j5"
6+
style={Object {}}
7+
>
8+
<div
9+
className="ant-spin-nested-loading css-dev-only-do-not-override-p7e5j5"
10+
>
11+
<div
12+
className="ant-spin-container"
13+
>
14+
<div
15+
className="ant-list-empty-text"
16+
>
17+
<div
18+
className="css-dev-only-do-not-override-p7e5j5 ant-empty ant-empty-normal"
19+
style={Object {}}
20+
>
21+
<div
22+
className="ant-empty-image"
23+
>
24+
<svg
25+
height="41"
26+
viewBox="0 0 64 41"
27+
width="64"
28+
xmlns="http://www.w3.org/2000/svg"
29+
>
30+
<g
31+
fill="none"
32+
fillRule="evenodd"
33+
transform="translate(0 1)"
34+
>
35+
<ellipse
36+
cx="32"
37+
cy="33"
38+
fill="#f5f5f5"
39+
rx="32"
40+
ry="7"
41+
/>
42+
<g
43+
fillRule="nonzero"
44+
stroke="#d9d9d9"
45+
>
46+
<path
47+
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
48+
/>
49+
<path
50+
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
51+
fill="#fafafa"
52+
/>
53+
</g>
54+
</g>
55+
</svg>
56+
</div>
57+
<div
58+
className="ant-empty-description"
59+
>
60+
No data
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
</div>
66+
</div>
67+
`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ElementVisual show canvas 1`] = `
4+
<canvas
5+
height="20px"
6+
id="ui-visual-canvas"
7+
style={
8+
Object {
9+
"borderColor": "red",
10+
"borderStyle": "solid",
11+
"borderWidth": "2px",
12+
"height": "20px",
13+
"width": "10px",
14+
}
15+
}
16+
width="10px"
17+
/>
18+
`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ExtensionInspector show nothing 1`] = `null`;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Extensions show extensions list exclude selected extensions 1`] = `
4+
<div
5+
className="ant-list ant-list-split ant-list-grid css-dev-only-do-not-override-p7e5j5"
6+
style={Object {}}
7+
>
8+
<div
9+
className="ant-spin-nested-loading css-dev-only-do-not-override-p7e5j5"
10+
>
11+
<div
12+
className="ant-spin-container"
13+
>
14+
<div
15+
className="ant-list-empty-text"
16+
>
17+
<div
18+
className="css-dev-only-do-not-override-p7e5j5 ant-empty ant-empty-normal"
19+
style={Object {}}
20+
>
21+
<div
22+
className="ant-empty-image"
23+
>
24+
<svg
25+
height="41"
26+
viewBox="0 0 64 41"
27+
width="64"
28+
xmlns="http://www.w3.org/2000/svg"
29+
>
30+
<g
31+
fill="none"
32+
fillRule="evenodd"
33+
transform="translate(0 1)"
34+
>
35+
<ellipse
36+
cx="32"
37+
cy="33"
38+
fill="#f5f5f5"
39+
rx="32"
40+
ry="7"
41+
/>
42+
<g
43+
fillRule="nonzero"
44+
stroke="#d9d9d9"
45+
>
46+
<path
47+
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
48+
/>
49+
<path
50+
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
51+
fill="#fafafa"
52+
/>
53+
</g>
54+
</g>
55+
</svg>
56+
</div>
57+
<div
58+
className="ant-empty-description"
59+
>
60+
No data
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
</div>
66+
</div>
67+
`;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Fix AssembleSpace Bug fix "enter AssembleSpace should reset" bug 1`] = `
4+
<div
5+
className="ant-list ant-list-split ant-list-grid css-dev-only-do-not-override-p7e5j5"
6+
style={Object {}}
7+
>
8+
<div
9+
className="ant-spin-nested-loading css-dev-only-do-not-override-p7e5j5"
10+
>
11+
<div
12+
className="ant-spin-container"
13+
>
14+
<div
15+
className="ant-list-empty-text"
16+
>
17+
<div
18+
className="css-dev-only-do-not-override-p7e5j5 ant-empty ant-empty-normal"
19+
style={Object {}}
20+
>
21+
<div
22+
className="ant-empty-image"
23+
>
24+
<svg
25+
height="41"
26+
viewBox="0 0 64 41"
27+
width="64"
28+
xmlns="http://www.w3.org/2000/svg"
29+
>
30+
<g
31+
fill="none"
32+
fillRule="evenodd"
33+
transform="translate(0 1)"
34+
>
35+
<ellipse
36+
cx="32"
37+
cy="33"
38+
fill="#f5f5f5"
39+
rx="32"
40+
ry="7"
41+
/>
42+
<g
43+
fillRule="nonzero"
44+
stroke="#d9d9d9"
45+
>
46+
<path
47+
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
48+
/>
49+
<path
50+
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
51+
fill="#fafafa"
52+
/>
53+
</g>
54+
</g>
55+
</svg>
56+
</div>
57+
<div
58+
className="ant-empty-description"
59+
>
60+
No data
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
</div>
66+
</div>
67+
`;

0 commit comments

Comments
 (0)