Skip to content

Commit

Permalink
fix(vwb): SKFP-1084 manage loading state (#4007)
Browse files Browse the repository at this point in the history
  • Loading branch information
lflangis authored May 24, 2024
1 parent 7187cd3 commit 5de0b61
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/store/notebook/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useSelector } from 'react-redux';

import { notebookSelector } from './selector';

export type { initialState as NotebookInitialState } from './types';
Expand Down
1 change: 1 addition & 0 deletions src/store/notebook/selector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RootState } from 'store/types';

import { initialState } from './types';

export type NotebookProps = initialState;
Expand Down
6 changes: 0 additions & 6 deletions src/store/notebook/slice.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

import { NotebookApiStatus } from 'services/api/notebook/model';

import { getNotebookClusterManifest } from './thunks';
import { initialState } from './types';

export const NotebookState: initialState = {
isLoading: false,
url: '',
status: NotebookApiStatus.unverified,
};

const notebookSlice = createSlice({
Expand All @@ -32,7 +28,6 @@ const notebookSlice = createSlice({
builder.addCase(getNotebookClusterManifest.pending, (state) => ({
...state,
isLoading: true,
status: NotebookApiStatus.createInProgress,
error: null,
}));
builder.addCase(getNotebookClusterManifest.fulfilled, (state) => ({
Expand All @@ -42,7 +37,6 @@ const notebookSlice = createSlice({
builder.addCase(getNotebookClusterManifest.rejected, (state, action) => ({
...state,
error: action.payload,
status: NotebookApiStatus.unverified,
isLoading: false,
}));
},
Expand Down
4 changes: 0 additions & 4 deletions src/store/notebook/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { NotebookApiStatus } from 'services/api/notebook/model';

export type initialState = {
url: string;
status: NotebookApiStatus;
error?: any;
isLoading: boolean;
};
17 changes: 4 additions & 13 deletions src/views/Dashboard/components/DashboardCards/Notebook/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useState } from 'react';
import intl from 'react-intl-universal';
import { useDispatch } from 'react-redux';
import { ApiOutlined, RocketOutlined } from '@ant-design/icons';
Expand All @@ -8,15 +8,13 @@ import { IFenceService } from '@ferlab/ui/core/components/Widgets/AuthorizedStud
import FencesAuthentificationModal from '@ferlab/ui/core/components/Widgets/AuthorizedStudies/FencesAuthentificationModal';
import GridCard from '@ferlab/ui/core/view/v2/GridCard';
import { Alert, Button, Space, Typography } from 'antd';
import { isNotebookStatusInProgress, isNotebookStatusLaunched } from 'helpers/notebook';
import CardHeader from 'views/Dashboard/components/CardHeader';
import { DashboardCardProps } from 'views/Dashboard/components/DashboardCards';

import { FENCE_NAMES } from 'common/fenceTypes';
import logo from 'components/assets/jupyterLab.png';
import KidsFirstLoginIcon from 'components/Icons/KidsFirstLoginIcon';
import NciIcon from 'components/Icons/NciIcon';
import OpenInNewIcon from 'components/Icons/OpenInIcon';
import { TUserGroups } from 'services/api/user/models';
import { useAtLeastOneFenceConnected, useFenceAuthentification } from 'store/fences';
import { fenceDisconnection, fenceOpenAuhentificationTab } from 'store/fences/thunks';
Expand Down Expand Up @@ -57,7 +55,7 @@ const Notebook = ({ id, key, className = '' }: DashboardCardProps) => {
];
const [isFenceModalAuthentificationOpen, setIsFenceModalAuthentificationOpen] =
useState<boolean>(false);
const { url, isLoading, error, status } = useNotebook();
const { isLoading, error } = useNotebook();
const { groups } = useUser();
const onCloseFenceAuthentificationModal = () => {
setIsFenceModalAuthentificationOpen(false);
Expand All @@ -69,7 +67,7 @@ const Notebook = ({ id, key, className = '' }: DashboardCardProps) => {
const hasAtLeastOneAuthentificatedFence = useAtLeastOneFenceConnected();

const isAllowed = groups.includes(TUserGroups.BETA);
const isProcessing = (isLoading || isNotebookStatusInProgress(status)) && !error;
const isProcessing = isLoading && !error;

const handleGetManifest = () => {
dispatch(getNotebookClusterManifest());
Expand Down Expand Up @@ -153,7 +151,7 @@ const Notebook = ({ id, key, className = '' }: DashboardCardProps) => {
</Button>
)}

{hasAtLeastOneAuthentificatedFence && !url && (
{hasAtLeastOneAuthentificatedFence && (
<Button
loading={isProcessing}
disabled={!isAllowed}
Expand All @@ -165,13 +163,6 @@ const Notebook = ({ id, key, className = '' }: DashboardCardProps) => {
{intl.get('screen.dashboard.cards.notebook.launch')}
</Button>
)}

{hasAtLeastOneAuthentificatedFence && url && isNotebookStatusLaunched(status) && (
<Button type="primary" size="small" href={url} target="_blank">
<span>{intl.get('screen.dashboard.cards.notebook.open')}</span>
<OpenInNewIcon width={12.5} height={12.5} />
</Button>
)}
</Space>

<Space className={styles.message} size={8} direction="vertical">
Expand Down

0 comments on commit 5de0b61

Please sign in to comment.