-
-
Notifications
You must be signed in to change notification settings - Fork 73
Add timings to stage view #814
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b3e5dd8
Add timings to stage view
timja ffd9f8e
Imports
timja 1924246
Add settings UI
timja 2d49427
refactor: move symbols to common
lewisbirks 248cebd
refactor: move settings control into react
lewisbirks 14292bf
Prettier
timja 38581e1
refactor: accessibility, file name standardisation, formatting
lewisbirks 6864ef1
Merge remote-tracking branch 'upstream/main' into fork/timja/display-…
lewisbirks e0d0683
add options to the stages page
lewisbirks 9bc3cda
Resolve merge conflicts
timja 47495ae
Format
timja f2da90d
Hide popup
timja 2e39bc7
Use preferences
timja 1f4ad27
Fixups
timja c29e548
Mostly there
timja 344081d
Closer
timja b8dc2bb
re-render on layout change
timja 7c7c421
Fix missing provider
timja 63d237c
Another place
timja e3aa025
Fix test
timja c8a6416
linting
lewisbirks ddad509
Update src/main/frontend/pipeline-graph-view/pipeline-graph/main/supp…
timja 324c87e
Compress stages a bit
timja 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 hidden or 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 hidden or 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,25 @@ | ||
| import { useId } from "react"; | ||
|
|
||
| export default function Checkbox({ | ||
| label, | ||
| value, | ||
| setValue, | ||
| }: { | ||
| label: string; | ||
| value: boolean; | ||
| setValue: (e: boolean) => void; | ||
| }) { | ||
| const id = useId(); | ||
| return ( | ||
| <div className="jenkins-checkbox"> | ||
| <input | ||
| type="checkbox" | ||
| id={id} | ||
| name={id} | ||
| checked={value} | ||
| onChange={(e) => setValue(e.target.checked)} | ||
| /> | ||
| <label htmlFor={id}>{label}</label> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
90 changes: 90 additions & 0 deletions
90
src/main/frontend/common/user/user-preferences-provider.tsx
This file contains hidden or 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,90 @@ | ||
| import { | ||
| createContext, | ||
| ReactNode, | ||
| useContext, | ||
| useEffect, | ||
| useState, | ||
| } from "react"; | ||
|
|
||
| interface PipelineGraphViewPreferences { | ||
| showNames: boolean; | ||
| setShowNames: (val: boolean) => void; | ||
| showDurations: boolean; | ||
| setShowDurations: (val: boolean) => void; | ||
| } | ||
|
|
||
| const defaultPreferences = { | ||
| showNames: false, | ||
| showDurations: false, | ||
| }; | ||
|
|
||
| const UserPreferencesContext = createContext< | ||
| PipelineGraphViewPreferences | undefined | ||
| >(undefined); | ||
|
|
||
| const makeKey = (setting: string) => `pgv-graph-view.${setting}`; | ||
|
|
||
| const loadFromLocalStorage = <T,>(key: string, fallback: T): T => { | ||
| if (typeof window === "undefined") { | ||
| return fallback; | ||
| } | ||
| try { | ||
| const value = window.localStorage.getItem(key); | ||
| if (value !== null) { | ||
| if (typeof fallback === "boolean") { | ||
| return (value === "true") as typeof fallback; | ||
| } | ||
| return value as unknown as T; | ||
| } | ||
| } catch (e) { | ||
| console.error(`Error loading localStorage key "${key}"`, e); | ||
| } | ||
| return fallback; | ||
| }; | ||
|
|
||
| export const UserPreferencesProvider = ({ | ||
| children, | ||
| }: { | ||
| children: ReactNode; | ||
| }) => { | ||
| const stageNamesKey = makeKey("stageNames"); | ||
| const stageDurationsKey = makeKey("stageDurations"); | ||
|
|
||
| const [showNames, setShowNames] = useState<boolean>( | ||
| loadFromLocalStorage(stageNamesKey, defaultPreferences.showNames), | ||
| ); | ||
| const [showDurations, setShowDurations] = useState<boolean>( | ||
| loadFromLocalStorage(stageDurationsKey, defaultPreferences.showDurations), | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| window.localStorage.setItem(stageNamesKey, String(showNames)); | ||
| }, [showNames]); | ||
|
|
||
| useEffect(() => { | ||
| window.localStorage.setItem(stageDurationsKey, String(showDurations)); | ||
| }, [showDurations]); | ||
|
|
||
| return ( | ||
| <UserPreferencesContext.Provider | ||
| value={{ | ||
| showNames, | ||
| setShowNames, | ||
| showDurations, | ||
| setShowDurations, | ||
| }} | ||
| > | ||
| {children} | ||
| </UserPreferencesContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export const useUserPreferences = (): PipelineGraphViewPreferences => { | ||
| const context = useContext(UserPreferencesContext); | ||
| if (!context) { | ||
| throw new Error( | ||
| "useMonitorPreferences must be used within a UserPreferencesProvider", | ||
| ); | ||
| } | ||
| return context; | ||
| }; |
This file contains hidden or 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 hidden or 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
51 changes: 51 additions & 0 deletions
51
src/main/frontend/multi-pipeline-graph-view/multi-pipeline-graph/main/overfow-dropdown.tsx
This file contains hidden or 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,51 @@ | ||
| import Checkbox from "../../../common/components/checkbox.tsx"; | ||
| import Dropdown from "../../../common/components/dropdown.tsx"; | ||
| import DropdownPortal from "../../../common/components/dropdown-portal.tsx"; | ||
| import { SETTINGS } from "../../../common/components/symbols.tsx"; | ||
| import { LocalizedMessageKey, useMessages } from "../../../common/i18n"; | ||
| import { useUserPermissions } from "../../../common/user/user-permission-provider.tsx"; | ||
| import { useUserPreferences } from "../../../common/user/user-preferences-provider.tsx"; | ||
|
|
||
| interface OverflowDropdownProps { | ||
| buttonPortal: HTMLElement; | ||
| } | ||
|
|
||
| export default function OverflowDropdown({ | ||
| buttonPortal, | ||
| }: OverflowDropdownProps) { | ||
| const { showNames, setShowNames, showDurations, setShowDurations } = | ||
| useUserPreferences(); | ||
| const { canConfigure } = useUserPermissions(); | ||
| const messages = useMessages(); | ||
| return ( | ||
| <DropdownPortal container={buttonPortal}> | ||
| <Dropdown | ||
| className={"jenkins-card__reveal"} | ||
| items={[ | ||
| <div className={"pgv-dropdown-checkboxes"} key={"settings-options"}> | ||
| <Checkbox | ||
| label={messages.format(LocalizedMessageKey.showNames)} | ||
| value={showNames} | ||
| setValue={setShowNames} | ||
| /> | ||
| <Checkbox | ||
| label={messages.format(LocalizedMessageKey.showDuration)} | ||
| value={showDurations} | ||
| setValue={setShowDurations} | ||
| /> | ||
| </div>, | ||
| canConfigure ? "separator" : <></>, | ||
| canConfigure ? ( | ||
| { | ||
| text: "Configure", | ||
| icon: SETTINGS, | ||
| href: `../configure`, | ||
| } | ||
| ) : ( | ||
| <></> | ||
| ), | ||
| ]} | ||
| /> | ||
| </DropdownPortal> | ||
| ); | ||
| } |
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.
needs to be re-added behind a setting, possibly we can calculate it based on longest stage name too so we don't have to lose all the value by shortening it