UNPKG

@adaptabletools/adaptable-cjs

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

41 lines (40 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getObjectTagsViewItems = void 0; const tslib_1 = require("tslib"); const react_1 = tslib_1.__importDefault(require("react")); const react_redux_1 = require("react-redux"); const SimpleButton_1 = tslib_1.__importDefault(require("../components/SimpleButton")); const getObjectTagsViewItems = (object, api) => { if (!api.internalApi.shouldDisplayTagSections() || !object?.Tags?.length) { return; } const currentLayoutName = api.layoutApi.getCurrentLayoutName(); const hasCurrentLayoutAsTag = (object?.Tags ?? [])?.includes(currentLayoutName); return { name: 'Tags', values: object?.Tags?.map((tag) => api.internalApi.getLabelForTag(tag)), viewAfter: (props) => { const dispatch = (0, react_redux_1.useDispatch)(); const viewOptions = props.module.getViewProperties(); const handleToggleTag = react_1.default.useCallback(() => { let tags = props.data.Tags ?? []; if (hasCurrentLayoutAsTag) { // remove layout tags = tags.filter((tag) => tag !== currentLayoutName); } else { tags.push(currentLayoutName); } const newObject = { ...props.data, Tags: tags, }; const editAction = viewOptions.getEditAction(newObject); dispatch(editAction); }, [hasCurrentLayoutAsTag, props.data]); return (react_1.default.createElement(SimpleButton_1.default, { onClick: handleToggleTag, mt: 1, icon: hasCurrentLayoutAsTag ? 'minus' : 'plus' }, hasCurrentLayoutAsTag ? 'Remove from Layout' : 'Add to Layout')); }, }; }; exports.getObjectTagsViewItems = getObjectTagsViewItems;