Skip to content

Commit

Permalink
feat: add track event in import model (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao92 authored Apr 20, 2023
1 parent 73501a1 commit b5d166d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 20 deletions.
12 changes: 6 additions & 6 deletions app/config/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ const service = {
importData: (params, config?) => {
return post('/api/import-tasks')(params, config);
},
stopImportTask: (id: number) => {
return get(`/api/import-tasks/${id}/stop`)();
stopImportTask: (id: number, config?) => {
return get(`/api/import-tasks/${id}/stop`)(undefined, config);
},
deleteImportTask: (id: number) => {
return _delete(`/api/import-tasks/${id}`)();
deleteImportTask: (id: number, config) => {
return _delete(`/api/import-tasks/${id}`)(undefined, config);
},
getTaskList: (params?, config?) => {
return get('/api/import-tasks')(params, config);
Expand All @@ -46,8 +46,8 @@ const service = {
getTaskConfig: (id: string | number) => `/api/import-tasks/${id}/download-config`,
getTaskLog: (id: string | number) => `/api/import-tasks/${id}/download-logs`,
// files
deteleFile: params => {
return _delete(`/api/files`)(undefined, { data: params });
deteleFile: (params, config?) => {
return _delete(`/api/files`)(undefined, { data: params, ...config });
},
getFiles: () => {
return get('/api/files')();
Expand Down
16 changes: 13 additions & 3 deletions app/pages/Import/TaskCreate/SchemaConfig/FileMapping/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ISchemaEnum } from '@app/interfaces/schema';
import { IEdgeFileItem, ITagFileItem } from '@app/stores/import';
import { IImportFile } from '@app/interfaces/import';
import { ICachedStore } from '@app/stores/datasource';
import { trackEvent } from '@app/utils/stat';
import styles from '../index.module.less';
import FileSelectModal from './FileSelectModal';

Expand Down Expand Up @@ -85,18 +86,27 @@ const VIDSetting = observer((props: {
dropdownMatchSelectWidth={false}
popupClassName={styles.selectItems}
onClick={e => e.stopPropagation()}
onChange={value => data.update({ [idFunction]: value })}
onChange={value => {
data.update({ [idFunction]: value });
trackEvent('import', 'add_vidFunction');
}}
>
<Option value="hash">Hash</Option>
</Select>
</div>}
{idPrefix && <div className={styles.rowItem}>
<span className={styles.label}>{intl.get('import.vidPrefix')}</span>
<Input className={styles.prefixInput} bordered={false} placeholder="Input prefix" value={data[idPrefix]} onChange={e => data.update({ [idPrefix]: e.target.value })} />
<Input className={styles.prefixInput} bordered={false} placeholder="Input prefix" value={data[idPrefix]} onChange={e => {
data.update({ [idPrefix]: e.target.value });
trackEvent('import', 'add_vidPrefix');
}} />
</div>}
{idSuffix && <div className={styles.rowItem}>
<span className={styles.label}>{intl.get('import.vidSuffix')}</span>
<Input className={styles.prefixInput} bordered={false} placeholder="Input suffix" value={data[idSuffix]} onChange={e => data.update({ [idSuffix]: e.target.value })} />
<Input className={styles.prefixInput} bordered={false} placeholder="Input suffix" value={data[idSuffix]} onChange={e => {
data.update({ [idSuffix]: e.target.value });
trackEvent('import', 'add_vidSuffix');
}} />
</div>}
{(data[idKey]?.length > 1 || data[idPrefix] || data[idSuffix]) && <div className={styles.concatPreview}>
<span className={styles.label}>{intl.get('import.preview')}</span>
Expand Down
9 changes: 6 additions & 3 deletions app/pages/Import/TaskCreate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import Breadcrumb from '@app/components/Breadcrumb';
import { observer } from 'mobx-react-lite';
import { useStore } from '@app/stores';
import { trackPageView } from '@app/utils/stat';
import { trackEvent, trackPageView } from '@app/utils/stat';
import cls from 'classnames';
import { useHistory } from 'react-router-dom';
import { DEFAULT_IMPORT_CONFIG, POSITIVE_INTEGER_REGEX } from '@app/utils/constant';
Expand Down Expand Up @@ -272,7 +272,7 @@ const TaskCreate = (props: IProps) => {
className={styles.addressCheckbox}
options={address}
value={basicConfig.address}
onChange={value => updateBasicConfig({ 'address': value })}
onChange={value => updateBasicConfig({ 'address': value as string[] })}
/>
</Form.Item>
</Col>
Expand All @@ -284,7 +284,10 @@ const TaskCreate = (props: IProps) => {
<span className={styles.label}>{item.label}</span>
<Instruction description={item.description} />
</>} name={item.key} rules={item.rules}>
<Input placeholder={item.placeholder.toString()} value={basicConfig[item.key]} onChange={e => updateBasicConfig(item.key, e.target.value)} />
<Input placeholder={item.placeholder.toString()} value={basicConfig[item.key]} onChange={e => {
updateBasicConfig({ [item.key]: e.target.value });
trackEvent('import', `update_config_${item.key}`);
}} />
</Form.Item>
</Col>
))}
Expand Down
28 changes: 24 additions & 4 deletions app/stores/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ export class DatasourceStore {
};

addDataSource = async (payload: IDatasourceAdd) => {
const { code } = await service.addDatasource(payload);
const { code } = await service.addDatasource(payload, {
trackEventConfig: {
category: 'datasource',
action: `add_${payload.type}_datasource`,
},
});
return code === 0;
};
updateDataSource = async (payload: IDatasourceUpdate) => {
const { code } = await service.updateDatasource(payload);
const { code } = await service.updateDatasource(payload, {
trackEventConfig: {
category: 'datasource',
action: `update_${payload.type}_config`,
},
});
return code === 0;
};
getDatasourceList = async (payload?: { type?: IDatasourceType }) => {
Expand All @@ -39,11 +49,21 @@ export class DatasourceStore {
}
};
deleteDataSource = async (id: number) => {
const { code } = await service.deleteDatasource(id);
const { code } = await service.deleteDatasource(id, {
trackEventConfig: {
category: 'datasource',
action: 'delete_datasource',
},
});
return code === 0;
};
batchDeleteDatasource = async (ids: number[]) => {
const { code } = await service.batchDeleteDatasource({ ids });
const { code } = await service.batchDeleteDatasource({ ids }, {
trackEventConfig: {
category: 'datasource',
action: 'batch_delete_datasources',
},
});
return code === 0;
};
getDatasourceDetail = async (payload: {
Expand Down
16 changes: 15 additions & 1 deletion app/stores/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class FilesStore {
headers: {
'content-type': 'multipart/form-data',
},
trackEventConfig: {
category: 'import',
action: 'upload_file',
},
};
const data = new FormData();
files.forEach(file => {
Expand All @@ -59,6 +63,11 @@ export class FilesStore {
deleteFile = async (names: string[]) => {
const res: any = await service.deteleFile({
names
}, {
trackEventConfig: {
category: 'import',
action: 'delete_file',
},
});
if (res.code === 0) {
message.success(intl.get('common.deleteSuccess'));
Expand All @@ -74,7 +83,12 @@ export class FilesStore {
delimiter?: string;
withHeader?: boolean;
}) => {
const res: any = await service.updateFileConfig(payload);
const res: any = await service.updateFileConfig(payload, {
trackEventConfig: {
category: 'import',
action: 'update_file_config',
},
});
return res;
};
}
Expand Down
18 changes: 15 additions & 3 deletions app/stores/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IBasicConfig, ITaskItem, IImportFile, IPropertyProps } from '@app/inter
import { ISchemaEnum } from '@app/interfaces/schema';
import { configToJson } from '@app/utils/import';
import { isEmpty } from '@app/utils/function';
import { trackEvent } from '@app/utils/stat';
import { getRootStore } from '.';

const handlePropertyMap = (item, defaultValueFields) => {
Expand Down Expand Up @@ -168,17 +169,26 @@ export class ImportStore {
const { code } = (await service.importData({
config: _config,
name
}, {
trackEventConfig: 'import',
action: config ? 'template_import' : 'import',
})) as any;
return code;
};

stopTask = async (id: number) => {
const res = await service.stopImportTask(id);
const res = await service.stopImportTask(id, {
trackEventConfig: 'import',
action: 'stop_task',
});
return res;
};

deleteTask = async (id: number) => {
const res = await service.deleteImportTask(id);
const res = await service.deleteImportTask(id, {
trackEventConfig: 'import',
action: 'delete_task',
});
return res;
};

Expand All @@ -187,6 +197,7 @@ export class ImportStore {
link.href = service.getTaskConfig(id);
link.download = `config.yml`;
link.click();
trackEvent('import', 'download_task_config');
};

downloadTaskLog = async (params: {
Expand All @@ -198,6 +209,7 @@ export class ImportStore {
link.href = service.getTaskLog(id) + `?name=${name}`;
link.download = `log.yml`;
link.click();
trackEvent('import', 'download_task_log');
};

getLogDetail = async (params: {
Expand Down Expand Up @@ -226,7 +238,7 @@ export class ImportStore {
});
};

updateBasicConfig = <T extends keyof IBasicConfig>(payload: { [K in T]?: Person[K] }) => {
updateBasicConfig = <T extends keyof IBasicConfig>(payload: { [K in T]?: IBasicConfig[K] }) => {
Object.keys(payload).forEach(key => {
if(isEmpty(payload[key])) {
delete this.basicConfig[key];
Expand Down

0 comments on commit b5d166d

Please sign in to comment.