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