-
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.
- Loading branch information
Showing
9 changed files
with
183 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { InternalPageType } from 'model/Page' | ||
import type { LunaticOverview, LunaticPageTag } from './lunaticType' | ||
|
||
const pageTagComparator = (a: LunaticPageTag, b: LunaticPageTag) => { | ||
const pageA = a.split(/\D/).map((v) => parseInt(v, 10)) | ||
const pageB = b.split(/\D/).map((v) => parseInt(v, 10)) | ||
// [0, 2, 1] is used to extract the significant part of the pageTag part (start with page, then iteration, then subpage) | ||
for (const index of [0, 2, 1]) { | ||
if (pageA[index] !== pageB[index]) { | ||
return (pageA[index] ?? -1) - (pageB[index] ?? -1) | ||
} | ||
} | ||
return 0 | ||
} | ||
|
||
const getCurrentAndNextSequenceLabel = ({ | ||
overview, | ||
currentPageTag, | ||
}: { | ||
overview: LunaticOverview | ||
currentPageTag: LunaticPageTag | ||
}) => { | ||
const sequences = overview.filter( | ||
(sequence) => pageTagComparator(currentPageTag, sequence.page) <= 0 | ||
) | ||
console.log(currentPageTag) | ||
console.log({ overview }) | ||
console.log({ sequences }) | ||
//overview is ordered so sequences too | ||
const currentSequence = sequences[0] | ||
const nextSequence = sequences[1] | ||
|
||
return { | ||
currentLabel: currentSequence.label, | ||
nextLabel: nextSequence?.label, | ||
currentStep: | ||
overview.findIndex((sequence) => sequence.id === currentSequence.id) + 1, | ||
} | ||
} | ||
|
||
export const getSteeperInfo = (params: { | ||
overview: LunaticOverview | ||
currentPageTag: LunaticPageTag | ||
currentPage: InternalPageType | ||
}) => { | ||
const { overview } = params | ||
|
||
if (overview.length === 0) return { displayOverview: false } | ||
|
||
const { currentLabel, nextLabel, currentStep } = | ||
getCurrentAndNextSequenceLabel(params) | ||
return { | ||
displayOverview: true, | ||
currentSequenceLabel: currentLabel, | ||
nextSequenceLabel: nextLabel, | ||
sequenceCount: overview.length, | ||
currentStep, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { LunaticComponentProps } from './lunaticType' | ||
|
||
export const isSequencePage = (components: LunaticComponentProps) => | ||
components.some((component) => component.componentType === 'Sequence') |
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 |
---|---|---|
|
@@ -757,10 +757,10 @@ | |
dependencies: | ||
react-number-format "^5.3.4" | ||
|
||
"@inseefr/[email protected].21": | ||
version "3.0.0-rc.21" | ||
resolved "https://registry.yarnpkg.com/@inseefr/lunatic/-/lunatic-3.0.0-rc.21.tgz#233a752d3120c8503b9b94af001c47458b3f2577" | ||
integrity sha512-D7P2h3JcdifO52DVj4xqaurgmoPGyUVWol0VLTxhKDelPIG3ZoSbFs9jyYdHDUXSSeQ3yo3SefGWZFp7duOkiQ== | ||
"@inseefr/[email protected].22": | ||
version "3.0.0-rc.22" | ||
resolved "https://registry.yarnpkg.com/@inseefr/lunatic/-/lunatic-3.0.0-rc.22.tgz#d83503b69c3ae2bc9b3a2104b37197a9b2a6dfb3" | ||
integrity sha512-dTCi5AYRi+sDV7QZdMgZA0jBpM0vK1DqiUWNq9AQJ2OteU0xfNVuUhUXe3KQjEsvWvp9YXWrYAQ7NCDmKbDDXA== | ||
dependencies: | ||
"@inseefr/trevas" "^0.1.20" | ||
"@inseefr/vtl-2.0-antlr-tools" "^0.1.0" | ||
|