vitess.io/vitess@v0.16.2/web/vtadmin/src/components/links/KeyspaceLink.tsx (about) 1 /** 2 * Copyright 2021 The Vitess Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import React from 'react'; 18 import { Link } from 'react-router-dom'; 19 import { stringify } from '../../util/queryString'; 20 21 interface Props { 22 className?: string; 23 clusterID: string | null | undefined; 24 name: string | null | undefined; 25 // Shorthand property equivalent to "shardFilter:${shard}" 26 // Note that `shard` will be ignored if `shardFilter` is defined. 27 shard?: string | null | undefined; 28 shardFilter?: string | null | undefined; 29 } 30 31 export const KeyspaceLink: React.FunctionComponent<Props> = ({ 32 children, 33 className, 34 clusterID, 35 name, 36 shard, 37 ...props 38 }) => { 39 if (!clusterID || !name) { 40 return <span className={className}>{children}</span>; 41 } 42 43 let shardFilter = props.shardFilter; 44 if (!shardFilter && !!shard) { 45 shardFilter = `shard:${shard}`; 46 } 47 48 const to = { 49 pathname: `/keyspace/${clusterID}/${name}`, 50 search: stringify({ shardFilter }), 51 }; 52 53 return ( 54 <Link className={className} to={to}> 55 {children} 56 </Link> 57 ); 58 };