Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: temporal info extension #111

Merged
merged 17 commits into from
Sep 5, 2022
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: 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