Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3a0d6d3
Remove depth and transparentBorder
tdurnford Mar 31, 2021
79aa2d6
Update OneOfField dropdown styles
tdurnford Mar 31, 2021
ef53dc5
Remove ObjectArrayField
tdurnford Mar 31, 2021
8696cc2
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Mar 31, 2021
8034416
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Apr 13, 2021
740c0b3
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Apr 14, 2021
4a683df
fix tests
tdurnford Apr 14, 2021
73d74b5
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Apr 14, 2021
a60deef
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Apr 14, 2021
dc29cb6
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Apr 16, 2021
29a6432
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Apr 16, 2021
87426a7
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Apr 19, 2021
fa54381
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Apr 28, 2021
cbcfdf6
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford Apr 30, 2021
49c9b72
Refactor OpenObjectField
tdurnford Apr 30, 2021
75793e4
Merge branch 'durnford/fix/refactor-adaptive-form' of github.com:micr…
tdurnford Apr 30, 2021
8dc4203
updated test
tdurnford Apr 30, 2021
bcb1fd4
minor
tdurnford Apr 30, 2021
ac3320a
fix test
tdurnford Apr 30, 2021
9063b01
Merge branch 'main' into durnford/fix/refactor-adaptive-form
beyackle Apr 30, 2021
5b323d6
Merge branch 'main' into durnford/fix/refactor-adaptive-form
beyackle Apr 30, 2021
015319e
minor
tdurnford Apr 30, 2021
0c040f6
Merge branch 'durnford/fix/refactor-adaptive-form' of github.com:micr…
tdurnford Apr 30, 2021
d071cfa
Merge branch 'main' into durnford/fix/refactor-adaptive-form
beyackle Apr 30, 2021
d43a6e1
Merge branch 'main' into durnford/fix/refactor-adaptive-form
beyackle May 3, 2021
00d6fcf
Merge branch 'main' into durnford/fix/refactor-adaptive-form
beyackle May 3, 2021
9647966
Merge branch 'main' into durnford/fix/refactor-adaptive-form
beyackle May 3, 2021
4032f5d
Merge branch 'main' into durnford/fix/refactor-adaptive-form
beyackle May 3, 2021
f3a1c77
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 4, 2021
553c999
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 4, 2021
9234107
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 5, 2021
9d5537e
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 5, 2021
0683dc4
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 6, 2021
017fd8f
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 7, 2021
212d183
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 10, 2021
82a1d7b
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 11, 2021
74cd6b3
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 11, 2021
99d2a8b
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 14, 2021
8b24391
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 17, 2021
87ed5fd
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 17, 2021
8a3ee8e
Merge branch 'main' into durnford/fix/refactor-adaptive-form
tdurnford May 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export const AdaptiveForm: React.FC<AdaptiveFormProps> = function AdaptiveForm(p
onChange={(newData) => onChange({ ...formData, ...newData })}
/>
<SchemaField
isRoot
definitions={schema?.definitions}
depth={-1}
id={formData?.$designer?.id ? `root[${formData?.$designer?.id}]` : 'root'}
name="root"
rawErrors={errors}
Expand Down
37 changes: 37 additions & 0 deletions Composer/packages/adaptive-form/src/components/AddButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import React from 'react';
import styled from '@emotion/styled';
import { ActionButton, IButtonStyles } from 'office-ui-fabric-react/lib/components/Button';
import { FluentTheme } from '@uifabric/fluent-theme';
import formatMessage from 'format-message';

export const ButtonContainer = styled.div({
borderTop: `1px solid ${FluentTheme.palette.neutralLight}`,
width: '100%',
});

export const actionButtonStyles: IButtonStyles = {
root: {
fontSize: FluentTheme.fonts.small.fontSize,
fontWeight: FluentTheme.fonts.small.fontWeight,
color: FluentTheme.palette.themePrimary,
paddingLeft: 8,
height: 20,
},
};

type Props = {
onClick: () => void;
};

export const AddButton = ({ children, onClick }: React.PropsWithChildren<Props>) => {
return (
<ButtonContainer>
<ActionButton styles={actionButtonStyles} onClick={onClick}>
{children ?? formatMessage('Add new')}
</ActionButton>
</ButtonContainer>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const styles = {
header: css`
background-color: #eff6fc;
display: flex;
margin: 4px 0px;
margin: 4px -18px;
align-items: center;
`,
};
Expand Down
4 changes: 0 additions & 4 deletions Composer/packages/adaptive-form/src/components/FormRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ export interface FormRowProps extends Omit<FieldProps, 'onChange'> {
export function getRowProps(rowProps: FormRowProps, field: string): FieldProps {
const {
id,
depth,
schema,
definitions,
value,
uiOptions,
transparentBorder,
className,
label,
rawErrors,
Expand Down Expand Up @@ -60,9 +58,7 @@ export function getRowProps(rowProps: FormRowProps, field: string): FieldProps {
uiOptions: newUiOptions,
value: !newUiOptions.additionalField && value ? value[field] : value,
onChange: !newUiOptions.additionalField ? handleChange : onChange,
depth,
definitions,
transparentBorder,
className,
onBlur,
onFocus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ const FormTitle: React.FC<FormTitleProps> = (props) => {
<div>
<EditableField
ariaLabel={formatMessage('form title')}
depth={0}
fontSize={FontSizes.size20}
id="form-title"
name="$designer.name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { getUIOptions, resolveFieldWidget, resolveRef, getUiLabel, getUiPlacehol
import { ErrorMessage } from './ErrorMessage';

const schemaField = {
container: (depth = 0) => css`
container: (isRoot?: boolean) => css`
display: flex;
flex-direction: column;
margin: 10px ${depth === 0 ? 18 : 0}px;
margin: 10px ${isRoot ? 18 : 0}px;

label: SchemaFieldContainer;
`,
Expand All @@ -34,6 +34,7 @@ export const SchemaField: React.FC<FieldProps> = (props) => {
expression,
onBlur,
id,
isRoot,
...rest
} = props;
const formUIOptions = useFormConfig();
Expand Down Expand Up @@ -108,7 +109,7 @@ export const SchemaField: React.FC<FieldProps> = (props) => {
};

return (
<div className={className} css={schemaField.container(props.depth)}>
<div className={className} css={schemaField.container(isRoot)}>
<FieldWidget {...fieldProps} />
{!hideError && !uiOptions.hideError && error}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function WithTypeIcons(WrappedComponent: FieldWidget): FieldWidget {
<div css={styles.mainWrapper}>
{iconText && <div css={styles.iconWrapper}>{iconText}</div>}
<div css={styles.componentWrapper}>
<WrappedComponent hasIcon {...props} label={undefined} />
<WrappedComponent hasIcon {...props} label={false} />
</div>
</div>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const field: FormRowProps = {
onChange: jest.fn(),
row: '',
definitions: {},
depth: 0,
id: 'test',
name: 'row',
schema: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jest.mock('@bfc/extension-client', () => ({

const defaultProps: FieldProps = {
onChange: jest.fn(),
depth: 0,
id: 'test-id',
name: 'test-name',
definitions: { foo: { type: 'string' } },
Expand Down
100 changes: 22 additions & 78 deletions Composer/packages/adaptive-form/src/components/fields/ArrayField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
// Licensed under the MIT License.
/** @jsx jsx */
import { jsx } from '@emotion/core';
import React, { useState } from 'react';
import { TextField } from 'office-ui-fabric-react/lib/TextField';
import { IconButton } from 'office-ui-fabric-react/lib/Button';
import { TooltipHost } from 'office-ui-fabric-react/lib/Tooltip';
import { SharedColors, NeutralColors, FontSizes } from '@uifabric/fluent-theme';
import React from 'react';
import { FieldProps } from '@bfc/extension-client';
import formatMessage from 'format-message';

import { getArrayItemProps, useArrayItems } from '../../utils';
import { FieldLabel } from '../FieldLabel';
import { AddButton } from '../AddButton';

import { arrayField } from './styles';
import { ArrayFieldItem } from './ArrayFieldItem';
import { UnsupportedField } from './UnsupportedField';

const ArrayField: React.FC<FieldProps<unknown[]>> = (props) => {
const {
value = [],
value,
onChange,
schema,
label,
Expand All @@ -29,89 +24,38 @@ const ArrayField: React.FC<FieldProps<unknown[]>> = (props) => {
uiOptions,
className,
required,
placeholder,
...rest
} = props;
const [newValue, setNewValue] = useState<string>();
const { arrayItems, handleChange, addItem } = useArrayItems(value, onChange);

const moreLabel = formatMessage('Item actions');

const handleNewChange = (_e: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, newValue?: string) =>
setNewValue(newValue || '');

const handleKeyDown = (event) => {
if (event.key.toLowerCase() === 'enter') {
event.preventDefault();

if (newValue) {
addItem(newValue);
setNewValue('');
}
}
};

const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;

const onClick = React.useCallback(() => {
addItem(undefined);
}, [addItem]);

if (!itemSchema || itemSchema === true) {
return <UnsupportedField {...props} />;
}

return (
<div className={className}>
<FieldLabel description={description} helpLink={uiOptions?.helpLink} id={id} label={label} required={required} />
<div>
{arrayItems.map((element, idx) => (
<ArrayFieldItem
{...rest}
key={element.id}
stackArrayItems
transparentBorder
error={rawErrors[idx]}
id={id}
label={false}
rawErrors={rawErrors[idx]}
schema={itemSchema}
uiOptions={uiOptions}
value={element.value}
{...getArrayItemProps(arrayItems, idx, handleChange)}
/>
))}
</div>
<div css={arrayField.inputFieldContainer}>
<div css={arrayField.field}>
<TextField
ariaLabel={formatMessage('New value')}
data-testid="string-array-text-input"
iconProps={{
iconName: 'ReturnKey',
style: { color: SharedColors.cyanBlue10, opacity: 0.6 },
}}
placeholder={placeholder}
styles={{ root: { width: '100%' } }}
value={newValue}
onChange={handleNewChange}
onKeyDown={handleKeyDown}
/>
<TooltipHost content={moreLabel}>
<IconButton
disabled
ariaLabel={moreLabel}
menuIconProps={{ iconName: 'MoreVertical' }}
styles={{
menuIcon: {
backgroundColor: NeutralColors.white,
color: NeutralColors.gray130,
fontSize: FontSizes.size16,
},
rootDisabled: {
backgroundColor: NeutralColors.white,
},
}}
/>
</TooltipHost>
</div>
</div>
{arrayItems.map((element, idx) => (
<ArrayFieldItem
{...rest}
key={element.id}
error={rawErrors[idx]}
id={id}
label={false}
rawErrors={rawErrors[idx]}
schema={itemSchema}
uiOptions={uiOptions}
value={element.value}
{...getArrayItemProps(arrayItems, idx, handleChange)}
/>
))}
<AddButton onClick={onClick} />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ const ArrayFieldItem: React.FC<ArrayFieldItemProps> = (props) => {
onRemove,
index,
label,
depth,
onBlur,
stackArrayItems,
transparentBorder,
uiOptions,
value,
className,
Expand Down Expand Up @@ -89,12 +86,10 @@ const ArrayFieldItem: React.FC<ArrayFieldItemProps> = (props) => {
<div css={arrayItem.field}>
<SchemaField
{...rest}
css={arrayItem.schemaFieldOverride(!!stackArrayItems)}
depth={depth + 1}
label={!stackArrayItems || label === false ? false : undefined}
css={arrayItem.schemaFieldOverride}
label={label}
placeholder={undefined}
rawErrors={typeof rawErrors === 'object' ? rawErrors[index] : rawErrors}
transparentBorder={!stackArrayItems ? transparentBorder : undefined}
uiOptions={{ ...uiOptions, placeholder: undefined }}
value={value}
onBlur={handleBlur}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,11 @@ import { FieldProps } from '@bfc/extension-client';
interface EditableFieldProps extends Omit<FieldProps, 'definitions'> {
fontSize?: string;
styles?: Partial<ITextFieldStyles>;
transparentBorder?: boolean;
ariaLabel?: string;
}

const EditableField: React.FC<EditableFieldProps> = (props) => {
const {
depth,
styles = {},
placeholder,
fontSize,
onChange,
onBlur,
value,
id,
error,
className,
transparentBorder,
ariaLabel,
} = props;
const { styles = {}, placeholder, fontSize, onChange, onBlur, value, id, error, className, ariaLabel } = props;
const [editing, setEditing] = useState<boolean>(false);
const [hasFocus, setHasFocus] = useState<boolean>(false);
const [localValue, setLocalValue] = useState<string | undefined>(value);
Expand All @@ -55,7 +41,7 @@ const EditableField: React.FC<EditableFieldProps> = (props) => {
let borderColor: string | undefined = undefined;

if (!editing && !error) {
borderColor = localValue || transparentBorder || depth > 1 ? 'transparent' : NeutralColors.gray30;
borderColor = localValue ? 'transparent' : NeutralColors.gray30;
}

return (
Expand Down
Loading