-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat: ability to edit table column #123
Draft
invisal
wants to merge
1
commit into
main
Choose a base branch
from
add-table-schema-editor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 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,9 @@ | ||
import styles from './cells.module.scss'; | ||
|
||
export default function CellCheckInput() { | ||
return ( | ||
<div className={styles.checkContainer}> | ||
<input type="checkbox" checked /> | ||
</div> | ||
); | ||
} |
81 changes: 81 additions & 0 deletions
81
src/renderer/components/OptimizeTable/CellGroupSelectInput.tsx
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,81 @@ | ||
import { useState, useEffect, useRef } from 'react'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import styles from './cells.module.scss'; | ||
import { faChevronDown } from '@fortawesome/free-solid-svg-icons'; | ||
import AvoidOffscreen from '../AvoidOffscreen'; | ||
import DropContainer from '../DropContainer'; | ||
import OptionList from '../OptionList'; | ||
import OptionListGroup from '../OptionList/OptionListGroup'; | ||
import OptionListItem from '../OptionList/OptionListItem'; | ||
import TextField from '../TextField'; | ||
|
||
interface CellGroupSelectInputProps { | ||
items: { name: string; items: { value: string; text: string }[] }[]; | ||
value?: string; | ||
} | ||
|
||
export default function CellGroupSelectInput({ | ||
items, | ||
value, | ||
}: CellGroupSelectInputProps) { | ||
const [show, setShow] = useState(false); | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
if (ref.current && show) { | ||
const onDocumentClick = (e: MouseEvent) => { | ||
if (ref.current && !ref.current.contains(e.target as Node)) { | ||
setShow(false); | ||
} | ||
}; | ||
|
||
document.addEventListener('click', onDocumentClick); | ||
return () => document.removeEventListener('click', onDocumentClick); | ||
} | ||
}, [ref, show, setShow]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's safe to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and so does |
||
|
||
return ( | ||
<div ref={ref} style={{ position: 'relative' }}> | ||
<div | ||
className={styles.dropdownContainer} | ||
onClick={() => { | ||
setShow(true); | ||
}} | ||
> | ||
<div className={styles.dropdownContent}>{value}</div> | ||
<div className={styles.dropdownArrow}> | ||
<FontAwesomeIcon icon={faChevronDown} /> | ||
</div> | ||
</div> | ||
{show && ( | ||
<div style={{ position: 'absolute', zIndex: 100 }}> | ||
<AvoidOffscreen> | ||
<DropContainer> | ||
<div style={{ padding: 5 }}> | ||
<TextField autoFocus placeholder="Search type" /> | ||
</div> | ||
<div | ||
style={{ height: 300, width: 250, overflowY: 'auto' }} | ||
className="scroll" | ||
> | ||
<OptionList> | ||
{items.map((group) => { | ||
return ( | ||
<OptionListGroup key={group.name} text={group.name}> | ||
{group.items.map((sub) => { | ||
return ( | ||
<OptionListItem key={sub.value} text={sub.text} /> | ||
); | ||
})} | ||
</OptionListGroup> | ||
); | ||
})} | ||
</OptionList> | ||
</div> | ||
</DropContainer> | ||
</AvoidOffscreen> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
44 changes: 44 additions & 0 deletions
44
src/renderer/components/OptimizeTable/CellSingleLineInput.tsx
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,44 @@ | ||
import styles from './cells.module.scss'; | ||
|
||
interface CellInputProps { | ||
onLostFocus?: (value: string | null | undefined) => void; | ||
readOnly?: boolean; | ||
value?: string | null; | ||
alignRight?: boolean; | ||
onChange?: (value: string) => void; | ||
} | ||
|
||
export default function CellSingleLineInput({ | ||
onLostFocus, | ||
readOnly, | ||
value, | ||
onChange, | ||
alignRight, | ||
}: CellInputProps) { | ||
return ( | ||
<div className={styles.inputContainer}> | ||
<input | ||
onKeyPress={(e) => { | ||
if (e.key === 'Enter') { | ||
if (onLostFocus) { | ||
onLostFocus(value); | ||
} | ||
} | ||
}} | ||
spellCheck="false" | ||
autoFocus | ||
type="text" | ||
readOnly={readOnly} | ||
className={styles.input} | ||
style={alignRight ? { textAlign: 'right' } : undefined} | ||
onBlur={() => { | ||
if (onLostFocus) onLostFocus(value); | ||
}} | ||
onChange={(e) => { | ||
if (onChange) onChange(e.currentTarget.value); | ||
}} | ||
value={value ?? ''} | ||
/> | ||
</div> | ||
); | ||
} |
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,46 @@ | ||
.checkContainer { | ||
display: flex; | ||
height: 100%; | ||
width: 100%; | ||
padding: 0px 10px; | ||
user-select: none; | ||
justify-content: center; | ||
|
||
input { | ||
transform: scale(1.2) | ||
} | ||
} | ||
|
||
.inputContainer { | ||
display: flex; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.input { | ||
padding: 5px 10px; | ||
border: 1px solid var(--color-surface); | ||
background: var(--color-surface); | ||
color: var(--color-text); | ||
box-sizing: border-box; | ||
width: 100%; | ||
height: 100%; | ||
outline: none; | ||
font-size: 1rem; | ||
} | ||
|
||
.dropdownContainer { | ||
display: flex; | ||
padding: 0px 10px; | ||
|
||
.dropdownContent, .dropdownArrow { | ||
line-height: 32px; | ||
} | ||
|
||
.dropdownContent { | ||
flex-grow: 1; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,14 @@ | ||
export default function OptionListGroup() { | ||
return <div></div>; | ||
import { PropsWithChildren } from 'react'; | ||
import styles from './styles.module.scss'; | ||
|
||
export default function OptionListGroup({ | ||
children, | ||
text, | ||
}: PropsWithChildren<{ text: string }>) { | ||
return ( | ||
<div> | ||
<div className={styles.groupLabel}>{text}</div> | ||
<div>{children}</div> | ||
</div> | ||
); | ||
} |
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
69 changes: 69 additions & 0 deletions
69
src/renderer/components/SchemaEditor/TableColumnsAlterDiff.ts
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,69 @@ | ||
import { TableColumnSchema } from 'types/SqlSchema'; | ||
|
||
interface TableColumnsAlterDiffNode { | ||
index: number; | ||
original: TableColumnSchema | null; | ||
changed: Partial<TableColumnSchema> | null; | ||
} | ||
|
||
interface ColumnNode extends TableColumnsAlterDiffNode { | ||
index: number; | ||
original: TableColumnSchema | null; | ||
changed: Partial<TableColumnSchema> | null; | ||
next: ColumnNode | null; | ||
prev: ColumnNode | null; | ||
} | ||
|
||
export class TableColumnsAlterDiff { | ||
protected root: ColumnNode | null = null; | ||
|
||
/** | ||
* Initial from original columns | ||
* | ||
* @param columns | ||
* @returns | ||
*/ | ||
constructor(columns: TableColumnSchema[]) { | ||
const root: ColumnNode = { | ||
next: null, | ||
prev: null, | ||
index: 0, | ||
original: columns[0], | ||
changed: {}, | ||
}; | ||
|
||
let currentNode = root; | ||
for (let i = 1; i < columns.length; i++) { | ||
const newNode: ColumnNode = { | ||
next: null, | ||
prev: currentNode, | ||
index: i, | ||
original: columns[i], | ||
changed: {}, | ||
}; | ||
|
||
currentNode.next = newNode; | ||
currentNode = newNode; | ||
} | ||
|
||
this.root = root; | ||
} | ||
|
||
toArray() { | ||
if (!this.root) return []; | ||
|
||
const arr: TableColumnsAlterDiffNode[] = []; | ||
let ptr: ColumnNode | null = this.root; | ||
|
||
while (ptr) { | ||
arr.push({ | ||
index: ptr.index, | ||
original: ptr.original ? Object.freeze({ ...ptr.original }) : null, | ||
changed: Object.freeze({ ...ptr.changed }), | ||
}); | ||
ptr = ptr.next; | ||
} | ||
|
||
return arr; | ||
} | ||
} |
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.
should allow 'asc' and 'desc' (lowercase)?