@headless-adminapp/fluent 0.0.17-alpha.59 → 0.0.17-alpha.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ const hooks_1 = require("@headless-adminapp/app/auth/hooks");
9
9
  const useIsSkipAuthCheck_1 = require("@headless-adminapp/app/auth/hooks/useIsSkipAuthCheck");
10
10
  const hooks_2 = require("@headless-adminapp/app/hooks");
11
11
  const locale_1 = require("@headless-adminapp/app/locale");
12
+ const route_1 = require("@headless-adminapp/app/route");
12
13
  const icons_1 = require("@headless-adminapp/icons");
13
14
  const react_1 = require("react");
14
15
  const AppLogo_1 = require("./AppLogo");
@@ -31,6 +32,7 @@ const AppHeaderContainer = ({ onNavToggle, }) => {
31
32
  }, [authSession?.fullName]);
32
33
  const quickActionItems = (0, hooks_2.useItemsWithKey)(app.quickActionItems);
33
34
  const accountMenuItems = (0, hooks_2.useItemsWithKey)(app.accountMenuItems);
35
+ const router = (0, route_1.useRouter)();
34
36
  return ((0, jsx_runtime_1.jsxs)("div", { style: {
35
37
  display: 'flex',
36
38
  alignItems: 'center',
@@ -69,7 +71,14 @@ const AppHeaderContainer = ({ onNavToggle, }) => {
69
71
  flex: 1,
70
72
  }, children: [(0, jsx_runtime_1.jsx)(react_components_1.Caption1Strong, { children: authSession?.fullName }), (0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { textOverflow: 'ellipsis', overflow: 'hidden' }, children: authSession?.email })] })] })), !isSkipAuthCheck && (0, jsx_runtime_1.jsx)(react_components_1.MenuDivider, { style: { marginInline: 0 } }), (0, jsx_runtime_1.jsxs)(react_components_1.MenuList, { style: { width: 200, marginBottom: 4 }, children: [accountMenuItems?.map((item) => {
71
73
  const Icon = item.icon;
72
- return ((0, jsx_runtime_1.jsx)(react_components_1.MenuItem, { icon: (0, jsx_runtime_1.jsx)(Icon, { size: "inherit" }), onClick: () => item.onClick?.(), children: item.localizedLabel?.[language] ?? item.label }, item.__key));
74
+ return ((0, jsx_runtime_1.jsx)(react_components_1.MenuItem, { icon: (0, jsx_runtime_1.jsx)(Icon, { size: "inherit" }), onClick: () => {
75
+ if (item.onClick) {
76
+ item.onClick();
77
+ }
78
+ else if (item.link) {
79
+ router.push(item.link);
80
+ }
81
+ }, children: item.localizedLabel?.[language] ?? item.label }, item.__key));
73
82
  }), !isSkipAuthCheck && ((0, jsx_runtime_1.jsx)(react_components_1.MenuItem, { icon: (0, jsx_runtime_1.jsx)(icons_1.Icons.SignOut, {}), onClick: () => logout(), children: strings.logout }))] })] })] }))] })] }));
74
83
  };
75
84
  exports.AppHeaderContainer = AppHeaderContainer;
@@ -65,7 +65,7 @@ function PromptDialog(props) {
65
65
  const errorMessage = fieldState.isTouched || formState.isSubmitted
66
66
  ? fieldState.error?.message
67
67
  : '';
68
- return ((0, jsx_runtime_1.jsx)(SectionControl_1.SectionControlWrapper, { label: attribute.label, labelPosition: "left", required: attribute.required, isError: isError, errorMessage: errorMessage, children: (0, jsx_runtime_1.jsx)(StandardControl_1.StandardControl, { attribute: attribute, name: attributeName, value: field.value, onChange: field.onChange, onBlur: field.onBlur, errorMessage: errorMessage, isError: isError }) }));
68
+ return ((0, jsx_runtime_1.jsx)(SectionControl_1.SectionControlWrapper, { label: attribute.label, labelPosition: "left", required: attribute.required, isError: isError, errorMessage: errorMessage, children: (0, jsx_runtime_1.jsx)(StandardControl_1.StandardControl, { attribute: attribute, name: attributeName, value: field.value, onChange: field.onChange, onBlur: field.onBlur, errorMessage: errorMessage, isError: isError, readOnly: attribute.readonly }) }));
69
69
  } }, attributeName));
70
70
  }) })] }), (0, jsx_runtime_1.jsxs)(react_components_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(react_components_1.Button, { appearance: "secondary", type: "button", onClick: () => {
71
71
  props.onCancel?.();
@@ -23,6 +23,7 @@ const RecordAvatar = () => {
23
23
  const dataService = (0, transport_1.useDataService)();
24
24
  const refresh = (0, mutable_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.refresh);
25
25
  const [showAvatarChangeDialog, setShowAvatarChangeDialog] = (0, react_1.useState)(false);
26
+ const fileService = (0, transport_1.useFileService)();
26
27
  const { showProgressIndicator, hideProgressIndicator } = (0, progress_indicator_1.useProgressIndicator)();
27
28
  const openErrorDialog = (0, dialog_1.useOpenErrorDialog)();
28
29
  if (!schema.avatarAttribute) {
@@ -73,7 +74,10 @@ const RecordAvatar = () => {
73
74
  }, children: [(0, jsx_runtime_1.jsx)(react_components_1.Avatar, { style: { width: 36, height: 36 }, name: recordTitle, color: (0, avatar_1.getAvatarColor)(recordTitle), image: {
74
75
  src: value?.url,
75
76
  }, onClick: () => {
77
+ if (!fileService) {
78
+ return;
79
+ }
76
80
  setShowAvatarChangeDialog(true);
77
- } }), !!recordId && ((0, jsx_runtime_1.jsx)(UploadImageDialog_1.UploadImageDialog, { recordTitle: recordTitle, currentImage: value, onChange: handleChange, recordId: recordId, open: showAvatarChangeDialog, onOpenChange: (open) => setShowAvatarChangeDialog(open) }))] }));
81
+ } }), !!recordId && !!fileService && ((0, jsx_runtime_1.jsx)(UploadImageDialog_1.UploadImageDialog, { recordTitle: recordTitle, currentImage: value, onChange: handleChange, recordId: recordId, open: showAvatarChangeDialog, onOpenChange: (open) => setShowAvatarChangeDialog(open) }))] }));
78
82
  };
79
83
  exports.RecordAvatar = RecordAvatar;
@@ -72,12 +72,13 @@ function getRelatedItems(currentSchema, schemas, relatedItems) {
72
72
  }
73
73
  function RelatedViewSelector(props) {
74
74
  const schema = (0, hooks_1.useDataFormSchema)();
75
+ const recordId = (0, hooks_1.useRecordId)();
75
76
  const formConfig = (0, hooks_1.useSelectedForm)();
76
77
  const { schemas } = (0, hooks_2.useMetadata)();
77
78
  const strings = (0, PageEntityFormStringContext_1.usePageEntityFormStrings)();
78
79
  const { language } = (0, locale_1.useLocale)();
79
80
  const data = (0, react_1.useMemo)(() => getRelatedItems(schema, schemas, formConfig.experience.relatedItems), [formConfig.experience.relatedItems, schema, schemas]);
80
- if (!data.length) {
81
+ if (!data.length || !recordId) {
81
82
  return null;
82
83
  }
83
84
  return ((0, jsx_runtime_1.jsxs)(react_components_1.Menu, { children: [(0, jsx_runtime_1.jsx)(react_components_1.MenuTrigger, { children: (0, jsx_runtime_1.jsxs)("button", { style: {
@@ -3,4 +3,4 @@ import { SchemaAttributes } from '@headless-adminapp/core/schema';
3
3
  export declare function SectionContainer<S extends SchemaAttributes = SchemaAttributes>({ section }: {
4
4
  section: Section<S>;
5
5
  readOnly: boolean;
6
- }): import("react/jsx-runtime").JSX.Element;
6
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -2,9 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SectionContainer = SectionContainer;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const dataform_1 = require("@headless-adminapp/app/dataform");
6
+ const constants_1 = require("@headless-adminapp/app/dataform/constants");
7
+ const utils_1 = require("@headless-adminapp/app/dataform/DataFormProvider/utils");
5
8
  const hooks_1 = require("@headless-adminapp/app/dataform/hooks");
9
+ const useEventManager_1 = require("@headless-adminapp/app/dataform/hooks/useEventManager");
6
10
  const locale_1 = require("@headless-adminapp/app/locale");
7
- const utils_1 = require("@headless-adminapp/app/locale/utils");
11
+ const utils_2 = require("@headless-adminapp/app/locale/utils");
12
+ const mutable_1 = require("@headless-adminapp/app/mutable");
13
+ const react_1 = require("react");
8
14
  const react_hook_form_1 = require("react-hook-form");
9
15
  const componentStore_1 = require("../componentStore");
10
16
  const SectionControl_1 = require("../DataForm/SectionControl");
@@ -15,9 +21,23 @@ function SectionContainer({ section }) {
15
21
  const schema = (0, hooks_1.useDataFormSchema)();
16
22
  const formInstance = (0, hooks_1.useFormInstance)();
17
23
  const recordId = (0, hooks_1.useRecordId)();
18
- const readonly = (0, hooks_1.useFormIsReadonly)();
24
+ const isFormReadonly = (0, hooks_1.useFormIsReadonly)();
19
25
  const { language } = (0, locale_1.useLocale)();
20
- return ((0, jsx_runtime_1.jsx)(layout_1.FormSection, { title: (0, utils_1.localizedLabel)(language, section), columnCount: section.columnCount, labelPosition: section.labelPosition, noPadding: section.noPadding, hideLabel: section.hideLabel, children: section.controls.map((control, index) => {
26
+ const eventManager = (0, useEventManager_1.useEventManager)();
27
+ const disabledControls = (0, mutable_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.disabledControls);
28
+ const hiddenControls = (0, mutable_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.hiddenControls);
29
+ const requiredFields = (0, mutable_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.requiredFields);
30
+ const hiddenSections = (0, mutable_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.hiddenSections);
31
+ const visibleControls = (0, react_1.useMemo)(() => section.controls.filter((control) => {
32
+ return !(0, utils_1.getIsControlHidden)({
33
+ control,
34
+ hiddenControls,
35
+ });
36
+ }), [section.controls, hiddenControls]);
37
+ if (hiddenSections[section.name] || visibleControls.length === 0) {
38
+ return null;
39
+ }
40
+ return ((0, jsx_runtime_1.jsx)(layout_1.FormSection, { title: (0, utils_2.localizedLabel)(language, section), columnCount: section.columnCount, labelPosition: section.labelPosition, noPadding: section.noPadding, hideLabel: section.hideLabel, children: visibleControls.map((control, index) => {
21
41
  switch (control.type) {
22
42
  case 'standard': {
23
43
  const attribute = schema.attributes[control.attributeName];
@@ -28,6 +48,17 @@ function SectionContainer({ section }) {
28
48
  Control = OverrideControl;
29
49
  }
30
50
  }
51
+ const disabled = (0, utils_1.getIsFieldDisabled)({
52
+ isFormReadonly,
53
+ disabledFields: disabledControls,
54
+ attribute,
55
+ control,
56
+ });
57
+ const required = (0, utils_1.getIsFieldRequired)({
58
+ attribute,
59
+ requiredFields,
60
+ control,
61
+ });
31
62
  return ((0, jsx_runtime_1.jsx)("div", { style: {
32
63
  gridColumn: control.span
33
64
  ? `var(--section-item-span-${control.span})`
@@ -42,7 +73,10 @@ function SectionContainer({ section }) {
42
73
  attribute.localizedLabels?.[language] ??
43
74
  control.label ??
44
75
  attribute.label;
45
- return ((0, jsx_runtime_1.jsx)(SectionControl_1.SectionControlWrapper, { label: label, labelPosition: section.labelPosition, required: attribute.required, isError: isError, errorMessage: errorMessage, children: (0, jsx_runtime_1.jsx)(Control, { attribute: attribute, name: control.attributeName, value: field.value, onChange: field.onChange, onBlur: field.onBlur, errorMessage: errorMessage, isError: isError, disabled: readonly, label: label, placeholder: label, allowNavigation: true, allowNewRecord: true, fileServiceContext: {
76
+ return ((0, jsx_runtime_1.jsx)(SectionControl_1.SectionControlWrapper, { label: label, labelPosition: section.labelPosition, required: required, isError: isError, errorMessage: errorMessage, children: (0, jsx_runtime_1.jsx)(Control, { attribute: attribute, name: control.attributeName, value: field.value, onChange: (value) => {
77
+ field.onChange(value);
78
+ eventManager.emit(constants_1.EVENT_KEY_ON_FIELD_CHANGE, control.attributeName, value);
79
+ }, onBlur: field.onBlur, errorMessage: errorMessage, isError: isError, readOnly: disabled, label: label, placeholder: label, allowNavigation: true, allowNewRecord: true, fileServiceContext: {
46
80
  type: 'entity-form',
47
81
  recordId,
48
82
  attributeName: control.attributeName,
@@ -11,7 +11,6 @@ export interface StandardControlProps {
11
11
  onChange: (value: any) => void;
12
12
  onBlur?: () => void;
13
13
  fileServiceContext?: Record<string, unknown>;
14
- disabled?: boolean;
15
14
  borderOnFocusOnly?: boolean;
16
15
  hideLabel?: boolean;
17
16
  hidePlaceholder?: boolean;
@@ -35,12 +35,12 @@ const StandardControl = (props) => {
35
35
  name, value, onBlur, onChange,
36
36
  // dataService,
37
37
  // fileService,
38
- disabled, borderOnFocusOnly, placeholder: _placeholder,
38
+ borderOnFocusOnly, placeholder: _placeholder,
39
39
  // hideLabel,
40
40
  hidePlaceholder, readOnly,
41
41
  // quickViewControl,
42
42
  allowNavigation, allowNewRecord, } = props;
43
- const isDisabled = attribute.readonly || disabled;
43
+ const isDisabled = readOnly;
44
44
  // const label = hideLabel ? undefined : _label ?? attribute.label;
45
45
  const placeholder = hidePlaceholder
46
46
  ? undefined
@@ -51,7 +51,7 @@ const StandardControl = (props) => {
51
51
  const { schemaStore, experienceStore } = (0, hooks_1.useMetadata)();
52
52
  // const { openQuickCreate } = useQuickCreateForm();
53
53
  switch (attribute.type) {
54
- case 'string':
54
+ case 'string': {
55
55
  const controlProps = {
56
56
  name,
57
57
  placeholder,
@@ -59,7 +59,7 @@ const StandardControl = (props) => {
59
59
  onChange,
60
60
  onBlur,
61
61
  error: isError,
62
- disabled: isDisabled,
62
+ disabled: readOnly,
63
63
  readOnly,
64
64
  };
65
65
  switch (attribute.format) {
@@ -91,6 +91,7 @@ const StandardControl = (props) => {
91
91
  default:
92
92
  return (0, jsx_runtime_1.jsx)(react_1.Fragment, {});
93
93
  }
94
+ }
94
95
  case 'number': {
95
96
  switch (attribute.format) {
96
97
  case 'decimal': {
@@ -38,6 +38,9 @@ const UploadImageDialog = ({ currentImage, recordTitle, recordId, onChange, open
38
38
  };
39
39
  const { isPending, mutate: handleApply } = (0, react_query_1.useMutation)({
40
40
  mutationFn: async () => {
41
+ if (!fileService) {
42
+ throw new Error('File service is not available');
43
+ }
41
44
  if (file) {
42
45
  const url = await fileService.uploadFile(file, {
43
46
  context: {
@@ -13,12 +13,12 @@ export declare function useAttachmentSelector({ fileService, fileServiceContext,
13
13
  selectFile: (accept: string) => void;
14
14
  };
15
15
  export interface AttachmentImageControlProps extends ControlProps<FileObject> {
16
- fileService: IFileService;
16
+ fileService: IFileService | null;
17
17
  fileServiceContext?: Record<string, unknown>;
18
18
  location: AttachmentAttribute['location'];
19
19
  }
20
20
  interface AttachmentControlProps extends ControlProps<FileObject> {
21
- fileService: IFileService;
21
+ fileService: IFileService | null;
22
22
  fileServiceContext?: Record<string, unknown>;
23
23
  location: AttachmentAttribute['location'];
24
24
  format: AttachmentAttribute['format'];
@@ -45,7 +45,7 @@ readOnly, }) {
45
45
  setInternalValue(value);
46
46
  onChange?.(Number(value));
47
47
  };
48
- return ((0, jsx_runtime_1.jsx)(react_components_1.Input, { placeholder: placeholder, id: id, autoFocus: autoFocus, name: name, value: internalValue, onChange: handleChange, onBlur: () => onBlur?.(), appearance: "filled-darker", onFocus: () => onFocus?.(), contentBefore: (0, jsx_runtime_1.jsx)("div", { children: symbol }), disabled: disabled, readOnly: readOnly, style: {
48
+ return ((0, jsx_runtime_1.jsx)(react_components_1.Input, { placeholder: placeholder, id: id, autoFocus: autoFocus, name: name, value: internalValue, onChange: handleChange, onBlur: () => onBlur?.(), appearance: "filled-darker", onFocus: () => onFocus?.(), contentBefore: (0, jsx_runtime_1.jsx)("div", { children: symbol }), readOnly: readOnly || disabled, style: {
49
49
  width: '100%',
50
50
  } }));
51
51
  }
@@ -46,7 +46,7 @@ function DecimalControl({ value, onChange, id, name, onBlur, onFocus, error, dis
46
46
  setInternalValue(value);
47
47
  onChange?.(Number(value));
48
48
  };
49
- return ((0, jsx_runtime_1.jsx)(react_components_1.Input, { placeholder: placeholder, id: id, appearance: "filled-darker", name: name, value: internalValue, onChange: handleChange, onBlur: () => onBlur?.(), onFocus: () => onFocus?.(), disabled: disabled, readOnly: readOnly, style: {
49
+ return ((0, jsx_runtime_1.jsx)(react_components_1.Input, { placeholder: placeholder, id: id, appearance: "filled-darker", name: name, value: internalValue, onChange: handleChange, onBlur: () => onBlur?.(), onFocus: () => onFocus?.(), readOnly: readOnly || disabled, style: {
50
50
  width: '100%',
51
51
  } }));
52
52
  }
@@ -3,4 +3,4 @@ export interface EmailControlProps extends ControlProps<string> {
3
3
  autoComplete?: string;
4
4
  textTransform?: 'capitalize' | 'uppercase' | 'lowercase' | 'none';
5
5
  }
6
- export declare function EmailControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, autoComplete, textTransform, readOnly, }: EmailControlProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare function EmailControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, autoComplete, textTransform, readOnly, }: Readonly<EmailControlProps>): import("react/jsx-runtime").JSX.Element;
@@ -15,7 +15,7 @@ function EmailControl({ value, onChange, id, name, onBlur, onFocus, placeholder,
15
15
  : onChange?.(e.target.value);
16
16
  }, onBlur: () => onBlur?.(), onFocus: () => onFocus?.(),
17
17
  // invalid={error}
18
- disabled: disabled, readOnly: readOnly, autoComplete: autoComplete, style: {
18
+ readOnly: disabled || readOnly, autoComplete: autoComplete, style: {
19
19
  flex: 1,
20
20
  paddingRight: react_components_1.tokens.spacingHorizontalXS,
21
21
  }, contentAfter: !!value ? ((0, jsx_runtime_1.jsx)(react_components_1.Button, { onClick: () => window.open(`mailto:${value}`, '_blank'), color: "primary", appearance: "transparent", icon: (0, jsx_runtime_1.jsx)(icons_1.Icons.Mail, {}), size: "small" })) : undefined }));
@@ -5,7 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  /* eslint-disable unused-imports/no-unused-vars */
6
6
  const react_components_1 = require("@fluentui/react-components");
7
7
  function IntegerControl({ value, onChange, id, name, onBlur, onFocus, error, disabled, placeholder, borderOnFocusOnly, readOnly, }) {
8
- return ((0, jsx_runtime_1.jsx)(react_components_1.SpinButton, { appearance: "filled-darker", placeholder: placeholder, id: id, name: name, value: value ?? null, onChange: (e, data) => {
8
+ return ((0, jsx_runtime_1.jsx)(react_components_1.SpinButton, { appearance: "filled-darker", placeholder: placeholder, id: id, name: name, value: value ?? null, readOnly: readOnly || disabled, onChange: (e, data) => {
9
9
  if (data.value !== undefined) {
10
10
  onChange?.(data.value);
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/fluent",
3
- "version": "0.0.17-alpha.59",
3
+ "version": "0.0.17-alpha.62",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -42,5 +42,5 @@
42
42
  "uuid": "11.0.3",
43
43
  "yup": "^1.4.0"
44
44
  },
45
- "gitHead": "813d07729a10a5613b46f012ba4b24bcaab384dc"
45
+ "gitHead": "7b4ba8b46dc270e88055b7352d74fae7a2363cd0"
46
46
  }