mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
fix column key reseting after column type change
This commit is contained in:
@@ -12,11 +12,16 @@ import { getFieldProp } from "@src/components/fields";
|
||||
import { analytics } from "analytics";
|
||||
import { useProjectContext } from "@src/contexts/ProjectContext";
|
||||
|
||||
const AUDIT_FIELD_TYPES = [
|
||||
FieldType.createdBy,
|
||||
FieldType.createdAt,
|
||||
FieldType.updatedBy,
|
||||
FieldType.updatedAt,
|
||||
];
|
||||
export interface INewColumnProps extends IMenuModalProps {
|
||||
data: Record<string, any>;
|
||||
openSettings: (column: any) => void;
|
||||
}
|
||||
|
||||
export default function NewColumn({
|
||||
open,
|
||||
data,
|
||||
@@ -31,16 +36,7 @@ export default function NewColumn({
|
||||
const [type, setType] = useState(FieldType.shortText);
|
||||
const requireConfiguration = getFieldProp("requireConfiguration", type);
|
||||
|
||||
const isAuditField =
|
||||
type === FieldType.createdBy ||
|
||||
type === FieldType.createdAt ||
|
||||
type === FieldType.updatedBy ||
|
||||
type === FieldType.updatedAt;
|
||||
|
||||
useEffect(() => {
|
||||
if (type !== FieldType.id && !isAuditField)
|
||||
setFieldKey(_camel(columnLabel));
|
||||
}, [columnLabel, type, isAuditField]);
|
||||
const isAuditField = AUDIT_FIELD_TYPES.includes(type);
|
||||
|
||||
useEffect(() => {
|
||||
switch (type) {
|
||||
@@ -90,7 +86,12 @@ export default function NewColumn({
|
||||
label="Column name"
|
||||
type="text"
|
||||
fullWidth
|
||||
onChange={(e) => setColumnLabel(e.target.value)}
|
||||
onChange={(e) => {
|
||||
setColumnLabel(e.target.value);
|
||||
if (type !== FieldType.id && !isAuditField) {
|
||||
setFieldKey(_camel(columnLabel));
|
||||
}
|
||||
}}
|
||||
helperText="Set the user-facing name for this column."
|
||||
/>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user