Skip to content

Commit

Permalink
Upgrade to Semantic UI React v3.
Browse files Browse the repository at this point in the history
Closes #8764.
  • Loading branch information
fniessink committed May 24, 2024
1 parent f1006bc commit a9e1fa3
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 136 deletions.
31 changes: 6 additions & 25 deletions components/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react-is": "^18.3.1",
"react-timeago": "^7.2.0",
"react-toastify": "^10.0.5",
"semantic-ui-react": "^2.1.5",
"semantic-ui-react": "^3.0.0-beta.2",
"use-local-storage-state": "^19.2.0",
"victory": "^37.0.2"
},
Expand Down
4 changes: 2 additions & 2 deletions components/frontend/src/measurement/MeasurementTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export function MeasurementTarget({ metric }) {
const today = new Date()
debtEndDateInThePast = endDate.toISOString().split("T")[0] < today.toISOString().split("T")[0]
}
const label = allIssuesDone || debtEndDateInThePast ? <Label color="grey">{target}</Label> : <span>{target}</span>
const label = allIssuesDone || debtEndDateInThePast ? <Label color="grey">{target}</Label> : target
return (
<Popup hoverable on={["hover", "focus"]} trigger={label}>
<Popup hoverable on={["hover", "focus"]} trigger={<span>{label}</span>}>
{popupText(metric, debtEndDateInThePast, allIssuesDone, dataModel)}
</Popup>
)
Expand Down
6 changes: 2 additions & 4 deletions components/frontend/src/measurement/MeasurementValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function MeasurementValue({ metric, reportDate }) {
const end = new Date(metric.latest_measurement.end)
const now = reportDate ?? new Date()
const staleMeasurementValue = now - end > MILLISECONDS_PER_HOUR // No new measurement for more than one hour means something is wrong
let trigger
let trigger = value
if (staleMeasurementValue) {
trigger = <Label color="red">{value}</Label>
} else if (metric.latest_measurement.outdated) {
Expand All @@ -27,11 +27,9 @@ export function MeasurementValue({ metric, reportDate }) {
<Icon loading name="hourglass" /> {value}
</Label>
)
} else {
trigger = <span>{value}</span>
}
return (
<Popup trigger={trigger} flowing hoverable>
<Popup trigger={<span>{trigger}</span>} flowing hoverable>
{staleMeasurementValue && (
<Message
negative
Expand Down
2 changes: 1 addition & 1 deletion components/frontend/src/measurement/SourceStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function SourceStatus({ metric, measurement_source }) {
flowing
header={header}
hoverable
trigger={<Label color="red">{source_label(true)}</Label>}
trigger={<span><Label color="red">{source_label(true)}</Label></span>}
/>
)
} else {
Expand Down
4 changes: 2 additions & 2 deletions components/frontend/src/measurement/TimeLeft.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export function TimeLeft({ metric, report }) {
let trigger = <Label color="red">{triggerText}</Label>
if (timeLeft >= 0) {
deadlineLabel = "Time left to address this metric is"
trigger = <span>{triggerText}</span>
trigger = triggerText
}
return (
<Popup flowing hoverable trigger={trigger}>
<Popup flowing hoverable trigger={<span>{trigger}</span>}>
<TimeAgoWithDate date={deadline}>{deadlineLabel}</TimeAgoWithDate>.
</Popup>
)
Expand Down
16 changes: 9 additions & 7 deletions components/frontend/src/source/SourceEntities.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ export function SourceEntities({ metric, metric_uuid, reload, report, source })
<Table.HeaderCell collapsing textAlign="center">
<Popup
trigger={
<Button
basic
compact
icon={hideIgnoredEntities ? "unhide" : "hide"}
onClick={() => setHideIgnoredEntities(!hideIgnoredEntities)}
primary
/>
<span>
<Button
basic
compact
icon={hideIgnoredEntities ? "unhide" : "hide"}
onClick={() => setHideIgnoredEntities(!hideIgnoredEntities)}
primary
/>
</span>
}
content={
hideIgnoredEntities
Expand Down
190 changes: 96 additions & 94 deletions components/frontend/src/widgets/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,107 +82,109 @@ export function AddDropdownButton({ itemSubtypes, itemType, onClick, allItemSubt
onClose={() => setPopupTriggered(false)}
open={!menuOpen && popupTriggered}
trigger={
<Dropdown
basic
className="button icon primary"
floating
//onBlur={() => setQuery("")}
onClose={() => setMenuOpen(false)}
onKeyDown={(event) => {
if (!menuOpen) {
return
}
if (event.key === "Escape") {
setQuery("")
}
if (!inputHasFocus) {
// Allow for editing the query without the input having focus
if (event.key === "Backspace") {
setQuery(query.slice(0, query.length - 1))
} else if (event.key.length === 1) {
setQuery(query + event.key)
<div style={{ "display": "inline-block" }}>
<Dropdown
basic
className="button icon primary"
floating
//onBlur={() => setQuery("")}
onClose={() => setMenuOpen(false)}
onKeyDown={(event) => {
if (!menuOpen) {
return
}
}
if (options.length === 0) {
return
}
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
let newIndex
if (event.key === "ArrowUp") {
newIndex = Math.max(selectedItem - 1, 0)
} else {
newIndex = Math.min(selectedItem + 1, options.length - 1)
if (event.key === "Escape") {
setQuery("")
}
if (!inputHasFocus) {
// Allow for editing the query without the input having focus
if (event.key === "Backspace") {
setQuery(query.slice(0, query.length - 1))
} else if (event.key.length === 1) {
setQuery(query + event.key)
}
}
setSelectedItem(newIndex)
event.target
.querySelectorAll("[role='option']")
if (options.length === 0) {
return
}
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
let newIndex
if (event.key === "ArrowUp") {
newIndex = Math.max(selectedItem - 1, 0)
} else {
newIndex = Math.min(selectedItem + 1, options.length - 1)
}
setSelectedItem(newIndex)
event.target
.querySelectorAll("[role='option']")
[newIndex]?.scrollIntoView({ block: "nearest" })
}
if (event.key === "Enter") {
onClick(options[selectedItem].value)
}
}}
onOpen={() => setMenuOpen(true)}
selectOnBlur={false}
selectOnNavigation={false}
trigger={
<>
<Icon name="add" /> {`Add ${itemType} `}
</>
}
if (event.key === "Enter") {
onClick(options[selectedItem].value)
}
}}
onOpen={() => setMenuOpen(true)}
selectOnBlur={false}
selectOnNavigation={false}
trigger={
<>
<Icon name="add" /> {`Add ${itemType} `}
</>
}
value={null} // Without this, a selected item becomes active (shown bold in the menu) and can't be selected again
>
<Dropdown.Menu>
<Dropdown.Header>{`Available ${itemType} types`}</Dropdown.Header>
<Dropdown.Divider />
<Input
className="search"
focus
icon="search"
iconPosition="left"
onBlur={(event) => {
setInputHasFocus(false)
if (allItemSubtypes) {
event.stopPropagation()
} // Prevent tabbing to the checkbox from clearing the input
}}
onChange={(_event, { value }) => setQuery(value)}
onClick={stopEventPropagation}
onFocus={() => {
setInputHasFocus(true)
}}
onKeyDown={stopEventPropagationOnSpace}
placeholder={`Filter ${itemType} types`}
value={query}
/>
{allItemSubtypes?.length > 0 && (
<FilterCheckbox
label={`Select from all ${itemType} types`}
filter={showUnsupportedItems}
setFilter={setShowUnsupportedItems}
value={null} // Without this, a selected item becomes active (shown bold in the menu) and can't be selected again
>
<Dropdown.Menu>
<Dropdown.Header>{`Available ${itemType} types`}</Dropdown.Header>
<Dropdown.Divider />
<Input
className="search"
focus
icon="search"
iconPosition="left"
onBlur={(event) => {
setInputHasFocus(false)
if (allItemSubtypes) {
event.stopPropagation()
} // Prevent tabbing to the checkbox from clearing the input
}}
onChange={(_event, { value }) => setQuery(value)}
onClick={stopEventPropagation}
onFocus={() => {
setInputHasFocus(true)
}}
onKeyDown={stopEventPropagationOnSpace}
placeholder={`Filter ${itemType} types`}
value={query}
/>
)}
{usedItemSubtypeKeys?.length > 0 && (
<FilterCheckbox
label={`Hide ${itemType} types already used`}
filter={hideUsedItems}
setFilter={setHideUsedItems}
/>
)}
<Dropdown.Menu scrolling>
{options.map((option, index) => (
<Dropdown.Item
content={option.content}
key={option.key}
onClick={(_event, { value }) => onClick(value)}
selected={selectedItem === index}
text={option.text}
value={option.value}
{allItemSubtypes?.length > 0 && (
<FilterCheckbox
label={`Select from all ${itemType} types`}
filter={showUnsupportedItems}
setFilter={setShowUnsupportedItems}
/>
)}
{usedItemSubtypeKeys?.length > 0 && (
<FilterCheckbox
label={`Hide ${itemType} types already used`}
filter={hideUsedItems}
setFilter={setHideUsedItems}
/>
))}
)}
<Dropdown.Menu scrolling>
{options.map((option, index) => (
<Dropdown.Item
content={option.content}
key={option.key}
onClick={(_event, { value }) => onClick(value)}
selected={selectedItem === index}
text={option.text}
value={option.value}
/>
))}
</Dropdown.Menu>
</Dropdown.Menu>
</Dropdown.Menu>
</Dropdown>
</Dropdown>
</div>
}
/>
)
Expand Down

0 comments on commit a9e1fa3

Please sign in to comment.