-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use the new refactored migrateSituation from `@publicodes/t…
…ools` (#577)
- Loading branch information
Showing
14 changed files
with
83 additions
and
234 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import { migrateSituation } from '@publicodes/tools/migration' | ||
import { MigrationType, Simulation } from '../types' | ||
import { Migration, migrateSituation } from '@publicodes/tools/migration' | ||
import { Simulation } from '../types' | ||
|
||
type Props = { | ||
simulation: Simulation | ||
migrationInstructions: MigrationType | ||
} | ||
type Return = Simulation | ||
|
||
export function migrateSimulation({ | ||
simulation: oldSimulation, | ||
migrationInstructions, | ||
}: Props): Return { | ||
const simulation = JSON.parse(JSON.stringify(oldSimulation)) as Simulation | ||
export function migrateSimulation( | ||
simulation: Simulation & { group?: string; poll?: string }, | ||
migrationInstructions: Migration | undefined | ||
): Simulation { | ||
if (migrationInstructions) { | ||
simulation.situation = migrateSituation( | ||
simulation.situation, | ||
migrationInstructions | ||
) | ||
|
||
const { situationMigrated, foldedStepsMigrated } = migrateSituation({ | ||
situation: simulation.situation, | ||
foldedSteps: simulation.foldedSteps, | ||
migrationInstructions, | ||
}) | ||
// NOTE: folded steps (i.e. answered rules) are can be map to a situation, | ||
// where the keys are the rule names and the value is undefined. | ||
simulation.foldedSteps = Object.keys( | ||
migrateSituation( | ||
Object.fromEntries( | ||
simulation.foldedSteps.map((step) => [step, undefined]) | ||
), | ||
migrationInstructions | ||
) | ||
) | ||
} | ||
// If group or poll is defined, we convert it to groups or polls and delete it | ||
if (simulation.group) { | ||
simulation.groups = [simulation.group] | ||
delete simulation.group | ||
} | ||
|
||
simulation.situation = situationMigrated | ||
simulation.foldedSteps = foldedStepsMigrated | ||
if (simulation.poll) { | ||
simulation.polls = [simulation.poll] | ||
delete simulation.poll | ||
} | ||
|
||
return simulation | ||
} |
27 changes: 0 additions & 27 deletions
27
src/publicodes-state/helpers/migration/convertSimulation.ts
This file was deleted.
Oops, something went wrong.
137 changes: 0 additions & 137 deletions
137
src/publicodes-state/helpers/migration/filterSimulation.ts
This file was deleted.
Oops, something went wrong.
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
5 changes: 3 additions & 2 deletions
5
src/publicodes-state/providers/userProvider/usePersistentSimulations.ts
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.