Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 067c00a0

Přidáno uživatelem Václav Honzík před asi 2 roky(ů)

path building algorithm implementation

re #9629

Zobrazit rozdíly:

frontend/src/features/TrackingTool/TrackingTool.tsx
91 91
                                    sx={{ mb: 1 }}
92 92
                                    fontWeight="600"
93 93
                                >
94
                                    Sought text
94
                                    Text
95 95
                                </Typography>
96 96
                                <Typography variant="body2">
97 97
                                    {formatHtmlStringToReactDom(
......
121 121
                        direction="row"
122 122
                        alignItems="flex-start"
123 123
                        spacing={2}
124
                        sx={{ m: 0, p: 0 }}
124
                        sx={{ mt: 1 }}
125 125
                    >
126 126
                        <Typography
127 127
                            variant="h5"
frontend/src/features/TrackingTool/trackingTool.ts
1
// Business logic for tracking tool
2

  
3
import { CatalogItemDto, PathDto } from '../../swagger/data-contracts'
4

  
5
// For more comprehensive code alias CatalogItemDto[] as path variant
6
export type PathVariant = CatalogItemDto[]
7

  
8
const getPathItemVariants = (
9
    catalogItems: CatalogItemDto[][],
10
    currentIdx: number,
11
    itemIdx: number
12
): PathVariant[] => {
13
    if (currentIdx < 0) {
14
        return []
15
    }
16

  
17
    const variants: PathVariant[] = []
18
    const nextIdx = currentIdx - 1
19
    const currentItem = catalogItems[currentIdx][itemIdx]
20
    for (let i = 0; i < catalogItems[nextIdx].length; i += 1) {
21
        const itemPaths = getPathItemVariants(catalogItems, nextIdx, i)
22
        // Push current item at the end
23
        itemPaths.forEach((variant) => {
24
            variant.push(currentItem)
25
        })
26
    }
27

  
28
    return variants
29
}
30

  
31
const buildPathVariants = (pathDto: PathDto) => {
32
    const catalogItems = pathDto.foundCatalogItems
33
    const pathVariants: PathVariant[] = []
34
    // If there are no items or list is empty return
35
    if (!catalogItems || catalogItems.length === 0) {
36
        return []
37
    }
38

  
39
    if (catalogItems.length === 1) {
40
        return catalogItems[0]
41
    }
42

  
43
    // Get items in the last idx since we start from the end
44
    const currentIdx = catalogItems.length - 1
45
    // For each of the items get all path variants
46
    for (let i = 0; i < catalogItems[currentIdx].length; i += 1) {
47
        pathVariants.concat(getPathItemVariants(catalogItems, currentIdx, i))
48
    }
49

  
50
    return pathVariants
51
}
52

  
53
export default buildPathVariants

Také k dispozici: Unified diff