1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { Dialog, DialogActions, Button, StyleRulesCallback, WithStyles, withStyles, DialogTitle, DialogContent, Tabs, Tab, DialogContentText } from '@material-ui/core';
7 import { WithDialogProps } from '~/store/dialog/with-dialog';
8 import { withDialog } from "~/store/dialog/with-dialog";
9 import { compose } from 'redux';
10 import { ADVANCED_TAB_DIALOG } from "~/store/advanced-tab/advanced-tab";
11 import { DefaultCodeSnippet } from "~/components/default-code-snippet/default-code-snippet";
12 import { MetadataTab } from '~/views-components/advanced-tab-dialog/metadataTab';
14 type CssRules = 'content' | 'codeSnippet' | 'spacing';
16 const styles: StyleRulesCallback<CssRules> = theme => ({
18 paddingTop: theme.spacing.unit * 3,
23 borderRadius: theme.spacing.unit * 0.5,
25 borderColor: theme.palette.grey["400"],
29 paddingBottom: theme.spacing.unit * 2
33 export const AdvancedTabDialog = compose(
34 withDialog(ADVANCED_TAB_DIALOG),
37 class extends React.Component<WithDialogProps<any> & WithStyles<CssRules>>{
43 this.setState({ value: 0 });
46 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
47 this.setState({ value });
50 const { classes, open, closeDialog } = this.props;
51 const { value } = this.state;
68 onExit={() => this.setState({ value: 0 })} >
69 <DialogTitle>Advanced</DialogTitle>
70 <Tabs value={value} onChange={this.handleChange} fullWidth>
71 <Tab label="API RESPONSE" />
72 <Tab label="METADATA" />
73 <Tab label="PYTHON EXAMPLE" />
74 <Tab label="CLI EXAMPLE" />
75 <Tab label="CURL EXAMPLE" />
77 <DialogContent className={classes.content}>
78 {value === 0 && <div>{dialogContentExample(apiResponse, classes)}</div>}
79 {value === 1 && <div>{metadata.items.length > 0 ? <MetadataTab items={metadata.items}/>: dialogContentHeader('(No metadata links found)')}</div>}
80 {value === 2 && dialogContent(pythonHeader, pythonExample, classes)}
82 {dialogContent(cliGetHeader, cliGetExample, classes)}
83 {dialogContent(cliUpdateHeader, cliUpdateExample, classes)}
85 {value === 4 && dialogContent(curlHeader, curlExample, classes)}
88 <Button variant='flat' color='primary' onClick={closeDialog}>
97 const dialogContent = (header: string, example: string, classes: any) =>
98 <div className={classes.spacing}>
99 {dialogContentHeader(header)}
100 {dialogContentExample(example, classes)}
103 const dialogContentHeader = (header: string) =>
106 </DialogContentText>;
108 const dialogContentExample = (example: string, classes: any) =>
110 className={classes.codeSnippet}
111 lines={[example]} />;