Skip to content

Commit

Permalink
default open app
Browse files Browse the repository at this point in the history
  • Loading branch information
rstijerina committed May 21, 2024
1 parent 91d6375 commit 582323c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions client/modules/_hooks/src/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {
appsListingQuery,
type TAppCategories,
type TAppCategory,
type TPortalApp,
} from './useAppsListing';
export {
default as useGetApps,
Expand Down
6 changes: 3 additions & 3 deletions client/modules/_hooks/src/workspace/useAppsListing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from '@tanstack/react-query';
import apiClient from '../apiClient';

type PortalApp = {
export type TPortalApp = {
app_id: string;
app_type: string;
bundle_id: number;
Expand All @@ -14,14 +14,14 @@ type PortalApp = {
};

export type TAppCategory = {
apps: PortalApp[];
apps: TPortalApp[];
priority: number;
title: string;
};

export type TAppCategories = {
categories: TAppCategory[];
htmlDefinitions: { [dynamic: string]: PortalApp };
htmlDefinitions: { [dynamic: string]: TPortalApp };
};

async function getAppsListing() {
Expand Down
23 changes: 21 additions & 2 deletions client/modules/workspace/src/AppsSideNav/AppsSideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import { Menu, MenuProps } from 'antd';
import { NavLink } from 'react-router-dom';
import styles from './AppsSideNav.module.css';
import { TAppCategory } from '@client/hooks';
import { TAppCategory, TPortalApp } from '@client/hooks';
import { useGetAppParams } from '../utils';

const AppsNavLink: React.FC<React.PropsWithChildren<{ to: string }>> = ({
to,
Expand Down Expand Up @@ -108,12 +109,30 @@ export const AppsSideNav: React.FC<{ categories: TAppCategory[] }> = ({
);
});

const { appId, appVersion } = useGetAppParams();

const currentApp = categories
.map((cat) => cat.apps)
.flat()
.find((app) => app.app_id === appId && app.version === (appVersion || ''));
const currentCategory = categories.find((cat) =>
cat.apps.includes(currentApp as TPortalApp)
);
const currentSubMenu = currentApp?.is_bundled
? `${currentApp.bundle_id}`
: '';
const defaultKey = `${appId}${appVersion || ''}${currentApp?.bundle_id}`;

return (
<div className={styles.appsBrowserSidebar}>
<h3>Applications:</h3>
<Menu
mode="inline"
defaultOpenKeys={[]} // TODOv3: Default open menu and submenu for selected app
defaultOpenKeys={[
(currentCategory as TAppCategory)?.title,
currentSubMenu,
]}
defaultSelectedKeys={[defaultKey]}
items={items}
className={styles.appsGridList}
/>
Expand Down
5 changes: 1 addition & 4 deletions designsafe/apps/workspace/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,7 @@ def _get_public_apps(self, user, verbose):
category_result = {
"title": category.category,
"priority": category.priority,
"apps": [
{k: v for k, v in app.items() if v != ""}
for app in valid_tapis_apps
], # Remove empty strings from response
"apps": valid_tapis_apps,
}

# Add html apps to html_definitions
Expand Down

0 comments on commit 582323c

Please sign in to comment.