Skip to content

Commit

Permalink
Merge pull request #177 from eino/master
Browse files Browse the repository at this point in the history
feat: allow duplicate values for URL params
  • Loading branch information
drstrangelooker authored Apr 29, 2024
2 parents 59d8940 + c87c929 commit 3288962
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/embed_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ interface LookerEmbedHostSettings {
}

export interface UrlParams {
[key: string]: string
[key: string]: string | string[]
}

function stringify(params: { [key: string]: string }) {
function stringify(params: UrlParams) {
const result = []
for (const key in params) {
result.push(`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
const value = params[key]
const valueArray = Array.isArray(value) ? value : [value]
for (const singleValue of valueArray) {
result.push(
`${encodeURIComponent(key)}=${encodeURIComponent(singleValue)}`
)
}
}
return result.join('&')
}
Expand Down
5 changes: 5 additions & 0 deletions tests/embed_builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ describe('LookerEmbedBuilder', () => {
expect(builder.embedUrl).toMatch('alpha=1&beta=2')
})

it('should allow multiple values for an url parameter', () => {
builder.withParams({ hide_filter: ['1', '2'] })
expect(builder.embedUrl).toMatch('hide_filter=1&hide_filter=2')
})

it('should allow specifying a theme', () => {
builder.withTheme('Fancy')
expect(builder.embedUrl).toMatch('theme=Fancy')
Expand Down

0 comments on commit 3288962

Please sign in to comment.