@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
64 lines (63 loc) • 4.24 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import * as React from 'react';
import SimpleButton from '../../components/SimpleButton';
import { Tag } from '../../components/Tag';
import { useAdaptable } from '../AdaptableContext';
import { AdaptableObjectListItem } from '../Components/AdaptableObjectList/AdaptableObjectList';
import { Box, Flex } from '../../components/Flex';
export const SharedEntityTypeItemView = (props) => {
const [isExpanded, setIsExpanded] = React.useState(false);
const adaptable = useAdaptable();
const moduleName = props.data.Module;
const module = adaptable.ModuleService.getModuleById(moduleName);
const sharedObject = props.data.Entity;
const item = module?.toView(sharedObject);
return (_jsxs(_Fragment, { children: [_jsxs(Flex, { className: "twa:my-2", children: [_jsx(Flex, { className: "twa:mr-2", alignItems: "center", children: _jsx(Tag, { className: "twa:m-0", children: props.data.Module }) }), item ? (isExpanded ? (_jsx(SimpleButton, { "data-name": "shared-entity-collapse-button", onClick: () => setIsExpanded(false), icon: "arrow-up", children: "Collapse" })) : (_jsx(SimpleButton, { "data-name": "shared-entity-expand-button", onClick: () => setIsExpanded(true), icon: "arrow-down", children: "Expand" }))) : null] }), isExpanded && item && (_jsx(Box, { as: "ul", className: "ab-Shared-Entity-Shared-Object twa:p-0 twa:flex twa:flex-col twa:gap-3", children: _jsx(AdaptableObjectListItem, { hideControls: true, data: item, module: module }) }))] }));
};
export const getSharedEntityActiveStatusObjectView = (isDependency) => (props) => {
const adaptable = useAdaptable();
const activeEntries = adaptable.api.internalApi.getState().TeamSharing.ActiveSharedEntityMap;
const sharedEntity = props.data;
const isAdaptableObjectPresentInLocalState = !!adaptable.api.internalApi
.getModuleService()
.getModuleById('TeamSharing')
.isAdaptableObjectPresentInLocalState(sharedEntity);
const isUpToDateAndActive = isAdaptableObjectPresentInLocalState &&
sharedEntity.Type === 'Active' &&
activeEntries[sharedEntity.Entity.Uuid]?.Revision === sharedEntity.Revision;
const staleActiveEntities = adaptable.api.internalApi
.getTeamSharingService()
.getStaleActiveSharedEntities();
const isStaleAndActive = isAdaptableObjectPresentInLocalState && !!staleActiveEntities[sharedEntity.Uuid];
let activeInfo = null;
if (isAdaptableObjectPresentInLocalState) {
const activeRevision = activeEntries?.[sharedEntity.Entity.Uuid]?.Revision;
if (sharedEntity.Type === 'Active') {
const newRevision = sharedEntity.Revision;
let statusInfo = null;
if (isUpToDateAndActive) {
statusInfo = (_jsx(Box, { className: "twa:ml-1 twa:text-success", children: _jsx("b", { children: "up-to-date" }) }));
}
if (isStaleAndActive) {
statusInfo = (_jsx(Box, { className: "twa:ml-1 twa:text-warn", children: ` (Rev. ${newRevision} available)` }));
}
activeInfo = activeRevision && (_jsxs(_Fragment, { children: [activeRevision &&
`Imported Rev. ${activeRevision} ${isStaleAndActive ? 'is stale' : ''} `, ' ', statusInfo] }));
}
else {
activeInfo = activeRevision && _jsx(_Fragment, { children: `Imported Rev. ${activeRevision}` });
}
}
const sharedValue = `by ${sharedEntity.UserName} at ${new Date(sharedEntity.Timestamp).toLocaleString()}`;
return (_jsxs(_Fragment, { children: [!isDependency && _jsx(Tag, { children: sharedValue }), activeInfo && _jsx(Tag, { children: activeInfo })] }));
};
export const getSharedEntityStaleDepsItemView = (staleDependencies) => () => {
let staleDepsString = 'Shared entity has';
if (staleDependencies?.length === 1) {
staleDepsString += ` one (${staleDependencies[0].Module}) stale dependency`;
}
else {
staleDepsString += ` ${staleDependencies.length} stale dependencies`;
}
return (_jsx(Tag, { children: _jsx(Box, { className: "twa:ml-1 twa:text-warn", children: staleDepsString }) }));
};