天天看点

superset 设置dashbord自动刷新的方法(从url参数指定)

dashbord默认需要手动选择action->set auto refresh来设置页面自动刷新。

没有通过url参数来指定自动刷新的功能,这样就不方便通过iframe来使用dashbord

我改了下superset的代码来实现这个功能。

修改DashBoard.jsx文件,在componentDidMount方法中加入以下代码(标红的代码)

function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var href = window.location.href
        var search = href.substr(href.indexOf('?'))
        var r = search.substr(1).match(reg); //匹配目标参数
        if (r != null) return unescape(r[2]);
        return null; //返回参数值
    }


class Dashboard extends React.PureComponent {
  constructor(props) {
    super(props);
    this.refreshTimer = null;
    this.firstLoad = true;
    this.loadingLog = new ActionLog({
      impressionId: props.impressionId,
      actionType: LOG_ACTIONS_PAGE_LO