Skip to content
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

Add mutualized api functions #455

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e594765
rebase: Add common API utility functions
Tristan-WorkGH Jul 11, 2024
8c7784c
rebase: Refactor existing fetchers
Tristan-WorkGH Jul 11, 2024
6a1dc70
Rework API variables
Tristan-WorkGH Jul 11, 2024
547319e
rebase: Add new common fetchers
Tristan-WorkGH Jul 11, 2024
b9c636c
rebase: `ElementExists` definition from filters
Tristan-WorkGH Jul 11, 2024
8ec3572
refactor fetchers access
Tristan-WorkGH Jul 16, 2024
47e07e4
Merge remote-tracking branch 'origin/main' into feat/add_directory_api
Tristan-WorkGH Jul 16, 2024
7f73212
Move non remote fetcher to dedicated file
Tristan-WorkGH Jul 18, 2024
c4989e9
Add fetchers for AboutDialog
Tristan-WorkGH Jul 18, 2024
de3df20
Resolve problem of `_API_GATEWAY` & `_WS_GATEWAY` variables for CRA apps
Tristan-WorkGH Jul 18, 2024
e3a16de
Add config server common fetchers
Tristan-WorkGH Jul 23, 2024
8e7d9a0
more simple use of AdboudDialog to get modules ... for us
Tristan-WorkGH Jul 23, 2024
a1930f9
better than casting
Tristan-WorkGH Jul 23, 2024
8b97ce0
Migrate common local-storage parameters
Tristan-WorkGH Jul 23, 2024
a0262f7
Merge remote-tracking branch 'origin/main' into feat/add_directory_api
Tristan-WorkGH Jul 24, 2024
eb1452c
Resolve fetchers namespace problem
Tristan-WorkGH Jul 24, 2024
571416f
Add user-admin user validation for auth
Tristan-WorkGH Jul 24, 2024
1246f1a
Merge remote-tracking branch 'origin/main' into feat/add_directory_api
Tristan-WorkGH Jul 26, 2024
bf87e31
fix bad import + cyclic dependencies
Tristan-WorkGH Jul 26, 2024
e51a054
Merge branch 'main' into feat/add_directory_api
Tristan-WorkGH Aug 6, 2024
6e3ab89
pick 120
Tristan-WorkGH Aug 6, 2024
3d0d71f
Merge remote-tracking branch 'origin/main' into feat/add_directory_api
Tristan-WorkGH Aug 6, 2024
d33b8bb
mutualize fixes
Tristan-WorkGH Jul 24, 2024
4df8b34
mutualize fixes & mutualize some fetchers
Tristan-WorkGH Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@

Library for sharing GridSuite apps commons components

#### For developers
## For developers

The commons-ui library have a demo app in which you can call your components to test them.
The `npm start` command install the library's dependencies then launches the demo app.

If you want to test your library integration with a consumer application my-app you have first
to build commons-ui via
to build commons-ui via
- `npm install` (if not already done to get `tsc`)
- `npm run build:pack`

Then in the my-app project :
- Change the commons-ui dependency in my-app's package.json from
`@gridsuite/commons-ui:"^x.x.x"`
to
`@gridsuite/commons-ui:"file:{PATH_TO_LIBRARY}/gridsuite-commons-ui-{LIBRARY_VERSION}.tgz"`
- Change the commons-ui dependency in my-app's package.json from `@gridsuite/commons-ui:"^x.x.x"`
to `@gridsuite/commons-ui:"file:{PATH_TO_LIBRARY}/gridsuite-commons-ui-{LIBRARY_VERSION}.tgz"`
- `npm install`
- `npm start`

*Warning* : with Create React App, we realised the library was not updating correctly if you try to install the library multiple times.
To fix this, run this command from the app **after** running "npm install"
- rm -Rf node_modules/.cache


#### For integrators
### Imports
Anything not exported at the root level of commons-ui is considered as internal and
not safe to use.


## For integrators

If you want to deploy a new version of commons-ui in the [NPM package registry](https://www.npmjs.com/package/@gridsuite/commons-ui),
you need to follow the steps below:
Expand All @@ -40,14 +42,16 @@ you need to follow the steps below:
- Click on "Publish release"
- It will trigger a job that will publish the release on NPM

#### License Headers and dependencies checking

## License Headers and dependencies checking

To check dependencies license compatibility with this project one locally, please run the following command :

```
npm run licenses-check
```

Notes :
Notes :
* Check [license-checker-config.json](license-checker-config.json) for license white list and exclusion.

If you need to update this list, please inform organization's owners.
2 changes: 1 addition & 1 deletion demo/src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import searchEquipments from '../data/EquipmentSearchBar';
import { EquipmentItem } from '../../src/components/ElementSearchDialog/equipment-item';
import OverflowableText from '../../src/components/OverflowableText';

import { setShowAuthenticationRouterLogin } from '../../src/redux/authActions';
import { setShowAuthenticationRouterLogin } from '../../src/utils/AuthActions';
import TableTab from './TableTab';
import FlatParametersTab from './FlatParametersTab';

Expand Down
16 changes: 11 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,29 @@
"react-dnd-html5-backend": "^16.0.1",
"react-querybuilder": "^7.2.0",
"react-virtualized": "^9.22.5",
"type-fest": "^4.21.0",
"uuid": "^9.0.1"
},
"peerDependencies": {
"@mui/system": "^5.15.15",
"@mui/x-tree-view": "^6.17.0",
"papaparse": "^5.4.1",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
"@hookform/resolvers": "^3.3.4",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
"@mui/material": "^5.15.14",
"@mui/system": "^5.15.15",
"@mui/x-tree-view": "^6.17.0",
"ag-grid-community": "^31.0.0",
"ag-grid-react": "^31.2.0",
"notistack": "^3.0.1",
"papaparse": "^5.4.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.2",
"react-intl": "^6.6.4",
"react-papaparse": "^4.1.0",
"react-router-dom": "^6.22.3",
"reconnecting-websocket": "^4.4.0",
"yup": "^1.4.0"
},
"devDependencies": {
Expand Down Expand Up @@ -129,7 +131,6 @@
"react-resizable": "^3.0.5",
"react-router-dom": "^6.22.3",
"ts-node": "^10.9.2",
"type-fest": "^4.14.0",
"typescript": "5.1.6",
"utf-8-validate": "^6.0.3",
"vite": "^5.2.7",
Expand Down
3 changes: 1 addition & 2 deletions src/components/AuthenticationRouter/AuthenticationRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import { Alert, AlertTitle, Grid } from '@mui/material';
import { FormattedMessage } from 'react-intl';
import { UserManager } from 'oidc-client';
import SignInCallbackHandler from '../SignInCallbackHandler';
import { AuthenticationActions } from '../../utils/AuthActions';
import { handleSigninCallback, handleSilentRenewCallback, login, logout } from '../../utils/AuthService';
import SilentRenewCallbackHandler from '../SilentRenewCallbackHandler';
import Login from '../Login';
import Logout from '../Login/Logout';

import { AuthenticationActions } from '../../redux/authActions';

export type AuthenticationRouterErrorState = {
userName?: string;
userValidationError?: { error: Error };
Expand Down
46 changes: 25 additions & 21 deletions src/components/DirectoryItemSelector/directory-item-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import getFileIcon from '../../utils/ElementIcon';
import { ElementType } from '../../utils/ElementType';
import TreeViewFinder, { TreeViewFinderNodeProps, TreeViewFinderProps } from '../TreeViewFinder/TreeViewFinder';
import { useSnackMessage } from '../../hooks/useSnackMessage';
import { fetchDirectoryContent, fetchElementsInfos, fetchRootFolders } from '../../services';
import { directorySvc, exploreSvc } from '../../services/instances';

const styles = {
icon: (theme: Theme) => ({
Expand Down Expand Up @@ -219,7 +219,8 @@ function DirectoryItemSelector({
);

const updateRootDirectories = useCallback(() => {
fetchRootFolders(types)
directorySvc
.fetchRootFolders(types)
.then((newData) => {
const [nrs, mdr] = updatedTree(rootsRef.current, nodeMap.current, null, newData);
setRootDirectories(nrs);
Expand All @@ -237,29 +238,32 @@ function DirectoryItemSelector({
const fetchDirectory = useCallback(
(nodeId: UUID): void => {
const typeList = types.includes(ElementType.DIRECTORY) ? [] : types;
fetchDirectoryContent(nodeId, typeList)
directorySvc
.fetchDirectoryContent(nodeId, typeList)
.then((children) => {
const childrenMatchedTypes = children.filter((item: any) => contentFilter().has(item.type));

if (childrenMatchedTypes.length > 0 && equipmentTypes && equipmentTypes.length > 0) {
fetchElementsInfos(
childrenMatchedTypes.map((e: any) => e.elementUuid),
types,
equipmentTypes
).then((childrenWithMetadata) => {
const filtredChildren = itemFilter
? childrenWithMetadata.filter((val: any) => {
// Accept every directory
if (val.type === ElementType.DIRECTORY) {
return true;
}
// otherwise filter with the custom itemFilter func
return itemFilter(val);
})
: childrenWithMetadata;
// update directory content
addToDirectory(nodeId, filtredChildren);
});
exploreSvc
.fetchElementsInfos(
childrenMatchedTypes.map((e: any) => e.elementUuid),
types,
equipmentTypes
)
.then((childrenWithMetadata) => {
const filtredChildren = itemFilter
? childrenWithMetadata.filter((val: any) => {
// Accept every directory
if (val.type === ElementType.DIRECTORY) {
return true;
}
// otherwise filter with the custom itemFilter func
return itemFilter(val);
})
: childrenWithMetadata;
// update directory content
addToDirectory(nodeId, filtredChildren);
});
} else {
// update directory content
addToDirectory(nodeId, childrenMatchedTypes);
Expand Down
32 changes: 11 additions & 21 deletions src/components/TopBar/AboutDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { LoadingButton } from '@mui/lab';
import { Apps, DnsOutlined, ExpandMore, Gavel, QuestionMark, Refresh, WidgetsOutlined } from '@mui/icons-material';
import { FormattedMessage } from 'react-intl';
import { LogoText } from './GridLogo';
import { studySvc } from '../../services/instances';
import { GridSuiteModule, ModuleType, moduleTypeSort } from './modules';

const styles = {
general: {
Expand Down Expand Up @@ -104,14 +106,6 @@ function getGlobalVersion(
return Promise.resolve(null);
}

const moduleTypeSort = {
app: 1,
server: 10,
other: 20,
};

type ModuleType = keyof typeof moduleTypeSort;

type ModuleDefinition = { name: string; type: ModuleType };

function compareModules(c1: ModuleDefinition, c2: ModuleDefinition) {
Expand All @@ -122,13 +116,7 @@ function compareModules(c1: ModuleDefinition, c2: ModuleDefinition) {
);
}

export type GridSuiteModule = {
name: string;
type: ModuleType;
version?: string;
gitTag?: string;
// license?: string;
};
export type { GridSuiteModule } from './modules';

export interface AboutDialogProps {
open: boolean;
Expand All @@ -138,7 +126,7 @@ export interface AboutDialogProps {
appVersion?: string;
appGitTag?: string;
appLicense?: string;
additionalModulesPromise?: () => Promise<GridSuiteModule[]>;
additionalModulesPromise?: string | (() => Promise<GridSuiteModule[]>);
logo?: ReactNode;
}

Expand Down Expand Up @@ -273,7 +261,7 @@ function Module({ type, name, version, gitTag }: GridSuiteModule) {
);
}

function AboutDialog({
export default function AboutDialog({
open,
onClose,
globalVersionPromise,
Expand All @@ -283,7 +271,7 @@ function AboutDialog({
appLicense,
additionalModulesPromise,
logo,
}: AboutDialogProps) {
}: Readonly<AboutDialogProps>) {
const theme = useTheme();
const [isRefreshing, setIsRefreshing] = useState(false);
const [loadingGlobalVersion, setLoadingGlobalVersion] = useState(false);
Expand Down Expand Up @@ -319,7 +307,11 @@ function AboutDialog({
// license: appLicense,
};
(additionalModulesPromise
? Promise.resolve(setLoadingAdditionalModules(true)).then(() => additionalModulesPromise())
? Promise.resolve(setLoadingAdditionalModules(true)).then(() =>
typeof additionalModulesPromise === 'string'
? studySvc.getServersInfos(additionalModulesPromise)
: additionalModulesPromise()
)
: Promise.reject(new Error('no getter'))
)
.then(
Expand Down Expand Up @@ -482,5 +474,3 @@ function AboutDialog({
</Dialog>
);
}

export default AboutDialog;
10 changes: 5 additions & 5 deletions src/components/TopBar/TopBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import { render } from '@testing-library/react';
import { IntlProvider } from 'react-intl';

import { red } from '@mui/material/colors';
import { createTheme, ThemeProvider } from '@mui/material';
import { expect, it } from '@jest/globals';
import TopBar, { LANG_ENGLISH } from './TopBar';
import { CommonMetadata, top_bar_en } from '../..';

import TopBar from './TopBar';
import { LANG_ENGLISH } from '../../utils/language';
import top_bar_en from '../translations/top-bar-en';
import { AppMetadataCommon } from '../../services';
import PowsyblLogo from '../images/powsybl_logo.svg?react';

const apps: CommonMetadata[] = [
const apps: AppMetadataCommon[] = [
{
name: 'App1',
url: '/app1',
Expand Down
15 changes: 4 additions & 11 deletions src/components/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ import { User } from 'oidc-client';
import GridLogo, { GridLogoProps } from './GridLogo';
import AboutDialog, { AboutDialogProps } from './AboutDialog';
import { LogoutProps } from '../Login/Logout';
import { CommonMetadata } from '../../services';
import { AppMetadataCommon } from '../../services';
import { GsLang, LANG_ENGLISH, LANG_FRENCH, LANG_SYSTEM } from '../../utils/language';
import { DARK_THEME, GsTheme, LIGHT_THEME } from '../../utils/theme';

const styles = {
grow: {
Expand Down Expand Up @@ -145,18 +147,9 @@ const CustomListItemIcon = styled(ListItemIcon)({
borderRadius: '25px',
});

export const DARK_THEME = 'Dark';
export const LIGHT_THEME = 'Light';
export const LANG_SYSTEM = 'sys';
export const LANG_ENGLISH = 'en';
export const LANG_FRENCH = 'fr';
const EN = 'EN';
const FR = 'FR';

export type GsLangUser = typeof LANG_ENGLISH | typeof LANG_FRENCH;
export type GsLang = GsLangUser | typeof LANG_SYSTEM;
export type GsTheme = typeof LIGHT_THEME | typeof DARK_THEME;

export type TopBarProps = Omit<GridLogoProps, 'onClick'> &
Omit<LogoutProps, 'disabled'> &
Omit<AboutDialogProps, 'open' | 'onClose'> & {
Expand All @@ -165,7 +158,7 @@ export type TopBarProps = Omit<GridLogoProps, 'onClick'> &
user?: User;
onAboutClick?: () => void;
logoAboutDialog?: ReactNode;
appsAndUrls: CommonMetadata[];
appsAndUrls: AppMetadataCommon[];
onThemeClick?: (theme: GsTheme) => void;
theme?: GsTheme;
onEquipmentLabellingClick?: (toggle: boolean) => void;
Expand Down
Loading
Loading