-
Couldn't load subscription status.
- Fork 17
Feat/react dashboard utils #1570
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
Closed
vani-walvekar1494
wants to merge
29
commits into
feat/react-dashboard
from
feat/react-dashboard-utils
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0bf844a
feat: recently accessed components
vani-walvekar1494 7a7c3b2
fix: format files to pass nx format check
vani-walvekar1494 6292b87
Fix: resolved merge conflicts and updated dashboard styles
vani-walvekar1494 35f37ad
chore: format AppsSideNav to pass format:check
vani-walvekar1494 3ccaa74
Fix: Replace 'any' with proper types in RecentProjects to satisfy lin…
vani-walvekar1494 9a6aa1b
chore: format files to pass nx format check
vani-walvekar1494 2fb2441
wip: partial DB connection setup and fix for recent tools issue
vani-walvekar1494 c439559
wip: partial DB connection setup and fix for recent tools issue
vani-walvekar1494 4ec4659
Merge remote-tracking branch 'origin/feat/react-dashboard' into feat/…
vani-walvekar1494 89f43e8
Apply local changes after merging feat/react-dashboard
vani-walvekar1494 ae7e243
Fix lint error and other updates
vani-walvekar1494 9698ff4
Fix lint error and update files after merging feat/react-dashboard
vani-walvekar1494 c4e91a4
Fix formatting issues
vani-walvekar1494 98b6f96
Format migration files with Black
vani-walvekar1494 db1aec1
chore: refactor dashboard API, cleanup migrations, remove unused icons
vani-walvekar1494 b5e6a15
fix: format files to pass lint checks
vani-walvekar1494 b5d0868
fix(AppsSideNav): add Applications header text to resolve failing test
vani-walvekar1494 b6045cd
fix: resolve AppsSideNav formatting issues
vani-walvekar1494 245cefe
fix: remove unused imports and variables in AppsSideNav to pass lint …
vani-walvekar1494 7af4852
Merge feat/react-dashboard into feat/react-dashboard-utils: resolved …
vani-walvekar1494 03e9fa5
feat(dashboard): update layout and fix recent projects visibility
vani-walvekar1494 aaeed75
Resolved merge conflicts and merged feat/react-dashboard into feat/re…
vani-walvekar1494 be8befc
Revert package-lock.json changes and formatting changes in api/datafi…
vani-walvekar1494 913da5a
changed sidebar styling and fixed tool navigation
vani-walvekar1494 294abbe
fixed linting for package-lock.json
vani-walvekar1494 6092a55
Fixed AppsSideNav hook usage
vani-walvekar1494 d23e6ef
fix: show Applications: header during loading to fix unit test
vani-walvekar1494 e582a90
Refactored favorites logic, fix types,updated styling and dependencies
vani-walvekar1494 63701fd
Restore apps.ts from main to include missing comments/docstrings
vani-walvekar1494 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; | ||
| import apiClient from './apiClient'; | ||
|
|
||
| export interface FavoriteTool { | ||
| tool_id: string; | ||
| version?: string; | ||
| } | ||
|
|
||
| const fetchFavorites = async ({ | ||
| signal, | ||
| }: { | ||
| signal: AbortSignal; | ||
| }): Promise<FavoriteTool[]> => { | ||
| const res = await apiClient.get('/api/workspace/user-favorites/', { signal }); | ||
| return res.data; | ||
| }; | ||
|
|
||
| const addFavorite = async (toolId: string): Promise<void> => { | ||
| await apiClient.post('/api/workspace/user-favorites/', { tool_id: toolId }); | ||
| }; | ||
|
|
||
| const removeFavorite = async (toolId: string): Promise<void> => { | ||
| await apiClient.post('/api/workspace/user-favorites/remove/', { | ||
| tool_id: toolId, | ||
| }); | ||
| }; | ||
|
|
||
| export const useFavorites = () => { | ||
| return useQuery({ | ||
| queryKey: ['workspace', 'favorites'], | ||
| queryFn: fetchFavorites, | ||
| staleTime: 5 * 60 * 1000, | ||
| refetchOnMount: false, | ||
| refetchOnWindowFocus: false, | ||
| }); | ||
| }; | ||
|
|
||
| export const useAddFavorite = () => { | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useMutation({ | ||
| mutationFn: addFavorite, | ||
| onMutate: async (toolId) => { | ||
| await queryClient.cancelQueries({ queryKey: ['workspace', 'favorites'] }); | ||
|
|
||
| const previousFavorites = queryClient.getQueryData<FavoriteTool[]>([ | ||
| 'workspace', | ||
| 'favorites', | ||
| ]); | ||
|
|
||
| queryClient.setQueryData<FavoriteTool[]>( | ||
| ['workspace', 'favorites'], | ||
| (old = []) => [...old, { tool_id: toolId }] | ||
| ); | ||
|
|
||
| return { previousFavorites }; | ||
| }, | ||
| onError: (_err, _toolId, context) => { | ||
| if (context?.previousFavorites) { | ||
| queryClient.setQueryData( | ||
| ['workspace', 'favorites'], | ||
| context.previousFavorites | ||
| ); | ||
| } | ||
| }, | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: ['workspace', 'favorites'] }); | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| export const useRemoveFavorite = () => { | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useMutation({ | ||
| mutationFn: removeFavorite, | ||
| onMutate: async (toolId) => { | ||
| await queryClient.cancelQueries({ queryKey: ['workspace', 'favorites'] }); | ||
|
|
||
| const previousFavorites = queryClient.getQueryData<FavoriteTool[]>([ | ||
| 'workspace', | ||
| 'favorites', | ||
| ]); | ||
|
|
||
| queryClient.setQueryData<FavoriteTool[]>( | ||
| ['workspace', 'favorites'], | ||
| (old = []) => old.filter((fav) => fav.tool_id !== toolId) | ||
| ); | ||
|
|
||
| return { previousFavorites }; | ||
| }, | ||
| onError: (_err, _toolId, context) => { | ||
| if (context?.previousFavorites) { | ||
| queryClient.setQueryData( | ||
| ['workspace', 'favorites'], | ||
| context.previousFavorites | ||
| ); | ||
| } | ||
| }, | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: ['workspace', 'favorites'] }); | ||
| }, | ||
| }); | ||
| }; |
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
62 changes: 55 additions & 7 deletions
62
client/modules/dashboard/src/Dashboard/Dashboard.module.css
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,7 +1,55 @@ | ||
| /* | ||
| * Replace this with your own classes | ||
| * | ||
| * e.g. | ||
| * .container { | ||
| * } | ||
| */ | ||
| .dashboardContainer { | ||
| display: flex; | ||
| min-height: 100vh; | ||
| background-color: #fafafa; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .sidebar { | ||
| width: 260px; | ||
| background-color: #f5f7fa; | ||
| padding: 1.5rem; | ||
| box-shadow: 0 0 10px rgba(0, 0, 0, 0.05); | ||
| position: sticky; | ||
| top: 80px; | ||
| border-radius: 8px; | ||
| min-height: calc(100vh - 80px); | ||
| overflow-y: auto; | ||
| } | ||
|
|
||
| .sidebarMargin { | ||
| flex: 1; | ||
| padding: 1rem 2rem; | ||
| overflow-y: auto; | ||
| min-height: calc(100vh - 80px); | ||
| } | ||
|
|
||
| .sidebarTitle { | ||
| font-size: 1.55rem; | ||
| font-weight: 600; | ||
| margin-bottom: 1.2rem; | ||
| color: #2c3e50; | ||
| border-bottom: 1px solid #ddd; | ||
| padding-bottom: 0.4rem; | ||
| } | ||
|
|
||
| .sidebarLink { | ||
| display: block; | ||
| margin: 0.75rem 0; | ||
| color: #1f2d3d; | ||
| font-size: 1.5rem; | ||
| font-weight: 500; | ||
| transition: all 0.2s ease; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| .sidebarLink:hover { | ||
| color: #007bff; | ||
| text-decoration: underline; | ||
| padding-left: 5px; | ||
| } | ||
|
|
||
| .sidebarIcon { | ||
| margin-right: 8px; | ||
| vertical-align: middle; | ||
| } |
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
158 changes: 158 additions & 0 deletions
158
client/modules/dashboard/src/Dashboard/FavoriteTools.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,158 @@ | ||
| import React, { useState } from 'react'; | ||
| import { Typography, List, Button } from 'antd'; | ||
| import { useFavorites, useRemoveFavorite, useAppsListing } from '@client/hooks'; | ||
| import type { TPortalApp } from '@client/hooks'; | ||
|
|
||
| const { Link, Text } = Typography; | ||
|
|
||
| interface Favorite { | ||
| app_id: string; | ||
| version?: string; | ||
| id: string; | ||
| } | ||
|
|
||
| interface RecentTool { | ||
| label: string; | ||
| path: string; | ||
| } | ||
|
|
||
| const parseToolId = (tool_id: string): { app_id: string; version?: string } => { | ||
| const parts = tool_id.split('-'); | ||
| if (parts.length > 1 && /^\d+(\.\d+)*$/.test(parts[parts.length - 1])) { | ||
| return { | ||
| app_id: parts.slice(0, -1).join('-'), | ||
| version: parts[parts.length - 1], | ||
| }; | ||
| } | ||
| return { app_id: tool_id }; | ||
| }; | ||
|
|
||
| const makeFavoriteKey = (fav: Favorite) => | ||
| fav.version ? `${fav.app_id}-${fav.version}` : fav.app_id; | ||
|
|
||
| const QuickLinksMenu: React.FC = () => { | ||
| const [showFavorites, setShowFavorites] = useState(false); | ||
| const { data: favoritesData, isLoading: loadingFavs } = useFavorites(); | ||
| const { data: appsData, isLoading: loadingApps } = useAppsListing(); | ||
| const removeFavoriteMutation = useRemoveFavorite(); | ||
| const [removingIds, setRemovingIds] = useState<Set<string>>(new Set()); | ||
|
|
||
| if (loadingFavs || loadingApps) return <div>Loading favorites...</div>; | ||
|
|
||
| const allApps: TPortalApp[] = | ||
| appsData?.categories.flatMap((cat) => cat.apps) ?? []; | ||
|
|
||
| const favorites: Favorite[] = (favoritesData ?? []).map((fav) => { | ||
| const { app_id, version } = parseToolId(fav.tool_id); | ||
| return { app_id, version, id: fav.tool_id }; | ||
| }); | ||
|
|
||
| const resolvedFavorites = favorites | ||
| .map((fav) => { | ||
| const matchedApp = allApps.find( | ||
| (app) => | ||
| app.app_id === fav.app_id && | ||
| (!fav.version || app.version === fav.version) | ||
| ); | ||
| if (!matchedApp) return null; | ||
| return { | ||
| key: makeFavoriteKey(fav), | ||
| app: matchedApp, | ||
| id: fav.id, | ||
| }; | ||
| }) | ||
| .filter(Boolean) as { key: string; app: TPortalApp; id: string }[]; | ||
|
|
||
| const handleRemove = async (key: string) => { | ||
| if (removingIds.has(key)) return; | ||
|
|
||
| setRemovingIds((prev) => new Set(prev).add(key)); | ||
|
|
||
| try { | ||
| await removeFavoriteMutation.mutateAsync(key); | ||
| } catch (error) { | ||
| console.error('Failed to remove favorite:', error); | ||
| } finally { | ||
| setRemovingIds((prev) => { | ||
| const newSet = new Set(prev); | ||
| newSet.delete(key); | ||
| return newSet; | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| const handleToolClick = (app: TPortalApp) => { | ||
| const href = app.version | ||
| ? `/workspace/${app.app_id}?appVersion=${app.version}` | ||
| : `/workspace/${app.app_id}`; | ||
|
|
||
| const recent: RecentTool[] = JSON.parse( | ||
| localStorage.getItem('recentTools') ?? '[]' | ||
| ); | ||
| const updated = [ | ||
| { label: app.label, path: href }, | ||
| ...recent.filter((r) => r.path !== href), | ||
| ].slice(0, 5); | ||
| localStorage.setItem('recentTools', JSON.stringify(updated)); | ||
|
|
||
| window.open(href, '_blank', 'noopener,noreferrer'); | ||
| }; | ||
|
|
||
| return ( | ||
| <nav> | ||
| <div style={{ marginBottom: 8 }}> | ||
| <Link | ||
| onClick={() => setShowFavorites((v) => !v)} | ||
| style={{ fontWeight: 'bold', cursor: 'pointer' }} | ||
| aria-expanded={showFavorites} | ||
| aria-controls="favorite-apps-list" | ||
| > | ||
| Favorite Apps | ||
| </Link> | ||
| </div> | ||
|
|
||
| {showFavorites && ( | ||
| <div id="favorite-apps-list" style={{ marginBottom: 16 }}> | ||
| {resolvedFavorites.length === 0 ? ( | ||
| <Text type="secondary">No favorite tools yet.</Text> | ||
| ) : ( | ||
| <List | ||
| size="small" | ||
| dataSource={resolvedFavorites} | ||
| bordered | ||
| style={{ background: '#fff' }} | ||
| renderItem={({ app, key }) => ( | ||
| <List.Item | ||
| key={key} | ||
| actions={[ | ||
| <Button | ||
| type="text" | ||
| loading={removingIds.has(key)} | ||
| onClick={() => handleRemove(key)} | ||
| aria-label={`Remove favorite ${app.label}`} | ||
| style={{ color: '#FAAD14' }} | ||
| > | ||
| ★ | ||
| </Button>, | ||
| ]} | ||
| > | ||
| <Link | ||
| onClick={() => handleToolClick(app)} | ||
| tabIndex={0} | ||
| onKeyDown={(e) => { | ||
| if (e.key === 'Enter') handleToolClick(app); | ||
| }} | ||
| > | ||
| {app.label} | ||
| </Link> | ||
| </List.Item> | ||
| )} | ||
| /> | ||
| )} | ||
| </div> | ||
| )} | ||
| </nav> | ||
| ); | ||
| }; | ||
|
|
||
| export default QuickLinksMenu; |
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.
Keeping in mind what Jake said about module boundaries, I think this should be refactored to use existing schema and types, similar to how
useAppsListinganduseGetAppParamswork. You probably don't need to reinvent the wheel with atool_idandversionwhenapp_idandversionalready exist.Again keeping in mind what Jake said about module boundaries, I think you also can probably handle some of these functions with existing code. Does
handleClickOutsideneed to be used when you can use code similar toPreviewModal?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.
The updated code now uses existing app_id and version types consistently, it also removes the unnecessary handleClickOutside logic, relying on React state and Ant Design components for UI control.