1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { Chip } from '@mui/material';
7 import { connect } from 'react-redux';
8 import { RootState } from 'store/store';
9 import CopyToClipboard from 'react-copy-to-clipboard';
10 import { getVocabulary } from 'store/vocabulary/vocabulary-selectors';
11 import { Dispatch } from 'redux';
12 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
13 import { getTagValueLabel, getTagKeyLabel, Vocabulary } from 'models/vocabulary';
15 interface PropertyChipComponentDataProps {
19 vocabulary: Vocabulary;
22 interface PropertyChipComponentActionProps {
23 onDelete?: () => void;
24 onCopy: (message: string) => void;
27 type PropertyChipComponentProps = PropertyChipComponentActionProps & PropertyChipComponentDataProps;
29 const mapStateToProps = ({ properties }: RootState) => ({
30 vocabulary: getVocabulary(properties),
33 const mapDispatchToProps = (dispatch: Dispatch) => ({
34 onCopy: (message: string) => dispatch(snackbarActions.OPEN_SNACKBAR({
37 kind: SnackbarKind.SUCCESS
41 // Renders a Chip with copyable-on-click tag:value data based on the vocabulary
42 export const PropertyChipComponent = connect(mapStateToProps, mapDispatchToProps)(
43 ({ propKey, propValue, vocabulary, className, onCopy, onDelete }: PropertyChipComponentProps) => {
44 const label = `${getTagKeyLabel(propKey, vocabulary)}: ${getTagValueLabel(propKey, propValue, vocabulary)}`;
46 <span onClick={(ev)=>ev.stopPropagation()}>
47 <CopyToClipboard key={propKey} text={label} onCopy={() => onCopy("Copied to clipboard")}>
48 <Chip onDelete={onDelete} key={propKey}
49 className={className} label={label} />
56 export const getPropertyChip = (k: string, v: string, handleDelete: any, className: string) =>
57 <PropertyChipComponent
58 key={`${k}-${v}`} className={className}
59 onDelete={handleDelete}
60 propKey={k} propValue={v} />;