-
Notifications
You must be signed in to change notification settings - Fork 0
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
x1032 Add user full name to Release Recipient #393
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ import { Input } from '../forms/Input'; | |
import BlueButton from '../buttons/BlueButton'; | ||
import { useMachine } from '@xstate/react'; | ||
import Success from '../notifications/Success'; | ||
import Warning from '../notifications/Warning'; | ||
import { capitalize } from 'lodash'; | ||
import WhiteButton from '../buttons/WhiteButton'; | ||
import PinkButton from '../buttons/PinkButton'; | ||
|
@@ -14,6 +13,7 @@ import { BooleanEntityRow } from './BooleanEntityRow'; | |
import { createEntityManagerMachine } from './entityManager.machine'; | ||
import { alphaNumericSortDefault } from '../../types/stan'; | ||
import CustomReactSelect, { OptionType } from '../forms/CustomReactSelect'; | ||
import Warning from '../notifications/Warning'; | ||
|
||
export type EntityValueType = boolean | string | number; | ||
|
||
|
@@ -23,6 +23,14 @@ type ValueFieldComponentInfo = { | |
valueOptions?: string[]; | ||
}; | ||
|
||
type ExtraEntityColumn<E> = { | ||
label: string; | ||
value: string; | ||
keyFieldPlaceholder: string; | ||
extraFieldPlaceholder: string; | ||
onChange(value: string, extraValue?: string): Promise<E>; | ||
}; | ||
|
||
type EntityManagerProps<E> = { | ||
/** | ||
* The initial entities to display in the table | ||
|
@@ -55,7 +63,7 @@ type EntityManagerProps<E> = { | |
* Callback when a new entity is to be created | ||
* @param value the value of the new entity | ||
*/ | ||
onCreate(value: string): Promise<E>; | ||
onCreate(value: string, extraValue?: string): Promise<E>; | ||
|
||
/** | ||
* Callback when value changes | ||
|
@@ -66,8 +74,12 @@ type EntityManagerProps<E> = { | |
* Display key field as a dropdown | ||
*/ | ||
displayKeyFieldAsDropDown?: boolean; | ||
}; | ||
|
||
/** | ||
* Extra property of the entity to display in the table | ||
*/ | ||
extraDisplayColumnName?: ExtraEntityColumn<E>; | ||
}; | ||
export default function EntityManager<E extends Record<string, EntityValueType>>({ | ||
initialEntities, | ||
displayKeyColumnName, | ||
|
@@ -76,22 +88,27 @@ export default function EntityManager<E extends Record<string, EntityValueType>> | |
valueFieldComponentInfo, | ||
onCreate, | ||
onChangeValue, | ||
displayKeyFieldAsDropDown = false | ||
displayKeyFieldAsDropDown = false, | ||
extraDisplayColumnName = undefined | ||
}: EntityManagerProps<E>) { | ||
const entityManagerMachine = React.useMemo(() => { | ||
return createEntityManagerMachine<E>(initialEntities, displayKeyColumnName, valueColumnName).withConfig({ | ||
services: { | ||
createEntity: (ctx, e) => { | ||
if (e.type !== 'CREATE_NEW_ENTITY') return Promise.reject(); | ||
return onCreate(e.value); | ||
return onCreate(e.value, e.extraValue); | ||
}, | ||
valueChanged: (context, e) => { | ||
if (e.type !== 'VALUE_CHANGE') return Promise.reject(); | ||
return onChangeValue(e.entity, e.value); | ||
}, | ||
updateExtraProperty: (context, e) => { | ||
if (e.type !== 'EXTRA_PROPERTY_UPDATE_VALUE' || !extraDisplayColumnName) return Promise.reject(); | ||
return extraDisplayColumnName.onChange(e.value, e.extraValue); | ||
} | ||
} | ||
}); | ||
}, [initialEntities, displayKeyColumnName, valueColumnName, onChangeValue, onCreate]); | ||
}, [initialEntities, displayKeyColumnName, valueColumnName, onChangeValue, onCreate, extraDisplayColumnName]); | ||
|
||
const [current, send] = useMachine(entityManagerMachine); | ||
|
||
|
@@ -118,6 +135,7 @@ export default function EntityManager<E extends Record<string, EntityValueType>> | |
* Will receive focus when it appears on screen. | ||
*/ | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
const extraInputRef = useRef<HTMLInputElement>(null); | ||
useEffect(() => { | ||
if (current.matches('draftCreation')) { | ||
inputRef.current?.select(); | ||
|
@@ -132,9 +150,13 @@ export default function EntityManager<E extends Record<string, EntityValueType>> | |
if (value === '') { | ||
return; | ||
} | ||
send({ type: 'CREATE_NEW_ENTITY', value }); | ||
let extraValue: string | undefined; | ||
if (extraDisplayColumnName) { | ||
extraValue = extraInputRef.current?.value.trim(); | ||
} | ||
send({ type: 'CREATE_NEW_ENTITY', value, extraValue }); | ||
setDraftValue(''); | ||
}, [draftValue, setDraftValue, send]); | ||
}, [draftValue, setDraftValue, send, extraDisplayColumnName]); | ||
|
||
/** | ||
* Callback handler for when an EntityRow changes (i.e. enabled property is toggled) | ||
|
@@ -171,6 +193,28 @@ export default function EntityManager<E extends Record<string, EntityValueType>> | |
*/ | ||
const handleOnCancel = () => send({ type: 'DISCARD_DRAFT' }); | ||
|
||
const handleExtraValueUpdate = useCallback( | ||
(keyValue: string, extraValue: string) => { | ||
send({ | ||
type: 'EXTRA_PROPERTY_UPDATE_VALUE', | ||
value: keyValue, | ||
extraValue: extraValue | ||
}); | ||
}, | ||
[send] | ||
); | ||
|
||
const handleOnChangeForExtraDisplayColumn = useCallback( | ||
(entity: E, extraValue: string) => { | ||
if (!extraDisplayColumnName) return; | ||
send({ | ||
type: 'EXTRA_PROPERTY_DRAFT_VALUE', | ||
entity: { ...entity, [extraDisplayColumnName.value]: extraValue } | ||
}); | ||
}, | ||
[send, extraDisplayColumnName] | ||
); | ||
|
||
const getValueFieldComponent = ( | ||
valueFieldComponentInfo: ValueFieldComponentInfo, | ||
entity: E | undefined, | ||
|
@@ -204,6 +248,47 @@ export default function EntityManager<E extends Record<string, EntityValueType>> | |
return <></>; | ||
} | ||
}; | ||
const setInputFieldsRow = () => { | ||
return ( | ||
<tr> | ||
<TableCell colSpan={2}> | ||
<Input | ||
type="text" | ||
placeholder={extraDisplayColumnName ? extraDisplayColumnName.keyFieldPlaceholder : ''} | ||
ref={inputRef} | ||
data-testid="input-field" | ||
disabled={isCreatingEntity} | ||
onChange={handleOnInputChange} | ||
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') { | ||
handleOnSave(); | ||
} else if (e.key === 'Escape') { | ||
handleOnCancel(); | ||
} | ||
}} | ||
/> | ||
</TableCell> | ||
{extraDisplayColumnName && ( | ||
<TableCell colSpan={2}> | ||
<Input | ||
type="text" | ||
placeholder={extraDisplayColumnName.extraFieldPlaceholder} | ||
ref={extraInputRef} | ||
data-testid="extra-input-field" | ||
disabled={isCreatingEntity} | ||
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') { | ||
handleOnSave(); | ||
} else if (e.key === 'Escape') { | ||
handleOnCancel(); | ||
} | ||
}} | ||
/> | ||
</TableCell> | ||
)} | ||
</tr> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="space-y-4"> | ||
|
@@ -212,8 +297,9 @@ export default function EntityManager<E extends Record<string, EntityValueType>> | |
<Table> | ||
<TableHead> | ||
<tr> | ||
<TableHeader>{displayKeyColumnName}</TableHeader> | ||
<TableHeader>{valueColumnName}</TableHeader> | ||
<TableHeader colSpan={2}>{displayKeyColumnName}</TableHeader> | ||
{extraDisplayColumnName && <TableHeader colSpan={2}>{extraDisplayColumnName.label}</TableHeader>} | ||
<TableHeader colSpan={2}>{valueColumnName}</TableHeader> | ||
</tr> | ||
</TableHead> | ||
<TableBody> | ||
|
@@ -241,7 +327,25 @@ export default function EntityManager<E extends Record<string, EntityValueType>> | |
) : ( | ||
orderedEntities.map((entity, indx) => ( | ||
<tr key={indx}> | ||
<TableCell>{entity[displayKeyColumnName]}</TableCell> | ||
<TableCell colSpan={2}>{entity[displayKeyColumnName]}</TableCell> | ||
{extraDisplayColumnName && ( | ||
<TableCell colSpan={2}> | ||
<Input | ||
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. Would it be better to switch it back to a label or input style resembling a label ,once user finishes editing or on blur? |
||
type="text" | ||
placeholder={extraDisplayColumnName.extraFieldPlaceholder} | ||
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') { | ||
handleExtraValueUpdate(String(entity[displayKeyColumnName]), e.currentTarget.value); | ||
e.currentTarget.blur(); | ||
} | ||
}} | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { | ||
handleOnChangeForExtraDisplayColumn(entity, e.target.value); | ||
}} | ||
value={String(entity[extraDisplayColumnName.value])} | ||
/> | ||
</TableCell> | ||
)} | ||
{getValueFieldComponent( | ||
valueFieldComponentInfo, | ||
entity, | ||
|
@@ -251,26 +355,7 @@ export default function EntityManager<E extends Record<string, EntityValueType>> | |
</tr> | ||
)) | ||
)} | ||
{showDraft && ( | ||
<tr> | ||
<TableCell colSpan={2}> | ||
<Input | ||
ref={inputRef} | ||
data-testid={'input-field'} | ||
type="text" | ||
disabled={isCreatingEntity} | ||
onChange={handleOnInputChange} | ||
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') { | ||
handleOnSave(); | ||
} else if (e.key === 'Escape') { | ||
handleOnCancel(); | ||
} | ||
}} | ||
/> | ||
</TableCell> | ||
</tr> | ||
)} | ||
{showDraft && setInputFieldsRow()} | ||
</TableBody> | ||
</Table> | ||
<div className="flex flex-row justify-end items-center space-x-3"> | ||
|
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.
Can we have the class style for the full name to be as no border (or a very subtle one) as in normal condition and when we start editing (that means when it gets focus), the border can appear? This way the field will look more similar to other, I think