Skip to content

Commit

Permalink
fix: fix mana version (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector authored Feb 1, 2024
1 parent 600cb57 commit 573a197
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 419 deletions.
8 changes: 4 additions & 4 deletions packages/secretnote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"@antv/s2": "^1.52.0",
"@codemirror/lang-python": "^6.1.2",
"@difizen/libro-jupyter": "^0.1.14",
"@difizen/mana-app": "^0.1.8",
"@difizen/mana-common": "^0.1.8",
"@difizen/mana-l10n": "^0.1.8",
"@difizen/mana-react": "^0.1.8",
"@difizen/mana-app": "^0.1.9",
"@difizen/mana-common": "^0.1.9",
"@difizen/mana-l10n": "^0.1.9",
"@difizen/mana-react": "^0.1.9",
"@kanaries/web-data-loader": "^0.1.7",
"@lumino/polling": "^1.11.4",
"@rjsf/antd": "^5.7.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FormInstance } from 'antd';
import { Input, Form, Select } from 'antd';

import type { SchemaItem } from '../type';
Expand All @@ -9,11 +10,18 @@ const labelCol = { span: 8 };
const wrapperCol = { offset: 4, span: 12 };

const TableConfig = {
tableConfig: (props: { root: SchemaItem }) => {
tableConfig: (props: { root: SchemaItem; form: FormInstance }) => {
const { root } = props;
const types = getByPath(root, '$inputTableConfig/types');
const attrs = getByPath(root, '$inputTableConfig/attrs');

const getInputType = () => {
const type = props.form.getFieldValue(['input', root.id, 'type']);
if (type) {
return type.split('.')[1];
}
};

return (
<Form.Item
label={root.id}
Expand Down Expand Up @@ -43,14 +51,17 @@ const TableConfig = {
<Input />
</Form.Item>
))}
<Form.Item
label="tables"
name={['input', root.id, 'tables']}
labelCol={labelCol}
wrapperCol={wrapperCol}
>
<TableSelector />
</Form.Item>
{getInputType() === 'table' && (
<Form.Item
label="tables"
name={['input', root.id, 'tables']}
labelCol={labelCol}
wrapperCol={wrapperCol}
dependencies={['input', root.id, 'type']}
>
<TableSelector />
</Form.Item>
)}
</Form.Item>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type Table = {

type TableValue = {
data_ref: Table[];
schema: SchemaValue;
schema?: SchemaValue;
schemas?: SchemaValue[];
};

type TableOption = {
Expand Down Expand Up @@ -64,9 +65,13 @@ const TableSelector = (props: TableSelectorProps) => {
return [];
};

const getDefaultSchema = () => {
const schema = props.value?.schema || {};
return schema;
const getDefaultSchema = (index: number) => {
const dataRef = props.value?.data_ref || [];
if (dataRef.length > 1) {
return props.value?.schemas?.[index];
} else if (dataRef.length === 1) {
return props.value?.schema;
}
};

const onTableChange = (index: number, value: string[]) => {
Expand All @@ -76,26 +81,38 @@ const TableSelector = (props: TableSelectorProps) => {
const dataRef = props.value?.data_ref || [];
dataRef[index] = { uri, party };
props.onChange({
...props.value,
data_ref: dataRef,
schema: props.value?.schema,
});
} else {
const dataRef = props.value?.data_ref || [];
dataRef.splice(index, 1);
props.onChange({
...props.value,
data_ref: dataRef,
schema: props.value?.schema,
});
}
}
};

const onTableSchemaChange = (value: SchemaValue) => {
const onTableSchemaChange = (index: number, value: SchemaValue) => {
if (props.onChange) {
props.onChange({
data_ref: props.value?.data_ref,
schema: { ...props.value?.schema, ...value },
});
const dataRef = props.value?.data_ref || [];
if (dataRef.length > 1) {
const schemas = props.value?.schemas || [];
schemas[index] = { ...schemas[index], ...value };
props.onChange({
...props.value,
schemas: schemas,
schema: undefined,
});
} else if (dataRef.length === 1) {
props.onChange({
...props.value,
schema: { ...props.value?.schema, ...value },
schemas: undefined,
});
}
}
};

Expand All @@ -111,23 +128,21 @@ const TableSelector = (props: TableSelectorProps) => {
options={table}
onChange={(val) => onTableChange(index, val as string[])}
/>
{index === 0 && (
<Popover
content={
<SchemaSelector
value={getDefaultSchema()}
onChange={onTableSchemaChange}
/>
}
placement="right"
title=""
overlayClassName="secretnote-table-selector-popover"
trigger="click"
arrow={false}
>
<Settings size={14} cursor="pointer" />
</Popover>
)}
<Popover
content={
<SchemaSelector
value={getDefaultSchema(index)}
onChange={(val) => onTableSchemaChange(index, val)}
/>
}
placement="right"
title=""
overlayClassName="secretnote-table-selector-popover"
trigger="click"
arrow={false}
>
<Settings size={14} cursor="pointer" />
</Popover>
</>
) : (
<span key={item.value} className="no-table">
Expand Down
5 changes: 4 additions & 1 deletion packages/secretnote/src/components/component-form/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export type AttrType = 'AT_STRING' | 'AT_BOOL' | 'AT_INT';
export type AttrType = 'AT_STRING' | 'AT_BOOL' | 'AT_INT' | 'AT_FLOAT';

export type ValueKey = 's' | 'ss' | 'i64' | 'f' | 'b';

Expand Down Expand Up @@ -27,6 +27,9 @@ export type Atomic = {
lowerBoundEnabled?: boolean;
lowerBound?: AtomicValue;
lowerBoundInclusive?: boolean;
upperBoundEnabled?: boolean;
upperBound?: AtomicValue;
upperBoundInclusive?: boolean;
};

export interface Attr {
Expand Down
29 changes: 24 additions & 5 deletions packages/secretnote/src/components/component-form/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,41 @@ const getRenderType = (attr: Attr): string => {
return 'number';
case 'AT_STRING':
return 'string';
case 'AT_FLOAT':
return 'number';
}
return 'string';
};

const getDefaultValue = (attr: Attr) => {
const getValue = (attr: Attr, key: 'defaultValue' | 'lowerBound' | 'upperBound') => {
switch (attr.type) {
case 'AT_BOOL':
return attr.atomic?.defaultValue?.b;
return attr.atomic?.[key]?.b;
case 'AT_INT':
return attr.atomic?.defaultValue?.i64;
return attr.atomic?.[key]?.i64;
case 'AT_STRING':
return attr.atomic?.defaultValue?.s;
return attr.atomic?.[key]?.s;
case 'AT_FLOAT':
return attr.atomic?.[key]?.f;
}
};

const isFieldRequired = (attr: Attr) => {
return !attr.atomic.isOptional;
};

const getMinimum = (attr: Attr) => {
if (attr.atomic.lowerBoundEnabled) {
return Number(getValue(attr, 'lowerBound'));
}
};

const getMaximum = (attr: Attr) => {
if (attr.atomic.upperBoundEnabled) {
return Number(getValue(attr, 'upperBound'));
}
};

export const setByPath = (
obj: any,
path: string | string[],
Expand Down Expand Up @@ -126,8 +143,10 @@ const transformSpecToJsonSchema: (spec: ComponentSpec) => SchemaItem = (
label: v,
value: v,
})),
$defaultValue: getDefaultValue(attr),
$defaultValue: getValue(attr, 'defaultValue'),
$required: isFieldRequired(attr),
minimum: getMinimum(attr),
maximum: getMaximum(attr),
};

setByPath(json, `properties/attrs/properties/${name}`, attrItem);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { ComponentSpec, Value, IOType } from '@/components/component-form';

const deviceConfig = {
runtime_config: { protocol: 'REF2K', field: 'FM64' },
link_desc: {
connect_retry_times: 60,
connect_retry_interval_ms: 1000,
brpc_channel_protocol: 'http',
brpc_channel_connection_type: 'pooled',
recv_timeout_ms: 1200000,
http_timeout_ms: 1200000,
},
};

const clusterConfig = {
public_config: {
ray_fed_config: {
Expand All @@ -23,8 +35,17 @@ const clusterConfig = {
name: 'spu',
type: 'spu',
parties: ['alice', 'bob'],
config:
'{"runtime_config":{"protocol":"REF2K","field":"FM64"},"link_desc":{"connect_retry_times":60,"connect_retry_interval_ms":1000,"brpc_channel_protocol":"http","brpc_channel_connection_type":"pooled","recv_timeout_ms":1200000,"http_timeout_ms":1200000}}',
config: JSON.stringify(deviceConfig),
},
{
name: 'heu',
type: 'heu',
parties: [],
config: JSON.stringify({
mode: 'PHEU',
schema: 'paillier',
key_size: 2048,
}),
},
],
},
Expand All @@ -41,12 +62,14 @@ const getAttrValue = (component: ComponentSpec, key: string, value: any) => {
return { b: value };
case 'AT_STRING':
return { s: value };
case 'AT_FLOAT':
return { f: value };
default:
return { s: value };
}
} else {
// input has no marked data type in the attr, so it can only be fixed
return { ss: [value] };
return { ss: (value || '').split(',') };
}
};

Expand Down Expand Up @@ -77,39 +100,45 @@ const generateComponentCellCode = (component: ComponentSpec, config: Value) => {
const { input, output, ...others } = config;

// attr
Object.entries(others).forEach(([key, value]) => {
componentConfig.attr_paths.push(key);
const attrValue = getAttrValue(component, key, value);
componentConfig.attrs.push(attrValue);
});
if (others) {
Object.entries(others).forEach(([key, value]) => {
componentConfig.attr_paths.push(key);
const attrValue = getAttrValue(component, key, value);
componentConfig.attrs.push(attrValue);
});
}

// input
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Object.entries(input).forEach(([key, value]: [string, any]) => {
const { type, tables } = value;

if (type && tables) {
componentConfig.inputs.push({
name: key,
type: type,
data_refs: tables.data_ref.map((ref: any) => ({
uri: ref.uri,
party: ref.party,
format: 'csv',
})),
meta: {
'@type': getIOMetaType(type),
schema: tables.schema,
line_count: -1,
},
});
}
});
if (input) {
Object.entries(input).forEach(([key, value]: [string, any]) => {
const { type, tables } = value;
const schemaKey = type === 'sf.table.individual' ? 'schema' : 'schemas';
if (type && tables) {
componentConfig.inputs.push({
name: key,
type: type,
data_refs: tables.data_ref.map((ref: any) => ({
uri: ref.uri,
party: ref.party,
format: 'csv',
})),
meta: {
'@type': getIOMetaType(type),
[schemaKey]: tables[schemaKey],
line_count: -1,
},
});
}
});
}

// output
Object.entries(output).forEach(([, value]) => {
componentConfig.output_uris.push(value);
});
if (output) {
Object.entries(output).forEach(([, value]) => {
componentConfig.output_uris.push(value);
});
}

return `
from secretflow.spec.v1.evaluation_pb2 import NodeEvalParam
Expand Down
Loading

0 comments on commit 573a197

Please sign in to comment.