All files / public/details channelMap.ts

89.55% Statements 60/67
69.69% Branches 23/33
92.3% Functions 12/13
89.55% Lines 60/67

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 1602x 6x     6x           6x   6x   6x       6x     6x     6x       6x       6x 1x   1x     1x       6x 4x 4x   4x 4x   4x 4x 4x     4x       4x     6x 2x 2x     6x 5x 1x   4x       6x 1x     6x 5x     6x 1x   1x                 1x         1x         7x 7x 28x 28x 1x     27x     27x           1x 1x   1x   4x     4x     4x 3x   1x       1x                       1x     6x 6x 6x        
const init = (packageName: string, channelMapButton: HTMLElement) => {
  const currentChannel = channelMapButton.querySelector(
    "[data-js='channel-map-selected']"
  ) as HTMLElement;
  const channelMapState = {
    channel: currentChannel?.innerText.split(" ")[0],
    version: currentChannel?.innerText.split(" ")[1],
    packageName,
  };
 
  const channelMap = document.querySelector(".p-channel-map");
 
  const mask = channelMap?.querySelector(".p-channel-map__mask");
 
  const channelMapContent = channelMap?.querySelector(
    ".p-channel-map__content"
  ) as HTMLElement;
 
  const channelMapArchFilter = channelMap?.querySelector(
    "[data-js='channel-map-arch-filter']"
  ) as HTMLSelectElement;
  const channelMapBaseFilter = channelMap?.querySelector(
    "[data-js='channel-map-base-filter']"
  ) as HTMLSelectElement;
  const channelsToBeFiltered = channelMap?.querySelectorAll(
    "[data-channel-map-channel]"
  ) as NodeListOf<Element>;
 
  const supportedBases = channelMap?.querySelectorAll(
    "[data-base-supported-archs]"
  ) as NodeListOf<Element>;
 
  const selectChannel = (track: string, channel: string) => {
    const page = window.location.pathname;
 
    Iif (track === "latest" && channel === "stable") {
      window.location.href = `${page}`;
    } else {
      window.location.href = `${page}?channel=${track}/${channel}`;
    }
  };
 
  const showChannelMap = () => {
    channelMap?.classList.remove("u-hide");
    channelMapButton.setAttribute("aria-expanded", "true");
 
    let track = "latest";
    let channel = channelMapState.channel;
 
    Eif (channel.includes("/")) {
      track = channel.split("/")[0];
      channel = channel.split("/")[1];
    }
 
    const selected = document.querySelector(
      `[data-channel-map-track="${track}"][data-channel-map-channel="${channel}"]`
    );
 
    selected?.classList.add("is-active");
  };
 
  const hideChannelMap = () => {
    channelMap?.classList.add("u-hide");
    channelMapButton.removeAttribute("aria-expanded");
  };
 
  const toggleChannelMap = () => {
    if (channelMapButton.getAttribute("aria-expanded")) {
      hideChannelMap();
    } else {
      showChannelMap();
    }
  };
 
  mask?.addEventListener("click", () => {
    hideChannelMap();
  });
 
  channelMapButton.addEventListener("click", () => {
    toggleChannelMap();
  });
 
  channelMapContent.addEventListener("click", (e) => {
    let row = e.target as HTMLElement;
 
    while (
      row.dataset &&
      !row.dataset.channelMapChannel &&
      row.parentNode &&
      row.nodeName !== "TABLE"
    ) {
      row = row.parentNode as HTMLElement;
    }
 
    Eif (
      row.dataset &&
      row.dataset.channelMapChannel &&
      row.dataset.channelMapTrack
    ) {
      selectChannel(row.dataset.channelMapTrack, row.dataset.channelMapChannel);
    }
  });
 
  function hideOlderChannels() {
    const seen = new Set();
    channelsToBeFiltered.forEach((el) => {
      const track = `${el.getAttribute("data-channel-map-track")}${el.getAttribute("data-channel-map-channel")}`;
      if (el.classList.contains("u-hide")) {
        return;
      }
 
      Iif (seen.has(track)) {
        el.classList.add("u-hide");
      } else {
        seen.add(track);
      }
    });
  }
 
  function handleFilterChange() {
    const archValue = channelMapArchFilter.value;
    const baseValue = channelMapBaseFilter.value;
 
    channelsToBeFiltered.forEach((el) => {
      const matchesArch =
        el?.getAttribute("data-channel-map-arch-filter")?.includes(archValue) ||
        archValue === "any";
      const matchesBase =
        el?.getAttribute("data-channel-map-base-filter")?.includes(baseValue) ||
        baseValue === "any";
 
      if (matchesArch && matchesBase) {
        el.classList.remove("u-hide");
      } else {
        el.classList.add("u-hide");
      }
    });
 
    supportedBases.forEach((el) => {
      const matchesBase =
        el?.getAttribute("data-base-supported-archs")?.includes(archValue) ||
        archValue === "any";
 
      if (matchesBase) {
        el.classList.remove("u-hide");
      } else {
        el.classList.add("u-hide");
      }
    });
 
    hideOlderChannels();
  }
 
  channelMapArchFilter.addEventListener("change", handleFilterChange);
  channelMapBaseFilter.addEventListener("change", handleFilterChange);
  hideOlderChannels();
};
 
export { init as channelMap };