-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make see fields generate draft (#810)
* Making a hook to share the generate functionality * Allowing a presave function to be called * Wiring up refresh button so it can handle generating the draft * Updating to use the new mutate context * Getting captures using the next context * Better way to check if the call worked * No longer need to pass disabled to refresh Better handling of errors for refresh button * Adding a hook to scroll elements into view * Having the general error scroll into view * Having validation errors scroll into view * Cleaning up logging * Adding in disabled so it can be disabled while the form is active * POST MERGE - fixing imports * Cleaning up more of the post generate mutate being passed around * PR : Commenting * PR : Commenting * Switching back to null so things do not fail silently * PR - cleaning up code a bit * This did nothing - reverting the changes * Allowing for options to be passed * PR Cleaning up comments and code
- Loading branch information
1 parent
8c10f80
commit a271364
Showing
20 changed files
with
948 additions
and
726 deletions.
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
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
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
55 changes: 41 additions & 14 deletions
55
src/components/editor/Bindings/FieldSelection/RefreshButton.tsx
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 |
---|---|---|
@@ -1,29 +1,56 @@ | ||
import { useEditorStore_id } from 'components/editor/Store/hooks'; | ||
import EntityCreateSave from 'components/shared/Entity/Actions/Save'; | ||
import { Button } from '@mui/material'; | ||
import useGenerateCatalog from 'components/materialization/useGenerateCatalog'; | ||
import useSave from 'components/shared/Entity/Actions/useSave'; | ||
import useEntityWorkflowHelpers from 'components/shared/Entity/hooks/useEntityWorkflowHelpers'; | ||
import { useMutateDraftSpec } from 'components/shared/Entity/MutateDraftSpecContext'; | ||
import { useState } from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { CustomEvents } from 'services/logrocket'; | ||
|
||
interface Props { | ||
disabled: boolean; | ||
logEvent: CustomEvents.MATERIALIZATION_TEST; | ||
buttonLabelId: string; | ||
logEvent: CustomEvents.MATERIALIZATION_TEST; | ||
disabled?: boolean; | ||
} | ||
|
||
function RefreshButton({ disabled, logEvent, buttonLabelId }: Props) { | ||
const { callFailed } = useEntityWorkflowHelpers(); | ||
|
||
// Draft Editor Store | ||
const draftId = useEditorStore_id(); | ||
const [updating, setUpdating] = useState(false); | ||
|
||
const generateCatalog = useGenerateCatalog(); | ||
const mutateDraftSpec = useMutateDraftSpec(); | ||
const saveCatalog = useSave(logEvent, callFailed, true, true); | ||
|
||
return ( | ||
<EntityCreateSave | ||
dryRun | ||
disabled={disabled || !draftId} | ||
onFailure={callFailed} | ||
logEvent={logEvent} | ||
buttonLabelId={buttonLabelId} | ||
forceLogsClosed | ||
/> | ||
<Button | ||
disabled={Boolean(updating || disabled)} | ||
onClick={async () => { | ||
setUpdating(true); | ||
|
||
let evaluatedDraftId; | ||
try { | ||
evaluatedDraftId = await generateCatalog(mutateDraftSpec); | ||
} catch (_error: unknown) { | ||
setUpdating(false); | ||
} | ||
|
||
// Make sure we have a draft id so we know the generate worked | ||
// if this is not returned then the function itself handled showing an error | ||
if (evaluatedDraftId) { | ||
try { | ||
await saveCatalog(evaluatedDraftId); | ||
} catch (_error: unknown) { | ||
setUpdating(false); | ||
} | ||
} | ||
|
||
// I do not think this is truly needed but being safe so the user is not stuck with a disabled button | ||
setUpdating(false); | ||
}} | ||
> | ||
<FormattedMessage id={buttonLabelId} /> | ||
</Button> | ||
); | ||
} | ||
export default RefreshButton; |
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.