Skip to content

Commit

Permalink
Fix action deduplicator
Browse files Browse the repository at this point in the history
  • Loading branch information
uncoolzero committed Dec 11, 2023
1 parent 189e3a6 commit 7bb7647
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions projects/ui/src/lib/Txn/FormTxn/FormTxnBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type FormTxnFarmStep =
* - it is intended for this to be called in an 'onSubmit' function where the user
* has confirmed which FarmSteps they want to perform.
* - setFarmSteps() deduplicates any FarmSteps that are implied by other FarmSteps
* as welll as any FarmSteps that are excluded by the form.
* as well as any FarmSteps that are excluded by the form.
*
* 3. Call build() to perform the bundling of FarmSteps into a single, executable Workflow.
* - It is assumed every FarmStep added to have previous been 'built'.
Expand All @@ -70,12 +70,6 @@ export class FormTxnBundler {

private after: Partial<FormTxnMap<FarmStep>>;

// FormTxns that imply other FormTxns when added
static implied: Partial<FormTxnMap> = {
[FormTxn.ENROOT]: FormTxn.MOW,
[FormTxn.PLANT]: FormTxn.MOW,
};

static presets = presets;

constructor(
Expand Down Expand Up @@ -189,14 +183,13 @@ export class FormTxnBundler {

/**
* @param data
* deduplicate farm steps & remove implicit actions.
* deduplicate farm steps.
*/
private static deduplicateFarmSteps(data: FormTxnBundlerInterface) {
const before = new Set(data.primary || []);
const after = new Set(data.secondary || []);

const allActions = new Set([...before, ...after]);

/// deduplicate
// if an action is in both primary and secondary, remove it from secondary
[...before].forEach((action) => {
Expand All @@ -205,24 +198,6 @@ export class FormTxnBundler {
}
});

/// deduplicate implied actions
[...allActions].forEach((action) => {
const implied = FormTxnBundler.implied[action];
if (implied) {
allActions.has(implied) && allActions.delete(implied);
before.has(implied) && before.delete(implied);
after.has(implied) && after.delete(implied);
}
});

const removeItems = [...(data.exclude || []), ...(data.implied || [])];

removeItems.forEach((toRemove) => {
allActions.has(toRemove) && allActions.delete(toRemove);
before.has(toRemove) && before.delete(toRemove);
after.has(toRemove) && after.delete(toRemove);
});

return {
before: [...before],
after: [...after],
Expand Down

0 comments on commit 7bb7647

Please sign in to comment.