@finos/legend-application-marketplace
Version:
Legend Marketplace application core
138 lines • 9.33 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { V1_LiteDataContractWithUserStatus } from '@finos/legend-graph';
import { DataGrid, } from '@finos/legend-lego/data-grid';
import { Box, CircularProgress, FormControlLabel, FormGroup, Switch, } from '@mui/material';
import { useEffect, useMemo, useState } from 'react';
import { useLegendMarketplaceBaseStore } from '../../../application/providers/LegendMarketplaceFrameworkProvider.js';
import { observer } from 'mobx-react-lite';
import { startCase } from '@finos/legend-shared';
import { useAuth } from 'react-oidc-context';
import { MultiUserRenderer, isContractInTerminalState, DataAccessRequestViewer, isApprovalStatusTerminal, } from '@finos/legend-extension-dsl-data-product';
import { flowResult } from 'mobx';
import { getCommonEntitlementsColDefs, getContractData, getSelectedRowId, getSelectedContractGuid, getOpenTaskAssignees, EntitlementsColumnHeader, CONTRACT_STATE_DISPLAY_LABELS, ENTITLEMENTS_DEFAULT_COL_DEF, ROW_KIND_CONTRACT, ROW_KIND_REQUEST, TERMINAL_DATA_REQUEST_STATES, UNKNOWN, useSelectedViewerState, useGetDataProductUrl, } from '../../../utils/EntitlementsUtils.js';
const AssigneesCellRenderer = observer((props) => {
const { row, entitlementsStore } = props;
if (!row) {
return null;
}
let assignees;
if (row.kind === ROW_KIND_CONTRACT) {
assignees =
(row.data instanceof V1_LiteDataContractWithUserStatus
? row.data.pendingTaskWithAssignees?.assignees.toSorted()
: row.data.sortedAssigneeIds) ?? [];
}
else {
assignees = getOpenTaskAssignees(row.data);
}
return (_jsx(MultiUserRenderer, { userIds: assignees, applicationStore: entitlementsStore.applicationStore, userSearchService: entitlementsStore.marketplaceBaseStore.userSearchService, disableOnClick: true, singleUserClassName: "marketplace-lakehouse-entitlements__grid__user-display" }));
});
export const EntitlementsPendingContractsDashboard = observer((props) => {
const { dashboardState } = props;
const { allContractsForUser, allContractsCreatedByUser, dataRequestsCreatedByUser, } = dashboardState;
const marketplaceBaseStore = useLegendMarketplaceBaseStore();
const auth = useAuth();
const getDataProductUrl = useGetDataProductUrl();
const myPendingContracts = useMemo(() => allContractsForUser?.filter((contract) => !isApprovalStatusTerminal(contract.status)) ?? [], [allContractsForUser]);
const myPendingContractIds = useMemo(() => new Set(myPendingContracts.map((c) => c.contractResultLite.guid)), [myPendingContracts]);
const pendingContractsForOthers = useMemo(() => allContractsCreatedByUser.filter((contract) => !isContractInTerminalState(contract.contractResultLite) &&
!myPendingContractIds.has(contract.contractResultLite.guid)), [allContractsCreatedByUser, myPendingContractIds]);
const pendingDataRequests = useMemo(() => (dataRequestsCreatedByUser ?? []).filter((dr) => !TERMINAL_DATA_REQUEST_STATES.has(dr.dataRequest.state)), [dataRequestsCreatedByUser]);
const [selectedRow, setSelectedRow] = useState();
const [contractErrors, setContractErrors] = useState(undefined);
const selectedRowId = getSelectedRowId(selectedRow);
const selectedViewerState = useSelectedViewerState(selectedRow, selectedRowId);
const [showForOthers, setShowForOthers] = useState(myPendingContracts.length === 0 && pendingContractsForOthers.length > 0);
useEffect(() => {
setContractErrors(undefined);
if (selectedRow?.kind === ROW_KIND_CONTRACT) {
const contract = selectedRow.data.contractResultLite;
dashboardState
.getContractErrors(contract.guid, auth.user?.access_token)
.then((result) => setContractErrors(result))
.catch(() => setContractErrors(undefined));
}
}, [selectedRow, auth.user?.access_token, dashboardState]);
const selectedContractGuid = getSelectedContractGuid(selectedRow);
const colDefs = useMemo(() => [
...getCommonEntitlementsColDefs(dashboardState),
{
headerName: EntitlementsColumnHeader.STATE,
valueGetter: (params) => {
if (!params.data) {
return UNKNOWN;
}
if (params.data.kind === ROW_KIND_CONTRACT) {
const state = getContractData(params.data)?.state;
return state
? (CONTRACT_STATE_DISPLAY_LABELS[state] ?? startCase(state))
: UNKNOWN;
}
return startCase(params.data.data.dataRequest.state);
},
},
{
headerName: EntitlementsColumnHeader.ASSIGNEES,
colId: 'assignees',
valueGetter: (params) => {
if (!params.data) {
return UNKNOWN;
}
if (params.data.kind === ROW_KIND_CONTRACT) {
const assignees = (params.data.data instanceof V1_LiteDataContractWithUserStatus
? params.data.data.pendingTaskWithAssignees?.assignees.toSorted()
: params.data.data.sortedAssigneeIds) ?? [];
return assignees.length > 0 ? assignees.join(', ') : UNKNOWN;
}
const openAssignees = getOpenTaskAssignees(params.data.data);
return openAssignees.length > 0 ? openAssignees.join(', ') : 'None';
},
cellRenderer: (params) => (_jsx(AssigneesCellRenderer, { row: params.data, entitlementsStore: dashboardState.lakehouseEntitlementsStore })),
},
], [dashboardState]);
const gridRowData = useMemo(() => {
const contracts = showForOthers
? [...myPendingContracts, ...pendingContractsForOthers]
: myPendingContracts;
return [
...contracts.map((c) => ({ kind: ROW_KIND_CONTRACT, data: c })),
...pendingDataRequests.map((r) => ({ kind: ROW_KIND_REQUEST, data: r })),
];
}, [
showForOthers,
myPendingContracts,
pendingContractsForOthers,
pendingDataRequests,
]);
return (_jsxs(Box, { className: "marketplace-lakehouse-entitlements__pending-contracts", children: [_jsx(FormGroup, { className: "marketplace-lakehouse-entitlements__pending-contracts__action-btns", children: _jsx(FormControlLabel, { control: dashboardState.fetchingContractsByUserState.isInProgress ? (_jsx(Box, { className: "marketplace-lakehouse-entitlements__pending-contracts__action-btn--loading", children: _jsx(CircularProgress, { size: 20 }) })) : (_jsx(Switch, { checked: showForOthers, onChange: (event) => setShowForOthers(event.target.checked) })), label: "Show my requests for others", title: dashboardState.fetchingContractsByUserState.isInProgress
? 'Loading requests for others'
: undefined, disabled: dashboardState.fetchingContractsByUserState.isInProgress, className: "marketplace-lakehouse-entitlements__pending-contracts__action-btn" }) }), _jsx(Box, { className: "marketplace-lakehouse-entitlements__pending-contracts__grid ag-theme-balham", children: _jsx(DataGrid, { rowData: gridRowData, onRowDataUpdated: (params) => {
params.api.refreshCells({ force: true });
}, suppressFieldDotNotation: true, suppressContextMenu: false, columnDefs: colDefs, onCellClicked: (event) => event.data && setSelectedRow(event.data), defaultColDef: ENTITLEMENTS_DEFAULT_COL_DEF, rowHeight: 45, overlayNoRowsTemplate: "You have no pending contracts or data requests", loading: dashboardState.fetchingContractsForUserState.isInProgress ||
dashboardState.fetchingDataRequestsCreatedByUserState.isInProgress, overlayLoadingTemplate: "Loading" }) }), selectedRow !== undefined && selectedViewerState !== undefined && (_jsx(DataAccessRequestViewer, { open: true, onClose: () => {
setSelectedRow(undefined);
setContractErrors(undefined);
}, contractErrors: contractErrors, viewerState: selectedViewerState, ...(selectedContractGuid
? {
onRefresh: async () => {
await flowResult(dashboardState.updateContract(selectedContractGuid, auth.user?.access_token));
},
}
: {}), getDataProductUrl: getDataProductUrl, dataProductEnvironment: marketplaceBaseStore.envState.lakehouseEnvironment }))] }));
});
//# sourceMappingURL=EntitlementsPendingContractsDashboard.js.map