generated from EasyWebApp/WebCell-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 7
[add] Prototype Generator model & component #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cbb57d7
Initial plan
Copilot 79764cc
Add PrototypeGeneratorToolbar component with 4 states
Copilot df58b66
Fix PrototypeVersion to use interface instead of Base class
Copilot 99c3c29
Improve error handling in PrototypeVersion model
Copilot 5a3a802
Add comprehensive documentation for PrototypeGeneratorToolbar
Copilot 91da1ac
Refactor to class component and use base updateOne method
Copilot 89b34b4
Refactor: split renderContent into separate methods and use for...of …
Copilot c5893d3
[migrate] replace SMS Code with Email OTP for sign-in
TechQuery a320a10
[refactor] simplify Status Check polling of Prototype Generation
TechQuery 94f1364
[fix] some GitHub Copilot bugs
TechQuery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| NEXT_PUBLIC_API_HOST = http://localhost:8080 |
This file contains hidden or 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 hidden or 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 hidden or 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,170 @@ | ||
| import { PrototypeType, PrototypeVersion } from '@idea2app/data-server'; | ||
| import { Box, Button, CircularProgress, Link, Typography } from '@mui/material'; | ||
| import { observable } from 'mobx'; | ||
| import { observer } from 'mobx-react'; | ||
| import { ObservedComponent } from 'mobx-react-helper'; | ||
| import { createRef } from 'react'; | ||
| import { inViewport, sleep } from 'web-utility'; | ||
|
|
||
| import { PrototypeVersionModel } from '../../models/PrototypeVersion'; | ||
| import { i18n, I18nContext } from '../../models/Translation'; | ||
|
|
||
| export interface PrototypeGeneratorProps { | ||
| projectId: number; | ||
| messageId: number; | ||
| type: PrototypeType; | ||
| prototype?: PrototypeVersion; | ||
| } | ||
|
|
||
| @observer | ||
| export class PrototypeGenerator extends ObservedComponent<PrototypeGeneratorProps, typeof i18n> { | ||
| static contextType = I18nContext; | ||
|
|
||
| versionStore = new PrototypeVersionModel(this.props.projectId, this.props.type); | ||
|
|
||
| @observable | ||
| accessor version = this.props.prototype; | ||
|
|
||
| private root = createRef<HTMLElement>(); | ||
|
|
||
| componentDidMount() { | ||
| super.componentDidMount(); | ||
|
|
||
| this.pollStatusCheck(); | ||
| } | ||
|
|
||
| async pollStatusCheck() { | ||
| const { props, version } = this, | ||
| rootElement = this.root.current; | ||
|
|
||
| while (version?.status === 'pending' || version?.status === 'processing') { | ||
| if (!rootElement?.isConnected) break; | ||
|
|
||
| if (inViewport(rootElement)) | ||
| this.version = await this.versionStore.getOne(props.prototype!.id); | ||
|
|
||
| await sleep(3); | ||
| } | ||
| } | ||
|
|
||
| handleGenerateClick = async () => { | ||
| this.version = await this.versionStore.updateOne({ | ||
| evaluationMessage: this.props.messageId, | ||
| }); | ||
|
|
||
| return this.pollStatusCheck(); | ||
| }; | ||
|
|
||
| renderPending() { | ||
| const { t } = this.observedContext; | ||
| const loading = this.versionStore.uploading > 0; | ||
|
|
||
| return ( | ||
| <Button | ||
| variant="contained" | ||
| color="primary" | ||
| size="small" | ||
| disabled={loading} | ||
| sx={{ textTransform: 'none' }} | ||
| onClick={this.handleGenerateClick} | ||
| > | ||
| {loading ? t('generating') : t('generate_prototype')} | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| renderGenerating() { | ||
| const { t } = this.observedContext; | ||
|
|
||
| return ( | ||
| <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}> | ||
| <CircularProgress size={16} /> | ||
| <Typography variant="body2">{t('prototype_generating')}</Typography> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| renderCompleted() { | ||
| const { t } = this.observedContext; | ||
| const { previewLink, gitLogsLink } = this.version || {}; | ||
|
|
||
| return ( | ||
| <Box sx={{ display: 'flex', gap: 1, flexWrap: 'wrap' }}> | ||
| {previewLink && ( | ||
| <Link | ||
| href={previewLink} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| sx={{ | ||
| textDecoration: 'none', | ||
| fontSize: '0.875rem', | ||
| fontWeight: 500, | ||
| color: 'primary.main', | ||
| }} | ||
| > | ||
| {t('view_preview')} | ||
| </Link> | ||
| )} | ||
| {gitLogsLink && ( | ||
| <Link | ||
| href={gitLogsLink} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| sx={{ | ||
| textDecoration: 'none', | ||
| fontSize: '0.875rem', | ||
| fontWeight: 500, | ||
| color: 'text.secondary', | ||
| }} | ||
| > | ||
| {t('view_ai_log')} | ||
| </Link> | ||
| )} | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| renderFailed() { | ||
| const { t } = this.observedContext; | ||
| const { errorMessage, gitLogsLink } = this.version || {}; | ||
|
|
||
| return ( | ||
| <Box sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}> | ||
| <Typography variant="body2" color="error" sx={{ fontSize: '0.875rem' }}> | ||
| {errorMessage || t('prototype_generation_failed')} | ||
| </Typography> | ||
| {gitLogsLink && ( | ||
| <Link | ||
| href={gitLogsLink} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| sx={{ | ||
| textDecoration: 'none', | ||
| fontSize: '0.875rem', | ||
| fontWeight: 500, | ||
| color: 'text.secondary', | ||
| }} | ||
| > | ||
| {t('view_ai_log')} | ||
| </Link> | ||
| )} | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| render() { | ||
| const { version } = this; | ||
|
|
||
| return ( | ||
| <Box ref={this.root} sx={{ borderTop: '1px solid', borderColor: 'divider' }}> | ||
| {!version || version.status === 'pending' | ||
| ? this.renderPending() | ||
| : version.status === 'processing' | ||
| ? this.renderGenerating() | ||
| : version.status === 'completed' | ||
| ? this.renderCompleted() | ||
| : this.renderFailed()} | ||
| </Box> | ||
| ); | ||
| } | ||
| } |
File renamed without changes.
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.