-
Notifications
You must be signed in to change notification settings - Fork 9
Issue 5525/implement split btn for resource #5563
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
Open
vushu
wants to merge
2
commits into
master
Choose a base branch
from
issue-5525/implement_split_btn_for_resource
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 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 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| import {Operation, ShortcutKey} from "@/ui-components/Operation"; | ||||||
| import {Operation, OperationEnabled, ShortcutKey} from "@/ui-components/Operation"; | ||||||
| import {IconName} from "@/ui-components/Icon"; | ||||||
| import { | ||||||
| ThemeColor, | ||||||
|
|
@@ -50,6 +50,9 @@ import {callAPI, noopCall} from "@/Authentication/DataHook"; | |||||
| import {injectResourceBrowserStyle, ShortcutClass} from "./ResourceBrowserStyle"; | ||||||
| import {ASC, DESC, Filter, FilterCheckbox, FilterInput, FilterOption, FilterWithOptions, MultiOption, MultiOptionFilter, SORT_BY, SORT_DIRECTION} from "./ResourceBrowserFilters"; | ||||||
| import {sendInformationNotification} from "@/Notifications"; | ||||||
| import { UFile } from "@/UCloud/UFile"; | ||||||
| import ReactClient from "react-dom/client"; | ||||||
| import {VmActionItem, VmActionSplitButton} from "@/Applications/Jobs/VmActionSplitButton"; | ||||||
|
|
||||||
| const CLEAR_FILTER_VALUE = "\n\nCLEAR_FILTER\n\n"; | ||||||
| const UTILITY_COLOR: ThemeColor = "textPrimary"; | ||||||
|
|
@@ -138,6 +141,8 @@ export interface OperationGroup<T, R> { | |||||
| backgroundColor?: ThemeColor, | ||||||
| operations: Operation<T, R>[]; | ||||||
| iconRotation?: number; | ||||||
| operationGroupId?: string; | ||||||
| buttonStyle?: string | ||||||
| } | ||||||
|
|
||||||
| export enum SelectionMode { | ||||||
|
|
@@ -1569,6 +1574,67 @@ export class ResourceBrowser<T> { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private renderVmActionSplitButton( | ||||||
| opGroup: OperationGroup<T, unknown>, | ||||||
| selected: T[], | ||||||
| callbacks: unknown, | ||||||
| page: T[] | ||||||
| ): HTMLElement { | ||||||
| const container = document.createElement("div"); | ||||||
| container.className = "operation"; | ||||||
| container.style.display = "flex"; | ||||||
|
|
||||||
| const root = ReactClient.createRoot(container); | ||||||
|
|
||||||
| const mainOp = opGroup.operations[0]; | ||||||
| const rest = opGroup.operations.slice(1); | ||||||
|
|
||||||
| const enableResult: OperationEnabled = mainOp.enabled(selected, callbacks, page); | ||||||
| const isEnabled = enableResult === true; | ||||||
|
|
||||||
|
|
||||||
| const getText = (op): string => { | ||||||
| return typeof op.text === "string" ? op.text : op.text(selected, callbacks); | ||||||
| } | ||||||
|
|
||||||
| // Rest are menu items | ||||||
| const menuItems: VmActionItem[] = rest.map((childOp, idx) => ({ | ||||||
| key: idx.toString(), | ||||||
| value: getText(childOp), | ||||||
| icon: childOp.icon, | ||||||
| color: childOp.color ?? "primaryMain" | ||||||
|
|
||||||
| })); | ||||||
|
|
||||||
| root.render( | ||||||
| <div onClick={stopPropagationAndPreventDefault}> | ||||||
| <VmActionSplitButton | ||||||
| tone="neutral" | ||||||
| disabled={!isEnabled} | ||||||
| buttonColor={mainOp.color ?? "secondaryMain"} | ||||||
| buttonText={getText(mainOp)} | ||||||
| buttonIcon={mainOp.icon ?? "ellipsis" } | ||||||
| menuItems={menuItems} | ||||||
| onSelectMenuItem={(item) => { | ||||||
| const foundOp = rest[parseInt(item.key)]; | ||||||
| if (foundOp && foundOp.enabled(selected, callbacks, page) === true) { | ||||||
| foundOp.onClick(selected, callbacks, page); | ||||||
| } | ||||||
| }} | ||||||
| onButtonClick={() => { | ||||||
| if (isEnabled) { | ||||||
| console.log("Enabled", mainOp); | ||||||
| mainOp.onClick(selected, callbacks, page); | ||||||
| } | ||||||
| }} | ||||||
| /> | ||||||
| </div> | ||||||
| ); | ||||||
|
|
||||||
| return container; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| private renderOperationsIn(useContextMenu: boolean, contextOpts?: { | ||||||
| x: number, | ||||||
| y: number, | ||||||
|
|
@@ -1879,7 +1945,13 @@ export class ResourceBrowser<T> { | |||||
| const target = this.operations; | ||||||
| target.innerHTML = ""; | ||||||
| for (const op of operations) { | ||||||
| target.append(renderOperation(op)); | ||||||
| if (op.buttonStyle === "split") { | ||||||
|
Contributor
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. buttonStyle exists for OperationGroup and not Operation, so this check can fix this:
Suggested change
|
||||||
| // Rendering SplitButton | ||||||
| target.append(this.renderVmActionSplitButton(op, selected, callbacks, page)); | ||||||
| } | ||||||
| else { | ||||||
| target.append(renderOperation(op)); | ||||||
| } | ||||||
| } | ||||||
| } else { | ||||||
| const posX = contextOpts?.x ?? 0; | ||||||
|
|
@@ -3868,3 +3940,4 @@ export function favoriteRowIcon(row: ResourceBrowserRow) { | |||||
| } | ||||||
| return favoriteIcon; | ||||||
| } | ||||||
|
|
||||||
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.
childOp.icon needs a fallback value here, otherwise is a compilation error.