Skip to content

Commit a8d1c62

Browse files
authored
chore(cli): Remove redundant loops and checks (#11929)
1 parent 6bbb925 commit a8d1c62

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

packages/cli/src/commands/generate/scaffold/scaffold.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ import {
4545
builder as serviceBuilder,
4646
} from '../service/service'
4747

48-
// note a better way to do this is in https://github.com/redwoodjs/redwood/pull/3783/files
49-
const NON_EDITABLE_COLUMNS = ['id', 'createdAt', 'updatedAt']
5048
// Any assets that should not trigger an overwrite error and require a --force
5149
const SKIPPABLE_ASSETS = ['scaffold.css']
5250
const PACKAGE_SET = 'Set'
@@ -59,12 +57,19 @@ const getIdName = (model) => {
5957
return model.fields.find((field) => field.isId)?.name
6058
}
6159

62-
const filterAutoGeneratedColumnsForScaffold = (column) => {
60+
const isAutoGeneratedColumnForScaffold = (column) => {
6361
const autoGeneratedFunctions = ['now', 'autoincrement']
64-
return !(
62+
63+
const columnDefaultFunction =
64+
typeof column.default === 'object' && 'name' in column.default
65+
? column.default?.name
66+
: ''
67+
68+
return (
6569
column.isId ||
6670
column.isUpdatedAt ||
67-
autoGeneratedFunctions.includes(column?.default?.name)
71+
column.name === 'createdAt' ||
72+
autoGeneratedFunctions.includes(columnDefaultFunction)
6873
)
6974
}
7075

@@ -400,11 +405,9 @@ const modelRelatedVariables = (model) => {
400405
isRelationalField,
401406
}
402407
})
403-
const editableColumns = columns
404-
.filter((column) => {
405-
return NON_EDITABLE_COLUMNS.indexOf(column.name) === -1
406-
})
407-
.filter(filterAutoGeneratedColumnsForScaffold)
408+
const editableColumns = columns.filter(
409+
(column) => !isAutoGeneratedColumnForScaffold(column),
410+
)
408411
const fieldsToImport = Object.keys(
409412
editableColumns.reduce((accumulator, column) => {
410413
accumulator[column.component] = true

0 commit comments

Comments
 (0)