-
Notifications
You must be signed in to change notification settings - Fork 453
frontend: Expose Activity API to plugins #4005
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
Draft
sniok
wants to merge
6
commits into
kubernetes-sigs:main
Choose a base branch
from
sniok:expose-activity-api
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ae33638
frontend: Add Activity to pluginLib
sniok cd0bfc3
headlamp-plugin: Export Activity type for plugins
sniok 26e9232
frontend: Extract activitySlice into a separate file
sniok d76b8a8
plugins: examples: Add example plugin for Activities
sniok edee10a
docs: Add documentation about Activities
sniok d3a1563
frontend: Add Activity to typedoc generation
sniok 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * Copyright 2025 The Kubernetes Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
| import type { Activity } from './Activity'; | ||
|
|
||
| export interface ActivityState { | ||
| /** History of opened activities, list of IDs */ | ||
| history: string[]; | ||
| /** Map of all open activities, key is the ID */ | ||
| activities: Record<string, Activity>; | ||
| } | ||
|
|
||
| const initialState: ActivityState = { | ||
| history: [], | ||
| activities: {}, | ||
| }; | ||
|
|
||
| export const activitySlice = createSlice({ | ||
| name: 'activity', | ||
| initialState, | ||
| reducers: { | ||
| launchActivity(state, action: PayloadAction<Activity>) { | ||
| // Add to history | ||
| if (!action.payload.minimized) { | ||
| state.history = state.history.filter(it => it !== action.payload.id); | ||
| state.history.push(action.payload.id); | ||
| } | ||
|
|
||
| // Close other temporary tabs | ||
| Object.values(state.activities).forEach(activity => { | ||
| if (activity.temporary) { | ||
| delete state.activities[activity.id]; | ||
| state.history = state.history.filter(it => it !== activity.id); | ||
| } | ||
| }); | ||
|
|
||
| if (!state.activities[action.payload.id]) { | ||
| // New activity, add it to the state | ||
| state.activities[action.payload.id] = action.payload; | ||
| } else { | ||
| // Existing activity, un-minimize it | ||
| state.activities[action.payload.id].minimized = false; | ||
| } | ||
|
|
||
| // Make it fullscreen on small windows | ||
| if (window.innerWidth < 1280) { | ||
| state.activities[action.payload.id] = { | ||
| ...state.activities[action.payload.id], | ||
| location: 'full', | ||
| }; | ||
| } | ||
|
|
||
| // Dispatch resize event so the content adjusts | ||
| // 200ms delay for animations | ||
| setTimeout(() => { | ||
| window?.dispatchEvent?.(new Event('resize')); | ||
| }, 200); | ||
| }, | ||
| close(state, action: PayloadAction<string>) { | ||
| // Remove the activity from history | ||
| state.history = state.history.filter(it => it !== action.payload); | ||
| // Remove from state | ||
| delete state.activities[action.payload]; | ||
| }, | ||
| update(state, action: PayloadAction<Partial<Activity> & { id: string }>) { | ||
| // Bump this activity in history | ||
| if (!action.payload.minimized) { | ||
| state.history = state.history.filter(it => it !== action.payload.id); | ||
| state.history.push(action.payload.id); | ||
| } | ||
|
|
||
| // Remove from history if it's minimized | ||
| if (action.payload.minimized) { | ||
| state.history = state.history.filter(it => it !== action.payload.id); | ||
| } | ||
|
|
||
| // Update the state | ||
| state.activities[action.payload.id] = { | ||
| ...state.activities[action.payload.id], | ||
| ...action.payload, | ||
| }; | ||
|
|
||
| // Dispatch resize event so the content adjusts | ||
| // 200ms delay for animations | ||
| setTimeout(() => { | ||
| window?.dispatchEvent?.(new Event('resize')); | ||
| }, 200); | ||
sniok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| reset() { | ||
| return initialState; | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const activityReducer = activitySlice.reducer; | ||
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
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,29 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # The output for npm run storybook-book, static html built storybook for the plugin | ||
| storybook-static | ||
|
|
||
| .eslintcache | ||
|
|
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,5 @@ | ||
| { | ||
| // See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
| // for the documentation about the extensions.json format | ||
| "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"] | ||
| } |
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,17 @@ | ||
| // Place your settings in this file to overwrite default and user settings. | ||
| { | ||
| "editor.formatOnSave": true, | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode", | ||
| "[javascript]": { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode" | ||
| }, | ||
| "[javascriptreact]": { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode" | ||
| }, | ||
| "[typescript]": { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode" | ||
| }, | ||
| "[typescriptreact]": { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode" | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.