mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
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:
11
packages/shared/src/utils/get-simple-hash.test.ts
Normal file
11
packages/shared/src/utils/get-simple-hash.test.ts
Normal 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');
|
||||
});
|
||||
});
|
||||
13
packages/shared/src/utils/get-simple-hash.ts
Normal file
13
packages/shared/src/utils/get-simple-hash.ts
Normal 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);
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user