mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
124 lines
3.6 KiB
TypeScript
124 lines
3.6 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { dateTime } from '@grafana/data';
|
|
import { Forms } from '@grafana/ui';
|
|
import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux';
|
|
import { ImportDashboardForm } from './ImportDashboardForm';
|
|
import { resetDashboard, saveDashboard } from '../state/actions';
|
|
import { DashboardInputs, DashboardSource, ImportDashboardDTO } from '../state/reducers';
|
|
import { StoreState } from 'app/types';
|
|
|
|
interface OwnProps {}
|
|
|
|
interface ConnectedProps {
|
|
dashboard: ImportDashboardDTO;
|
|
inputs: DashboardInputs;
|
|
source: DashboardSource;
|
|
meta?: any;
|
|
folderId: number;
|
|
}
|
|
|
|
interface DispatchProps {
|
|
resetDashboard: typeof resetDashboard;
|
|
saveDashboard: typeof saveDashboard;
|
|
}
|
|
|
|
type Props = OwnProps & ConnectedProps & DispatchProps;
|
|
|
|
interface State {
|
|
uidReset: boolean;
|
|
}
|
|
|
|
class ImportDashboardOverviewUnConnected extends PureComponent<Props, State> {
|
|
state: State = {
|
|
uidReset: false,
|
|
};
|
|
|
|
onSubmit = (form: ImportDashboardDTO) => {
|
|
this.props.saveDashboard(form);
|
|
};
|
|
|
|
onCancel = () => {
|
|
this.props.resetDashboard();
|
|
};
|
|
|
|
onUidReset = () => {
|
|
this.setState({ uidReset: true });
|
|
};
|
|
|
|
render() {
|
|
const { dashboard, inputs, meta, source, folderId } = this.props;
|
|
const { uidReset } = this.state;
|
|
|
|
return (
|
|
<>
|
|
{source === DashboardSource.Gcom && (
|
|
<div style={{ marginBottom: '24px' }}>
|
|
<div>
|
|
<Forms.Legend>
|
|
Importing Dashboard from{' '}
|
|
<a
|
|
href={`https://grafana.com/dashboards/${dashboard.gnetId}`}
|
|
className="external-link"
|
|
target="_blank"
|
|
>
|
|
Grafana.com
|
|
</a>
|
|
</Forms.Legend>
|
|
</div>
|
|
<table className="filter-table form-inline">
|
|
<tbody>
|
|
<tr>
|
|
<td>Published by</td>
|
|
<td>{meta.orgName}</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Updated on</td>
|
|
<td>{dateTime(meta.updatedAt).format('YYYY-MM-DD HH:mm:ss')}</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
<Forms.Form
|
|
onSubmit={this.onSubmit}
|
|
defaultValues={{ ...dashboard, constants: [], dataSources: [], folderId }}
|
|
validateOnMount
|
|
validateFieldsOnMount={['title', 'uid']}
|
|
validateOn="onChange"
|
|
>
|
|
{({ register, errors, control, getValues }) => (
|
|
<ImportDashboardForm
|
|
register={register}
|
|
errors={errors}
|
|
control={control}
|
|
getValues={getValues}
|
|
uidReset={uidReset}
|
|
inputs={inputs}
|
|
onCancel={this.onCancel}
|
|
onUidReset={this.onUidReset}
|
|
onSubmit={this.onSubmit}
|
|
initialFolderId={folderId}
|
|
/>
|
|
)}
|
|
</Forms.Form>
|
|
</>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (state: StoreState) => ({
|
|
dashboard: state.importDashboard.dashboard,
|
|
meta: state.importDashboard.meta,
|
|
source: state.importDashboard.source,
|
|
inputs: state.importDashboard.inputs,
|
|
folderId: state.location.routeParams.folderId ? Number(state.location.routeParams.folderId) : 0,
|
|
});
|
|
|
|
const mapDispatchToProps: MapDispatchToProps<DispatchProps, OwnProps> = {
|
|
resetDashboard,
|
|
saveDashboard,
|
|
};
|
|
|
|
export const ImportDashboardOverview = connect(mapStateToProps, mapDispatchToProps)(ImportDashboardOverviewUnConnected);
|
|
ImportDashboardOverview.displayName = 'ImportDashboardOverview';
|