All files / maas-ui/src/app/subnets urls.ts

100% Statements 13/13
75% Branches 6/8
100% Functions 5/5
100% Lines 13/13

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              760x   760x     21x 21x 21x                                         760x 546x 760x 546x 760x 9x 760x 2x        
import type { Fabric, FabricMeta } from "@/app/store/fabric/types";
import type { Space, SpaceMeta } from "@/app/store/space/types";
import type { Subnet, SubnetMeta } from "@/app/store/subnet/types";
import type { VLAN, VLANMeta } from "@/app/store/vlan/types";
import type { SubnetsUrlParams } from "@/app/subnets/types";
import { argPath, isId } from "@/app/utils";
 
const withSubnetId = argPath<{ id: Subnet[SubnetMeta.PK] }>;
 
const urls = {
  index: "/networks",
  indexWithParams: (options: SubnetsUrlParams): string => {
    const defaults = { by: "fabric", q: "" };
    const { by, q } = { ...defaults, ...options };
    return `/networks?by=${by}&q=${q}`;
  },
  fabric: {
    index: argPath<{ id: Fabric[FabricMeta.PK] }>("/fabric/:id"),
  },
  space: {
    index: argPath<{ id: Space[SpaceMeta.PK] }>("/space/:id"),
  },
  subnet: {
    summary: withSubnetId("/subnet/:id/summary"),
    staticRoutes: withSubnetId("/subnet/:id/static-routes"),
    addressReservation: withSubnetId("/subnet/:id/address-reservation"),
    dhcpSnippets: withSubnetId("/subnet/:id/dhcp-snippets"),
    usedIpAddresses: withSubnetId("/subnet/:id/used-ip-addresses"),
    index: argPath<{ id: Subnet[SubnetMeta.PK] }>("/subnet/:id"),
  },
  vlan: {
    index: argPath<{ id: VLAN[VLANMeta.PK] }>("/vlan/:id"),
  },
} as const;
 
const getFabricLink = (id?: Fabric["id"]): string | null =>
  isId(id) ? urls.fabric.index({ id }) : null;
const getSpaceLink = (id?: Space["id"]): string | null =>
  isId(id) ? urls.space.index({ id }) : null;
const getVLANLink = (id?: VLAN["id"]): string | null =>
  isId(id) ? urls.vlan.index({ id }) : null;
const getSubnetLink = (id?: Subnet["id"]): string | null =>
  isId(id) ? urls.subnet.index({ id }) : null;
 
export default urls;
export { getFabricLink, getSpaceLink, getVLANLink, getSubnetLink };