Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dynamic value field between #379

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -90,7 +90,6 @@ const ActionTable = ({ actions }: ActionProps) => {
accessorKey: 'value',
meta: {
list: 'value',
as: 'textarea',
},
},
{
Expand Down Expand Up @@ -131,6 +130,9 @@ const ActionTable = ({ actions }: ActionProps) => {
updateData: (selectedActionId: RANDOM_UUID, columnId: string, value: any) => {
dispatch(updateAction({ selectedActionId, name: columnId, value }));
},
updateValueFieldTypes: (selectedActionId: RANDOM_UUID, valueFieldType: 'input' | 'textarea') => {
dispatch(updateAction({ selectedActionId, name: 'valueFieldType', value: valueFieldType }));
},
},
});

Expand Down
27 changes: 24 additions & 3 deletions apps/acf-options-page/src/app/configs/action/editable-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getFieldNameValue } from '@apps/acf-options-page/src/util/element';
import { Action } from '@dhruv-techapps/acf-common';
import { ColumnDef } from '@tanstack/react-table';
import { useEffect, useRef, useState } from 'react';
import { Form } from 'react-bootstrap';
import { Button, Form, InputGroup, OverlayTrigger, Tooltip } from 'react-bootstrap';

export const defaultColumn: Partial<ColumnDef<Action>> = {
cell: Cell,
Expand All @@ -14,6 +14,7 @@ function Cell({ getValue, row: { original }, column: { id, columnDef }, table })
const [value, setValue] = useState(initialValue);
const [isInvalid, setIsInvalid] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);
const [valueFieldType, setValueFieldType] = useState<'input' | 'textarea'>(original.valueFieldType || 'input');

const onBlur = (e) => {
const update = getFieldNameValue(e, { [id]: initialValue });
Expand All @@ -33,14 +34,14 @@ function Cell({ getValue, row: { original }, column: { id, columnDef }, table })
setValue(initialValue);
}, [initialValue, id, original.error]);

return (
const getInput = (as: any) => (
<Form.Control
ref={inputRef}
aria-label={meta?.ariaLabel}
type={meta?.type}
value={value || ''}
name={id}
as={meta?.as}
as={as}
rows={1}
onChange={onChange}
onBlur={onBlur}
Expand All @@ -51,4 +52,24 @@ function Cell({ getValue, row: { original }, column: { id, columnDef }, table })
autoComplete='off'
/>
);

const onValueFieldTypeChange = () => {
const newFieldType = valueFieldType === 'input' ? 'textarea' : 'input';
setValueFieldType(newFieldType);
table.options.meta?.updateValueFieldTypes(original.id, newFieldType);
};

if (id === 'value') {
return (
<InputGroup>
<OverlayTrigger overlay={<Tooltip id={id}>{valueFieldType === 'input' ? `Switch to Textarea` : 'Switch to Input'}</Tooltip>}>
<Button type='button' variant='outline-secondary' id='action-field-type' onClick={onValueFieldTypeChange}>
{valueFieldType === 'input' ? 'I' : 'T'}
</Button>
</OverlayTrigger>
{getInput(valueFieldType)}
</InputGroup>
);
}
return <>{getInput(meta?.as)}</>;
}
3 changes: 2 additions & 1 deletion libs/acf/common/src/lib/model/action-model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Addon } from './addon-model';
import { RANDOM_UUID } from '../common';
import { Addon } from './addon-model';
import { RETRY_OPTIONS } from './setting-model';

// Action Condition
Expand Down Expand Up @@ -73,6 +73,7 @@ export type Action = {
settings?: ActionSettings;
status?: string;
error?: string[];
valueFieldType?: 'text' | 'textarea';
};

export const getDefaultAction = (): Action => ({
Expand Down
Loading