Skip to content

Commit

Permalink
Merge pull request #116 from ssi-dk/feat/create-new-workspace-from-se…
Browse files Browse the repository at this point in the history
…lection-microreact

feat: create workspace from microreact selection
  • Loading branch information
sjkp authored Nov 1, 2024
2 parents fe7d58b + ba7bd50 commit 2d63187
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 76 deletions.
12 changes: 10 additions & 2 deletions app/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import { CacheSwitch, CacheRoute } from "react-router-cache-route";
import { Authorize } from "auth/authorize";
import appTheme from "app/app.theme";
import { Callback } from "auth/auth-callback";
import { globalCss } from "./app.styles";
import "./i18n";
import AnalysisPage from "./analysis/analysis-page";
import ApprovalHistory from "./approval-history/approval-history";
import ManualUploadPage from "./manual-upload/manual-upload-page";
import GdprPage from "./gdpr/gdpr";
import ComparativeAnalysis from "./comparative-analysis/comparative-analysis";
import "./style-reset.css";
import i18n from "./i18n";
import { Workspaces } from "./workspaces/workspaces";
import { Workspace } from "./workspaces/workspace";
import { CreateWorkspaceFromMicroreact } from "./workspaces/create-workspace-from-microreact";

export default function App() {
return (
Expand Down Expand Up @@ -57,6 +56,15 @@ export default function App() {
</Authorize>
)}
/>
<Route
exact
path="/createworkspace"
render={() => (
<Authorize>
<CreateWorkspaceFromMicroreact />
</Authorize>
)}
/>
<Route
exact
path="/gdpr"
Expand Down
69 changes: 69 additions & 0 deletions app/src/app/workspaces/create-workspace-from-microreact.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import HalfHolyGrailLayout from "layouts/half-holy-grail";
import React from "react";
import { Box, Heading, Button, Input } from "@chakra-ui/react";
import { AddIcon } from "@chakra-ui/icons";
import { useMutation } from "redux-query-react";
import { useLocation, Redirect } from "react-router-dom";
import { useMemo } from "react";
import { createWorkspace } from "./workspaces-query-configs";

export function CreateWorkspaceFromMicroreact() {
const [name, setName] = React.useState("");
const { search } = useLocation();
const searchParams = useMemo(() => new URLSearchParams(search), [search]);
const [isSending, setIsSending] = React.useState(false);
const [isCreated, setIsCreated] = React.useState(false);
const [isRequired, setIsRequired] = React.useState(false)

const [
createWorkspaceQueryState,
createWorkspaceMutation,
] = useMutation((workspaceName: string, samples: string[]) => createWorkspace({ name: workspaceName, samples: samples }));

const content = (
<React.Fragment>
<Box role="navigation" gridColumn="2 / 4" pb={5}>
<div style={{ display: "flex", justifyContent: "space-between" }}>
<Heading>New workspace</Heading>
<div style={{ width: "300px" }}></div>
</div>
</Box>
<Box role="main" gridColumn="2 / 4" borderWidth="1px" rounded="md">
<Input
placeholder="Workspace name"
value={name}
required={isRequired}
onChange={(x) => {
setName(x.target.value);
}}
/>

<Button
leftIcon={<AddIcon />}
onClick={() => {
if(!name){
setIsRequired(true)
setTimeout(() => setIsRequired(false), 250)
return;
}
setIsSending(true)
const ids = searchParams.get("ids");
if (ids) {
const idArr = ids.split(",");
createWorkspaceMutation(name, idArr );
setIsCreated(true)
setIsSending(false)
alert("Workspace created.")
}
}}
disabled={isSending && !isCreated}
>
{"Create workspace"}
</Button>
</Box>
{isCreated ? <Redirect to="/workspaces" /> : null}
</React.Fragment>
);

return <HalfHolyGrailLayout content={content} sidebar={null} />;
}
3 changes: 1 addition & 2 deletions bifrost/bifrost_queue_broker/common/config/column_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

def gen_default_column(field_name: str) -> ColumnDict:
return {
"id": "",
"approvable": False,
"internal_approval_only": False,
"editable": False,
Expand All @@ -40,8 +41,6 @@ def columns() -> List[Dict[str, str]]:
# build up dictionary of default configs
openapi_columns = analysis.openapi_types.items()
for attr, _ in openapi_columns:
if attr == "id":
continue
cols.update({attr: gen_default_column(attr)})
# apply configuration file on top
with open(PATH + "/column-config.jsonc") as js_file:
Expand Down
144 changes: 76 additions & 68 deletions microreact_defaults.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,77 @@
module.exports = {
externalRequests: {
secret: process.env.MICROREACT_ENCRYPTION_SECRET
},
auth: {
openidconnect: {
id: "keycloak",
name: "Keycloak",
wellKnown: process.env.AUTH_WELLKNOWN_URI,
type: "oauth",
authorization: {
params: {
scope: "openid email profile"
}
},
checks:[],
idToken: true,
clientSecret: "can-be-any-thing-not-used",
clientId: "SOFI_APP",
idAttribute: "sub"
},
email: {
server: {
host: process.env.SMTP_HOST,
port: parseInt(process.env.SMTP_PORT),
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
},
secure: process.env.SMTP_SECURE === "true"
},
from: "Microreact <[email protected]>",
subject: "Login link for Microreact",
text: "Hello!\nAccess your account here: http://localhost:80/auth/passwordless/callback?token=<%= tokenToSend %>&uid=",
html: "views/emails/passwordless.html"
},
secret: process.env.AUTH_SECRET,
session: {
maxAge: 2592000,
updateAge: 86400
}
},
baseUrl: process.env.BASE_URL,
bodySizeLimit: "16mb",
experimentalFlags: {
publicFolders: false
},
helpDesk: {
email: "[email protected]",
subject: "Feedback from Microreact.org"
},
mapboxApiAccessToken: "NOT-USED",
mongodb: {
url: process.env.MONGODB_CONNECTION,
database: process.env.MONGODB_DATABASE
},
repoPath: "./files",
showcaseFolders: [],
smtp: {
host: process.env.SMTP_HOST,
port: parseInt(process.env.SMTP_PORT),
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
},
secure: process.env.SMTP_SECURE === "true",
from: "Microreact <[email protected]>"
}
module.exports = {
externalRequests: {
secret: process.env.MICROREACT_ENCRYPTION_SECRET
},
downloadActions: [
{
id: "createnewworkspace",
label: "Create new workspace from selection",
type: "selection",
url: process.env.SOFI_BASE_URL + "/createworkspace?ids="
}
],
auth: {
openidconnect: {
id: "keycloak",
name: "Keycloak",
wellKnown: process.env.AUTH_WELLKNOWN_URI,
type: "oauth",
authorization: {
params: {
scope: "openid email profile"
}
},
checks:[],
idToken: true,
clientSecret: "can-be-any-thing-not-used",
clientId: "SOFI_APP",
idAttribute: "sub"
},
email: {
server: {
host: process.env.SMTP_HOST,
port: parseInt(process.env.SMTP_PORT),
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
},
secure: process.env.SMTP_SECURE === "true"
},
from: "Microreact <[email protected]>",
subject: "Login link for Microreact",
text: "Hello!\nAccess your account here: http://localhost:80/auth/passwordless/callback?token=<%= tokenToSend %>&uid=",
html: "views/emails/passwordless.html"
},
secret: process.env.AUTH_SECRET,
session: {
maxAge: 2592000,
updateAge: 86400
}
},
baseUrl: process.env.BASE_URL,
bodySizeLimit: "16mb",
experimentalFlags: {
publicFolders: false
},
helpDesk: {
email: "[email protected]",
subject: "Feedback from Microreact.org"
},
mapboxApiAccessToken: "NOT-USED",
mongodb: {
url: process.env.MONGODB_CONNECTION,
database: process.env.MONGODB_DATABASE
},
repoPath: "./files",
showcaseFolders: [],
smtp: {
host: process.env.SMTP_HOST,
port: parseInt(process.env.SMTP_PORT),
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
},
secure: process.env.SMTP_SECURE === "true",
from: "Microreact <[email protected]>"
}
};
3 changes: 1 addition & 2 deletions web/src/SAP/common/config/column_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

def gen_default_column(field_name: str) -> ColumnDict:
return {
"id": "",
"approvable": False,
"internal_approval_only": False,
"editable": False,
Expand All @@ -40,8 +41,6 @@ def columns() -> List[Dict[str, str]]:
# build up dictionary of default configs
openapi_columns = analysis.openapi_types.items()
for attr, _ in openapi_columns:
if attr == "id":
continue
cols.update({attr: gen_default_column(attr)})
# apply configuration file on top
with open(PATH + "/column-config.jsonc") as js_file:
Expand Down
3 changes: 1 addition & 2 deletions web/src/SAP/src/repositories/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ def get_workspace_data(user: str, token_info: Dict[str, str], workspace_id: str)
csv = ",".join(f'"{column}"' for column in authorized)
for sample in workspace["samples"]:
csv += "\n" + ",".join(
f'"{sample[column]}"' if sample[column] else ""
f'"{sample[column]}"' if column in sample and sample[column] else ""
for column in authorized
if column in sample
)

file = io.BytesIO(bytes(csv, "utf-8"))
Expand Down

0 comments on commit 2d63187

Please sign in to comment.