-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1194 from facebookresearch/form-composer-add-css-…
…files-support Enable CSS insertions in FormComposer
- Loading branch information
Showing
20 changed files
with
269 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) Meta Platforms and its affiliates. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import { | ||
FormComposerBaseFrontend, | ||
LoadingScreen, | ||
} from "./components/core_components_dynamic.jsx"; | ||
import { useMephistoTask, ErrorBoundary } from "mephisto-task-multipart"; | ||
|
||
/* ================= Application Components ================= */ | ||
|
||
function MainApp() { | ||
const { | ||
isLoading, | ||
initialTaskData, | ||
handleSubmit, | ||
handleFatalError, | ||
} = useMephistoTask(); | ||
|
||
if (isLoading || !initialTaskData) { | ||
return <LoadingScreen />; | ||
} | ||
|
||
return ( | ||
<div> | ||
<ErrorBoundary handleError={handleFatalError}> | ||
<FormComposerBaseFrontend | ||
taskData={initialTaskData} | ||
onSubmit={handleSubmit} | ||
onError={handleFatalError} | ||
/> | ||
</ErrorBoundary> | ||
</div> | ||
); | ||
} | ||
|
||
ReactDOM.render(<MainApp />, document.getElementById("app")); |
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
File renamed without changes.
49 changes: 49 additions & 0 deletions
49
examples/form_composer_demo/webapp/src/components/core_components_simple.jsx
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,49 @@ | ||
/* | ||
* Copyright (c) Meta Platforms and its affiliates. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from "react"; | ||
import { FormComposer } from "react-form-composer"; | ||
|
||
function LoadingScreen() { | ||
return <Directions>Loading...</Directions>; | ||
} | ||
|
||
function Directions({ children }) { | ||
return ( | ||
<section className="hero is-light" data-cy="directions-container"> | ||
<div className="hero-body"> | ||
<div className="container"> | ||
<p className="subtitle is-5">{children}</p> | ||
</div> | ||
</div> | ||
</section> | ||
); | ||
} | ||
|
||
function FormComposerBaseFrontend({ | ||
taskData, | ||
onSubmit, | ||
onError, | ||
finalResults = null, | ||
}) { | ||
let initialConfigFormData = taskData.form; | ||
|
||
if (!initialConfigFormData) { | ||
return <div>Passed form data is invalid... Recheck your task config.</div>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<FormComposer | ||
data={initialConfigFormData} | ||
onSubmit={onSubmit} | ||
finalResults={finalResults} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export { LoadingScreen, FormComposerBaseFrontend }; |
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,11 @@ | ||
/* | ||
* Copyright (c) Meta Platforms and its affiliates. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import "bootstrap/dist/css/bootstrap.css"; | ||
import "bootstrap-select/dist/css/bootstrap-select.min.css"; | ||
import "./app_dynamic.jsx"; | ||
import "./css/style.css"; | ||
// Add your additional imports with styles here |
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,11 @@ | ||
/* | ||
* Copyright (c) Meta Platforms and its affiliates. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import "bootstrap/dist/css/bootstrap.css"; | ||
import "bootstrap-select/dist/css/bootstrap-select.min.css"; | ||
import "./app_simple.jsx"; | ||
import "./css/style.css"; | ||
// Add your additional imports with styles here |
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
62 changes: 62 additions & 0 deletions
62
examples/form_composer_demo/webapp/src/reviewapp_dynamic.jsx
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,62 @@ | ||
/* | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* All rights reserved. | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import { FormComposerBaseFrontend } from "./components/core_components_dynamic.jsx"; | ||
|
||
function Reviewapp_dynamic() { | ||
const appRef = React.useRef(null); | ||
const [reviewData, setReviewData] = React.useState(null); | ||
|
||
// Requirement #1. Render review components after receiving Task data via message | ||
window.onmessage = function (e) { | ||
const data = JSON.parse(e.data); | ||
setReviewData(data["REVIEW_DATA"]); | ||
}; | ||
|
||
// Requirement #2. Resize iframe height to fit its content | ||
React.useLayoutEffect(() => { | ||
function updateSize() { | ||
if (appRef.current) { | ||
window.top.postMessage( | ||
JSON.stringify({ | ||
IFRAME_DATA: { | ||
height: appRef.current.offsetHeight, | ||
}, | ||
}), | ||
"*" | ||
); | ||
} | ||
} | ||
window.addEventListener("resize", updateSize); | ||
updateSize(); | ||
// HACK: Catch-all resize, if normal resizes failed (e.g. acync long loading images) | ||
setTimeout(() => { | ||
updateSize(); | ||
}, 3000); | ||
return () => window.removeEventListener("resize", updateSize); | ||
}, []); | ||
|
||
// Requirement #3. This component must return a div with `ref={appRef}` | ||
// so we can get displayed height of this component (for iframe resizing) | ||
return ( | ||
<div ref={appRef}> | ||
{reviewData ? ( | ||
<FormComposerBaseFrontend | ||
taskData={reviewData["inputs"]} | ||
finalResults={reviewData["outputs"]} | ||
/> | ||
) : ( | ||
<div>Loading...</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
ReactDOM.render(<Reviewapp_dynamic />, document.getElementById("app")); |
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
Oops, something went wrong.