Skip to content

Commit

Permalink
Merge pull request #84 from ssi-dk/feat/trees
Browse files Browse the repository at this point in the history
Added tree calculation to send to microreact
  • Loading branch information
allanhvam authored Jun 28, 2024
2 parents 81d417a + 5605f6d commit 26cd563
Show file tree
Hide file tree
Showing 29 changed files with 168 additions and 792 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
dmx_data/
files/
logs/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export const sequencesFromIsolateId = (isolateId: string) => {
return {
analysisHistory: response.items
? arrayToNormalizedHashmap(
response.items.map((a) => AnalysisResultFromJSON(a)),
"id"
)
response.items.map((a) => AnalysisResultFromJSON(a)),
"id"
)
: {},
};
};
Expand Down
35 changes: 17 additions & 18 deletions app/src/app/analysis/analysis-selection-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ interface SelectionState {
selection: DataTableSelection<AnalysisResult>;
}

export const updateSelectionOriginal = createAction<Record<string, AnalysisResult>>(
"analysis/updateSelectionOriginal"
);
export const updateSelectionOriginal = createAction<
Record<string, AnalysisResult>
>("analysis/updateSelectionOriginal");

export const setSelection = createAction<DataTableSelection<AnalysisResult>>(
"analysis/setSelection"
Expand All @@ -28,26 +28,25 @@ export const selectionReducer = createReducer(initialState, (builder) => {
.addCase(updateSelectionOriginal, (state, action) => {
const payload = action.payload;
const payloadKeys = Object.keys(payload);
const selectionKeys = Object.keys(state.selection)
const selectionKeys = Object.keys(state.selection);

const intersection = payloadKeys.filter(value => selectionKeys.includes(value));
const intersection = payloadKeys.filter((value) =>
selectionKeys.includes(value)
);
if (intersection.length === 0) {
return;
}

state.selection = selectionKeys.reduce(
(o, k) => {
const value = state.selection[k];
if (payload[k]) {
value.original = payload[k];
}
return {
...o,
[k]: value,
};
},
{} as DataTableSelection<AnalysisResult>
);
state.selection = selectionKeys.reduce((o, k) => {
const value = state.selection[k];
if (payload[k]) {
value.original = payload[k];
}
return {
...o,
[k]: value,
};
}, {} as DataTableSelection<AnalysisResult>);
})
.addCase(clearSelection, (state) => {
state.selection = {} as DataTableSelection<AnalysisResult>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const NearestNeighborModal = (props: Props) => {
const [isSearching, setIsSearching] = useState<boolean>(false);
const [cutoff, setCutoff] = React.useState(15);
const onChangeCutoff = (value: string) => setCutoff(parseInt(value));
const [unknownsAreDiffs, setUnknownsAreDiffs] = useState<boolean>(true);
const [unknownsAreDiffs, setUnknownsAreDiffs] = useState<boolean>(false);
const toast = useToast();
const dispatch = useDispatch();
const [searchIndex, setSearchIndex] = useState(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { post, NearestNeighborsResponse, NearestNeighborsRequest } from "sap-client";
import {
post,
NearestNeighborsResponse,
NearestNeighborsRequest,
} from "sap-client";
import { getUrl } from "service";

export type NearestNeighborsResponseSlice = {
Expand All @@ -18,7 +22,8 @@ export const getNearestNeighbors = (params: NearestNeighborsRequest) => {
};

base.update = {
nearestNeighborsResponses: (oldValue, newValue) => Object.assign(newValue, oldValue ?? {}),
nearestNeighborsResponses: (oldValue, newValue) =>
Object.assign(newValue, oldValue ?? {}),
};

// Force a network call to be made. Making it promise as well.
Expand Down
25 changes: 18 additions & 7 deletions app/src/app/workspaces/send-to-microreact-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { useMutation } from "redux-query-react";
import { sendToMicroreact as sendToMicroreactQuery } from "./microreact-query-configs";
import { RootState } from "app/root-reducer";
import { useSelector } from "react-redux";
import { UserInfo, WorkspaceInfo } from "sap-client";
import { TreeMethod, UserInfo, WorkspaceInfo } from "sap-client";
import { TreeMethodSelect } from "./tree-method-select";

type Props = {
workspace: string;
Expand All @@ -29,8 +30,11 @@ export const SendToMicroreactModal = (props: Props) => {
const localStorageKey = useMemo(() => {
return `${user.userId}-microreact-token`;
}, [user]);
const [token, setToken] = useState<string>(localStorage.getItem(localStorageKey));
const [token, setToken] = useState<string>(
localStorage.getItem(localStorageKey) ?? ""
);
const [isSending, setIsSending] = useState<boolean>(false);
const [treeMethod, setTreeMethod] = useState<string>();

const workspaceInfo = useSelector<RootState>(
(s) => s.entities.workspace ?? {}
Expand All @@ -41,6 +45,7 @@ export const SendToMicroreactModal = (props: Props) => {
return sendToMicroreactQuery({
workspace: workspace,
mr_access_token: token,
tree_method: TreeMethod[treeMethod],
});
});

Expand All @@ -51,7 +56,6 @@ export const SendToMicroreactModal = (props: Props) => {
}
}, [workspaceInfo, status]);


const onSend = useCallback(async () => {
setIsSending(true);
sendToWorkspace();
Expand All @@ -66,21 +70,28 @@ export const SendToMicroreactModal = (props: Props) => {
<ModalHeader pl="7">{`${t("Send To Microreact")}`}</ModalHeader>
<ModalCloseButton />
<ModalBody px="7">
{!isPending && status ? (
{!isPending && status >= 200 && status < 300 ? (
<div>Workspace sent to Microreact.</div>
) : null}
{!isPending && (status < 200 || status >= 300) ? (
<div>Failed to send workspace to Microreact.</div>
) : null}
{!isPending && !status ? (
<div
style={{ display: "flex", flexDirection: "column", gap: "8px" }}
>
<div>
Token:
{t("Token")}:
<Input
value={token}
onChange={handleChange}
placeholder="Token"
placeholder={t("Token")}
/>
</div>
<div>
{t("Tree method")}:
<TreeMethodSelect onChange={setTreeMethod} />
</div>
</div>
) : null}
{isPending ? <Spinner size="xl" /> : null}
Expand All @@ -93,7 +104,7 @@ export const SendToMicroreactModal = (props: Props) => {
colorScheme="blue"
mr={3}
onClick={onSend}
disabled={isSending || !token}
disabled={isSending || !token || !treeMethod}
>
{t("Send")}
</Button>
Expand Down
21 changes: 0 additions & 21 deletions app/src/app/workspaces/trees-button.tsx

This file was deleted.

71 changes: 0 additions & 71 deletions app/src/app/workspaces/trees-modal.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions app/src/app/workspaces/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { AnalysisViewSelector } from "app/analysis/view-selector/analysis-view-s
import { DeleteIcon } from "@chakra-ui/icons";
import { SendToMicroreactButton } from "./send-to-microreact-button";
import { OpenInMicroreactButton } from "./open-in-microreact-button";
import { TreesButton } from "./trees-button";

type Props = {
id: string;
Expand Down Expand Up @@ -176,7 +175,6 @@ export function Workspace(props: Props) {
<Heading>{`${workspace?.name}`}</Heading>
<OpenInMicroreactButton />
<SendToMicroreactButton workspace={workspace.id} />
<TreesButton workspace={workspace.id} />
<div style={{ width: "300px" }}>
<AnalysisViewSelector manageViews={false} />
</div>
Expand Down
8 changes: 0 additions & 8 deletions app/src/app/workspaces/workspaces-query-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,3 @@ export const updateWorkspace = (params: PostWorkspaceRequest) => {
base.force = true;
return base;
};

export const buildWorkspaceTree = (params: BuildWorkspaceTreeRequest) => {
const base = buildWorkspaceTreeApi(params);
base.url = getUrl(base.url);

base.force = true;
return base;
};
4 changes: 3 additions & 1 deletion app/src/auth/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const logout = () => {
clearAccessToken(undefined);
clearRefreshToken(undefined);
window.location.replace(
`${Environment.signoutUrl}?post_logout_redirect_uri=${encodeURIComponent(`${window.location.protocol}//${window.location.host}`)}&id_token_hint=${access}`
`${Environment.signoutUrl}?post_logout_redirect_uri=${encodeURIComponent(
`${window.location.protocol}//${window.location.host}`
)}&id_token_hint=${access}`
);
};
12 changes: 8 additions & 4 deletions app/src/middleware/selection-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { updateSelectionOriginal } from "app/analysis/analysis-selection-configs
const { MUTATE_SUCCESS, REQUEST_SUCCESS } = actionTypes;

export const selectionMiddleware = (store) => (next) => (action) => {
if (action.type === MUTATE_SUCCESS &&
action.url.indexOf("/api/analysis/changes") !== -1) {
if (
action.type === MUTATE_SUCCESS &&
action.url.indexOf("/api/analysis/changes") !== -1
) {
// When analysis are updated, dispatch action to maintain the original selection state
store.dispatch(updateSelectionOriginal(action.responseBody));
}

if (action.type === REQUEST_SUCCESS &&
action.url.indexOf("/api/analysis/by_id") !== -1) {
if (
action.type === REQUEST_SUCCESS &&
action.url.indexOf("/api/analysis/by_id") !== -1
) {
// When analysis are approved, dispatch action to maintain the original selection state
const id = action.body.sequence_id;
const payload = {};
Expand Down
Loading

0 comments on commit 26cd563

Please sign in to comment.