-
Notifications
You must be signed in to change notification settings - Fork 95
feat(lightspeed): implement Notebooks list/dashboard view #2537
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
lokanandaprabhu
wants to merge
1
commit into
redhat-developer:main
Choose a base branch
from
lokanandaprabhu:lightspeed-notebooks-updates
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.
Open
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions
5
workspaces/lightspeed/.changeset/notebooks-dashboard-rename-delete.md
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 @@ | ||
| --- | ||
| '@red-hat-developer-hub/backstage-plugin-lightspeed': minor | ||
| --- | ||
|
|
||
| Add AI notebooks UI, hooks, and backend support for listing/renaming/deleting sessions. |
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
112 changes: 112 additions & 0 deletions
112
workspaces/lightspeed/plugins/lightspeed/src/api/NotebooksApiClient.ts
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,112 @@ | ||
| /* | ||
| * Copyright Red Hat, Inc. | ||
| * | ||
| * 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 { ConfigApi, FetchApi } from '@backstage/core-plugin-api'; | ||
|
|
||
| import { NotebookSession } from '../types'; | ||
| import { NotebooksAPI } from './notebooksApi'; | ||
|
|
||
| /** | ||
| * @public | ||
| * AI Notebooks API client options | ||
| */ | ||
| export type NotebooksOptions = { | ||
| configApi: ConfigApi; | ||
| fetchApi: FetchApi; | ||
| }; | ||
|
|
||
| /** | ||
| * @public | ||
| * AI Notebooks API client implementation | ||
| */ | ||
| export class NotebooksApiClient implements NotebooksAPI { | ||
| private readonly configApi: ConfigApi; | ||
| private readonly fetchApi: FetchApi; | ||
|
|
||
| constructor(options: NotebooksOptions) { | ||
| this.configApi = options.configApi; | ||
| this.fetchApi = options.fetchApi; | ||
| } | ||
|
|
||
| async getBaseUrl() { | ||
| return `${this.configApi.getString('backend.baseUrl')}/api/lightspeed/ai-notebooks`; | ||
| } | ||
|
|
||
| private async fetchJson<T>(url: string, init?: RequestInit): Promise<T> { | ||
| const response = await this.fetchApi.fetch(url, { | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| ...init, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| let errorMessage = `failed to fetch data, status ${response.status}: ${response.statusText}`; | ||
| try { | ||
| const errorText = await response.text(); | ||
| if (errorText) { | ||
| try { | ||
| const errorBody = JSON.parse(errorText); | ||
| if (errorBody?.error) { | ||
| errorMessage = errorBody.error; | ||
| } | ||
| } catch { | ||
| errorMessage = errorText; | ||
| } | ||
| } | ||
| } catch (e) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn(e); | ||
| } | ||
| throw new Error(errorMessage); | ||
| } | ||
|
|
||
| const text = await response.text(); | ||
| if (!text) { | ||
| return {} as T; | ||
| } | ||
| return JSON.parse(text) as T; | ||
| } | ||
|
|
||
| async listSessions() { | ||
| const baseUrl = await this.getBaseUrl(); | ||
| const response = await this.fetchJson<{ sessions?: NotebookSession[] }>( | ||
| `${baseUrl}/v1/sessions`, | ||
| ); | ||
| return response?.sessions ?? []; | ||
| } | ||
|
|
||
| async renameSession(sessionId: string, name: string) { | ||
| const baseUrl = await this.getBaseUrl(); | ||
| await this.fetchJson( | ||
| `${baseUrl}/v1/sessions/${encodeURIComponent(sessionId)}`, | ||
| { | ||
| method: 'PUT', | ||
| body: JSON.stringify({ name }), | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| async deleteSession(sessionId: string) { | ||
| const baseUrl = await this.getBaseUrl(); | ||
| await this.fetchJson( | ||
| `${baseUrl}/v1/sessions/${encodeURIComponent(sessionId)}`, | ||
| { | ||
| method: 'DELETE', | ||
| }, | ||
| ); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
workspaces/lightspeed/plugins/lightspeed/src/api/notebooksApi.ts
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,37 @@ | ||
| /* | ||
| * Copyright Red Hat, Inc. | ||
| * | ||
| * 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 { createApiRef } from '@backstage/core-plugin-api'; | ||
|
|
||
| import { NotebookSession } from '../types'; | ||
|
|
||
| /** | ||
| * @public | ||
| * AI Notebooks API | ||
| */ | ||
| export type NotebooksAPI = { | ||
| listSessions: () => Promise<NotebookSession[]>; | ||
| renameSession: (sessionId: string, name: string) => Promise<void>; | ||
| deleteSession: (sessionId: string) => Promise<void>; | ||
| }; | ||
|
|
||
| /** | ||
| * @public | ||
| * AI Notebooks API interface | ||
| */ | ||
| export const notebooksApiRef = createApiRef<NotebooksAPI>({ | ||
| id: 'plugin.lightspeed.notebooks.service', | ||
| }); |
161 changes: 161 additions & 0 deletions
161
workspaces/lightspeed/plugins/lightspeed/src/components/DeleteNotebookModal.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,161 @@ | ||
| /* | ||
| * Copyright Red Hat, Inc. | ||
| * | ||
| * 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 { makeStyles } from '@material-ui/core/styles'; | ||
| import CloseIcon from '@mui/icons-material/Close'; | ||
| import Alert from '@mui/material/Alert'; | ||
| import Box from '@mui/material/Box'; | ||
| import Button from '@mui/material/Button'; | ||
| import Dialog from '@mui/material/Dialog'; | ||
| import DialogActions from '@mui/material/DialogActions'; | ||
| import DialogContent from '@mui/material/DialogContent'; | ||
| import DialogTitle from '@mui/material/DialogTitle'; | ||
| import IconButton from '@mui/material/IconButton'; | ||
| import Typography from '@mui/material/Typography'; | ||
|
|
||
| import { useDeleteNotebook } from '../hooks/useDeleteNotebook'; | ||
| import { useTranslation } from '../hooks/useTranslation'; | ||
|
|
||
| const useStyles = makeStyles(theme => ({ | ||
| dialogPaper: { | ||
| borderRadius: 16, | ||
| }, | ||
| dialogTitle: { | ||
| padding: '16px 20px', | ||
| fontStyle: 'inherit', | ||
| }, | ||
| dialogContent: { | ||
| paddingTop: 0, | ||
| paddingBottom: theme.spacing(5), | ||
| }, | ||
| titleRow: { | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: theme.spacing(1), | ||
| }, | ||
| titleText: { | ||
| fontWeight: 'bold', | ||
| }, | ||
| closeButton: { | ||
| position: 'absolute', | ||
| right: theme.spacing(1), | ||
| top: theme.spacing(1), | ||
| color: theme.palette.grey[700], | ||
| }, | ||
| errorBox: { | ||
| maxWidth: 650, | ||
| marginLeft: theme.spacing(2.5), | ||
| marginRight: theme.spacing(2.5), | ||
| }, | ||
| dialogActions: { | ||
| justifyContent: 'left', | ||
| padding: theme.spacing(2.5), | ||
| gap: theme.spacing(1), | ||
| }, | ||
| deleteButton: { | ||
| textTransform: 'none', | ||
| borderRadius: 999, | ||
| }, | ||
| cancelButton: { | ||
| textTransform: 'none', | ||
| borderRadius: 999, | ||
| }, | ||
| })); | ||
|
|
||
| export const DeleteNotebookModal = ({ | ||
| isOpen, | ||
| onClose, | ||
| sessionId, | ||
| name, | ||
| }: { | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| sessionId: string; | ||
| name: string; | ||
| }) => { | ||
| const classes = useStyles(); | ||
| const { t } = useTranslation(); | ||
| const { mutateAsync: deleteNotebook, isError, error } = useDeleteNotebook(); | ||
|
|
||
| const handleDelete = async () => { | ||
| try { | ||
| await deleteNotebook(sessionId); | ||
| onClose(); | ||
| } catch (e) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn(e); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog | ||
| open={isOpen} | ||
| onClose={onClose} | ||
| aria-labelledby="delete-notebook-modal" | ||
| aria-describedby="delete-notebook-modal-body" | ||
| fullWidth | ||
| PaperProps={{ | ||
| className: classes.dialogPaper, | ||
| }} | ||
| > | ||
| <DialogTitle className={classes.dialogTitle}> | ||
| <Box className={classes.titleRow}> | ||
| <Typography component="span" className={classes.titleText}> | ||
| {t('notebooks.delete.title').replace('{{name}}', name)} | ||
| </Typography> | ||
| <IconButton | ||
| aria-label="close" | ||
| onClick={onClose} | ||
| title={t('common.close')} | ||
| size="large" | ||
| className={classes.closeButton} | ||
| > | ||
| <CloseIcon /> | ||
| </IconButton> | ||
| </Box> | ||
| </DialogTitle> | ||
| <DialogContent | ||
| id="delete-notebook-modal-body" | ||
| className={classes.dialogContent} | ||
| > | ||
| <Typography variant="body2">{t('notebooks.delete.message')}</Typography> | ||
| </DialogContent> | ||
| {isError && ( | ||
| <Box className={classes.errorBox}> | ||
| <Alert severity="error">{String(error)}</Alert> | ||
| </Box> | ||
| )} | ||
| <DialogActions className={classes.dialogActions}> | ||
| <Button | ||
| variant="contained" | ||
| color="error" | ||
| className={classes.deleteButton} | ||
| onClick={handleDelete} | ||
| > | ||
| {t('notebooks.delete.action')} | ||
| </Button> | ||
| <Button | ||
| key="cancel" | ||
| variant="outlined" | ||
| className={classes.cancelButton} | ||
| onClick={onClose} | ||
| > | ||
| {t('common.cancel')} | ||
| </Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
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.
2. Delete spammable
🐞 Bug⛯ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools