refresh edited insights panel on change (#10180)

* refresh edited insights panel on change

* move api simpleHash to shared utils getSimpleHash

* Simply reactivity fix for time-series

* Remove unused import

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
Azri Kahar
2021-12-02 01:26:55 +08:00
committed by GitHub
parent 569a8dd7db
commit 8dec148ca2
5 changed files with 21 additions and 12 deletions

View File

@@ -0,0 +1,11 @@
import { getSimpleHash } from './get-simple-hash';
describe('getSimpleHash', () => {
it('returns "364492" for string "test"', () => {
expect(getSimpleHash('test')).toBe('364492');
});
it('returns "28cb67ba" for stringified object "{ key: \'value\' }"', () => {
expect(getSimpleHash(JSON.stringify({ key: 'value' }))).toBe('28cb67ba');
});
});

View File

@@ -0,0 +1,13 @@
/**
* Generate a simple short hash for a given string
* This is not cryptographically secure in any way, and has a high chance of collision
*/
export function getSimpleHash(str: string) {
let hash = 0;
for (let i = 0; i < str.length; hash &= hash) {
hash = 31 * hash + str.charCodeAt(i++);
}
return Math.abs(hash).toString(16);
}

View File

@@ -6,6 +6,7 @@ export * from './get-collection-type';
export * from './get-fields-from-template';
export * from './get-filter-operators-for-type';
export * from './get-relation-type';
export * from './get-simple-hash';
export * from './is-dynamic-variable';
export * from './is-extension';
export * from './merge-filters';