Skip to content

Commit

Permalink
store
Browse files Browse the repository at this point in the history
  • Loading branch information
huaxiabuluo committed Jan 16, 2023
1 parent 25066b1 commit 15b14b4
Showing 1 changed file with 71 additions and 35 deletions.
106 changes: 71 additions & 35 deletions app/stores/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import { ISchemaEnum } from '@app/interfaces/schema';
import { getRootStore } from '.';

const handlePropertyMap = (item, defaultValueFields) => {
let type = item.Type;
if(item.Type.startsWith('fixed_string')) {
type = 'string';
} else if (item.Type.startsWith('int')) {
type = 'int';
}
// let type = item.Type;
// if(item.Type.startsWith('fixed_string')) {
// type = 'string';
// } else if (item.Type.startsWith('int')) {
// type = 'int';
// }

// const typeConverters = [
// { start: 'fixed_string', target: 'string' },
// { start: 'int', target: 'int' },
// ];
// const type = typeConverters.find(i => item.Type.startsWith(i.start))?.target || item.Type;
const type = item.Type.startsWith('fixed_string') ? 'string' : item.Type.startsWith('int') ? 'int' : item.Type;
return {
name: item.Field,
type,
Expand All @@ -22,24 +29,23 @@ const handlePropertyMap = (item, defaultValueFields) => {
};
};

type TagConfig = IImportSchemaConfig<ISchemaEnum.Tag>;
type EdgeConfig = IImportSchemaConfig<ISchemaEnum.Edge>;

class ITagFileItemStore {
class TagFileItem {
file: IImportFile;
props = observable.array<IPropertyProps>([]);
vidIndex?: number;
vidFunction?: string;
vidPrefix?: string;

constructor() {
makeAutoObservable(this, {});
makeAutoObservable(this);
}
update = (payload: Partial<ITagFileItemStore>) => {

update = (payload: Partial<TagFileItem>) => {
Object.keys(payload).forEach(key => Object.prototype.hasOwnProperty.call(this, key) && (this[key] = payload[key]));
};
}
class IEdgeFileItemStore {

class EdgeFileItem {
file: IImportFile;
props = observable.array<IPropertyProps>([]);
stcIdIndex?: number;
Expand All @@ -50,16 +56,46 @@ class IEdgeFileItemStore {
dstIdPrefix?: string;

constructor() {
makeAutoObservable(this, {});
makeAutoObservable(this);
}
update = (payload: Partial<IEdgeFileItemStore>) => {
update = (payload: Partial<EdgeFileItem>) => {
Object.keys(payload).forEach(key => Object.prototype.hasOwnProperty.call(this, key) && (this[key] = payload[key]));
};
}


class ImportSchemaConfigItem<T extends ISchemaEnum, F = T extends ISchemaEnum.Edge ? EdgeFileItem : TagFileItem> {
_id = uuidv4();
type: T;
name?: string;
props = observable.array<IPropertyProps>([]);
files = observable.array<F>([]);

constructor({ name, type }: { type: T; name?: string }) {
makeAutoObservable(this);
this.type = type;
this.name = name;
}

addFileItem = (item: F) => this.files.push(item);

deleteFileItem = (fileItem: F) => this.files.remove(fileItem);

addProp = (item: IPropertyProps) => this.props.push(item);

deleteProp = (prop: IPropertyProps) => this.props.remove(prop);

updateProp = (prop: IPropertyProps, payload: Partial<IPropertyProps>) =>
Object.keys(payload).forEach((key) => (prop[key] = payload[key]));
}

type ITagItem = ImportSchemaConfigItem<ISchemaEnum.Tag>;
type IEdgeItem = ImportSchemaConfigItem<ISchemaEnum.Edge>;

export class ImportStore {
taskList: ITaskItem[] = [];
tagConfig = observable.array<TagConfig>([]);
edgesConfig = observable.array<EdgeConfig>([]);
tagConfig = observable.array<ITagItem>([], { deep: false });
edgesConfig = observable.array<IEdgeItem>([], { deep: false });
basicConfig: IBasicConfig = { taskName: '' };
constructor() {
makeAutoObservable(this, {
Expand All @@ -76,6 +112,18 @@ export class ImportStore {
Object.keys(payload).forEach(key => Object.prototype.hasOwnProperty.call(this, key) && (this[key] = payload[key]));
};

addTagConfig = () => this.tagConfig.push(new ImportSchemaConfigItem({ type: ISchemaEnum.Tag }));
deleteTagConfig = (item: ITagItem) => this.tagConfig.remove(item);

addEdgeConfig = () => this.edgesConfig.push(new ImportSchemaConfigItem({ type: ISchemaEnum.Edge }));
deleteEdgeConfig = (item: IEdgeItem) => this.edgesConfig.remove(item);

// addConfigItem = (type: ISchemaEnum) => {
// type === ISchemaEnum.Tag
// ? this.tagConfig.push(new ImportSchemaConfigItem({ type: ISchemaEnum.Tag }))
// : this.edgesConfig.push(new ImportSchemaConfigItem({ type: ISchemaEnum.Edge }));
// }

getTaskList = async () => {
const { code, data } = await service.getTaskList();
if (code === 0 && data) {
Expand Down Expand Up @@ -113,10 +161,7 @@ export class ImportStore {
spaceVidType
});
}
const { code } = (await service.importData({
config: _config,
name
})) as any;
const { code } = await service.importData({ config: _config, name });
return code;
};

Expand Down Expand Up @@ -161,20 +206,6 @@ export class ImportStore {
return null;
};

addConfigItem = (type: ISchemaEnum) => {
const item = {
_id: uuidv4(),
name: undefined,
files: [],
props: [],
};
type === ISchemaEnum.Tag ? this.tagConfig.push({ ...item, type }) : this.edgesConfig.push({ ...item, type });
};

removeConfigItem = (data: IImportSchemaConfig) => {
data.type === ISchemaEnum.Tag ? this.tagConfig.remove(data) : this.edgesConfig.remove(data);
};

updateConfigItemTarget = async (payload: {
data: IImportSchemaConfig;
value: string;
Expand All @@ -188,7 +219,12 @@ export class ImportStore {
});
};

/**
* this.tagConfig[0].addFileItem(new TagFileItem());
* this.edgesConfig[0].addFileItem(new EdgeFileItem());
*/
addFileSource = (item: IImportSchemaConfig) => {
this.tagConfig[0].addFileItem(new TagFileItem());
item.files = [...item.files, {
file: undefined,
props: item.props,
Expand Down

0 comments on commit 15b14b4

Please sign in to comment.