Skip to content

Commit

Permalink
fix(platform): element assemble: fix custom: now if new name exist, w…
Browse files Browse the repository at this point in the history
…arn and not dispatch
  • Loading branch information
yyc-git committed Feb 18, 2024
1 parent d46dff9 commit 3440cf4
Show file tree
Hide file tree
Showing 23 changed files with 4,305 additions and 6 deletions.
4 changes: 2 additions & 2 deletions doc/1.3.0.org
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,11 @@ TODO update:
# TODO editor loop will increase


* TODO perf(editor): optimize editor loading
# * TODO perf(editor): optimize editor loading



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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@ open Antd
open AssembleSpaceType

module Method = {
let _isNameExist = (name, customs) => {
customs
->Meta3dCommonlib.ListSt.find((custom: CommonType.custom) => {
custom.name == name
})
->Meta3dCommonlib.OptionSt.isSome
}

let getNewCode = (
service: service,
dispatch,
getNameFunc,
setCurrentCustomNameToGlobalFunc,
buildUpdateActionFunc,
name,
newOriginCode,
newTranspiledCode,
customs,
) => {
let newTranspiledCode = newTranspiledCode->CodeEditUtils.convertTranspliedCodeToUMDCode

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

setCurrentCustomNameToGlobalFunc(newName)
_isNameExist(newName, customs)
? service.console.warn(. {j`name:${newName}已经存在,请换个name`}, None)
: {
setCurrentCustomNameToGlobalFunc(newName)

dispatch(buildUpdateActionFunc(name, newName, newOriginCode, newTranspiledCode->Some))
dispatch(buildUpdateActionFunc(name, newName, newOriginCode, newTranspiledCode->Some))
}
}

let getCode = (name, customs) => {
Expand Down Expand Up @@ -61,6 +75,7 @@ let make = (
code={code}
getNewCodeFunc={(newOriginCode, newTranspiledCode) =>
Method.getNewCode(
service,
dispatch,
getNameFunc,
setCurrentCustomNameToGlobalFunc,
Expand All @@ -69,6 +84,7 @@ let make = (
getCurrentCustomNameFromGlobalFunc()->Meta3dCommonlib.NullableSt.getExn,
newOriginCode,
newTranspiledCode,
customs,
)}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ let make = (~service: FrontendType.service, ~env: EnvType.env) => {
getNeedConfigData: (. configLib) => Meta3d.Main.getNeedConfigData(configLib),
},
console: {
warn: (. warnMessage, durationOpt) => MessageUtils.warn(warnMessage, durationOpt),
error: (. errorMessage, durationOpt) => MessageUtils.error(errorMessage, durationOpt),
errorWithExn: (. error, durationOpt) => MessageUtils.errorWithExn(error, durationOpt),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type useDispatch = unit => dispatch

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

type warn = (. string, option<int>) => unit

// type error = (. Antd__Message.error, errorFunc, Js.Exn.t, option<int>) => unit
type error = (. string, option<int>) => unit

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

type consoleService = {error: error, errorWithExn: errorWithExn}
type consoleService = {warn: warn, error: error, errorWithExn: errorWithExn}

type convertAllFileDataForApp = (
. array<Meta3d.ExtensionFileType.contributeFileData>,
Expand Down
8 changes: 7 additions & 1 deletion platform/frontend/test/features/customInputCodeEdit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ Feature: CustomInputCodeEdit
When get new code
Then should convert new code to umd
And get new input name from it
# dispatch UpdateCustomInputFileStr with converted new code and generate input name and default file str
# dispatch UpdateCustomInputFileStr with converted new code and generate input name and default file str

Scenario: if input name exist, warn and not dispatch
Given add exist input with name as n1
And build input name as n1 and new code
When get new code
Then shouldn't dispatch


Rule: getCode
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Contributes show contributes list 1`] = `
<div
className="ant-list ant-list-split ant-list-grid css-dev-only-do-not-override-p7e5j5"
style={Object {}}
>
<div
className="ant-spin-nested-loading css-dev-only-do-not-override-p7e5j5"
>
<div
className="ant-spin-container"
>
<div
className="ant-list-empty-text"
>
<div
className="css-dev-only-do-not-override-p7e5j5 ant-empty ant-empty-normal"
style={Object {}}
>
<div
className="ant-empty-image"
>
<svg
height="41"
viewBox="0 0 64 41"
width="64"
xmlns="http://www.w3.org/2000/svg"
>
<g
fill="none"
fillRule="evenodd"
transform="translate(0 1)"
>
<ellipse
cx="32"
cy="33"
fill="#f5f5f5"
rx="32"
ry="7"
/>
<g
fillRule="nonzero"
stroke="#d9d9d9"
>
<path
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"
/>
<path
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"
fill="#fafafa"
/>
</g>
</g>
</svg>
</div>
<div
className="ant-empty-description"
>
No data
</div>
</div>
</div>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ElementVisual show canvas 1`] = `
<canvas
height="20px"
id="ui-visual-canvas"
style={
Object {
"borderColor": "red",
"borderStyle": "solid",
"borderWidth": "2px",
"height": "20px",
"width": "10px",
}
}
width="10px"
/>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ExtensionInspector show nothing 1`] = `null`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Extensions show extensions list exclude selected extensions 1`] = `
<div
className="ant-list ant-list-split ant-list-grid css-dev-only-do-not-override-p7e5j5"
style={Object {}}
>
<div
className="ant-spin-nested-loading css-dev-only-do-not-override-p7e5j5"
>
<div
className="ant-spin-container"
>
<div
className="ant-list-empty-text"
>
<div
className="css-dev-only-do-not-override-p7e5j5 ant-empty ant-empty-normal"
style={Object {}}
>
<div
className="ant-empty-image"
>
<svg
height="41"
viewBox="0 0 64 41"
width="64"
xmlns="http://www.w3.org/2000/svg"
>
<g
fill="none"
fillRule="evenodd"
transform="translate(0 1)"
>
<ellipse
cx="32"
cy="33"
fill="#f5f5f5"
rx="32"
ry="7"
/>
<g
fillRule="nonzero"
stroke="#d9d9d9"
>
<path
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"
/>
<path
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"
fill="#fafafa"
/>
</g>
</g>
</svg>
</div>
<div
className="ant-empty-description"
>
No data
</div>
</div>
</div>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Fix AssembleSpace Bug fix "enter AssembleSpace should reset" bug 1`] = `
<div
className="ant-list ant-list-split ant-list-grid css-dev-only-do-not-override-p7e5j5"
style={Object {}}
>
<div
className="ant-spin-nested-loading css-dev-only-do-not-override-p7e5j5"
>
<div
className="ant-spin-container"
>
<div
className="ant-list-empty-text"
>
<div
className="css-dev-only-do-not-override-p7e5j5 ant-empty ant-empty-normal"
style={Object {}}
>
<div
className="ant-empty-image"
>
<svg
height="41"
viewBox="0 0 64 41"
width="64"
xmlns="http://www.w3.org/2000/svg"
>
<g
fill="none"
fillRule="evenodd"
transform="translate(0 1)"
>
<ellipse
cx="32"
cy="33"
fill="#f5f5f5"
rx="32"
ry="7"
/>
<g
fillRule="nonzero"
stroke="#d9d9d9"
>
<path
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"
/>
<path
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"
fill="#fafafa"
/>
</g>
</g>
</svg>
</div>
<div
className="ant-empty-description"
>
No data
</div>
</div>
</div>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Publish show publish button 1`] = `
<button
className="ant-btn css-dev-only-do-not-override-p7e5j5 ant-btn-default"
disabled={false}
onClick={[Function]}
style={Object {}}
type="button"
>
<span>
发 布
</span>
</button>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RunElementVisualController if data not ready, show waiting 1`] = `
<button
className="ant-btn css-dev-only-do-not-override-p7e5j5 ant-btn-default"
disabled={true}
onClick={[Function]}
style={Object {}}
type="button"
>
<span>
运 行
</span>
</button>
`;

exports[`RunElementVisualController if data ready, show run button 1`] = `
<button
className="ant-btn css-dev-only-do-not-override-p7e5j5 ant-btn-default"
disabled={false}
onClick={[Function]}
style={Object {}}
type="button"
>
<span>
运 行
</span>
</button>
`;
Loading

0 comments on commit 3440cf4

Please sign in to comment.