Skip to content

Commit

Permalink
JNG-6120 dynamic operation flows
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Jan 20, 2025
1 parent 2ff8d83 commit e1a5c62
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export default function GodGodEarthAccessViewPage() {
try {
setIsLoading(true);
await godServiceForEarthImpl.bang(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postBangForPlanetAction) {
await customActions.postBangForPlanetAction(target!);
} else {
Expand Down Expand Up @@ -290,6 +291,7 @@ export default function GodGodEarthAccessViewPage() {
try {
setIsLoading(true);
await godServiceForEarthImpl.endWar(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postEndWarForPlanetAction) {
await customActions.postEndWarForPlanetAction(target!);
} else {
Expand Down Expand Up @@ -318,6 +320,7 @@ export default function GodGodEarthAccessViewPage() {
try {
setIsLoading(true);
await godServiceForEarthImpl.startWar(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postStartWarForPlanetAction) {
await customActions.postStartWarForPlanetAction(target!);
} else {
Expand All @@ -337,6 +340,7 @@ export default function GodGodEarthAccessViewPage() {
try {
setIsLoading(true);
await godServiceForEarthImpl.createLife(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postCreateLifeForPlanetAction) {
await customActions.postCreateLifeForPlanetAction(target!);
} else {
Expand All @@ -356,6 +360,7 @@ export default function GodGodEarthAccessViewPage() {
try {
setIsLoading(true);
await godServiceForEarthImpl.destroyLife(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postDestroyLifeForPlanetAction) {
await customActions.postDestroyLifeForPlanetAction(target!);
} else {
Expand Down Expand Up @@ -461,6 +466,7 @@ export default function GodGodEarthAccessViewPage() {
try {
setIsLoading(true);
const { data: result } = await godServiceForEarthImpl.chooseTheMessiah(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postCreaturesChooseTheMessiahForPlanetAction) {
await customActions.postCreaturesChooseTheMessiahForPlanetAction(target!, result);
} else if (shouldUseCustomFlow && shouldUseCustomFlow(result)) {
Expand Down Expand Up @@ -496,6 +502,7 @@ export default function GodGodEarthAccessViewPage() {
try {
setIsLoading(true);
const { data: result } = await godServiceForEarthImpl.hateGodForCreatures(target!);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postCreaturesHateGodForCreatureAction) {
await customActions.postCreaturesHateGodForCreatureAction(target!, result);
} else if (shouldUseCustomFlow && shouldUseCustomFlow(result)) {
Expand All @@ -518,6 +525,7 @@ export default function GodGodEarthAccessViewPage() {
try {
setIsLoading(true);
const { data: result } = await godServiceForEarthImpl.loveGodForCreatures(target!);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postCreaturesLoveGodForCreatureAction) {
await customActions.postCreaturesLoveGodForCreatureAction(target!, result);
} else if (shouldUseCustomFlow && shouldUseCustomFlow(result)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export default function ViewStarPlanetsRelationViewPage() {
try {
setIsLoading(true);
await viewStarServiceForPlanetsImpl.bang(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postBangForPlanetAction) {
await customActions.postBangForPlanetAction(target!);
} else {
Expand Down Expand Up @@ -219,6 +220,7 @@ export default function ViewStarPlanetsRelationViewPage() {
try {
setIsLoading(true);
await viewStarServiceForPlanetsImpl.endWar(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postEndWarForPlanetAction) {
await customActions.postEndWarForPlanetAction(target!);
} else {
Expand Down Expand Up @@ -247,6 +249,7 @@ export default function ViewStarPlanetsRelationViewPage() {
try {
setIsLoading(true);
await viewStarServiceForPlanetsImpl.startWar(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postStartWarForPlanetAction) {
await customActions.postStartWarForPlanetAction(target!);
} else {
Expand All @@ -266,6 +269,7 @@ export default function ViewStarPlanetsRelationViewPage() {
try {
setIsLoading(true);
await viewStarServiceForPlanetsImpl.createLife(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postCreateLifeForPlanetAction) {
await customActions.postCreateLifeForPlanetAction(target!);
} else {
Expand All @@ -285,6 +289,7 @@ export default function ViewStarPlanetsRelationViewPage() {
try {
setIsLoading(true);
await viewStarServiceForPlanetsImpl.destroyLife(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postDestroyLifeForPlanetAction) {
await customActions.postDestroyLifeForPlanetAction(target!);
} else {
Expand Down Expand Up @@ -390,6 +395,7 @@ export default function ViewStarPlanetsRelationViewPage() {
try {
setIsLoading(true);
const { data: result } = await viewStarServiceForPlanetsImpl.chooseTheMessiah(data);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postCreaturesChooseTheMessiahForPlanetAction) {
await customActions.postCreaturesChooseTheMessiahForPlanetAction(target!, result);
} else if (shouldUseCustomFlow && shouldUseCustomFlow(result)) {
Expand Down Expand Up @@ -425,6 +431,7 @@ export default function ViewStarPlanetsRelationViewPage() {
try {
setIsLoading(true);
const { data: result } = await viewStarServiceForPlanetsImpl.hateGodForCreatures(target!);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postCreaturesHateGodForCreatureAction) {
await customActions.postCreaturesHateGodForCreatureAction(target!, result);
} else if (shouldUseCustomFlow && shouldUseCustomFlow(result)) {
Expand All @@ -447,6 +454,7 @@ export default function ViewStarPlanetsRelationViewPage() {
try {
setIsLoading(true);
const { data: result } = await viewStarServiceForPlanetsImpl.loveGodForCreatures(target!);
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
if (customActions?.postCreaturesLoveGodForCreatureAction) {
await customActions.postCreaturesLoveGodForCreatureAction(target!, result);
} else if (shouldUseCustomFlow && shouldUseCustomFlow(result)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,8 @@ public static String toSafeCamelCase(String input) {
public static String escapeString(String input) {
return input.replaceAll("\n", "\\\\n");
}

public static boolean elementHasAnnotation(NamedElement element, String annotation) {
return element != null && element.getAnnotations().stream().anyMatch(a -> a.getName().equals(annotation));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// To define a custom operation output handler, create the `actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs` file
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {{ simpleActionDefinitionName action.actionDefinition }} = async ({{# if a
{{# unless operation.isStatic }}produceDataAdjustedOwner(),{{/ unless }}
data
);
{{> actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs operation=operation action=action }}
if (customActions?.post{{ firstToUpper (simpleActionDefinitionName action.actionDefinition) }}) {
await customActions.post{{ firstToUpper (simpleActionDefinitionName action.actionDefinition) }}(
{{# if action.actionDefinition.targetType }}target!,{{/ if }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {{ simpleActionDefinitionName action.actionDefinition }} = async ({{# if a
{{# if operation.output }}const { data: result } = {{/ if }}await {{ getServiceImplForPage page }}.{{ operation.name }}{{ operationCallSuffix action }}(
{{# unless operation.isStatic }}ownerData, {{/ unless }}selectionDiff[0]
);
{{> actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs operation=operation action=action }}
if (customActions?.post{{ firstToUpper (simpleActionDefinitionName action.actionDefinition) }}) {
await customActions.post{{ firstToUpper (simpleActionDefinitionName action.actionDefinition) }}(
{{# if action.actionDefinition.targetType }}target!,{{/ if }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {{ simpleActionDefinitionName action.actionDefinition }} = async ({{# if a
{{/ unless }}
{{/ if }}
);
{{> actor/src/fragments/operations/operation-primary-output-handler.fragment.hbs operation=operation action=action }}
if (customActions?.post{{ firstToUpper (simpleActionDefinitionName action.actionDefinition) }}) {
await customActions.post{{ firstToUpper (simpleActionDefinitionName action.actionDefinition) }}(
{{# if action.actionDefinition.targetType }}target!,{{/ if }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const OPERATION_FLOW_MANAGER_INTERFACE_KEY = 'OperationFlowManager';

export interface OperationFlowManager {
handleResult: ResultHandler;
shouldUseCustomFlow: (input?: JudoStored<any>) => boolean;
shouldUseCustomFlow?: (input?: JudoStored<any>) => boolean;
}

export function useOperationUtils() {
Expand All @@ -69,7 +69,7 @@ export function useOperationUtils() {
{{/ each }}

const processRedirect: (response: JudoStored<any>) => Promise<void> = useCallback(async (response) => {
if (!handleResult || !shouldUseCustomFlow || !shouldUseCustomFlow(response)) {
if (!handleResult) {
return;
}
const { actor, access, filterRecords, operation } = handleResult(response);
Expand Down

0 comments on commit e1a5c62

Please sign in to comment.