Skip to content

Commit

Permalink
Merge pull request #111 from Kanaries/beta
Browse files Browse the repository at this point in the history
feat: temporal info extension
  • Loading branch information
ObservedObserver authored Sep 5, 2022
2 parents 37be361 + 5738677 commit dab3e52
Show file tree
Hide file tree
Showing 18 changed files with 644 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/rath-client/public/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"title": "Download Data"
},
"extend": {
"title": "Extend Features"
"title": "Extend Information"
}
},
"meta": {
Expand Down
2 changes: 1 addition & 1 deletion packages/rath-client/public/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"title": "下载数据"
},
"extend": {
"title": "扩展维度"
"title": "扩展信息"
}
},
"meta": {
Expand Down
39 changes: 39 additions & 0 deletions packages/rath-client/src/dev/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { IRow } from "visual-insights";
import { IRawField } from "rath-client/src/interfaces";
import { workerService } from "rath-client/src/service";
/* eslint import/no-webpack-loader-syntax:0 */
// @ts-ignore
// eslint-disable-next-line
import ExpandDateTimeWorker from './workers/dateTimeExpand.worker.js?worker';
import { dateTimeExpand, doTest } from './workers/engine/dateTimeExpand'
import { checkExpandEnv } from './workers/engine/checkExpandEnv'

interface ExpandDateTimeProps {
dataSource: IRow[];
fields: IRawField[];
}
const ExpandEnv = checkExpandEnv();

export async function expandDateTimeService (props: ExpandDateTimeProps): Promise<ExpandDateTimeProps> {
if (ExpandEnv === 'debug') {
doTest()
let res = dateTimeExpand(props) as ExpandDateTimeProps
return res
}
else {
try {
const worker = new ExpandDateTimeWorker()
const result = await workerService<ExpandDateTimeProps, ExpandDateTimeProps>(worker, props)
worker.terminate();
if (result.success) {
return result.data
}
else {
throw new Error(`[ExpandDateTimeWorker]: ${result.message}`)
}
} catch (error) {
console.error(`[ExpandDateTimeWorker]: ${error}`)
throw error;
}
}
}
21 changes: 21 additions & 0 deletions packages/rath-client/src/dev/workers/dateTimeExpand.worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint no-restricted-globals: 0 */
import { dateTimeExpand } from "./engine/dateTimeExpand";
import { timer } from '../../workers/timer';

const expandService = e => {
try {
const { fields, dataSource } = e.data;
const res = dateTimeExpand({ fields, dataSource })
self.postMessage({
success: true,
data: res
})
} catch (error) {
self.postMessage({
success: false,
message: `[expandService]${error}\n${error.stack}`
})
}
}

self.addEventListener('message', timer(expandService), false)
12 changes: 12 additions & 0 deletions packages/rath-client/src/dev/workers/engine/checkExpandEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function checkExpandEnv(): string {
if (typeof window === 'object') {
const url = new URL(window.location.href).searchParams.get('expand');
if(url) {
(window as any).ExpandEnv = url
return url
}
else return ''
}
if (process.env.EXPAND_ENV) return process.env.EXPAND_ENV
else return ''
}
Loading

0 comments on commit dab3e52

Please sign in to comment.