Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"tslint": "tsc",
"all": "eslint './src/**/*.ts*' & react-scripts test --all & tsc"
},
"homepage": "/login",
"browserslist": {
"production": [
">0.2%",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/routes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { routePaths } from '../routes/routePaths';
export const loggedOutRoute = routePaths.login;
export const loggedInRoute = routePaths.home;
export const loggedInRoute = routePaths.home(':string');
20 changes: 10 additions & 10 deletions src/redux/reducers/projectsReducer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_PROJECT_NAME } from '../../constants';
import { camelCaseArray } from '../../utils/camelCase';
import { projectActionTypes } from '../actionTypes';
import { byKeyInsert, idsInsert } from './reducerHelpers';
Expand All @@ -7,7 +8,7 @@ export interface State {
byId: Record<TId, Projects>;
myProjectIds: TId[];
selectedProject: string;
projectStats: any
projectStats: any;
}

type ProjectsPayload = Projects[];
Expand All @@ -25,20 +26,20 @@ export const initialState: State = {
byId: {},
myProjectIds: [],
selectedProject: '',
projectStats: {}
projectStats: {},
};

const newState = (
state: State,
projects: Projects[],
defaultSelectedProject?: string,
projectStats?: object
projectStats?: object,
): State => ({
...state,
ids: idsInsert(state.ids, projects),
byId: byKeyInsert(state.byId, projects),
selectedProject: defaultSelectedProject as string,
projectStats: projectStats
projectStats: projectStats,
});

const projectsReducer = (
Expand All @@ -55,7 +56,7 @@ const projectsReducer = (
(project: Projects) => project.id,
);
if (action.requestParams.selectDefault === undefined) {
const defaultSelectedProject = projects[0].name;
const defaultSelectedProject = DEFAULT_PROJECT_NAME;
return {
...newState(state, projects, defaultSelectedProject),
myProjectIds,
Expand All @@ -73,22 +74,21 @@ const projectsReducer = (
const myProjectIds: TId[] = allProjects.map(
(project: Projects) => project.id,
);

return {
...newState(state, allProjects, seletecdProject),
myProjectIds,
};
}


case projectActionTypes.getMyProjectStats.success: {
// const { projectStats } = action.payload as any;
const projectStats = action.payload;
return { ...newState(state, projectStats) };

return { ...newState(state, projectStats) };
}

default:
default:
return state;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/routes/appRoutesConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const routes = [
},
},
{
path: routePaths.home,
path: routePaths.home(':string'),
Component: Home,
visibility: {
authentication: RouteVisibilityAuthentication.authenticatedOnly,
Expand Down
11 changes: 5 additions & 6 deletions src/routes/routePaths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ export const routePaths = {
signup: '/signup',
userEmail: `/user-email`,
forgot: '/forgot-password',
home: '/',
home: (project: string): string => `/projects/${project}`,
pipelines: {
base: `/pipelines`,
list: (project: string): string => `/projects/${project}/pipelines/list`,
allRuns: (project: string): string =>
`/projects/${project}/pipelines/all-runs`,
allRuns: (project: string): string => `/projects/${project}/all-runs`,
},
pipeline: {
base: (id: TId): string => `/pipelines/${id}`,
Expand Down Expand Up @@ -63,11 +62,11 @@ export const routePaths = {
`/components/${pipelineId}/runs/${id}/tensorboard`,
},
run: {
base: (runId: TId): string => `/runs/${runId}`,
base: (runId: TId): string => `/all-runs/${runId}`,
statistics: (project: string, id: TId, type?: string): string =>
`/projects/${project}/runs/${id}/dag`,
`/projects/${project}/all-runs/${id}/dag`,
results: (project: string, runId: TId): string =>
`/projects/${project}/runs/${runId}/configuration`,
`/projects/${project}/all-runs/${runId}/configuration`,
tensorboard: (runId: TId): string => `/runs/${runId}/tensorboard`,
},
},
Expand Down
85 changes: 8 additions & 77 deletions src/routes/utils/replaceRouteIfNeeded.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,9 @@
// import { RouteVisibilityAuthentication } from '../RouteVisibility';
// import { loggedOutRoute, loggedInRoute } from '../../constants';

// const isUnauthenticatedOrMissingRoute = (
// currentLocation: any | undefined,
// ): boolean =>
// currentLocation
// ? currentLocation.visibility &&
// currentLocation.visibility.authentication ===
// RouteVisibilityAuthentication.unauthenticatedOnly
// : false;

// const isAuthenticatedOrMissingRoute = (
// currentLocation: any | undefined,
// ): boolean =>
// currentLocation
// ? currentLocation.visibility &&
// currentLocation.visibility.authentication ===
// RouteVisibilityAuthentication.authenticatedOnly
// : false;

// let timeout = null as any;

// export const replaceRouteIfNeeded = ({
// user,
// isAuthenticated,
// currentLocation,
// replaceRoute,
// routeFromSearchParam,
// }: {
// user: any;
// isAuthenticated: any;
// currentLocation: any | undefined;
// replaceRoute: (arg1: string) => void;
// routeFromSearchParam: null | string;
// }): void => {
// clearTimeout(timeout);

// const routeToReplace = () => {
// return isAuthenticated ? loggedInRoute : loggedOutRoute;
// };
// const replaceToLoggedInRoute =
// isAuthenticated && isUnauthenticatedOrMissingRoute(currentLocation);

// const replaceToLoggedOutRoute =
// !isAuthenticated && isAuthenticatedOrMissingRoute(currentLocation);

// const replaceToLoggedInRouteForEmailOptedIn =
// isAuthenticated &&
// user?.emailOptedIn === null &&
// currentLocation?.path !== `/user-email`;
// const shouldReplaceRoute =
// replaceToLoggedInRoute ||
// replaceToLoggedOutRoute ||
// replaceToLoggedInRouteForEmailOptedIn;

// if (shouldReplaceRoute) {
// timeout = setTimeout(() => {
// let route = routeToReplace();
// if (user?.emailOptedIn === null) {
// route = `/user-email`;
// }
// console.log(currentLocation, 'currentLocation', routeFromSearchParam);

// if (replaceToLoggedOutRoute && currentLocation) {
// route = `${route}?route=${currentLocation.path}`;
// } else if (replaceToLoggedInRoute && routeFromSearchParam) {
// route = routeFromSearchParam;
// }

// replaceRoute(route);
// }, 0);
// }
// };

import {
RouteInterface,
RouteVisibilityAuthentication,
} from '../RouteVisibility';
import { loggedOutRoute } from '../../constants';
import { loggedOutRoute, DEFAULT_PROJECT_NAME } from '../../constants';
import { routePaths } from '../routePaths';

const isUnauthenticatedOrMissingRoute = (
currentLocation: RouteInterface | undefined,
Expand Down Expand Up @@ -117,7 +43,12 @@ export const replaceRouteIfNeeded = ({
clearTimeout(timeout);

const routeToReplace = () => {
const logRoute = user?.emailOptedIn === null ? `/user-email` : '/';
// const url = window.location.search;
const logRoute =
user?.emailOptedIn === null
? `/user-email`
: routePaths.home(DEFAULT_PROJECT_NAME);

return isAuthenticated ? logRoute : loggedOutRoute;
};
const replaceToLoggedInRoute =
Expand Down
62 changes: 43 additions & 19 deletions src/ui/layouts/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
pipelinePagesActions,
runPagesActions,
} from '../../redux/actions';
import { NotFound } from '../../ui/layouts/NotFound';

import Tour from './Tour';

Expand Down Expand Up @@ -84,6 +85,7 @@ export const Home: React.FC = () => {
const stackComponentsTypes: any[] = useSelector(
stackComponentSelectors.stackComponentTypes,
);
const [notFound, setNotFound] = useState(false);

const selectedProject = useSelector(projectSelectors.selectedProject);
const projects = useSelector(projectSelectors.myProjects);
Expand Down Expand Up @@ -119,32 +121,52 @@ export const Home: React.FC = () => {
{ headers: { Authorization: `bearer ${authToken}` } },
);

await dispatch(
projectsActions.getSelectedProject({
allProjects: projects,
seletecdProject: selectedProject
? selectedProject
: DEFAULT_PROJECT_NAME,
}),
);
await dispatch(
pipelinesActions.getMy({
project: selectedProject ? selectedProject : DEFAULT_PROJECT_NAME,
onSuccess: () => stopLoad(),
onFailure: () => stopLoad(),
}),
);
// await dispatch(
// projectsActions.getMy({
// selectDefault: false,
// selectedProject: selectedProject,
// onSuccess: () => stopLoad(),
// onFailure: () => stopLoad(),
// }),
// );

// await dispatch(
// projectsActions.getSelectedProject({
// allProjects: projects,
// seletecdProject: selectedProject
// ? selectedProject
// : DEFAULT_PROJECT_NAME,
// }),
// );

// await dispatch(
// pipelinesActions.getMy({
// project: selectedProject ? selectedProject : DEFAULT_PROJECT_NAME,
// onSuccess: () => stopLoad(),
// onFailure: () => stopLoad(),
// }),
// );

setDashboardData(data);
setFetching(false);
} catch (err) {
// @ts-ignore
} catch (e) {
dispatch(
showToasterAction({
description: translate('toasts.successful.passwordText'),
type: toasterTypes.success,
description: 'Not found',
type: toasterTypes.failure,
}),
);

await dispatch(
projectsActions.getMy({
selectDefault: false,
selectedProject: DEFAULT_PROJECT_NAME,
onSuccess: () => setNotFound(true),
onFailure: () => stopLoad(),
}),
);

// push(routePaths.home(DEFAULT_PROJECT_NAME));
}
};
getDashboardData();
Expand All @@ -166,6 +188,8 @@ export const Home: React.FC = () => {
setBox('');
setIsHover(false);
};
console.log(notFound, 'notFound');
if (notFound) return <NotFound />;

return (
<AuthenticatedLayout>
Expand Down
Loading