Skip to content

Commit

Permalink
(feat) O3-3109 deprecate type within inbuiltControls
Browse files Browse the repository at this point in the history
  • Loading branch information
pirupius committed Apr 25, 2024
1 parent 7c35750 commit 2d08d77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 39 deletions.
54 changes: 18 additions & 36 deletions src/registry/inbuilt-components/inbuiltControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,96 +26,78 @@ import UiSelectExtended from '../../components/inputs/ui-select-extended/ui-sele

export const inbuiltControls: Array<RegistryItem<React.ComponentType<FormFieldProps>>> = [
{
name: 'TextField',
name: 'text',
component: TextField,
type: 'text',
},
{
name: 'Radio',
name: 'radio',
component: Radio,
type: 'radio',
},
{
name: 'DateField',
name: 'date',
component: DateField,
type: 'date',
},
{
name: 'NumberField',
name: 'number',
component: NumberField,
type: 'number',
alias: 'numeric',
},
{
name: 'MultiSelect',
name: 'checkbox',
component: MultiSelect,
type: 'checkbox',
alias: 'multiCheckbox',
},
{
name: 'ContentSwitcher',
name: 'content-switcher',
component: ContentSwitcher,
type: 'content-switcher',
},
{
name: 'Dropdown',
name: 'select',
component: Dropdown,
type: 'select',
},
{
name: 'TextArea',
name: 'textarea',
component: TextArea,
type: 'textarea',
},
{
name: 'Toggle',
name: 'toggle',
component: Toggle,
type: 'toggle',
},
{
name: 'ObsGroup',
name: 'group',
component: ObsGroup,
type: 'group',
},
{
name: 'Repeat',
name: 'repeating',
component: Repeat,
type: 'repeating',
},
{
name: 'FixedValue',
name: 'fixed-value',
component: FixedValue,
type: 'fixed-value',
},
{
name: 'Markdown',
name: 'markdown',
component: Markdown,
type: 'markdown',
},
{
name: 'ExtensionParcel',
name: 'extension-widget',
component: ExtensionParcel,
type: 'extension-widget',
},
{
name: 'DateField',
name: 'datetime',
component: DateField,
type: 'datetime',
},
{
name: 'UiSelectExtended',
name: 'ui-select-extended',
component: UiSelectExtended,
type: 'ui-select-extended',
},
{
name: 'File',
name: 'file',
component: File,
type: 'file',
},
{
name: 'WorkspaceLauncher',
name: 'workspace-launcher',
component: WorkspaceLauncher,
type: 'workspace-launcher',
},
...controlTemplates.map((template) => ({
name: `${template.name}Control`,
Expand Down
7 changes: 4 additions & 3 deletions src/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export interface FieldSubmissionHandlerRegistration extends ComponentRegistratio
type: string;
}


export interface FormsRegistryStoreState {
controls: CustomControlRegistration[];
fieldValidators: ComponentRegistration<FormFieldValidator>[];
Expand Down Expand Up @@ -116,11 +115,13 @@ export async function getRegisteredControl(renderType: string) {
if (registryCache.controls[renderType]) {
return registryCache.controls[renderType];
}
let component = inbuiltControls.find((item) => item.type === renderType || item?.alias === renderType)?.component;
let component = inbuiltControls.find(
(control) => control.name === renderType || control?.alias === renderType,
)?.component;
// if undefined, try serching through the registered custom controls
if (!component) {
const importedControl = await getFormsStore()
.controls.find((item) => item.type === renderType || item?.alias === renderType)
.controls.find((control) => control.name === renderType || control?.alias === renderType)
?.load?.();
component = importedControl?.default;
}
Expand Down

0 comments on commit 2d08d77

Please sign in to comment.