UNPKG

@knockout-js/org

Version:
198 lines (197 loc) 10.6 kB
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _object_spread } from "@swc/helpers/_/_object_spread"; import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props"; import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array"; import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime"; import { useState } from "react"; import { ProTable } from "@ant-design/pro-components"; import { gid, instanceName } from "@knockout-js/api"; import { OrderDirection, OrgKind as UcenterOrgKind, OrgOrderField } from "@knockout-js/api/ucenter"; import { useLocale } from "../locale"; import { gql, paging } from "@knockout-js/ice-urql/request"; import { Modal } from "@knockout-js/layout"; var // fix publish error: Property 'kind' of exported interface has or is using private name 'OrgKind'. OrgKind; (function(OrgKind) { OrgKind[OrgKind["Org"] = UcenterOrgKind.Org] = "Org"; OrgKind[OrgKind["Root"] = UcenterOrgKind.Root] = "Root"; })(OrgKind || (OrgKind = {})); var appOrgListQuery = gql("query appOrgList($gid: GID!,$first: Int,$orderBy:OrgOrder,$where:OrgWhereInput){\n node(id:$gid){\n ... on App{\n id,\n orgs(first:$first,orderBy: $orderBy,where: $where){\n totalCount,pageInfo{ hasNextPage,hasPreviousPage,startCursor,endCursor }\n edges{\n cursor,node{\n id,ownerID,parentID,kind,profile,\n domain,code,name,countryCode,timezone,\n owner { id,displayName }\n }\n }\n }\n }\n }\n}"); var orgListQuery = gql("query orgList($first: Int,$orderBy:OrgOrder,$where:OrgWhereInput){\n organizations(first:$first,orderBy: $orderBy,where: $where){\n totalCount,pageInfo{ hasNextPage,hasPreviousPage,startCursor,endCursor }\n edges{\n cursor,node{\n id,ownerID,parentID,kind,profile,\n domain,code,name,countryCode,timezone,\n owner { id,displayName }\n }\n }\n }\n}"); export default function(props) { var locale = useLocale("OrgModal"), glocale = useLocale("global"), _useState = _sliced_to_array(useState([]), 2), dataSource = _useState[0], setDataSource = _useState[1], _useState1 = _sliced_to_array(useState([]), 2), selectedRowKeys = _useState1[0], setSelectedRowKeys = _useState1[1], columns = [ { title: locale.name, dataIndex: "name" }, { title: locale.domain, dataIndex: "domain" }, { title: locale.owner, dataIndex: "owner", search: false, render: function(text, record) { var _record_owner, _record; return /*#__PURE__*/ _jsx("div", { children: ((_record = record) === null || _record === void 0 ? void 0 : (_record_owner = _record.owner) === null || _record_owner === void 0 ? void 0 : _record_owner.displayName) || "-" }); } }, { title: locale.desc, dataIndex: "profile", search: false } ]; return /*#__PURE__*/ _jsx(Modal, _object_spread_props(_object_spread({ width: 900, title: props.title }, props.modalProps), { open: props.open, onOk: function() { props.onClose(dataSource.filter(function(item) { return selectedRowKeys.includes(item.id); })); }, onCancel: function() { props.onClose(); }, children: /*#__PURE__*/ _jsx(ProTable, _object_spread_props(_object_spread({ size: "small", scroll: { x: "max-content", y: 300 } }, props.proTableProps), { rowKey: "id", search: { searchText: glocale.query, resetText: glocale.reset, labelWidth: "auto" }, options: false, columns: columns, request: function() { var _ref = _async_to_generator(function(params) { var table, where, orderBy, _result_data_node, _result_data, result, _result_data_node_orgs_edges, _result_data1, result1, _result_data_organizations_edges; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: table = { data: [], success: true, total: 0 }, where = _object_spread({}, props.where), orderBy = { direction: OrderDirection.Asc, field: OrgOrderField.DisplaySort }; where.kind = props.kind; where.nameContains = params.name; where.domain = params.domain; where.pathHasPrefix = props.orgId ? "".concat(props.orgId, "/") : undefined; if (!props.appId) return [ 3, 2 ]; return [ 4, paging(appOrgListQuery, { gid: gid("App", props.appId), first: params.pageSize, where: where, orderBy: orderBy }, params.current || 1, { instanceName: instanceName.UCENTER }) ]; case 1: result = _state.sent(); if (((_result_data = result.data) === null || _result_data === void 0 ? void 0 : (_result_data_node = _result_data.node) === null || _result_data_node === void 0 ? void 0 : _result_data_node.__typename) === "App") { ; (_result_data_node_orgs_edges = result.data.node.orgs.edges) === null || _result_data_node_orgs_edges === void 0 ? void 0 : _result_data_node_orgs_edges.forEach(function(item) { var _item; if ((_item = item) === null || _item === void 0 ? void 0 : _item.node) { table.data.push(item.node); } }); table.total = result.data.node.orgs.totalCount; } return [ 3, 4 ]; case 2: return [ 4, paging(orgListQuery, { first: params.pageSize, where: where, orderBy: orderBy }, params.current || 1, { instanceName: instanceName.UCENTER }) ]; case 3: result1 = _state.sent(); if ((_result_data1 = result1.data) === null || _result_data1 === void 0 ? void 0 : _result_data1.organizations.totalCount) { ; (_result_data_organizations_edges = result1.data.organizations.edges) === null || _result_data_organizations_edges === void 0 ? void 0 : _result_data_organizations_edges.forEach(function(item) { var _item; if ((_item = item) === null || _item === void 0 ? void 0 : _item.node) { table.data.push(item.node); } }); table.total = result1.data.organizations.totalCount; } _state.label = 4; case 4: setDataSource(table.data); return [ 2, table ]; } }); }); return function(params) { return _ref.apply(this, arguments); }; }(), pagination: { showSizeChanger: true }, rowSelection: { selectedRowKeys: selectedRowKeys, onChange: function(selectedRowKeys) { setSelectedRowKeys(selectedRowKeys); }, type: props.isMultiple ? "checkbox" : "radio" }, onRow: function(record) { return { onClick: function() { if (props.isMultiple) { if (selectedRowKeys.includes(record.id)) { setSelectedRowKeys(selectedRowKeys.filter(function(id) { return id != record.id; })); } else { selectedRowKeys.push(record.id); setSelectedRowKeys(_to_consumable_array(selectedRowKeys)); } } else { setSelectedRowKeys([ record.id ]); } } }; } })) })); }; //# sourceMappingURL=index.js.map