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

fix: fix empty props in template import #415

Merged
merged 3 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions app/config/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@
"importYaml": "Import the YAML file",
"templateMatchError": "The {type} in the configuration does not match the current login account/host",
"uploadSuccessfully": "Upload files successfully.",
"fileSizeLimit": "The file is too large and exceeds the upload limit({size}), please modify the MaxBytes in the startup configuration file and restart the service"
"fileSizeLimit": "The file is too large and exceeds the upload limit({size}), please modify the MaxBytes in the startup configuration file and restart the service",
"noHttp": "The address in the configuration file does not support http protocol, please remove http(s)://",
"addressMatch": "The address in the configuration file must contain the Graph address of current login connection. Separate multiple addresses with "
},
"schema": {
"spaceList": "Graph Space List",
Expand Down Expand Up @@ -264,7 +266,9 @@
"danglingEdge": "Dangling edge",
"showDDL": "View Schema DDL",
"downloadNGQL": "Download.nGQL",
"getDDLError": "Failed to get the schema DDL, Please try again"
"getDDLError": "Failed to get the schema DDL, Please try again",
"totalVertices": "Total Vertices Count",
"totalEdges": "Total Edges Count"
},
"empty": {
"stats": "No Statistics Data",
Expand Down
8 changes: 6 additions & 2 deletions app/config/locale/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@
"importYaml": "导入 YAML 文件",
"templateMatchError": "配置中的{type}与当前登录账号/地址不匹配",
"uploadSuccessfully": "上传文件成功",
"fileSizeLimit": "文件过大,超过上传限制({size}),请修改启动配置文件中的 MaxBytes 并重启服务"
"fileSizeLimit": "文件过大,超过上传限制({size}),请修改启动配置文件中的 MaxBytes 并重启服务",
"noHttp": "配置文件中的 address 不支持携带 http 协议,请去除 http(s)://",
"addressMatch": "配置文件中的 address 字段必须包含当前登录的 Graph 地址。多个地址用“,”隔开。"
},
"schema": {
"spaceList": "图空间列表",
Expand Down Expand Up @@ -264,7 +266,9 @@
"danglingEdge": "悬挂边",
"showDDL": "查看 Schema DDL",
"downloadNGQL": "下载 .NGQL 文件",
"getDDLError": "获取 Schema DDL 失败, 请重试"
"getDDLError": "获取 Schema DDL 失败, 请重试",
"totalVertices": "总计点数量",
"totalEdges": "总计边数量"
},
"empty": {
"stats": "暂无统计数据",
Expand Down
25 changes: 13 additions & 12 deletions app/pages/Console/ExportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ const ExportModal = (props: IProps) => {
const { headers, tables } = data;
const { intl } = useI18n();
const handleExport = (values) => {
const { type, vertexId, srcId, dstId, edgeType, rank } = values;
const { type, vertexIds, srcId, dstId, edgeType, rank } = values;
const vertexes =
type === 'vertex'
? tables
.map(vertex => {
if (vertex.type === 'vertex') {
return vertex.vid;
} else {
return vertex[vertexId].toString();
}
})
.filter(vertexId => vertexId !== '')
? tables.reduce((acc, cur) => {
if (cur.type === 'vertex') {
acc.push(cur.vid);
} else {
vertexIds.forEach(id => {
acc.push(cur[id].toString());
});
}
return acc;
}, []).filter(vertexId => vertexId !== '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tables.reduce((acc, cur) => {
  if (cur.type === 'vertex') {
    cur.vid && acc.push(cur.vid);
  } else {
    vertexIds.forEach(id => {
      acc.push(cur[id].toString());
    });
  }
  return acc;
}, [])

: tables
.map(edge => [edge[srcId], edge[dstId]])
.flat()
Expand Down Expand Up @@ -90,8 +91,8 @@ const ExportModal = (props: IProps) => {
const type = getFieldValue('type');
return type === 'vertex' ? <>
<p>{intl.get('console.exportVertex')}</p>
<Form.Item label="vid" name="vertexId" rules={[{ required: true, message: intl.get('formRules.vidRequired') }]}>
<Select>
<Form.Item label="vid" name="vertexIds" rules={[{ required: true, message: intl.get('formRules.vidRequired') }]}>
<Select mode="multiple" allowClear>
{headers.map(i => (
<Option value={i} key={i}>
{i}
Expand Down
14 changes: 14 additions & 0 deletions app/pages/Import/TaskList/TemplateModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const TemplateModal = (props: IProps) => {
const parseContent = yaml.load(content);
if(typeof parseContent === 'object') {
const connection = parseContent.clientSettings?.connection || {};
if(connection.address.startsWith('http')) {
throw new Error(intl.get('import.noHttp'));
}
if(connection.address !== host) {
throw new Error(intl.get('import.templateMatchError', { type: 'address' }));
}
Expand All @@ -50,6 +53,17 @@ const TemplateModal = (props: IProps) => {
throw new Error(intl.get('import.fileNotExist', { name: file.path }));
}
});
// empty props in yaml will converted to null, but its required in nebula-importer
parseContent.files.forEach(file => {
if(file.schema.edge) {
file.schema.edge.props = file.schema.edge?.props || [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file.schema.edge.props ||= [];

}
if(file.schema.vertex) {
file.schema.vertex?.tags.forEach(tag => {
tag.props = tag.props || [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tag.props ||= [];

});
}
});
setConfig(JSON.stringify(parseContent, null, 2));
form.setFieldsValue({
name: `task-${Date.now()}`,
Expand Down
28 changes: 18 additions & 10 deletions app/pages/Schema/SchemaConfig/List/SpaceStats/index.module.less
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
@import '~@app/common.less';
.nebulaStats {
.operations {
.row {
margin: 20px 0 17px;
font-size: 14px;
display: flex;
justify-content: space-between;
align-items: center;
}
.operations {
display: flex;
align-items: center;
font-size: 14px;
:global(.ant-btn) {
width: 110px;
}
.label, .tip{
margin-left: 30px;
color: @darkGray;
}
.label::after {
content: ": ";
padding-right: 5px;
}
}
.label, .tip{
margin-left: 30px;
color: @darkGray;
}
.label::after {
content: ": ";
padding-right: 5px;
}
.totalItem {
display: inline-block;
}
}
79 changes: 59 additions & 20 deletions app/pages/Schema/SchemaConfig/List/SpaceStats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ const SpaceStats = () => {
const timer = useRef<NodeJS.Timeout | null>(null);
const { intl } = useI18n();
const { schema: { getJobStatus, submitStats, getStats, currentSpace } } = useStore();
const [data, setData] = useState([]);
const [data, setData] = useState<{
list: {
Type: string,
Name: string,
Count: number,
}[],
total: {
vertices: number,
edges: number,
} | null
} | null>(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const [data, setData] = useState<{
  list: { Type: string; Name: string; Count: number }[];
  total?: { vertices: number; edges: number };
}>({ list: [], total: undefined });

const [updateTime, setUpdateTime] = useState('');
const [jobId, setJobId] = useState<any>(null);
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -44,13 +54,30 @@ const SpaceStats = () => {
const initData = () => {
setJobId(null);
setUpdateTime('');
setData([]);
setData({
list: [],
total: null
});
};

const getData = async () => {
const { code, data } = await getStats();
if (code === 0) {
setData(data.tables);
const _data = data.tables.reduce((prev, cur) => {
if (cur.Type === 'Space') {
if(!prev.total) {
prev.total = {
vertex: 0,
edge: 0,
};
}
prev.total[cur.Name] = cur.Count;
} else {
prev.list.push(cur);
}
return prev;
}, { list: [], total: null });
Copy link
Contributor

@huaxiabuluo huaxiabuluo Dec 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const nextData = data.tables.reduce((prev, cur) => {
  if (cur.Type === 'Space') {
    prev.total ||= { vertex: 0, edge: 0 };
    prev.total[cur.Name] = cur.Count;
  } else {
    prev.list.push(cur);
  }
  return prev;
}, { list: [], total: undefined } as typeof data });

setData(_data);
}
};

Expand Down Expand Up @@ -99,25 +126,37 @@ const SpaceStats = () => {
const showTime = updateTime && jobId == null && !loading;
return (
<div className={styles.nebulaStats}>
<div className={styles.operations}>
<Button
type="primary"
onClick={handleSubmitStats}
loading={loading || jobId !== null}
>
{intl.get(updateTime ? 'schema.refresh' : 'schema.startStat')}
</Button>
{showTime ? <>
<span className={styles.label}>{intl.get('schema.lastRefreshTime')}</span>
<span>
{dayjs(updateTime).format('YYYY-MM-DD HH:mm:ss')}
</span>
</> : <span className={styles.tip}>
{intl.get('schema.statTip')}
</span>}
<div className={styles.row}>
<div className={styles.operations}>
<Button
type="primary"
onClick={handleSubmitStats}
loading={loading || jobId !== null}
>
{intl.get(updateTime ? 'schema.refresh' : 'schema.startStat')}
</Button>
{showTime ? <>
<span className={styles.label}>{intl.get('schema.lastRefreshTime')}</span>
<span>
{dayjs(updateTime).format('YYYY-MM-DD HH:mm:ss')}
</span>
</> : <span className={styles.tip}>
{intl.get('schema.statTip')}
</span>}
</div>
{data?.total && <div className={styles.totalCount}>
<div className={styles.totalItem}>
<span className={styles.label}>{intl.get('schema.totalVertices')}</span>
<span>{data.total.vertices}</span>
</div>
<div className={styles.totalItem}>
<span className={styles.label}>{intl.get('schema.totalEdges')}</span>
<span>{data.total.edges}</span>
</div>
</div>}
</div>
<Table
dataSource={data}
dataSource={data?.list || []}
columns={columns}
rowKey="Name"
locale={{ emptyText: <EmptyTableTip text={intl.get('empty.stats')} tip={intl.get('empty.statsTip')} /> }}
Expand Down
1 change: 1 addition & 0 deletions app/stores/sketchModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export class SketchStore {
this.editor = new VEditor({
dom: container,
showBackGrid: false,
disableCopy: true,
...options
});
this.container = container;
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@tweenjs/tween.js": "^18.6.4",
"@vesoft-inc/force-graph": "2.0.7",
"@vesoft-inc/i18n": "^1.0.0",
"@vesoft-inc/veditor": "4.3.6",
"@vesoft-inc/veditor": "4.4.2",
"accessor-fn": "^1.3.2",
"antd": "^4.23.0",
"axios": "^0.21.1",
Expand Down