-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/dto-form-field' into feat/dto-form
# Conflicts: # src/types/field/index.ts
- Loading branch information
Showing
20 changed files
with
145 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,29 @@ | ||
import { BasicField, IColumnSchema } from '../../../types' | ||
import { | ||
IColumnSchema, | ||
IDropdownFieldSchema, | ||
IShortTextFieldSchema, | ||
OmitUnusedValidatorProps, | ||
} from '../../../types' | ||
|
||
/** | ||
* Return type of createAnswerFieldFromColumn(). | ||
* This is a subset of IFieldSchema (note that the | ||
* fieldType is restricted) and allows the result to be | ||
* passed into validateField(). | ||
* */ | ||
type ColumnWithFieldProperties = IColumnSchema & { | ||
getQuestion: { (): string } | ||
description: string | ||
disabled: boolean | ||
fieldType: BasicField.ShortText | BasicField.Dropdown | ||
} | ||
type ColumnWithFieldProperties = | ||
| OmitUnusedValidatorProps<IShortTextFieldSchema> | ||
| OmitUnusedValidatorProps<IDropdownFieldSchema> | ||
|
||
/** | ||
* Takes a table field column and generates a form field by | ||
* filling in the missing attributes. | ||
* filling in the missing fieldType attribute. | ||
* */ | ||
export const createAnswerFieldFromColumn = ( | ||
column: IColumnSchema, | ||
): ColumnWithFieldProperties => { | ||
const columnField = { | ||
// Convert mongoose document to object first, | ||
// otherwise the values will not be correctly spread | ||
return { | ||
...column.toObject(), | ||
disabled: false, | ||
description: 'some description', | ||
get fieldType() { | ||
return column.columnType | ||
}, | ||
getQuestion() { | ||
return 'some question' | ||
}, | ||
} | ||
return columnField as ColumnWithFieldProperties | ||
fieldType: column.columnType, | ||
} as ColumnWithFieldProperties | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.