github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/util/query.ts (about)

     1  export function appendLabelToQuery(
     2    query: string,
     3    label: string,
     4    labelValue: string
     5  ) {
     6    const case1Regexp = new RegExp(`${label}=.+?(\\}|,)`);
     7    if (query.match(case1Regexp)) {
     8      return query.replace(case1Regexp, `${label}="${labelValue}"$1`);
     9    }
    10    if (query.indexOf('{}') !== -1) {
    11      return query.replace('}', `${label}="${labelValue}"}`);
    12    }
    13    if (query.indexOf('}') !== -1) {
    14      return query.replace('}', `, ${label}="${labelValue}"}`);
    15    }
    16  
    17    console.warn('TODO: handle this case');
    18    return query;
    19  }