Skip to content

Commit

Permalink
Merge pull request #169 from Tauffer-Consulting/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
vinicvaz authored Nov 27, 2023
2 parents 98848ca + cdcfcac commit 526c5bc
Show file tree
Hide file tree
Showing 86 changed files with 3,563 additions and 942 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# v0.8.0

### Features
* Install missing repositories from Workflows Gallery modal when importing a workflow [PR #180].
* Create default user `[email protected]`, password `admin` when platform is created [Issue #177].
* Add search bar for Pieces in Workflows Editor page [Issue #168].
* Workflows gallery with more examples and easy installation fo repositories.
* Installing multiple repositories on a new workspace if platform `github_token` provide.


### Fixes
* Improved terminal messages for `domino platform run-compose` and `domino platform stop-compose` CLI.
* Add optional platform level github token in `run-in-compose` CLI [Issue #176].
* Fix token expiration date bug [Issue #147].
* Fix validation bugs.
* Performance improved on `create_piece_repository`
* Allow for optional secrets.



# v0.7.0

### Features
Expand Down
1 change: 1 addition & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ services:
- DOMINO_DEFAULT_PIECES_REPOSITORY_TOKEN=${DOMINO_DEFAULT_PIECES_REPOSITORY_TOKEN}
- DOMINO_GITHUB_ACCESS_TOKEN_WORKFLOWS=${DOMINO_GITHUB_ACCESS_TOKEN_WORKFLOWS}
- DOMINO_GITHUB_WORKFLOWS_REPOSITORY=${DOMINO_GITHUB_WORKFLOWS_REPOSITORY}
- CREATE_DEFAULT_USER=true
- DOMINO_DEPLOY_MODE=local-compose
- AIRFLOW_ADMIN_USERNAME=airflow
- AIRFLOW_ADMIN_PASSWORD=airflow
Expand Down
6 changes: 5 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@mui/x-data-grid": "^6.15.0",
"@mui/x-date-pickers": "^6.5.0",
"@types/react-dom": "^18.0.9",
"@types/react-plotly.js": "^2.6.3",
"@types/uuid": "^9.0.0",
"@uiw/react-textarea-code-editor": "^2.1.1",
"@vitejs/plugin-react": "^4.1.0",
Expand All @@ -29,14 +30,17 @@
"dotenv": "^16.3.1",
"elkjs": "^0.8.2",
"localforage": "^1.10.0",
"plotly.js": "^2.27.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-draggable": "^4.4.5",
"react-hook-form": "^7.45.1",
"react-markdown": "^8.0.7",
"react-markdown": "9.0.0",
"react-plotly.js": "^2.6.0",
"react-router-dom": "^6.6.0",
"react-toastify": "^9.1.1",
"reactflow": "^11.4.0",
"remark-gfm": "^4.0.0",
"swr": "^2.0.0",
"typescript": "*",
"uuid": "^9.0.0",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/@types/piece/piece.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface Piece {

source_image: string;
source_url: string | null;
repository_url: string;
dependency: {
docker_image: string | null;
dockerfile: string | null;
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/@types/piece/properties.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export type SimpleInputSchemaProperty =

type AnyOfObjectProperty = DefaultPropertyProps & {
anyOf: StringProperty[];
default:
| ArrayObjectProperty.default
| NumberProperty.default
| StringProperty.default;
};

export type InputSchemaProperty =
Expand Down
51 changes: 43 additions & 8 deletions frontend/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CloseIcon from "@mui/icons-material/Close";
import {
Button,
Dialog,
Expand All @@ -6,6 +7,7 @@ import {
type DialogProps,
DialogTitle,
Grid,
IconButton,
} from "@mui/material";
import React, { useCallback, useImperativeHandle, useState } from "react";

Expand All @@ -16,6 +18,9 @@ interface Props {
fullWidth?: boolean;
confirmFn?: () => void;
cancelFn?: () => void;
onClose?: () => void;
confirmText?: string;
cancelText?: string;
}

export interface ModalRef {
Expand All @@ -24,7 +29,20 @@ export interface ModalRef {
}

export const Modal = React.forwardRef<ModalRef, Props>(
({ cancelFn, confirmFn, title, content, maxWidth, fullWidth }, ref) => {
(
{
onClose,
cancelFn,
confirmFn,
title,
content,
maxWidth,
fullWidth,
confirmText,
cancelText,
},
ref,
) => {
const [isOpen, setIsOpen] = useState(false);

const open = () => {
Expand All @@ -35,9 +53,12 @@ export const Modal = React.forwardRef<ModalRef, Props>(
if (cancelFn) {
cancelFn();
}
if (onClose) {
onClose();
}

setIsOpen(false);
}, [cancelFn]);
}, [cancelFn, onClose]);

const handleConfirm = useCallback(() => {
if (confirmFn) {
Expand All @@ -59,22 +80,36 @@ export const Modal = React.forwardRef<ModalRef, Props>(
maxWidth={maxWidth}
fullWidth={fullWidth}
>
<IconButton
aria-label="close"
onClick={handleClose}
sx={{
position: "absolute",
right: 8,
top: 8,
color: (theme) => theme.palette.grey[500],
}}
>
<CloseIcon />
</IconButton>
<DialogTitle>{title}</DialogTitle>
<DialogContent>{content}</DialogContent>
<DialogActions>
<Grid container justifyContent="center" spacing={4}>
{cancelFn && (
<Grid item>
<Button onClick={handleClose} variant="contained">
Cancel
{cancelText ?? "Cancel"}
</Button>
</Grid>
)}
{confirmFn && (
<Grid item>
<Button onClick={handleConfirm} variant="contained">
{confirmText ?? "OK"}
</Button>
</Grid>
)}
<Grid item>
<Button onClick={handleConfirm} variant="contained">
OK
</Button>
</Grid>
</Grid>
</DialogActions>
</Dialog>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/context/authentication/api/postAuthLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface IPostAuthLoginResponseInterface {
user_id: string;
group_ids: number[];
access_token: string;
token_expires_in: number;
}

/**
Expand All @@ -29,4 +30,5 @@ export const postAuthLoginMockResponse: IPostAuthLoginResponseInterface = {
user_id: "some_id",
group_ids: [0],
access_token: "MOCK ACCESS TOKEN",
token_expires_in: new Date().getTime() + 10000,
};
6 changes: 4 additions & 2 deletions frontend/src/context/authentication/api/postAuthRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ interface IPostAuthRegisterParams {
}

interface IPostAuthRegisterResponseInterface {
id: string;
user_id: string;
email: string;
token_expires_in: number;
groups: Array<{ group_id: number; group_name: string }>;
}

Expand All @@ -27,7 +28,8 @@ export const postAuthRegister: (

export const postAuthRegisterMockResponse: IPostAuthRegisterResponseInterface =
{
id: "some_id",
user_id: "some_id",
email: "[email protected]",
token_expires_in: 3600,
groups: [{ group_id: 0, group_name: "some group" }],
};
69 changes: 54 additions & 15 deletions frontend/src/context/authentication/authentication.context.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Loading from "components/Loading";
import React, {
type ReactNode,
useCallback,
Expand All @@ -13,6 +14,7 @@ import { createCustomContext } from "utils";

import { postAuthLogin, postAuthRegister } from "./api";
import {
authStatus,
type IAuthenticationContext,
type IAuthenticationStore,
} from "./authentication.interface";
Expand All @@ -29,6 +31,7 @@ export const AuthenticationProvider: React.FC<{ children: ReactNode }> = ({
children,
}) => {
const navigate = useNavigate();
const [status, setStatus] = useState(authStatus.Loading);
const [authLoading, setAuthLoading] = useState(false);
const [store, setStore] = useState<IAuthenticationStore>({
token: localStorage.getItem("auth_token"),
Expand All @@ -38,15 +41,25 @@ export const AuthenticationProvider: React.FC<{ children: ReactNode }> = ({
const isLogged = useRef(!!store.token);

const login = useCallback(
(token: string, userId: string, redirect = "") => {
(token: string, userId: string, tokenExpiresIn: number, redirect = "") => {
isLogged.current = true;
setStore((store) => ({
...store,
token,
userId,
tokenExpiresIn,
}));
const currentDate = new Date();
const tokenExpirationDate = new Date(
currentDate.getTime() + tokenExpiresIn * 1000,
);
localStorage.setItem("auth_token", token);
localStorage.setItem("userId", userId);
localStorage.setItem(
"tokenExpiresAtTimestamp",
tokenExpirationDate.getTime().toString(),
);
setStatus(authStatus.SignedIn);
navigate(redirect);
},
[navigate],
Expand All @@ -60,19 +73,21 @@ export const AuthenticationProvider: React.FC<{ children: ReactNode }> = ({
...store,
token: null,
}));
setStatus(authStatus.SignedOut);
navigate("/sign-in");
}, [navigate]);

/**
* @todo improve error handling
*/
const authenticate = useCallback(
async (email: string, password: string) => {
setAuthLoading(true);
void postAuthLogin({ email, password })
.then((res) => {
if (res.status === 200) {
login(res.data.access_token, res.data.user_id);
login(
res.data.access_token,
res.data.user_id,
res.data.token_expires_in,
);
}
})
.finally(() => {
Expand Down Expand Up @@ -107,16 +122,15 @@ export const AuthenticationProvider: React.FC<{ children: ReactNode }> = ({
[authenticate],
);

const value = useMemo((): IAuthenticationContext => {
return {
store,
isLogged: isLogged.current,
authLoading,
logout,
authenticate,
register,
};
}, [store, logout, authenticate, register, authLoading]);
const tokenExpired = useCallback(() => {
const tokenTimestamp = localStorage.getItem("tokenExpiresAtTimestamp");
if (tokenTimestamp) {
const date1 = Number(tokenTimestamp);
const date2 = new Date().getTime();
return date1 <= date2;
}
return true;
}, []);

/**
* Listen to "logout" event and handles it (ie. unauthorized request)
Expand All @@ -132,6 +146,31 @@ export const AuthenticationProvider: React.FC<{ children: ReactNode }> = ({
};
}, [logout]);

useEffect(() => {
const expired = tokenExpired();

if (expired) {
logout();
} else {
setStatus(authStatus.SignedIn);
}
}, [tokenExpired]);

const value = useMemo((): IAuthenticationContext => {
return {
store,
isLogged: isLogged.current,
authLoading,
logout,
authenticate,
register,
};
}, [store, logout, authenticate, register, authLoading]);

if (status === authStatus.Loading) {
return <Loading />;
}

return (
<AuthenticationContext.Provider value={value}>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ export interface IAuthenticationStore {
userId: string | null;
}

export enum authStatus {
Loading,
SignedIn,
SignedOut,
}

export interface IAuthenticationContext {
store: IAuthenticationStore;
isLogged: boolean;
Expand Down
Loading

0 comments on commit 526c5bc

Please sign in to comment.