-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add custom input fields for editing metadata #354
Merged
aswallace
merged 15 commits into
feature/metadata-editing/develop
from
feature/metadata-editing/custom-input-fields
Jan 6, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
db639f6
customize input field depending on data type
aswallace 30cf176
create new components for duration and number inputs
aswallace 3091cbc
add combobox for dropdown type
aswallace 214cbce
respond to UX feedback for fields
aswallace b11a1fd
update labels to match designs
aswallace 6787233
minor component fixes
aswallace 5d6832e
right align number inputs
aswallace f13faee
address styling feedback
aswallace b6aba61
add option to prevent draggable modals
aswallace 384ed32
add duration restrictions and file count check
aswallace 0ffab9a
add validation for in-bounds number inputs
aswallace 43ddfec
fix duration regex and add unit tests
aswallace c47206a
fix double semicolon
aswallace 83709f3
remove bool assignment
aswallace 9328a44
add time selection for DateTime types
aswallace 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
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
47 changes: 47 additions & 0 deletions
47
packages/core/components/DateRangePicker/DateTimePicker.module.css
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,47 @@ | ||
.display-block { | ||
display: block; | ||
} | ||
|
||
.dateTimeWrapper { | ||
display: flex; | ||
} | ||
|
||
.date-range-root { | ||
width: 300px; | ||
min-width: 145px; | ||
} | ||
|
||
.date-range-text-field div, .time-picker { | ||
background-color: var(--secondary-background-color); | ||
border: none; | ||
border-radius: var(--small-border-radius); | ||
color: var(--primary-text-color); | ||
} | ||
|
||
.date-range-text-field div::after, .time-picker:focus-visible { | ||
border: 1px solid var(--aqua); | ||
outline: none; | ||
} | ||
|
||
.date-range-text-field > div, .time-picker { | ||
border: 1px solid var(--border-color) | ||
} | ||
|
||
.date-range-text-field i, .time-picker i { | ||
color: var(--primary-text-color); | ||
} | ||
|
||
.read-only-placeholder { | ||
margin-right: 20px; | ||
font-style: italic; | ||
font-size: var(--s-paragraph-size) !important; /* override FluentUI button callout font size*/ | ||
color: var(--primary-text-color); | ||
} | ||
|
||
.time-picker { | ||
height: 34px; | ||
margin: 0 0 5px 5px; | ||
color-scheme: dark; | ||
width: 150px; | ||
padding: 0 5px; | ||
} |
63 changes: 63 additions & 0 deletions
63
packages/core/components/DateRangePicker/DateTimePicker.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,63 @@ | ||
import { DatePicker } from "@fluentui/react"; | ||
import * as React from "react"; | ||
|
||
import styles from "./DateTimePicker.module.css"; | ||
|
||
interface DateTimePickerProps { | ||
className?: string; | ||
placeholder: string; | ||
defaultDate?: Date; | ||
onSelectDate: (date: Date | null | undefined) => void; | ||
showTimeSelection?: boolean; // Show time input; default false | ||
} | ||
|
||
/** | ||
* DatePicker that can also function as DateTimePicker | ||
* by including showTimeSelection prop | ||
*/ | ||
export default function DateTimePicker(props: DateTimePickerProps) { | ||
const { onSelectDate } = props; | ||
const [date, setDate] = React.useState<Date | undefined>(props?.defaultDate); | ||
const [time, setTime] = React.useState<string | undefined>(""); | ||
|
||
React.useEffect(() => { | ||
if (!date && !time) return; | ||
// Prioritize the date from datePicked, otherwise set to today | ||
const combinedDateTime: Date = date || new Date(); | ||
if (time) { | ||
combinedDateTime.setHours(Number(time.split(":")[0])); | ||
combinedDateTime.setMinutes(Number(time.split(":")[1])); | ||
combinedDateTime.setSeconds(Number(time.split(":")[2])); | ||
} | ||
onSelectDate(combinedDateTime); | ||
}, [date, time, onSelectDate]); | ||
|
||
return ( | ||
<> | ||
<DatePicker | ||
className={props?.className} | ||
styles={{ | ||
root: styles.dateRangeRoot, | ||
readOnlyPlaceholder: styles.readOnlyPlaceholder, | ||
textField: styles.dateRangeTextField, | ||
}} | ||
placeholder={props.placeholder} | ||
onSelectDate={(date) => setDate(date || undefined)} | ||
value={date} | ||
/> | ||
{props?.showTimeSelection && ( | ||
<input | ||
type="time" | ||
className={styles.timePicker} | ||
step="2" | ||
onChange={(ev) => setTime(ev.target.value)} | ||
value={time} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
DateTimePicker.defaultProps = { | ||
showTimeSelection: false, | ||
}; |
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
14 changes: 14 additions & 0 deletions
14
packages/core/components/DurationForm/DurationForm.module.css
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,14 @@ | ||
.input-wrapper { | ||
display: flex; | ||
} | ||
|
||
.input-field { | ||
margin-right: 3px; | ||
max-height: fit-content; | ||
} | ||
|
||
.input-field > input { | ||
padding: 6px; | ||
font-size: var(--s-paragraph-size); | ||
max-width: 70px; | ||
} |
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,79 @@ | ||
import * as React from "react"; | ||
|
||
import NumberField from "../NumberRangePicker/NumberField"; | ||
import annotationFormatterFactory, { AnnotationType } from "../../entity/AnnotationFormatter"; | ||
|
||
import styles from "./DurationForm.module.css"; | ||
|
||
interface DurationFormProps { | ||
className?: string; | ||
onChange: (totalDuration: number) => void; | ||
title?: string; | ||
} | ||
|
||
/** | ||
* This component renders a simple form for entering durations | ||
*/ | ||
export default function DurationForm(props: DurationFormProps) { | ||
const { onChange } = props; | ||
const [days, setDurationDays] = React.useState<string>("0"); | ||
const [hours, setDurationHours] = React.useState<string>("0"); | ||
const [minutes, setDurationMinutes] = React.useState<string>("0"); | ||
const [seconds, setDurationSeconds] = React.useState<string>("0"); | ||
const durationFormatter = annotationFormatterFactory(AnnotationType.DURATION); | ||
|
||
React.useEffect(() => { | ||
const durationString = `${Number(days) || 0}D ${Number(hours) || 0}H ${ | ||
Number(minutes) || 0 | ||
}M ${Number(seconds) || 0}S`; | ||
const totalDurationInMs = Number(durationFormatter.valueOf(durationString)); | ||
onChange(totalDurationInMs); | ||
}, [days, hours, minutes, seconds, durationFormatter, onChange]); | ||
|
||
return ( | ||
<div> | ||
<h3 className={styles.title}>{props?.title}</h3> | ||
<div className={styles.inputWrapper}> | ||
<NumberField | ||
aria-label="Days" | ||
className={styles.inputField} | ||
id="durationDays" | ||
label="Days" | ||
onChange={(event) => setDurationDays(event?.target?.value || "")} | ||
defaultValue={days} | ||
min={0} | ||
/> | ||
<NumberField | ||
aria-label="Hours" | ||
aswallace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
className={styles.inputField} | ||
id="durationHours" | ||
label="Hrs" | ||
onChange={(event) => setDurationHours(event?.target?.value || "")} | ||
defaultValue={hours} | ||
min={0} | ||
max={23} | ||
/> | ||
<NumberField | ||
aria-label="Minutes" | ||
className={styles.inputField} | ||
id="durationMinutes" | ||
label="Mins" | ||
onChange={(event) => setDurationMinutes(event?.target?.value || "")} | ||
defaultValue={minutes} | ||
min={0} | ||
max={59} | ||
/> | ||
<NumberField | ||
aria-label="Seconds" | ||
className={styles.inputField} | ||
id="durationSeconds" | ||
label="Secs" | ||
onChange={(event) => setDurationSeconds(event?.target?.value || "")} | ||
defaultValue={seconds} | ||
min={0} | ||
max={59} | ||
/> | ||
</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
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.
Seems like this component could exclusively pass around
Number
type values (for cases with leading zeroes it would just not yet return a value AKAundefined
); NBD to keep this thoughThere 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.
I agree in theory, but running into some implementation bugs