« get me outta code hell

generateArtTagSidebar.js « dependencies « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateArtTagSidebar.js
blob: b5b4ced367fc5fb5797f3fec0d1ff4e4cfd80451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {stitchArrays} from '#sugar';
import {collectTreeLeaves} from '#wiki-data';

export default {
  contentDependencies: [
    'generateArtTagAncestorDescendantMapList',
    'linkArtTagDynamically',
  ],

  extraDependencies: ['html', 'language', 'wikiData'],

  sprawl: ({artTagData}) =>
    ({artTagData}),

  query(sprawl, artTag) {
    const baobab = artTag.ancestorArtTagBaobabTree;
    const uniqueLeaves = new Set(collectTreeLeaves(baobab));

    // Just match the order in tag data.
    const furthestAncestorArtTags =
      sprawl.artTagData
        .filter(artTag => uniqueLeaves.has(artTag));

    return {furthestAncestorArtTags};
  },

  relations: (relation, query, sprawl, artTag) => ({
    artTagLink: relation('linkArtTagDynamically', artTag),

    furthestAncestorArtTagMapLists:
      query.furthestAncestorArtTags
        .map(ancestorArtTag =>
          relation('generateArtTagAncestorDescendantMapList',
            ancestorArtTag,
            artTag)),
  }),

  data: query => ({
    furthestAncestorArtTagNames:
      query.furthestAncestorArtTags
        .map(ancestorArtTag => ancestorArtTag.name),
  }),

  generate: (data, relations, {html, language}) => ({
    leftSidebarContent: [
      html.tag('h1',
        relations.artTagLink),

      stitchArrays({
        name: data.furthestAncestorArtTagNames,
        list: relations.furthestAncestorArtTagMapLists,
      }).map(({name, list}) =>
          html.tag('details',
            {
              class: 'has-tree-list',
              open: relations.furthestAncestorArtTagMapLists.length === 1,
            },
            [
              html.tag('summary',
                html.tag('span', {class: 'group-name'},
                  language.sanitize(name))),

              list,
            ])),
    ],
  }),
};