Skip to content

Commit

Permalink
MAT-7184: move draft click logic to its own function per review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
nmorasb committed May 8, 2024
1 parent de3b7e1 commit 6eec91d
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/components/cqlLibraryList/CqlLibraryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,27 @@ export default function CqlLibraryList({ cqlLibraryList, onListUpdate }) {
setAnchorEl(null);
};

const onDraftClicked = (selectedCQLLibrary: CqlLibrary) => {
cqlLibraryServiceApi
.fetchCqlLibrary(selectedCQLLibrary.id)
.then((cqlLibrary) => {
setSelectedCqlLibrary(cqlLibrary);
setCreateDraftDialog({
open: true,
cqlLibrary: cqlLibrary,
});
})
.catch(() => {
setSnackBar({
message: "An error occurred while fetching the CQL Library!",
open: true,
severity: "error",
});
});
setOptionsOpen(false);
setAnchorEl(null);
};

return (
<div data-testid="cqlLibrary-list">
<Snackbar
Expand Down Expand Up @@ -354,27 +375,7 @@ export default function CqlLibraryList({ cqlLibraryList, onListUpdate }) {
{!selectedCQLLibrary.draft && canEdit && (
<button
data-testid={`create-new-draft-${selectedCQLLibrary.id}-button`}
onClick={() => {
cqlLibraryServiceApi
.fetchCqlLibrary(selectedCQLLibrary.id)
.then((cqlLibrary) => {
setSelectedCqlLibrary(cqlLibrary);
setCreateDraftDialog({
open: true,
cqlLibrary: cqlLibrary,
});
})
.catch(() => {
setSnackBar({
message:
"An error occurred while fetching the CQL Library!",
open: true,
severity: "error",
});
});
setOptionsOpen(false);
setAnchorEl(null);
}}
onClick={() => onDraftClicked(selectedCQLLibrary)}
>
Draft
</button>
Expand Down

0 comments on commit 6eec91d

Please sign in to comment.