@progress/sitefinity-nextjs-sdk
Version:
Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.
107 lines (106 loc) • 4.77 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { getMinimumWidgetContext } from '../../../editor/widget-framework/widget-context';
import { htmlAttributes, setWarning } from '../../../editor/widget-framework/attributes';
import { getChoiceItems } from './dynamic-list.view-props';
import { Tracer } from '@progress/sitefinity-nextjs-sdk/diagnostics/empty';
import { RenderView } from '../../common/render-view';
import { CheckboxesDefaultView } from '../checkboxes/checkboxes.view';
import { DropdownDefaultView } from '../dropdown/dropdown.view';
import { classNames } from '../../../editor/utils/classNames';
import { StylingConfig } from '../../styling/styling-config';
import { SelectionMode } from './selection-modes';
export async function DynamicList(props) {
const { span, ctx } = Tracer.traceWidget(props, true);
const entity = props.model.Properties;
const requestContext = props.requestContext;
const choices = await getChoiceItems(entity, requestContext, ctx);
let defaultRender;
const baseEntity = {
Choices: choices,
CssClass: entity.CssClass,
Hidden: entity.Hidden,
InstructionalText: entity.InstructionalText,
SfFieldName: entity.SfFieldName,
Required: entity.Required,
RequiredErrorMessage: entity.RequiredErrorMessage || '',
SfViewName: 'Default',
Label: entity.Label || ''
};
if (entity.SfViewName === 'Dropdown') {
if (choices.length > 0) {
choices.unshift({ Name: 'Select', Value: '', Selected: true });
}
const cssClass = entity.CssClass || '';
const viewProps = {
choices: choices || [],
cssClass: classNames(cssClass, StylingConfig.FieldSizeClasses[('Width' + entity.FieldSize)]) || '',
instructionalText: entity.InstructionalText,
label: entity.Label || '',
required: entity.Required,
requiredErrorMessage: entity.RequiredErrorMessage || '',
fieldSize: entity.FieldSize,
sorting: 'Manual',
sfFieldName: entity.SfFieldName,
attributes: {},
widgetContext: {
requestContext: props.requestContext,
model: {
Id: props.model.Id
}
}
};
defaultRender = (_jsx(DropdownDefaultView, { ...viewProps }));
}
else {
const viewProps = {
choices: baseEntity.Choices || [],
cssClass: entity.CssClass || '',
hasAdditionalChoice: false,
instructionalText: entity.InstructionalText || '',
label: entity.Label || '',
required: entity.Required,
requiredErrorMessage: entity.RequiredErrorMessage,
columnsNumber: entity.ColumnsNumber,
sfFieldName: entity.SfFieldName,
attributes: {},
widgetContext: {
requestContext: props.requestContext,
model: {
Id: props.model.Id
}
}
};
defaultRender = (_jsx(CheckboxesDefaultView, { ...viewProps }));
}
const dataAttributes = htmlAttributes(props);
if (props.requestContext.isEdit) {
if (entity.ListType === SelectionMode.Content) {
if (entity.SelectedContent === null || entity.SelectedContent.Content === null || !entity.SelectedContent.Content[0].Type) {
setWarning(dataAttributes, 'No list type have been selected');
}
else if (choices.length === 0) {
setWarning(dataAttributes, 'Selected list is empty');
}
}
else if (entity.ListType === SelectionMode.Classification) {
if (entity.ClassificationSettings === null || entity.ClassificationSettings.selectionMode === null || entity.ClassificationSettings.selectedTaxonomyName === null) {
setWarning(dataAttributes, 'No list type have been selected');
}
else if (choices.length === 0) {
setWarning(dataAttributes, 'Selected list is empty');
}
}
}
const viewProps = {
label: entity.Label,
instructionalText: entity.InstructionalText,
choices: choices,
columnsNumber: entity.ColumnsNumber,
cssClass: entity.CssClass,
fieldName: entity.SfViewName,
required: entity.Required,
attributes: { ...dataAttributes },
widgetContext: getMinimumWidgetContext(props)
};
return (_jsx(RenderView, { viewName: entity.SfViewName, widgetKey: props.model.Name, traceSpan: span, viewProps: viewProps, children: _jsx("div", { ...viewProps.attributes, children: defaultRender }) }));
}