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

Feature/Models (master) #951

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
29eb0d8
Added the base models
cccs-nr Feb 16, 2024
d1e44ed
Added UI models
cccs-nr Feb 16, 2024
daed4bc
Typed the layout components
cccs-nr Feb 16, 2024
b65a472
Typed the admin routes
cccs-nr Feb 16, 2024
af5b6b2
Typed the admin service routes
cccs-nr Feb 16, 2024
a258ae8
Typed the statistics routes
cccs-nr Feb 16, 2024
98d967e
Typed the submission routes
cccs-nr Feb 16, 2024
e96e65d
Typed the remaining routes
cccs-nr Feb 16, 2024
2066c05
Typed the Search Result components
cccs-nr Feb 16, 2024
7e0a58f
Typed the Result Card components
cccs-nr Feb 16, 2024
a020368
Typed the File Detail components
cccs-nr Feb 16, 2024
892952b
Typed the Archive Detail components
cccs-nr Feb 16, 2024
7749cd3
Typed the common visual components
cccs-nr Feb 16, 2024
e191262
Typed the ServiceManagement components
cccs-nr Feb 16, 2024
0903133
Typed the Notification component
cccs-nr Feb 16, 2024
056d116
Fixed and added todo to enhanced table
cccs-nr Feb 16, 2024
e10ffcc
Modifying the main hooks types
cccs-nr Feb 16, 2024
cbd5d28
Removed the use of any
cccs-nr Feb 16, 2024
3d477d7
Generalized the ButtonSkeletonProps
cccs-nr Feb 16, 2024
1b3dbf9
Removed the API type in favor of generalizing the apiCall function
cccs-nr Feb 16, 2024
5f767ad
Removed unused Routes type
cccs-nr Feb 16, 2024
7c8f132
The useMyAPI doesn't like any memoization like useCallback. This need…
cccs-nr Feb 16, 2024
3208773
Typed the User Settings and related Service.
cccs-nr Feb 16, 2024
0771148
Fixed the MultiTypeParam typing
cccs-nr Feb 16, 2024
6594d87
Typed the ResetButton
cccs-nr Feb 16, 2024
cdfddb0
Typed the Alerts
cccs-nr Feb 16, 2024
cc94793
Minor typing
cccs-nr Feb 16, 2024
1c88501
Typed alert in workflow actions
cccs-nr Feb 16, 2024
4b251f9
Cleaning some types
cccs-nr Feb 19, 2024
904474e
Change colors to color
cccs-nr Feb 19, 2024
4bfff6d
Set Alert type
cccs-nr Feb 19, 2024
8459565
Moved the WhoAmIProps in the models folder
cccs-nr Feb 19, 2024
d8df05d
Reverting LinkRow props
cccs-nr Feb 20, 2024
d3a0608
Fixing the types
cccs-nr Feb 21, 2024
7c18d08
Added the submission report types
cccs-nr Feb 22, 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
5 changes: 2 additions & 3 deletions src/commons/addons/carousel/Carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
import makeStyles from '@mui/styles/makeStyles';
import { isArrowDown, isArrowLeft, isArrowRight, isArrowUp, isEscape } from 'commons/components/utils/keyboard';
import React, { useEffect, useRef } from 'react';

// TODO: Add in the commons
import React, { useEffect, useRef } from 'react';

const useStyles = makeStyles(theme => ({
container: {
Expand All @@ -19,7 +18,7 @@ export interface CarouselProps {
disableArrowRight?: boolean;
escapeCallback?: () => void;
enableSwipe?: boolean;
style?: any;
style?: React.CSSProperties;
children: React.ReactNode;
onNext: () => void;
onPrevious: () => void;
Expand Down
4 changes: 2 additions & 2 deletions src/commons/components/app/AppConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export type AppBarThemeConfigs = {

// Specification interface of describing which appbar styles are configurable.
export type AppBarStyles = {
color?: any; // Configure appbar css color style.
backgroundColor?: any; // Configure appbar css background color style.
color?: React.CSSProperties['color']; // Configure appbar css color style.
backgroundColor?: React.CSSProperties['backgroundColor']; // Configure appbar css background color style.
};

// Specification interface describing a sitemap route rendered within breadcrumbs.
Expand Down
7 changes: 3 additions & 4 deletions src/commons/components/app/AppSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AppsIcon from '@mui/icons-material/Apps';
import { Divider, List, styled, Toolbar, useMediaQuery, useTheme } from '@mui/material';
import Skeleton from '@mui/material/Skeleton';
import useAppLayout from 'commons/components/app/hooks/useAppLayout';
import { DetailedHTMLProps, HTMLAttributes } from 'react';
import { AppBarBase } from '../topnav/AppBar';
import { AppUserAvatar } from '../topnav/UserProfile';
import { AppLeftNavElement } from './AppConfigs';
Expand Down Expand Up @@ -288,12 +289,10 @@ const LeftNavElementsSkeleton = ({ elements, withText }: LeftNavElementsSkeleton
);
};

interface ButtonSkeletonProps {
style: { [styleAttr: string]: any };
// eslint-disable-next-line react/require-default-props
interface ButtonSkeletonProps extends DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
withText?: boolean;
[propName: string]: any;
}

const ButtonSkeleton = ({ style, withText, ...boxProps }: ButtonSkeletonProps) => {
const theme = useTheme();
const isXs = useMediaQuery(theme.breakpoints.only('xs'));
Expand Down
119 changes: 62 additions & 57 deletions src/components/hooks/useMyAPI.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { Configuration } from 'components/models/base/config';
import { getFileName } from 'helpers/utils';
import getXSRFCookie from 'helpers/xsrf';
import { useTranslation } from 'react-i18next';
import useALContext from './useALContext';
import useMySnackbar from './useMySnackbar';
import { ConfigurationDefinition, WhoAmIProps } from './useMyUser';
import { WhoAmIProps } from './useMyUser';

const DEFAULT_RETRY_MS = 32;

export type APIResponseProps = {
export type APIResponseProps<APIResponse extends any> = {
api_error_message: string;
api_response: any;
api_response: APIResponse;
api_server_version: string;
api_status_code: number;
};

export type DownloadResponseProps = {
export type DownloadResponseProps<APIResponse extends any> = {
api_error_message: string;
api_response: any;
api_response: APIResponse;
api_server_version: string;
api_status_code: number;
filename?: string;
Expand All @@ -31,45 +32,51 @@ export type LoginParamsProps = {
allow_pw_rest: boolean;
};

export default function useMyAPI() {
const { t } = useTranslation();
const { showErrorMessage, closeSnackbar } = useMySnackbar();
const { configuration: systemConfig } = useALContext();
type APICallProps<SuccessData extends any, FailureData extends any> = {
url: string;
contentType?: string;
method?: string;
body?: any;
reloadOnUnauthorize?: boolean;
allowCache?: boolean;
onSuccess?: (api_data: APIResponseProps<SuccessData>) => void;
onFailure?: (api_data: APIResponseProps<FailureData>) => void;
onEnter?: () => void;
onExit?: () => void;
onFinalize?: (api_data: APIResponseProps<any>) => void;
retryAfter?: number;
};

type APICallProps = {
url: string;
contentType?: string;
method?: string;
body?: any;
reloadOnUnauthorize?: boolean;
allowCache?: boolean;
onSuccess?: (api_data: APIResponseProps) => void;
onFailure?: (api_data: APIResponseProps) => void;
onEnter?: () => void;
onExit?: () => void;
onFinalize?: (api_data: APIResponseProps) => void;
retryAfter?: number;
};
type BootstrapProps = {
switchRenderedApp: (value: string) => void;
setConfiguration: (cfg: Configuration) => void;
setLoginParams: (params: LoginParamsProps) => void;
setUser: (user: WhoAmIProps) => void;
setReady: (isReady: boolean) => void;
retryAfter?: number;
};

type BootstrapProps = {
switchRenderedApp: (value: string) => void;
setConfiguration: (cfg: ConfigurationDefinition) => void;
setLoginParams: (params: LoginParamsProps) => void;
setUser: (user: WhoAmIProps) => void;
setReady: (isReady: boolean) => void;
retryAfter?: number;
};
type DownloadBlobProps<SuccessData extends any, FailureData extends any> = {
url: string;
onSuccess?: (blob: DownloadResponseProps<SuccessData>) => void;
onFailure?: (api_data: DownloadResponseProps<FailureData>) => void;
onEnter?: () => void;
onExit?: () => void;
retryAfter?: number;
};

type DownloadBlobProps = {
url: string;
onSuccess?: (blob: DownloadResponseProps) => void;
onFailure?: (api_data: DownloadResponseProps) => void;
onEnter?: () => void;
onExit?: () => void;
retryAfter?: number;
};
type UseMyAPIReturn = {
apiCall: <SuccessData = any, FailureData = any>(props: APICallProps<SuccessData, FailureData>) => void;
bootstrap: (props: BootstrapProps) => void;
downloadBlob: <SuccessData = any, FailureData = any>(props: DownloadBlobProps<SuccessData, FailureData>) => void;
};

function isAPIData(value: any) {
const useMyAPI = (): UseMyAPIReturn => {
const { t } = useTranslation();
const { showErrorMessage, closeSnackbar } = useMySnackbar();
const { configuration: systemConfig } = useALContext();

const isAPIData = (value: any): boolean => {
if (
value !== undefined &&
value !== null &&
Expand All @@ -81,21 +88,19 @@ export default function useMyAPI() {
return true;
}
return false;
}
};

function bootstrap({
const bootstrap = ({
switchRenderedApp,
setConfiguration,
setLoginParams,
setUser,
setReady,
retryAfter = DEFAULT_RETRY_MS
}: BootstrapProps) {
}: BootstrapProps) => {
const requestOptions: RequestInit = {
method: 'GET',
headers: {
'X-XSRF-TOKEN': getXSRFCookie()
},
headers: { 'X-XSRF-TOKEN': getXSRFCookie() },
credentials: 'same-origin'
};

Expand Down Expand Up @@ -167,9 +172,9 @@ export default function useMyAPI() {
switchRenderedApp('load');
}
});
}
};

function apiCall({
const apiCall = <SuccessData, FailureData>({
url,
contentType = 'application/json',
method = 'GET',
Expand All @@ -182,7 +187,7 @@ export default function useMyAPI() {
onExit,
onFinalize,
retryAfter = DEFAULT_RETRY_MS
}: APICallProps) {
}: APICallProps<SuccessData, FailureData>) => {
const requestOptions: RequestInit = {
method,
credentials: 'same-origin',
Expand Down Expand Up @@ -300,22 +305,20 @@ export default function useMyAPI() {
}
if (onFinalize) onFinalize(api_data);
});
}
};

function downloadBlob({
const downloadBlob = <SuccessData, FailureData>({
url,
onSuccess,
onFailure,
onEnter,
onExit,
retryAfter = DEFAULT_RETRY_MS
}: DownloadBlobProps) {
}: DownloadBlobProps<SuccessData, FailureData>) => {
const requestOptions: RequestInit = {
method: 'GET',
credentials: 'same-origin',
headers: {
'X-XSRF-TOKEN': getXSRFCookie()
}
headers: { 'X-XSRF-TOKEN': getXSRFCookie() }
};

// Run enter callback
Expand Down Expand Up @@ -409,7 +412,9 @@ export default function useMyAPI() {
if (retryAfter !== DEFAULT_RETRY_MS) closeSnackbar();
}
});
}
};

return { apiCall, bootstrap, downloadBlob };
}
};

export default useMyAPI;
Loading