add initial panel on did mount

Signed-off-by: blalov <boyko.lalov@tick42.com>
This commit is contained in:
blalov 2019-11-16 00:26:43 +02:00
parent ebe5380433
commit 77da5e7ab4

View file

@ -20,29 +20,21 @@ interface PanelListState {
timeDriftError: string | null; timeDriftError: string | null;
} }
const initialPanel = {
id: generateID(),
key: '0',
options: PanelDefaultOptions,
};
class PanelList extends Component<RouteComponentProps & PathPrefixProps, PanelListState> { class PanelList extends Component<RouteComponentProps & PathPrefixProps, PanelListState> {
constructor(props: PathPrefixProps) { constructor(props: PathPrefixProps) {
super(props); super(props);
const urlPanels = decodePanelOptionsFromQueryString(window.location.search);
this.state = { this.state = {
panels: urlPanels.length ? urlPanels : [initialPanel], panels: decodePanelOptionsFromQueryString(window.location.search),
pastQueries: [], pastQueries: [],
metricNames: [], metricNames: [],
fetchMetricsError: null, fetchMetricsError: null,
timeDriftError: null, timeDriftError: null,
}; };
!urlPanels.length && this.updateURL();
} }
componentDidMount() { componentDidMount() {
!this.state.panels.length && this.addPanel()
fetch(`${this.props.pathPrefix}/api/v1/label/__name__/values`, { cache: 'no-store' }) fetch(`${this.props.pathPrefix}/api/v1/label/__name__/values`, { cache: 'no-store' })
.then(resp => { .then(resp => {
if (resp.ok) { if (resp.ok) {