-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from ssi-dk/feat/clone-workspaces
feat: add ability to clone workspaces
- Loading branch information
Showing
15 changed files
with
431 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useCallback, useEffect, useState } from "react"; | ||
import { useToast } from "@chakra-ui/react"; | ||
import { useMutation } from "redux-query-react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { cloneWorkspace } from "./workspaces-query-configs"; | ||
import { IconButton } from "@chakra-ui/react"; | ||
import { CopyIcon } from "@chakra-ui/icons"; | ||
|
||
type Props = { | ||
id: string; | ||
samples: string[]; | ||
}; | ||
|
||
export function CloneWorkspace(props: Props) { | ||
const { t } = useTranslation(); | ||
const toast = useToast(); | ||
|
||
const [ | ||
cloneWorkspaceQueryState, | ||
cloneWorkspaceMutation, | ||
] = useMutation((name: string, id: string) => cloneWorkspace({ name, id, samples: props.samples })); | ||
|
||
const [needsNotify, setNeedsNotify] = useState(true); | ||
|
||
const cloneWorkspaceCallback = useCallback(() => { | ||
const name = prompt("Workspace name"); | ||
if (name) { | ||
setNeedsNotify(true); | ||
cloneWorkspaceMutation(name, props.id); | ||
} | ||
}, [cloneWorkspaceMutation, setNeedsNotify, props.id]); | ||
|
||
useEffect(() => { | ||
if ( | ||
needsNotify && | ||
cloneWorkspaceQueryState.status >= 200 && | ||
cloneWorkspaceQueryState.status < 300 && | ||
!cloneWorkspaceQueryState.isPending | ||
) { | ||
toast({ | ||
title: t("Workspace cloned"), | ||
status: "info", | ||
duration: 3000, | ||
isClosable: true, | ||
}); | ||
setNeedsNotify(false); | ||
} | ||
}, [t, cloneWorkspaceQueryState, toast, needsNotify, setNeedsNotify]); | ||
|
||
return ( | ||
<IconButton | ||
icon={<CopyIcon />} | ||
aria-label={`${t("Clone workspace")}`} | ||
onClick={cloneWorkspaceCallback} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// tslint:disable | ||
/** | ||
* SOFI | ||
* SOFI Sekvensanalyseplatform | ||
* | ||
* The version of the OpenAPI document: 0.1.0 | ||
* | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
import { exists, mapValues } from '../runtime'; | ||
/** | ||
* | ||
* @export | ||
* @interface CloneWorkspace | ||
*/ | ||
export interface CloneWorkspace { | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof CloneWorkspace | ||
*/ | ||
name: string; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof CloneWorkspace | ||
*/ | ||
id: string; | ||
} | ||
|
||
export function CloneWorkspaceFromJSON(json: any): CloneWorkspace { | ||
return { | ||
'name': json['name'], | ||
'id': json['id'], | ||
}; | ||
} | ||
|
||
export function CloneWorkspaceToJSON(value?: CloneWorkspace): any { | ||
if (value === undefined) { | ||
return undefined; | ||
} | ||
return { | ||
'name': value.name, | ||
'id': value.id, | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.