From 4cfb7221769ff082bed0bf095271bc30af96dcb5 Mon Sep 17 00:00:00 2001 From: Jandiasnow <88074479@qq.com> Date: Thu, 2 Mar 2023 10:29:13 +0800 Subject: [PATCH] feat: add channel detail api (#36) --- bff-sdk/sdk.ts | 42 ++-- src/pages/NetworkChannelDetail/index.jsx | 129 +++++++++-- src/pages/NetworkDetail/index.jsx | 23 +- src/pages/OrganizationDetail/index.jsx | 272 ++++++++++++----------- 4 files changed, 287 insertions(+), 179 deletions(-) diff --git a/bff-sdk/sdk.ts b/bff-sdk/sdk.ts index 2813d07..b073500 100644 --- a/bff-sdk/sdk.ts +++ b/bff-sdk/sdk.ts @@ -74,6 +74,8 @@ export type Epolicy = { creationTimestamp?: Maybe; /** 描述 */ description?: Maybe; + /** 更新时间 */ + lastHeartbeatTime?: Maybe; /** name */ name: Scalars['ID']; /** 策略内容 */ @@ -187,7 +189,7 @@ export type Mutation = { /** 从联盟中驱逐一个组织(返回true:只表示这个操作触发成功,而不是驱逐组织成功) */ federationRemoveOrganization: Scalars['Boolean']; /** 创建IBPPeer节点 */ - ibppeerCreate: Ibppeer; + ibppeerCreate: Array; /** 创建网络 */ networkCreate: Network; /** 删除网络 */ @@ -245,6 +247,7 @@ export type MutationFederationRemoveOrganizationArgs = { }; export type MutationIbppeerCreateArgs = { + count?: InputMaybe; organization: Scalars['String']; }; @@ -658,6 +661,8 @@ export type User = { email: Scalars['String']; /** 是否为组织管理员(组织列表中) */ isOrganizationAdmin?: Maybe; + /** 加入组织时间(组织列表中) */ + joinedAt?: Maybe; /** 用户名 */ name: Scalars['ID']; /** 密码 */ @@ -778,6 +783,8 @@ export type GetEpoliciesQuery = { description?: string | null; channel: string; value: string; + creationTimestamp?: string | null; + lastHeartbeatTime?: string | null; }>; }; @@ -993,12 +1000,13 @@ export type GetIbppeersQuery = { }; export type CreateIbppeerMutationVariables = Exact<{ - organization: Scalars['String']; + org: Scalars['String']; + count?: InputMaybe; }>; export type CreateIbppeerMutation = { __typename?: 'Mutation'; - ibppeerCreate: { + ibppeerCreate: Array<{ __typename?: 'Ibppeer'; name: string; creationTimestamp: string; @@ -1008,7 +1016,7 @@ export type CreateIbppeerMutation = { cpu: string; memory: string; } | null; - }; + }>; }; export type GetNetworksQueryVariables = Exact<{ [key: string]: never }>; @@ -1202,18 +1210,9 @@ export type GetOrganizationQuery = { __typename?: 'User'; name: string; isOrganizationAdmin?: boolean | null; + joinedAt?: string | null; }> | null; - ibppeers?: Array<{ - __typename?: 'Ibppeer'; - name: string; - creationTimestamp: string; - status?: IbppeerStatus | null; - limits?: { - __typename?: 'SpecResource'; - cpu: string; - memory: string; - } | null; - }> | null; + ibppeers?: Array<{ __typename?: 'Ibppeer'; name: string }> | null; }; }; @@ -1438,6 +1437,8 @@ export const GetEpoliciesDocument = gql` description channel value + creationTimestamp + lastHeartbeatTime } } `; @@ -1597,8 +1598,8 @@ export const GetIbppeersDocument = gql` } `; export const CreateIbppeerDocument = gql` - mutation createIbppeer($organization: String!) { - ibppeerCreate(organization: $organization) { + mutation createIbppeer($org: String!, $count: Float) { + ibppeerCreate(organization: $org, count: $count) { name creationTimestamp status @@ -1760,15 +1761,10 @@ export const GetOrganizationDocument = gql` users { name isOrganizationAdmin + joinedAt } ibppeers { name - creationTimestamp - status - limits { - cpu - memory - } } } } diff --git a/src/pages/NetworkChannelDetail/index.jsx b/src/pages/NetworkChannelDetail/index.jsx index 0cd30a3..2d8d431 100644 --- a/src/pages/NetworkChannelDetail/index.jsx +++ b/src/pages/NetworkChannelDetail/index.jsx @@ -106,19 +106,58 @@ class NetworkChannelDetail$$Page extends React.Component { column={1} items={[ { - children: null, + children: ( + + {__$$eval( + () => + this.props.useGetChannel?.data?.channel + ?.name || '-' + )} + + ), key: '9qhq7vaoun', label: this.i18n('i18n-9e87qfos') /* 名称 */, span: 1, }, { - children: null, + children: ( + + {__$$eval( + () => + this.props.useGetChannel?.data?.channel + ?.description || '-' + )} + + ), key: 'pvlb9npuf1', label: this.i18n('i18n-8weq4mfy9lf') /* 描述 */, span: 1, }, { - children: null, + children: ( + + this.props.useGetChannel?.data?.channel + ?.creationTimestamp || '-' + )} + /> + ), key: '3fvfujee7p7', label: this.i18n('i18n-9ox4rx1wtwv') /* 创建时间 */, span: 1, @@ -142,7 +181,11 @@ class NetworkChannelDetail$$Page extends React.Component { strong={false} style={{ fontSize: '' }} > - text + {__$$eval( + () => + this.props.useGetChannel?.data?.channel + ?.name || '-' + )} } @@ -159,7 +202,11 @@ class NetworkChannelDetail$$Page extends React.Component { strong={false} style={{ fontSize: '' }} > - text + {__$$eval( + () => + this.props.useGetChannel?.data?.channel + ?.description || '-' + )} } @@ -173,7 +220,11 @@ class NetworkChannelDetail$$Page extends React.Component { __component_name="Typography.Time" format="" relativeTime={false} - time="" + time={__$$eval( + () => + this.props.useGetChannel?.data?.channel + ?.creationTimestamp || '-' + )} /> } @@ -221,6 +272,9 @@ class NetworkChannelDetail$$Page extends React.Component { }, ]} dataSource={__$$eval(() => [{}])} + loading={__$$eval( + () => this.props.useGetChannel?.loading + )} pagination={false} rowKey="id" scroll={{ scrollToFirstRowOnChange: true, y: 130 }} @@ -269,12 +323,19 @@ class NetworkChannelDetail$$Page extends React.Component { }, { _unsafe_MixedSetter_title_select: 'StringSetter', - dataIndex: 'version', - key: 'age', + dataIndex: 'name', + key: 'name', title: 'mspid', }, ]} - dataSource={__$$eval(() => [{}])} + dataSource={__$$eval( + () => + this.props.useGetChannel?.data?.channel?.members || + [] + )} + loading={__$$eval( + () => this.props.useGetChannel?.loading + )} pagination={false} rowKey="id" scroll={{ scrollToFirstRowOnChange: true, y: 130 }} @@ -322,8 +383,8 @@ class NetworkChannelDetail$$Page extends React.Component { title: this.i18n('i18n-9e87qfos') /* 名称 */, }, { - dataIndex: 'version', - key: 'age', + dataIndex: 'namespace', + key: 'namespace', title: this.i18n('i18n-2uy76ea1') /* 组织 */, }, { @@ -332,7 +393,13 @@ class NetworkChannelDetail$$Page extends React.Component { title: this.i18n('i18n-db5zj61b') /* 错节点 */, }, ]} - dataSource={__$$eval(() => [{}])} + dataSource={__$$eval( + () => + this.props.useGetChannel?.data?.channel?.peers || [] + )} + loading={__$$eval( + () => this.props.useGetChannel?.loading + )} pagination={false} rowKey="id" scroll={{ scrollToFirstRowOnChange: true, y: 130 }} @@ -378,8 +445,8 @@ class NetworkChannelDetail$$Page extends React.Component { title: this.i18n('i18n-87kp314f') /* 策略名称 */, }, { - dataIndex: 'version', - key: 'age', + dataIndex: 'description', + key: 'description', title: this.i18n('i18n-w3qy6omh') /* 策略描述 */, }, { @@ -389,12 +456,31 @@ class NetworkChannelDetail$$Page extends React.Component { title: this.i18n('i18n-xnyhdqu3') /* 应用合约数 */, }, { - dataIndex: 'crea', - key: 'crea', + dataIndex: 'creationTimestamp', + key: 'creationTimestamp', + render: (text, record, index) => + ((__$$context) => ( + record?.creationTimestamp)} + /> + ))( + __$$createChildContext(__$$context, { + text, + record, + index, + }) + ), title: this.i18n('i18n-9ox4rx1wtwv') /* 创建时间 */, }, ]} - dataSource={__$$eval(() => [{}])} + dataSource={__$$eval( + () => + this.props.useGetChannel?.data?.channel?.epolicy || [] + )} + loading={__$$eval(() => this.props.useGetChannel?.loading)} pagination={false} rowKey="id" scroll={{ scrollToFirstRowOnChange: true, y: 130 }} @@ -429,7 +515,14 @@ export default () => { }; return ( ( { - item = `'${item}'`; + item = `'${item}.member'`; if (i === 0) { return 'AND(' + item; } @@ -5349,8 +5349,25 @@ class NetworkDetail$$Page extends React.Component { this.i18n('i18n-w3qy6omh') /* 策略描述 */, }, { - dataIndex: 'channels', - key: 'channels', + dataIndex: 'lastHeartbeatTime', + key: 'lastHeartbeatTime', + render: (text, record, index) => + ((__$$context) => ( + record?.lastHeartbeatTime + )} + /> + ))( + __$$createChildContext(__$$context, { + text, + record, + index, + }) + ), title: this.i18n('i18n-watjije0jk') /* 更新时间 */, }, diff --git a/src/pages/OrganizationDetail/index.jsx b/src/pages/OrganizationDetail/index.jsx index 1681b1d..e46a92b 100644 --- a/src/pages/OrganizationDetail/index.jsx +++ b/src/pages/OrganizationDetail/index.jsx @@ -56,15 +56,15 @@ class OrganizationDetail$$Page extends React.Component { __$$i18n._inject2(this); this.state = { - current: 1, - filter: 'ALL', isOpenModal: false, modalType: 'create', - peers: [], - record: {}, - searchKey: 'name', + filter: 'ALL', searchValue: undefined, + searchKey: 'name', size: 10, + current: 1, + record: {}, + peers: [], }; } @@ -78,6 +78,101 @@ class OrganizationDetail$$Page extends React.Component { componentWillUnmount() {} + async getIbppeers() { + var _this$match, _this$match$params; + const res = await this.props.appHelper.utils.bff.getIbppeers({ + organization: + (_this$match = this.match) === null || _this$match === void 0 + ? void 0 + : (_this$match$params = _this$match.params) === null || + _this$match$params === void 0 + ? void 0 + : _this$match$params.id, + }); + this.setState({ + peers: (res === null || res === void 0 ? void 0 : res.ibppeers) || [], + }); + } + + openCreateModal() { + this.setState({ + isOpenModal: true, + modalType: 'create', + }); + } + + openCreateNodeModal() { + this.setState( + { + isOpenModal: true, + modalType: 'createnode', + }, + () => { + setTimeout(() => { + var _this$props$useGetOrg, + _this$props$useGetOrg2, + _this$$, + _this$$$formRef, + _this$$$formRef$curre, + _this$state$peers; + const organization = + ((_this$props$useGetOrg = this.props.useGetOrganization) === null || + _this$props$useGetOrg === void 0 + ? void 0 + : (_this$props$useGetOrg2 = _this$props$useGetOrg.data) === + null || _this$props$useGetOrg2 === void 0 + ? void 0 + : _this$props$useGetOrg2.organization) || {}; + const form = + (_this$$ = this.$('formily_create_node')) === null || + _this$$ === void 0 + ? void 0 + : (_this$$$formRef = _this$$.formRef) === null || + _this$$$formRef === void 0 + ? void 0 + : (_this$$$formRef$curre = _this$$$formRef.current) === null || + _this$$$formRef$curre === void 0 + ? void 0 + : _this$$$formRef$curre.form; + form.setValues({ + organization: organization.name, + nodes: + ((_this$state$peers = this.state.peers) === null || + _this$state$peers === void 0 + ? void 0 + : _this$state$peers.length) || 0, + number: 1, + storage: 1, + time: '', + }); + }, 0); + } + ); + } + + openCreateSuccessModal() { + this.setState({ + isOpenModal: true, + modalType: 'createsuccess', + }); + } + + openTransferModal(e, payload) { + this.setState({ + isOpenModal: true, + modalType: 'transfer', + record: payload === null || payload === void 0 ? void 0 : payload.record, + }); + } + + openDeleteModal(e, payload) { + this.setState({ + isOpenModal: true, + modalType: 'delete', + record: payload === null || payload === void 0 ? void 0 : payload.record, + }); + } + closeModal() { this.setState({ isOpenModal: false, @@ -149,7 +244,7 @@ class OrganizationDetail$$Page extends React.Component { }); } - confirmCreateNodelModal(e, payload) { + confirmTransferModal(e, payload) { var _this$props$useGetOrg, _this$props$useGetOrg2, _this$$, @@ -164,7 +259,7 @@ class OrganizationDetail$$Page extends React.Component { ? void 0 : _this$props$useGetOrg2.organization) || {}; const form = - (_this$$ = this.$('formily_create_node')) === null || _this$$ === void 0 + (_this$$ = this.$('formily_transfer')) === null || _this$$ === void 0 ? void 0 : (_this$$$formRef = _this$$.formRef) === null || _this$$$formRef === void 0 @@ -175,18 +270,19 @@ class OrganizationDetail$$Page extends React.Component { : _this$$$formRef$curre.form; form.submit(async (v) => { try { - const res = await this.props.appHelper.utils.bff.createIbppeer({ - organization: organization.name, + await this.props.appHelper.utils.bff.updateOrganization({ + name: organization.name, + organization: v, }); this.closeModal(); this.utils.notification.success({ - message: this.i18n('i18n-x26twb9oy0l'), + message: this.i18n('i18n-hjonznxjara'), }); - this.getIbppeers(); + this.props.useGetOrganization.mutate(); } catch (error) { var _error$response; this.utils.notification.warnings({ - message: this.i18n('i18n-43getajmxf3'), + message: this.i18n('i18n-zzu9mo73zo'), errors: error === null || error === void 0 ? void 0 @@ -253,7 +349,7 @@ class OrganizationDetail$$Page extends React.Component { } } - confirmTransferModal(e, payload) { + confirmCreateNodelModal(e, payload) { var _this$props$useGetOrg, _this$props$useGetOrg2, _this$$, @@ -268,7 +364,7 @@ class OrganizationDetail$$Page extends React.Component { ? void 0 : _this$props$useGetOrg2.organization) || {}; const form = - (_this$$ = this.$('formily_transfer')) === null || _this$$ === void 0 + (_this$$ = this.$('formily_create_node')) === null || _this$$ === void 0 ? void 0 : (_this$$$formRef = _this$$.formRef) === null || _this$$$formRef === void 0 @@ -279,19 +375,19 @@ class OrganizationDetail$$Page extends React.Component { : _this$$$formRef$curre.form; form.submit(async (v) => { try { - await this.props.appHelper.utils.bff.updateOrganization({ - name: organization.name, - organization: v, + const res = await this.props.appHelper.utils.bff.createIbppeer({ + org: organization.name, + count: v.count, }); this.closeModal(); this.utils.notification.success({ - message: this.i18n('i18n-hjonznxjara'), + message: this.i18n('i18n-x26twb9oy0l'), }); - this.props.useGetOrganization.mutate(); + this.getIbppeers(); } catch (error) { var _error$response; this.utils.notification.warnings({ - message: this.i18n('i18n-zzu9mo73zo'), + message: this.i18n('i18n-43getajmxf3'), errors: error === null || error === void 0 ? void 0 @@ -304,22 +400,6 @@ class OrganizationDetail$$Page extends React.Component { }); } - async getIbppeers() { - var _this$match, _this$match$params; - const res = await this.props.appHelper.utils.bff.getIbppeers({ - organization: - (_this$match = this.match) === null || _this$match === void 0 - ? void 0 - : (_this$match$params = _this$match.params) === null || - _this$match$params === void 0 - ? void 0 - : _this$match$params.id, - }); - this.setState({ - peers: (res === null || res === void 0 ? void 0 : res.ibppeers) || [], - }); - } - handleFilterChange(e) { this.setState({ filter: e.target.value, @@ -327,35 +407,13 @@ class OrganizationDetail$$Page extends React.Component { }); } - handleNodeFilterChange(e) { - this.setState({ - filter: e.target.value, - current: 1, - }); - } - - handleNodePaginationChange(c, s) { - this.setState({ - size: s, - current: c, - }); - } - - handleNodeSearchValueChange(e) { + handleSearchValueChange(e) { this.setState({ searchValue: e.target.value, current: 1, }); } - handleNodeTableChange(pagination, filters, sorter, extra) { - this.setState({ - pagination, - filters, - sorter, - }); - } - handlePaginationChange(c, s) { this.setState({ size: s, @@ -363,13 +421,6 @@ class OrganizationDetail$$Page extends React.Component { }); } - handleSearchValueChange(e) { - this.setState({ - searchValue: e.target.value, - current: 1, - }); - } - handleTableChange(pagination, filters, sorter, extra) { this.setState({ pagination, @@ -378,92 +429,42 @@ class OrganizationDetail$$Page extends React.Component { }); } - nodePaginationShowTotal(total, range) { + paginationShowTotal(total, range) { return `${this.i18n('i18n-5xl7aihzcuy')} ${total} ${this.i18n( 'i18n-v7xu122b9o' )}`; } - openCreateModal() { + handleNodeFilterChange(e) { this.setState({ - isOpenModal: true, - modalType: 'create', + filter: e.target.value, + current: 1, }); } - openCreateNodeModal() { - this.setState( - { - isOpenModal: true, - modalType: 'createnode', - }, - () => { - setTimeout(() => { - var _this$props$useGetOrg, - _this$props$useGetOrg2, - _this$$, - _this$$$formRef, - _this$$$formRef$curre, - _this$state$peers; - const organization = - ((_this$props$useGetOrg = this.props.useGetOrganization) === null || - _this$props$useGetOrg === void 0 - ? void 0 - : (_this$props$useGetOrg2 = _this$props$useGetOrg.data) === - null || _this$props$useGetOrg2 === void 0 - ? void 0 - : _this$props$useGetOrg2.organization) || {}; - const form = - (_this$$ = this.$('formily_create_node')) === null || - _this$$ === void 0 - ? void 0 - : (_this$$$formRef = _this$$.formRef) === null || - _this$$$formRef === void 0 - ? void 0 - : (_this$$$formRef$curre = _this$$$formRef.current) === null || - _this$$$formRef$curre === void 0 - ? void 0 - : _this$$$formRef$curre.form; - form.setValues({ - organization: organization.name, - nodes: - ((_this$state$peers = this.state.peers) === null || - _this$state$peers === void 0 - ? void 0 - : _this$state$peers.length) || 0, - number: 1, - storage: 1, - time: '', - }); - }, 0); - } - ); - } - - openCreateSuccessModal() { + handleNodeSearchValueChange(e) { this.setState({ - isOpenModal: true, - modalType: 'createsuccess', + searchValue: e.target.value, + current: 1, }); } - openDeleteModal(e, payload) { + handleNodePaginationChange(c, s) { this.setState({ - isOpenModal: true, - modalType: 'delete', - record: payload === null || payload === void 0 ? void 0 : payload.record, + size: s, + current: c, }); } - openTransferModal(e, payload) { + handleNodeTableChange(pagination, filters, sorter, extra) { this.setState({ - isOpenModal: true, - modalType: 'transfer', - record: payload === null || payload === void 0 ? void 0 : payload.record, + pagination, + filters, + sorter, }); } - paginationShowTotal(total, range) { + nodePaginationShowTotal(total, range) { return `${this.i18n('i18n-5xl7aihzcuy')} ${total} ${this.i18n( 'i18n-v7xu122b9o' )}`; @@ -788,8 +789,9 @@ class OrganizationDetail$$Page extends React.Component { relativeTime={false} time={__$$eval( () => - this.props.useGetOrganization?.data?.organization - ?.joinAt + this.props.useGetOrganization?.data?.organization?.users?.find( + (item) => item.isOrganizationAdmin + )?.joinedAt )} /> } @@ -1153,7 +1155,7 @@ class OrganizationDetail$$Page extends React.Component { record.joinedAt)} /> ))( __$$createChildContext(__$$context, { @@ -2555,7 +2557,7 @@ class OrganizationDetail$$Page extends React.Component { }} decoratorProps={{ 'x-decorator-props': { size: 'default' } }} fieldProps={{ - name: 'number', + name: 'count', title: this.i18n('i18n-rjt0ywiz') /* 新增节点数量 */, 'x-validator': [], }}