Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const options = {
containerId = 'file-picker-container',
baseUrl = 'https://app.stackone.com',
fields = ['name', 'path', 'driveId'],
showBranding = false,
onFilesPicked = (files) => {
console.log('Selected files:', files);
},
Expand All @@ -80,6 +81,7 @@ const filePicker = new FilePicker(options);
| **containerId** | string | No | ID of the container element where the file picker will be mounted. |
| **baseUrl** | string | No | Which API instance should it connect to. |
| **fields** | string[] | No | Which fields from the raw picked file will be mapped on the files picked callback. |
| **showBranding** | boolean | No | Show StackOne footer on the file picker, it is defaulted to true. |
| **onFilesPicked** | function | No | Called when files are selected. |
| **onOpen()** | function | No | Called when the file picker is opened. |
| **onClose()** | function | No | Called every time the file picker is closed regardless of whether a file has been picked or not. |
Expand Down
4 changes: 4 additions & 0 deletions src/filePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class FilePicker {
#apiUrl: string;
#iframe: HTMLIFrameElement | null = null;
#isListenerAttached = false;
#showBranding = true;
#fields?: string[];
#onFilesPicked: (data: File[]) => void;
#onClose: () => void;
Expand All @@ -23,6 +24,7 @@ export class FilePicker {
baseUrl,
apiUrl,
fields,
showBranding,
onFilesPicked,
onClose,
onOpen,
Expand All @@ -34,6 +36,7 @@ export class FilePicker {
this.#fields = fields;
this.#baseUrl = baseUrl ?? 'https://app.stackone.com';
this.#apiUrl = apiUrl ?? 'https://api.stackone.com';
this.#showBranding = showBranding ?? true;
this.#onFilesPicked = onFilesPicked ?? (() => {});
this.#onClose = onClose ?? (() => {});
this.#onOpen = onOpen ?? (() => {});
Expand Down Expand Up @@ -71,6 +74,7 @@ export class FilePicker {
window.origin,
this.#fields,
this.#apiUrl,
this.#showBranding,
);
this.#iframe.src = url;
}
Expand Down
21 changes: 21 additions & 0 deletions src/specs/url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,26 @@ describe('#url', () => {
expect(parsedUrl.searchParams.has('fields')).toBe(false);
});
});

describe('when showBranding is false', () => {
it('creates URL without showBranding parameter', () => {
const baseUrl = 'https://example.com';
const sessionToken = 'test-token';
const origin = 'https://myapp.com';
const showBranding = false;

const url = createUrl(
baseUrl,
sessionToken,
origin,
undefined,
undefined,
showBranding,
);
const parsedUrl = new URL(url);

expect(parsedUrl.searchParams.get('showBranding')).toBe('false');
});
});
});
});
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface FilePickerOptions {
baseUrl?: string;
apiUrl?: string;
fields?: string[];
showBranding?: boolean;
onFilesPicked?: (data: File[]) => void;
onError?: (error: Error) => void;
onClose?: () => void;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ export const createUrl = (
origin: string,
fields?: string[],
apiUrl?: string,
showBranding?: boolean,
) => {
const url = new URL(baseUrl);
url.searchParams.set('token', sessionToken);
url.searchParams.set('origin', btoa(origin));
url.searchParams.set('showBranding', showBranding ? 'true' : 'false');

if (fields) {
url.searchParams.set('fields', btoa(JSON.stringify(fields)));
Expand Down