-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14130 from influxdata/static-templates
Static templates
- Loading branch information
Showing
14 changed files
with
2,192 additions
and
744 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Libraries | ||
import React, {PureComponent, MouseEvent} from 'react' | ||
import _ from 'lodash' | ||
import {connect} from 'react-redux' | ||
import {withRouter, WithRouterProps} from 'react-router' | ||
import { | ||
Button, | ||
ComponentSize, | ||
ComponentSpacer, | ||
FlexDirection, | ||
JustifyContent, | ||
} from '@influxdata/clockface' | ||
|
||
// Components | ||
import {ResourceList} from 'src/clockface' | ||
|
||
// Actions | ||
import {createResourceFromStaticTemplate} from 'src/templates/actions' | ||
|
||
// Selectors | ||
import {viewableLabels} from 'src/labels/selectors' | ||
|
||
// Types | ||
import {TemplateSummary, ILabel} from '@influxdata/influx' | ||
import {ComponentColor} from '@influxdata/clockface' | ||
import {AppState, Organization} from 'src/types' | ||
|
||
// Constants | ||
interface OwnProps { | ||
template: TemplateSummary | ||
name: string | ||
onFilterChange: (searchTerm: string) => void | ||
} | ||
|
||
interface DispatchProps { | ||
onCreateFromTemplate: typeof createResourceFromStaticTemplate | ||
} | ||
|
||
interface StateProps { | ||
labels: ILabel[] | ||
org: Organization | ||
} | ||
|
||
type Props = DispatchProps & OwnProps & StateProps | ||
|
||
class StaticTemplateCard extends PureComponent<Props & WithRouterProps> { | ||
public render() { | ||
const {template} = this.props | ||
|
||
return ( | ||
<ResourceList.Card | ||
testID="template-card" | ||
contextMenu={() => this.contextMenu} | ||
description={() => this.description} | ||
name={() => ( | ||
<ResourceList.Name | ||
onClick={this.handleNameClick} | ||
name={template.meta.name} | ||
parentTestID="template-card--name" | ||
buttonTestID="template-card--name-button" | ||
inputTestID="template-card--input" | ||
/> | ||
)} | ||
metaData={() => [this.templateType]} | ||
/> | ||
) | ||
} | ||
|
||
private get contextMenu(): JSX.Element { | ||
return ( | ||
<ComponentSpacer | ||
margin={ComponentSize.Medium} | ||
direction={FlexDirection.Row} | ||
justifyContent={JustifyContent.FlexEnd} | ||
> | ||
<Button | ||
text="Create" | ||
color={ComponentColor.Primary} | ||
size={ComponentSize.ExtraSmall} | ||
onClick={this.handleCreate} | ||
/> | ||
</ComponentSpacer> | ||
) | ||
} | ||
|
||
private get description(): JSX.Element { | ||
const {template} = this.props | ||
const description = _.get(template, 'content.data.attributes.description') | ||
|
||
return ( | ||
<ResourceList.Description description={description || 'No description'} /> | ||
) | ||
} | ||
|
||
private get templateType(): JSX.Element { | ||
const {template} = this.props | ||
|
||
return ( | ||
<div className="resource-list--meta-item"> | ||
{_.get(template, 'content.data.type')} | ||
</div> | ||
) | ||
} | ||
|
||
private handleCreate = () => { | ||
const {onCreateFromTemplate, name} = this.props | ||
|
||
onCreateFromTemplate(name) | ||
} | ||
|
||
private handleNameClick = (e: MouseEvent<HTMLAnchorElement>) => { | ||
e.preventDefault() | ||
this.handleViewTemplate() | ||
} | ||
|
||
private handleViewTemplate = () => { | ||
const {router, org, name} = this.props | ||
|
||
router.push(`/orgs/${org.id}/templates/${name}/static/view`) | ||
} | ||
} | ||
|
||
const mstp = ({labels, orgs: {org}}: AppState): StateProps => { | ||
return { | ||
org, | ||
labels: viewableLabels(labels.list), | ||
} | ||
} | ||
|
||
const mdtp: DispatchProps = { | ||
onCreateFromTemplate: createResourceFromStaticTemplate, | ||
} | ||
|
||
export default connect<StateProps, DispatchProps, OwnProps>( | ||
mstp, | ||
mdtp | ||
)(withRouter<Props>(StaticTemplateCard)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, {PureComponent} from 'react' | ||
import {withRouter, WithRouterProps} from 'react-router' | ||
import _ from 'lodash' | ||
|
||
// Components | ||
import ViewOverlay from 'src/shared/components/ViewOverlay' | ||
import {ErrorHandling} from 'src/shared/decorators/errors' | ||
|
||
// Types | ||
import {RemoteDataState} from '@influxdata/clockface' | ||
import {DocumentCreate} from '@influxdata/influx' | ||
|
||
import {staticTemplates} from 'src/templates/constants/defaultTemplates' | ||
|
||
interface OwnProps { | ||
params: {id: string} | ||
} | ||
|
||
type Props = OwnProps & WithRouterProps | ||
|
||
@ErrorHandling | ||
class TemplateExportOverlay extends PureComponent<Props> { | ||
public render() { | ||
return ( | ||
<ViewOverlay | ||
resource={this.template} | ||
overlayHeading={this.overlayTitle} | ||
onDismissOverlay={this.onDismiss} | ||
status={RemoteDataState.Done} | ||
/> | ||
) | ||
} | ||
|
||
private get template(): DocumentCreate { | ||
const { | ||
params: {id}, | ||
} = this.props | ||
|
||
return staticTemplates[id] | ||
} | ||
|
||
private get overlayTitle() { | ||
return this.template.meta.name | ||
} | ||
|
||
private onDismiss = () => { | ||
const {router} = this.props | ||
|
||
router.goBack() | ||
} | ||
} | ||
|
||
export default withRouter<Props>(TemplateExportOverlay) |
Oops, something went wrong.