-
Notifications
You must be signed in to change notification settings - Fork 229
feat(data-modeling): open diagram COMPASS-9546 #7127
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
17 commits
Select commit
Hold shift + click to select a range
8db037e
add import file button
mabaasit 26ac7b8
import diagram
mabaasit b285178
Merge branch 'main' of https://github.com/mongodb-js/compass into COM…
mabaasit d76618c
open diagram back
mabaasit bd331ea
e2e tests
mabaasit 8a87bcc
clean up
mabaasit f64c626
make ts happy
mabaasit 92ba8c2
bot review
mabaasit 79c97b1
Merge branch 'main' of https://github.com/mongodb-js/compass into COM…
mabaasit bea3e3d
use existing diagram
mabaasit 9db4b8e
change text to import
mabaasit fc64ffb
cleaner error handling
mabaasit 88744b5
better names for import
mabaasit ad151ea
rename filinput
mabaasit 7e6a8a4
Merge branch 'main' into COMPASS-9546-open-diagram
mabaasit f658ed2
rephrase
mabaasit dfd34ad
Merge branch 'COMPASS-9546-open-diagram' of https://github.com/mongod…
mabaasit 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
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
43 changes: 43 additions & 0 deletions
43
packages/compass-components/src/components/file-selector.tsx
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,43 @@ | ||
import React, { type InputHTMLAttributes, useRef } from 'react'; | ||
|
||
type FileSelectorTriggerProps = { | ||
onClick: () => void; | ||
}; | ||
|
||
type FileSelectorProps = Omit< | ||
InputHTMLAttributes<HTMLInputElement>, | ||
'onChange' | 'onSelect' | 'type' | 'style' | 'ref' | ||
> & { | ||
trigger: (props: FileSelectorTriggerProps) => React.ReactElement; | ||
onSelect: (files: File[]) => void; | ||
}; | ||
|
||
export function FileSelector({ | ||
trigger, | ||
onSelect, | ||
...props | ||
}: FileSelectorProps) { | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const onFilesChanged = React.useCallback( | ||
(evt: React.ChangeEvent<HTMLInputElement>) => { | ||
onSelect(Array.from(evt.currentTarget.files ?? [])); | ||
}, | ||
[onSelect] | ||
); | ||
|
||
return ( | ||
<> | ||
<input | ||
{...props} | ||
ref={inputRef} | ||
type="file" | ||
onChange={onFilesChanged} | ||
style={{ display: 'none' }} | ||
/> | ||
{trigger({ | ||
onClick: () => inputRef.current?.click(), | ||
})} | ||
</> | ||
); | ||
} |
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
34 changes: 34 additions & 0 deletions
34
packages/compass-data-modeling/src/components/import-diagram-button.tsx
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,34 @@ | ||
import React from 'react'; | ||
import { Button, FileSelector } from '@mongodb-js/compass-components'; | ||
|
||
type importDiagramButtonProps = Omit< | ||
React.ComponentProps<typeof Button>, | ||
'onClick' | ||
> & { | ||
onImportDiagram: (file: File) => void; | ||
}; | ||
|
||
export const ImportDiagramButton = ({ | ||
onImportDiagram, | ||
...buttonProps | ||
}: importDiagramButtonProps) => { | ||
return ( | ||
<FileSelector | ||
id="import-diagram-file-input" | ||
data-testid="import-diagram-file-input" | ||
multiple={false} | ||
accept=".compass" | ||
onSelect={(files) => { | ||
if (files.length === 0) { | ||
return; | ||
} | ||
onImportDiagram(files[0]); | ||
}} | ||
trigger={({ onClick }) => ( | ||
<Button {...buttonProps} onClick={onClick}> | ||
Import Diagram | ||
</Button> | ||
)} | ||
/> | ||
); | ||
}; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily completely your problem to solve, but the fact that we now expose two file inputs from compass-components is very confusing. In the spirit of trying to make code universal, maybe we should rename the other one to make it clear that it's electron only and mark it as deprecated with a JSDoc annotation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming it makes sense, but why deprecation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Universal code should be the default almost always, everything else should be an exception, we call this out often in a lot of places, but something that highlights component as "do not use unless you're really truly sure about it" seems to be a useful mechanism,
@deprecated
is just a tool to achieve that if people just pick up components automatically based on import suggestionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in ad151ea. let me know if it looks good, especially the name :)