diff --git a/web/packages/shared/components/ClusterDropdown/ClusterDropdown.story.tsx b/web/packages/shared/components/ClusterDropdown/ClusterDropdown.story.tsx new file mode 100644 index 0000000000000..1a26d46287c49 --- /dev/null +++ b/web/packages/shared/components/ClusterDropdown/ClusterDropdown.story.tsx @@ -0,0 +1,133 @@ +/** + * Teleport + * Copyright (C) 2023 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import React from 'react'; +import { MemoryRouter } from 'react-router'; + +import { Cluster } from 'teleport/services/clusters'; +import { createTeleportContext } from 'teleport/mocks/contexts'; +import { ContextProvider } from 'teleport/index'; +import { Text, Box } from 'design'; + +import { ClusterDropdown } from './ClusterDropdown'; + +export default { + title: 'Shared/ClusterDropdown', +}; + +const fetchClusters = () => null; + +export const Dropdown = () => { + const ctx = createTeleportContext(); + return ( + + + + 500 clusters + null} + /> + + + 2 clusters + null} + /> + + + 20 clusters + null} + /> + + + 5 clusters + null} + /> + + + no clusters (shouldn't be displayed) + null} + /> + + + 1 cluster (shouldn't be displayed) + null} + /> + + + + ); +}; + +Dropdown.storyName = 'ClusterDropdown'; + +const lotsOfClusters = new Array(500).fill(null).map( + (_, i) => + ({ + clusterId: `cluster-${i}`, + }) as Cluster +); + +const oneCluster = [ + { + clusterId: `cluster-1`, + } as Cluster, +]; + +const twoClusters = new Array(2).fill(null).map( + (_, i) => + ({ + clusterId: `cluster-${i}`, + }) as Cluster +); + +const twentyClusters = new Array(20).fill(null).map( + (_, i) => + ({ + clusterId: `cluster-${i}`, + }) as Cluster +); + +const fiveClusters = new Array(5).fill(null).map( + (_, i) => + ({ + clusterId: `cluster-${i}`, + }) as Cluster +); diff --git a/web/packages/shared/components/ClusterDropdown/ClusterDropdown.tsx b/web/packages/shared/components/ClusterDropdown/ClusterDropdown.tsx index 7e73a61ee1f21..a8175f479ecbf 100644 --- a/web/packages/shared/components/ClusterDropdown/ClusterDropdown.tsx +++ b/web/packages/shared/components/ClusterDropdown/ClusterDropdown.tsx @@ -126,7 +126,8 @@ export function ClusterDropdown({ setAnchorEl(null); }; - if (options.length < 1) { + // If only a single cluster is available, hide the dropdown + if (options.length < 2) { return null; }