-
Notifications
You must be signed in to change notification settings - Fork 12
[SAFE-EMAIL-TEST-1] PLU-386: setup infra to display app-specific tooltips in check step #1645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ogp-weeloong
wants to merge
1
commit into
develop-v2
Choose a base branch
from
feat/ses/safe-test-emails/tooltip
base: develop-v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,19 @@ | ||
| import type { FrontEndAppExtension } from './types' | ||
|
|
||
| // Nothing for now | ||
| const APP_EXTENSIONS: Record<string, FrontEndAppExtension> = {} | ||
|
|
||
| export function getExtension( | ||
| appKey?: string, | ||
| stepKey?: string, | ||
| ): FrontEndAppExtension | null { | ||
| if (!appKey || !stepKey) { | ||
| return null | ||
| } | ||
| return APP_EXTENSIONS[`${appKey}-${stepKey}`] ?? null | ||
| } | ||
|
|
||
| export type { | ||
| CheckStepButtonExtensionProps, | ||
| FrontEndAppExtension, | ||
| } from './types' |
This file contains hidden or 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,22 @@ | ||
| import type { IStep } from '@plumber/types' | ||
|
|
||
| import type { ComponentType, ReactNode } from 'react' | ||
|
|
||
| export interface CheckStepButtonExtensionProps { | ||
| step: IStep | ||
| /** The Check Step / Check Step Again button itself. */ | ||
| children: ReactNode | ||
| } | ||
|
|
||
| export interface FrontEndAppExtension { | ||
| /** | ||
| * Wraps the Check Step / Check Step Again button. | ||
| * | ||
| * Mounted ONLY WHEN the button is enabled. | ||
| * TBD: Allow extending when button is disabled (for showing custom failure | ||
| * tooltip etc) | ||
| **/ | ||
| CheckStepButton?: ComponentType<CheckStepButtonExtensionProps> | ||
|
|
||
| // Room to grow: ResultPanelWrapper, SubstepWrapper, etc. | ||
| } |
This file contains hidden or 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 hidden or 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,6 +1,13 @@ | ||
| import { IBaseTrigger, IStep, ITriggerInstructions } from '@plumber/types' | ||
|
|
||
| import { useContext, useEffect, useMemo, useRef, useState } from 'react' | ||
| import { | ||
| forwardRef, | ||
| useContext, | ||
| useEffect, | ||
| useMemo, | ||
| useRef, | ||
| useState, | ||
| } from 'react' | ||
| import { useFormContext } from 'react-hook-form' | ||
| import { BiChevronDown, BiChevronUp } from 'react-icons/bi' | ||
| import { | ||
|
|
@@ -20,6 +27,7 @@ import { | |
| Infobox, | ||
| } from '@opengovsg/design-system-react' | ||
|
|
||
| import { CheckStepButtonExtensionProps, getExtension } from '@/app-extensions' | ||
| import { EditorContext } from '@/contexts/Editor' | ||
| import { validateStepParams } from '@/helpers/validateStepParams' | ||
| import { useStepMetadata } from '@/hooks/useStepMetadata' | ||
|
|
@@ -63,25 +71,32 @@ type CheckStepTooltipProps = { | |
| children: React.ReactNode | ||
| } | ||
|
|
||
| const CheckStepTooltip = (props: CheckStepTooltipProps) => { | ||
| const { children, hasDeletedVars, isDisabled, isReadOnly } = props | ||
| return ( | ||
| <Tooltip | ||
| label={ | ||
| isReadOnly | ||
| ? 'Unpublish your pipe to check step' | ||
| : hasDeletedVars | ||
| ? 'Remove variables from deleted steps to check step' | ||
| : 'Complete required fields to check step' | ||
| } | ||
| aria-label="check step tooltip" | ||
| isDisabled={isDisabled} | ||
| hasArrow | ||
| > | ||
| {children} | ||
| </Tooltip> | ||
| ) | ||
| } | ||
| const CheckStepTooltip = forwardRef<HTMLDivElement, CheckStepTooltipProps>( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
| (props, ref) => { | ||
| const { children, hasDeletedVars, isDisabled, isReadOnly } = props | ||
| return ( | ||
| <Tooltip | ||
| ref={ref} | ||
| label={ | ||
| isReadOnly | ||
| ? 'Unpublish your pipe to check step' | ||
| : hasDeletedVars | ||
| ? 'Remove variables from deleted steps to check step' | ||
| : 'Complete required fields to check step' | ||
| } | ||
| aria-label="check step tooltip" | ||
| isDisabled={isDisabled} | ||
| hasArrow | ||
| > | ||
| {children} | ||
| </Tooltip> | ||
| ) | ||
| }, | ||
| ) | ||
|
|
||
| const NoOpCheckStepButtonExtension = ({ | ||
| children, | ||
| }: CheckStepButtonExtensionProps) => children | ||
|
|
||
| export default function FlowStepTestController( | ||
| props: FlowStepTestControllerProps, | ||
|
|
@@ -248,6 +263,12 @@ export default function FlowStepTestController( | |
| return collapseDirection === 'up' ? <BiChevronUp /> : <BiChevronDown /> | ||
| } | ||
|
|
||
| const appExtension = getExtension(step.appKey, step.key) | ||
| const CheckStepButtonExtension = | ||
| shouldAllowCheckStep && appExtension?.CheckStepButton != null | ||
| ? appExtension.CheckStepButton | ||
| : NoOpCheckStepButtonExtension | ||
|
|
||
| return ( | ||
| <> | ||
| {isWebhookSubstep && ( | ||
|
|
@@ -337,14 +358,16 @@ export default function FlowStepTestController( | |
| {!isDirty ? 'Saved' : 'Save without checking'} | ||
| </Button> | ||
| )} | ||
| <CheckAgainButton | ||
| isUnstyledInfobox={isStepUnchecked} | ||
| onClick={handleSaveAndTest} | ||
| isLoading={isTestExecuting} | ||
| isDisabled={!isValid || readOnly} | ||
| step={step} | ||
| executionStepMetadata={currentTestExecutionStep?.metadata} | ||
| /> | ||
| <CheckStepButtonExtension step={step}> | ||
| <CheckAgainButton | ||
| isUnstyledInfobox={isStepUnchecked} | ||
| onClick={handleSaveAndTest} | ||
| isLoading={isTestExecuting} | ||
| isDisabled={!isValid || readOnly} | ||
| step={step} | ||
| executionStepMetadata={currentTestExecutionStep?.metadata} | ||
| /> | ||
| </CheckStepButtonExtension> | ||
| </Flex> | ||
| </Flex> | ||
| </Infobox> | ||
|
|
@@ -379,20 +402,22 @@ export default function FlowStepTestController( | |
| {isDirty ? 'Save' : 'Saved'} | ||
| </Button> | ||
| )} | ||
| <CheckStepTooltip | ||
| hasDeletedVars={hasDeletedVars} | ||
| isDisabled={shouldAllowCheckStep} | ||
| isReadOnly={readOnly} | ||
| > | ||
| <Button | ||
| onClick={() => handleSaveAndTest()} | ||
| data-test="flow-substep-continue-button" | ||
| isDisabled={!shouldAllowCheckStep} | ||
| isLoading={isTestExecuting} | ||
| <CheckStepButtonExtension step={step}> | ||
| <CheckStepTooltip | ||
| hasDeletedVars={hasDeletedVars} | ||
| isDisabled={shouldAllowCheckStep} | ||
| isReadOnly={readOnly} | ||
| > | ||
| Check step | ||
| </Button> | ||
| </CheckStepTooltip> | ||
| <Button | ||
| onClick={() => handleSaveAndTest()} | ||
| data-test="flow-substep-continue-button" | ||
| isDisabled={!shouldAllowCheckStep} | ||
| isLoading={isTestExecuting} | ||
| > | ||
| Check step | ||
| </Button> | ||
| </CheckStepTooltip> | ||
| </CheckStepButtonExtension> | ||
| </HStack> | ||
| </VStack> | ||
| )} | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will migrate this to extension approach in a later PR