Skip to content

Commit

Permalink
Merge pull request #139 from Tauffer-Consulting/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
luiztauffer authored Nov 3, 2023
2 parents eb62a84 + 8b03889 commit c75fe30
Show file tree
Hide file tree
Showing 59 changed files with 703 additions and 458 deletions.
2 changes: 1 addition & 1 deletion Dockerfile-airflow-domino.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM apache/airflow:2.6.3-python3.9
FROM apache/airflow:2.7.2-python3.9

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-airflow-domino.prod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM apache/airflow:2.6.3-python3.9
FROM apache/airflow:2.7.2-python3.9

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
Expand Down
4 changes: 2 additions & 2 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
version: '3.8'
x-airflow-common:
&airflow-common
image: apache/airflow:2.6.3-python3.9
image: apache/airflow:2.7.2-python3.9
# build: .
environment:
&airflow-common-env
Expand Down Expand Up @@ -309,7 +309,7 @@ services:
- DOMINO_DB_HOST=domino_postgres
- DOMINO_DB_PORT=5432
- DOMINO_DB_NAME=postgres
- DOMINO_DEFAULT_PIECES_REPOSITORY_VERSION=0.4.3
- DOMINO_DEFAULT_PIECES_REPOSITORY_VERSION=0.4.5
- 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}
Expand Down
22 changes: 13 additions & 9 deletions frontend/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Dialog,
DialogActions,
DialogContent,
DialogContentText,
type DialogProps,
DialogTitle,
Grid,
} from "@mui/material";
Expand All @@ -12,7 +12,8 @@ import React, { useCallback, useImperativeHandle, useState } from "react";
interface Props {
title: string;
content?: string | React.ReactNode;

maxWidth?: DialogProps["maxWidth"];
fullWidth?: boolean;
confirmFn?: () => void;
cancelFn?: () => void;
}
Expand All @@ -23,7 +24,7 @@ export interface ModalRef {
}

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

const open = () => {
Expand All @@ -36,27 +37,30 @@ export const Modal = React.forwardRef<ModalRef, Props>(
}

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

const handleConfirm = useCallback(() => {
if (confirmFn) {
confirmFn();
}

setIsOpen(false);
}, []);
}, [confirmFn]);

useImperativeHandle(ref, () => ({
open,
close: handleClose,
}));

return (
<Dialog open={isOpen} onClose={handleClose}>
<Dialog
open={isOpen}
onClose={handleClose}
maxWidth={maxWidth}
fullWidth={fullWidth}
>
<DialogTitle>{title}</DialogTitle>
<DialogContent>
<DialogContentText>{content}</DialogContentText>
</DialogContent>
<DialogContent>{content}</DialogContent>
<DialogActions>
<Grid container justifyContent="center" spacing={4}>
{cancelFn && (
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/context/workspaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./workspaces";
export * from "./repositories";
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const PiecesProvider: React.FC<{ children: React.ReactNode }> = ({
data,
error: repositoriesError,
isValidating: repositoriesLoading,
// mutate: repositoriesRefresh
// mutate: repositoriesRefresh,
} = useAuthenticatedGetPieceRepositories({});

const repositories: PieceRepository[] = useMemo(
Expand All @@ -59,21 +59,25 @@ const PiecesProvider: React.FC<{ children: React.ReactNode }> = ({
const updateRepositoriesPieces = async () => {
const repositoryPiecesAux: PiecesRepository = {};
const foragePieces: PieceForageSchema = {};
for (const repo of repositories) {
fetchRepoById({ id: repo.id })
.then((pieces: any) => {
repositoryPiecesAux[repo.id] = [];
for (const op of pieces) {
repositoryPiecesAux[repo.id].push(op);
foragePieces[op.id] = op;
}
setRepositoryPieces(repositoryPiecesAux);
void localForage.setItem("pieces", foragePieces);
})
.catch((e) => {
console.log(e);
});
// Set piece item to storage -> {piece_id: Piece}
if (!repositories?.length) {
void localForage.setItem("pieces", foragePieces);
} else {
for (const repo of repositories) {
fetchRepoById({ id: repo.id })
.then((pieces: any) => {
repositoryPiecesAux[repo.id] = [];
for (const op of pieces) {
repositoryPiecesAux[repo.id].push(op);
foragePieces[op.id] = op;
}
setRepositoryPieces(repositoryPiecesAux);
void localForage.setItem("pieces", foragePieces);
})
.catch((e) => {
console.log(e);
});
// Set piece item to storage -> {piece_id: Piece}
}
}
};
void updateRepositoriesPieces();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export const WorkspacesProvider: FC<IWorkspacesProviderProps> = ({
})
.catch((error) => {
console.log("Removing user error:", error.response.data.detail);
toast.error(error.response.data.detail);
});
},
[removeUserWorkspace, workspacesRefresh],
Expand All @@ -134,7 +133,6 @@ export const WorkspacesProvider: FC<IWorkspacesProviderProps> = ({
})
.catch((error) => {
console.log("Inviting user error:", error.response.data.detail);
toast.error(error.response.data.detail);
});
},
[inviteWorkspace, workspaceUsersRefresh()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ToggleButtonGroup,
Typography,
} from "@mui/material";
import { useWorkflowsEditor } from "features/workflowEditor/context";
import { usesPieces } from "context/workspaces";
import { type FC, useState } from "react";

import PiecesSidebarNode from "./sidebarNode";
Expand All @@ -28,8 +28,7 @@ interface Props {
}

const SidebarAddNode: FC<Props> = ({ setOrientation, orientation }) => {
const { repositories, repositoriesLoading, repositoryPieces } =
useWorkflowsEditor();
const { repositories, repositoriesLoading, repositoryPieces } = usesPieces();

const [piecesMap, setPiecesMap] = useState<Record<string, Piece[]>>({});
const [expandedRepos, setExpandedRepos] = useState<string[]>([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import {
useWatch,
} from "react-hook-form";

import { type ArrayOption } from "../upstreamOptions";
import {
type ComplexArrayOption,
type ArrayOption,
type Option,
} from "../upstreamOptions";

import { disableCheckboxOptions } from "./disableCheckboxOptions";
import ObjectInputComponent from "./objectInput";
Expand All @@ -32,7 +36,7 @@ interface ArrayInputItemProps {
schema: any;
control: Control<IWorkflowPieceData, any>;
definitions?: any;
upstreamOptions: ArrayOption;
upstreamOptions: ArrayOption | ComplexArrayOption;
}

const ArrayInput: React.FC<ArrayInputItemProps> = ({
Expand Down Expand Up @@ -206,7 +210,7 @@ const ArrayInput: React.FC<ArrayInputItemProps> = ({
<SelectUpstreamInput
name={`${name}.${index}`}
label={schema?.title}
options={upstreamOptions.items}
options={upstreamOptions.items as Option[]}
/>
</Grid>
)}
Expand Down Expand Up @@ -313,7 +317,7 @@ const ArrayInput: React.FC<ArrayInputItemProps> = ({
name={`${name}.${index}`}
schema={schema}
definitions={definitions}
upstreamOptions={upstreamOptions.items}
upstreamOptions={upstreamOptions as ComplexArrayOption}
/>
</Grid>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, { useCallback, useMemo, useState } from "react";
import { useWatch } from "react-hook-form";
import { getDefinition } from "utils";

import { type Option } from "../upstreamOptions";
import { type ComplexArrayOption } from "../upstreamOptions";

import { disableCheckboxOptions } from "./disableCheckboxOptions";
import SelectUpstreamInput from "./selectUpstreamInput";
Expand All @@ -15,7 +15,7 @@ interface Prop {
name: `inputs.${string}.value.${number}`;
schema: ArrayObjectProperty;
definitions: Definitions;
upstreamOptions: Option[];
upstreamOptions: ComplexArrayOption;
}

const ObjectInputComponent: React.FC<Prop> = ({
Expand Down Expand Up @@ -92,7 +92,11 @@ const ObjectInputComponent: React.FC<Prop> = ({
<SelectUpstreamInput
label={key}
name={`${name}.upstreamValue.${key}`}
options={upstreamOptions}
options={
upstreamOptions[key] !== undefined
? upstreamOptions[key].items
: []
}
object
/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ export interface ArrayOption {
items: Option[];
}

export type ComplexArrayOption = Record<string, ArrayOption>;

export type UpstreamOptions = Record<string, Option[] | ArrayOption>;

const getInputType = (schema: Record<string, any>) => {
let type = schema.format ? schema.format : schema.type;
if ("allOf" in schema || "oneOf" in schema || "anyOf" in schema) {
if ("allOf" in schema || "oneOf" in schema) {
type = "enum";
} else if ("anyOf" in schema) {
type = [];
for (const item of schema.anyOf) {
type.push(item.type);
}
}
return type === "number" ? "float" : (type as string);
};
Expand All @@ -36,7 +43,11 @@ const getOptions = (
for (const property in upSchema) {
const upType = getInputType(upSchema[property]);

if (upType === type || (upType === "string" && type === "object")) {
if (
upType === type ||
(upType === "string" && type === "object") ||
(Array.isArray(type) && type.includes(upType))
) {
const value = `${upPiece?.name} (${getUuidSlice(upPiece.id)}) - ${
upSchema[property].title
}`;
Expand Down Expand Up @@ -88,16 +99,24 @@ export const getUpstreamOptions = (
itemsSchema = schema.definitions?.[subItemSchemaName];
}

const itemsType = getInputType(itemsSchema);

const array = getOptions(upstreamPieces, currentType);
const items = getOptions(upstreamPieces, itemsType);

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
upstreamOptions[key] = { array, items } as ArrayOption;
if (itemsSchema.type === "object") {
const __data: any = {};
Object.keys(itemsSchema.properties).forEach((subKey) => {
const subSchema = itemsSchema.properties[subKey];
const subType = getInputType(subSchema);
const items = getOptions(upstreamPieces, subType);
__data[subKey] = { array, items };
});
upstreamOptions[key] = __data;
} else {
const itemsType = getInputType(itemsSchema);
const items = getOptions(upstreamPieces, itemsType);
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
upstreamOptions[key] = { array, items } as ArrayOption;
}
} else {
const options = getOptions(upstreamPieces, currentType);

upstreamOptions[key] = options;
}
});
Expand Down
Loading

0 comments on commit c75fe30

Please sign in to comment.