Skip to content

Commit

Permalink
Merge branch 'devel' into CB-4773-incorrect-error-when-exceeding-the-…
Browse files Browse the repository at this point in the history
…number-of-active-users
  • Loading branch information
dariamarutkina authored Feb 28, 2024
2 parents a35dee9 + ac75405 commit 38232e6
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { observer } from 'mobx-react-lite';

import type { ObjectPropertyInfo } from '@cloudbeaver/core-sdk';
import { removeMetadataFromBase64 } from '@cloudbeaver/core-utils';
import { removeMetadataFromDataURL } from '@cloudbeaver/core-utils';

import { FieldCheckbox } from '../../FormControls/Checkboxes/FieldCheckbox';
import { Combobox } from '../../FormControls/Combobox';
Expand Down Expand Up @@ -187,7 +187,7 @@ export const RenderField = observer<RenderFieldProps>(function RenderField({
disabled={disabled}
fileName={passwordSavedMessage}
className={className}
mapValue={removeMetadataFromBase64}
mapValue={removeMetadataFromDataURL}
>
{property.displayName}
</InputFileTextContent>
Expand Down
32 changes: 32 additions & 0 deletions webapp/packages/core-utils/src/downloadFromURL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/

export function downloadFromURL(url: string): Promise<Blob> {
const req = new XMLHttpRequest();
req.open('GET', url, true);
req.responseType = 'blob';

let resolve: (value: Blob) => void;
let reject: (reason?: any) => void;
const promise = new Promise<Blob>((res, rej) => {
resolve = res;
reject = rej;
});

req.onload = () => {
resolve(req.response);
};

req.onerror = e => {
reject(e);
};

req.send();

return promise;
}
8 changes: 4 additions & 4 deletions webapp/packages/core-utils/src/getMIME.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getMIME } from './getMIME';

describe('getMIME', () => {
it('should return null if binary is empty', () => {
expect(getMIME('')).toBe(null);
it("should return 'application/octet-stream' if binary is empty", () => {
expect(getMIME('')).toBe('application/octet-stream');
});

it('should return image/jpeg if binary starts with /', () => {
Expand All @@ -26,7 +26,7 @@ describe('getMIME', () => {
expect(getMIME(webpBase64Image)).toBe('image/webp');
});

it('should return null if binary starts with anything else', () => {
expect(getMIME('aasdqwe')).toBe(null);
it("should return 'application/octet-stream' if binary starts with anything else", () => {
expect(getMIME('aasdqwe')).toBe('application/octet-stream');
});
});
6 changes: 3 additions & 3 deletions webapp/packages/core-utils/src/getMIME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* you may not use this file except in compliance with the License.
*/

export function getMIME(binary: string): string | null {
export function getMIME(binary: string): string {
if (binary.length === 0) {
return null;
return 'application/octet-stream';
}

switch (binary[0]) {
Expand All @@ -21,7 +21,7 @@ export function getMIME(binary: string): string | null {
case 'U':
return 'image/webp';
default:
return null;
return 'application/octet-stream';
}
}

Expand Down
3 changes: 2 additions & 1 deletion webapp/packages/core-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export * from './isMapsEqual';
export * from './isObjectsEqual';
export * from './openCenteredPopup';
export * from './download';
export * from './downloadFromURL';
export * from './getTextFileReadingProcess';
export * from './getTextBetween';
export * from './timestampToDate';
Expand All @@ -70,7 +71,7 @@ export * from './TempMap';
export * from './uriToBlob';
export * from './utf8ToBase64';
export * from './createLastPromiseGetter';
export * from './removeMetadataFromBase64';
export * from './removeMetadataFromDataURL';
export * from './renamePathName';
export * from './removeLineBreak';
export * from './replaceSubstring';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { removeMetadataFromBase64 } from './removeMetadataFromBase64';
import { removeMetadataFromDataURL } from './removeMetadataFromDataURL';

const BASE64 =
'data:application/zip;base64,UEsDBBQACAgIAIB8CVUAAAAAAAAAAAAAAAALAAAAZXdhbGxldC5wZW3Nmceyq0qyhuc8Rc+JExiBgEEP8C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mWQgReFhIDl7+xu8kWPygEaHJN9C1dqPnXCzwlcFthA0t24i7pnXBW2ogErgmuAUt2Ta7vAOIk97lzDNiYVnazSZNJxvZh4jsUgC0NXTFPcErqCsFM71V9LK/hvoY9Q5LOQ2xqxagSoZTU60mrx/F+8TnEvy04rld021haT2K3TibVzBLAjRdMp+AjnVAVUx0r1MHGOeVyJlaXdgn7e4GUBO8pPtwQpYstUPZh3NA0U/NrHj1r3nu2BeD39YIgnwSyxGqnBEEFOv2ed42EyGN+276BRjte5v4+iYVHIR3/PigS3w6bXx5Jw1C9h2Zqy/gOljLXVSqqXz6PeG52M8JX0HjjuuP6T47aOcqGw3vkyz0jTkqnbh11a4UqtPUWqbNwIQb+AAkWwmHjeEb0J+ZBA2KD+HcniVdWIDRjVu5lyOFQX1cLF6l1+61eqh9Qmi+PlpAJFH2S29zej+GtlwLk8iIeh2gSQ+50ZMfXqLHLo80R47Eb9LlulN2GEapa6ecuQ/RAJoOBa8S8LRivfCuMOxdI';
Expand All @@ -14,14 +14,14 @@ const BASE64_NO_METADATA =

describe('Remove metadata from base64', () => {
test('should return base64 without metadata when base64 with metadata is passed', () => {
expect(removeMetadataFromBase64(BASE64)).toMatch(BASE64_NO_METADATA);
expect(removeMetadataFromDataURL(BASE64)).toMatch(BASE64_NO_METADATA);
});

test('should return base64 when base64 with no metadata is passed', () => {
expect(removeMetadataFromBase64(BASE64_NO_METADATA)).toMatch(BASE64_NO_METADATA);
expect(removeMetadataFromDataURL(BASE64_NO_METADATA)).toMatch(BASE64_NO_METADATA);
});

test('should return empty string when empty string is passed', () => {
expect(removeMetadataFromBase64('')).toMatch('');
expect(removeMetadataFromDataURL('')).toMatch('');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
* you may not use this file except in compliance with the License.
*/

export function removeMetadataFromBase64(base64: string) {
const parts = base64.split(',');
const dataUrlFilter = /data:(.*?)\/(.*?);base64,(.*)/;

if (parts[1]) {
return parts[1];
export function removeMetadataFromDataURL(base64: string) {
const matches = base64.match(dataUrlFilter);

if (!matches) {
return base64;
}

return parts[0];
return matches[3];
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ export class DataGridContextMenuSaveContentService {
isDisabled: context => {
const content = context.data.model.source.getAction(context.data.resultIndex, ResultSetDataContentAction);

return (
context.data.model.isLoading() ||
(!!content.activeElement && ResultSetDataKeysUtils.isElementsKeyEqual(context.data.key, content.activeElement))
);
return context.data.model.isLoading() || content.isLoading(context.data.key);
},
});
this.dataGridContextMenuService.add(this.dataGridContextMenuService.getMenuToken(), {
Expand All @@ -76,10 +73,7 @@ export class DataGridContextMenuSaveContentService {
isDisabled: context => {
const content = context.data.model.source.getAction(context.data.resultIndex, ResultSetDataContentAction);

return (
context.data.model.isLoading() ||
(!!content.activeElement && ResultSetDataKeysUtils.isElementsKeyEqual(context.data.key, content.activeElement))
);
return context.data.model.isLoading() || content.isLoading(context.data.key);
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface IDatabaseDataCacheAction<TKey, TResult extends IDatabaseDataRes
get<T>(key: TKey, scope: symbol): T | undefined;
set<T>(key: TKey, scope: symbol, value: T): void;
delete(key: TKey, scope: symbol): void;
deleteAll(scope: symbol): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import type { IResultSetElementKey } from './IResultSetDataKey';

export interface IResultSetDataContentAction {
activeElement: IResultSetElementKey | null;
isLoading: (element: IResultSetElementKey) => boolean;
isBlobTruncated: (element: IResultSetElementKey) => boolean;
isTextTruncated: (element: IResultSetElementKey) => boolean;
isDownloadable: (element: IResultSetElementKey) => boolean;
getFileDataUrl: (element: IResultSetElementKey) => Promise<string>;
resolveFileDataUrl: (element: IResultSetElementKey) => Promise<string>;
retrieveFileDataUrlFromCache: (element: IResultSetElementKey) => string | undefined;
resolveFileDataUrl: (element: IResultSetElementKey) => Promise<Blob>;
retrieveBlobFromCache: (element: IResultSetElementKey) => Blob | undefined;
downloadFileData: (element: IResultSetElementKey) => Promise<void>;
clearCache: () => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { makeObservable, observable } from 'mobx';
import { action, makeObservable, observable } from 'mobx';

import { ResultDataFormat } from '@cloudbeaver/core-sdk';

Expand Down Expand Up @@ -33,6 +33,11 @@ export class ResultSetCacheAction

makeObservable<this, 'cache'>(this, {
cache: observable,
set: action,
setRow: action,
delete: action,
deleteAll: action,
deleteRow: action,
});
}

Expand Down Expand Up @@ -94,6 +99,12 @@ export class ResultSetCacheAction
}
}

deleteAll(scope: symbol) {
for (const [, keyCache] of this.cache) {
keyCache.delete(scope);
}
}

deleteRow(key: IResultSetRowKey, scope: symbol) {
const keyCache = this.getRowCache(key);

Expand Down
Loading

0 comments on commit 38232e6

Please sign in to comment.