-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
590 additions
and
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.addAttributeButtonContainer { | ||
display: inline-block; | ||
margin-left: 10px; | ||
|
||
.addAttributeButton { | ||
all: unset; | ||
align-items: center; | ||
border-radius: 50%; | ||
color: #333; | ||
cursor: pointer; | ||
display: flex; | ||
font-size: 11px; | ||
font-weight: bold; | ||
height: 12px; | ||
opacity: 0.5; | ||
|
||
&:hover { | ||
opacity: 1; | ||
} | ||
|
||
svg { | ||
background: #333; | ||
border-radius: 50%; | ||
height: 12px; | ||
margin-right: 5px; | ||
width: 12px; | ||
|
||
path { | ||
fill: white; | ||
} | ||
} | ||
} | ||
} |
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,28 @@ | ||
import React from "react"; | ||
import { ICollection, ICollections } from "../types"; | ||
|
||
import AddIcon from "../assets/add-icon.svg"; | ||
|
||
import css from "./add-attribute-button.scss"; | ||
|
||
interface IProps { | ||
collectionId: number; | ||
collections: ICollections; | ||
handleAddAttribute?: (collection: ICollection, attrName: string) => Promise<void>; | ||
} | ||
|
||
export const AddAttributeButton: React.FC<IProps> = ({collections, collectionId, handleAddAttribute}: IProps) => { | ||
|
||
const handleAddAttributeToCollection = async () => { | ||
const collection = collections.find((c) => c.id === collectionId); | ||
collection && handleAddAttribute && await handleAddAttribute(collection, ""); | ||
}; | ||
|
||
return ( | ||
<div className={css.addAttributeButtonContainer}> | ||
<button onClick={handleAddAttributeToCollection} className={css.addAttributeButton}> | ||
<AddIcon /> Add Attribute to Collection | ||
</button> | ||
</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
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,5 +1,23 @@ | ||
.editableTableCell { | ||
height: 100%; | ||
min-height: 16px; | ||
width: 100%; | ||
|
||
div:first-child { | ||
height: 100%; | ||
min-height: 16px; | ||
width: 100%; | ||
|
||
span:empty { | ||
display: block; | ||
height: 100%; | ||
min-height: 16px; | ||
width: 100%; | ||
} | ||
} | ||
|
||
input { | ||
background: white; | ||
width: calc(100% - 8px); | ||
} | ||
} |
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,64 @@ | ||
import React, { ReactNode, useState } from "react"; | ||
import { Editable, EditablePreview, EditableInput } from "@chakra-ui/react"; | ||
|
||
import css from "./editable-table-cell.scss"; | ||
|
||
interface IProps { | ||
attrId: number; | ||
collectionName: string; | ||
collectionId: number; | ||
children?: ReactNode; | ||
hasFocus?: boolean; | ||
selectedDataSetName?: string; | ||
renameAttribute: (collectionName: string, attrId: number, oldName: string, newName: string) => Promise<void>; | ||
} | ||
|
||
export const EditableTableHeader = (props: IProps) => { | ||
const { attrId, collectionName, hasFocus, renameAttribute } = props; | ||
const [displayValue, setDisplayValue] = useState(collectionName); | ||
const [editingValue, setEditingValue] = useState(displayValue); | ||
const [isEditing, setIsEditing] = useState(hasFocus); | ||
|
||
const handleChangeValue = (newValue: string) => { | ||
setEditingValue(newValue); | ||
}; | ||
|
||
const handleCancel = () => { | ||
setEditingValue(displayValue); | ||
setIsEditing(false); | ||
}; | ||
|
||
const handleSubmit = async (newValue: string) => { | ||
if (newValue === displayValue) { | ||
setIsEditing(false); | ||
return; | ||
} | ||
|
||
try { | ||
await renameAttribute(collectionName, attrId, displayValue, newValue); | ||
setDisplayValue(newValue); | ||
setEditingValue(newValue); | ||
setIsEditing(false); | ||
} catch (e) { | ||
console.error("Case not updated: ", e); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={css.editableTableCell}> | ||
<Editable | ||
isPreviewFocusable={true} | ||
onCancel={handleCancel} | ||
onChange={handleChangeValue} | ||
onEdit={() => setIsEditing(true)} | ||
onSubmit={handleSubmit} | ||
startWithEditView={hasFocus} | ||
submitOnBlur={true} | ||
value={isEditing ? editingValue : displayValue} | ||
> | ||
{!isEditing && <EditablePreview />} | ||
<EditableInput /> | ||
</Editable> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.