@shko.online/lookupobjects-mock
Version:
Mocking Dataverse Lookup Objects to simplify writing soties for PCF components
42 lines • 1.91 kB
JavaScript
import React, { useState } from 'react';
import SelectedEntityFilter from './SelectedEntityFilter';
function MultiEntityFilter(_ref) {
let {
entityTypes,
db,
results,
searchByEntityRecords
} = _ref;
const [selectedEntity, setSelectedEntity] = useState();
return selectedEntity == null ? /*#__PURE__*/React.createElement("div", {
className: "so.m-1 so.rounded so.bg-zinc-50 so.h-8 ",
role: "presentation"
}, /*#__PURE__*/React.createElement("div", {
className: "so.flex so.flex-row so.items-center",
role: "presentation"
}, /*#__PURE__*/React.createElement("div", {
className: "so.pl-2 so.text-sm so.text-center so.text-neutral-800 so.cursor-default",
role: "presentation"
}, `Results from: `), /*#__PURE__*/React.createElement("ul", {
className: "so.flex so.flex-wrap so.overflow-hidden"
}, entityTypes.map(value => {
const metadata = db.getTableMetadata(value);
return /*#__PURE__*/React.createElement("li", {
key: value
}, /*#__PURE__*/React.createElement("button", {
className: "so.flex so.text-xs so.py-1 so.px-2 so.m-1 so.leading-4 so.border so.border-neutral-300 disabled:so.border-opacity-30 so.border-solid so.rounded so.bg-white disabled:so.bg-zinc-100 disabled:so.bg-opacity-30 so.text-neutral-800 disabled:so.text-stone-950 disabled:so.text-opacity-50 so.cursor-pointer",
disabled: results?.filter(i => i.entityType === value).length === 0,
onClick: () => {
setSelectedEntity(metadata), searchByEntityRecords(value);
},
role: "button",
type: "button"
}, /*#__PURE__*/React.createElement("span", null, metadata.DisplayName || metadata.LogicalName)));
})))) : /*#__PURE__*/React.createElement(SelectedEntityFilter, {
OnAllClick: () => {
searchByEntityRecords(), setSelectedEntity(null);
},
entity: selectedEntity
});
}
export default MultiEntityFilter;