Repository navigation
add transportation table and creation functionality #66
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8f1993a
add transportation table and creation functionality
yaely20 0fb2daf
update transportation fields and filters
yaely20 3a28c08
address review remarks
yaely20 40ce04c
timeInput
yaely20 6aec46c
Merge branch 'buzz-code:main' into main
yaely20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { | ||
| DateField, | ||
| DateTimeInput, | ||
| ReferenceField, | ||
| required, | ||
| TextField, | ||
| TextInput, | ||
| NumberInput, | ||
| maxLength, | ||
| SelectField, | ||
| } from "react-admin"; | ||
| import { CommonDatagrid } from "@shared/components/crudContainers/CommonList"; | ||
| import { getResourceComponents } from "@shared/components/crudContainers/CommonEntity"; | ||
| import CommonReferenceInput from "@shared/components/fields/CommonReferenceInput"; | ||
| import { useUnique } from "@shared/utils/useUnique"; | ||
| import { commonAdminFilters } from "@shared/components/fields/PermissionFilter"; | ||
| import { defaultYearFilter, yearChoices } from "@shared/utils/yearFilter"; | ||
| import CommonAutocompleteInput from "@shared/components/fields/CommonAutocompleteInput"; | ||
| import CommonTimeInput from "@shared/components/fields/CommonTimeInput"; | ||
|
|
||
| const filters = [ | ||
| ...commonAdminFilters, | ||
| <CommonAutocompleteInput source="year" choices={yearChoices} alwaysOn />, | ||
| <TextInput source="key:$cont" label="שילוט" />, | ||
| <TextInput source="description:$cont" label="תיאור" />, | ||
| ]; | ||
|
|
||
| const filterDefaultValues = { | ||
| year: defaultYearFilter.year, | ||
| }; | ||
|
|
||
| const Datagrid = ({ isAdmin, children, ...props }) => { | ||
| return ( | ||
| <CommonDatagrid {...props}> | ||
| {children} | ||
| {isAdmin && <TextField source="id" />} | ||
| {isAdmin && <ReferenceField source="userId" reference="user" />} | ||
| <TextField source="key" /> | ||
| <TextField source="departureTime" /> | ||
| <TextField source="description" /> | ||
| <SelectField source="year" choices={yearChoices} /> | ||
| {isAdmin && <DateField showDate showTime source="createdAt" />} | ||
| {isAdmin && <DateField showDate showTime source="updatedAt" />} | ||
| </CommonDatagrid> | ||
| ); | ||
| }; | ||
|
|
||
| const Inputs = ({ isCreate, isAdmin }) => { | ||
| const unique = useUnique(); | ||
| return ( | ||
| <> | ||
| {!isCreate && isAdmin && <TextInput source="id" disabled />} | ||
| {isAdmin && ( | ||
| <CommonReferenceInput | ||
| source="userId" | ||
| reference="user" | ||
| validate={required()} | ||
| /> | ||
| )} | ||
|
|
||
| <NumberInput source="key" validate={[required(), unique()]} /> | ||
| <CommonTimeInput source="departureTime" validate={[required()]} /> | ||
| <CommonAutocompleteInput | ||
| source="year" | ||
| choices={yearChoices} | ||
| validate={required()} | ||
| defaultValue={defaultYearFilter.year} | ||
| /> | ||
|
|
||
| <TextInput source="description" multiline validate={maxLength(1000)} /> | ||
|
|
||
| {!isCreate && isAdmin && <DateTimeInput source="createdAt" disabled />} | ||
| {!isCreate && isAdmin && <DateTimeInput source="updatedAt" disabled />} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| const Representation = 'key'; | ||
|
|
||
| const importer = { | ||
| fields: ["key", "departureTime", "description"], | ||
| }; | ||
|
|
||
| const entity = { | ||
| Datagrid, | ||
| Inputs, | ||
| Representation, | ||
| filters, | ||
| filterDefaultValues, | ||
| importer, | ||
| }; | ||
|
|
||
| export default getResourceComponents(entity); |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { | ||
| Column, | ||
| CreateDateColumn, | ||
| Entity, | ||
| Index, | ||
| JoinColumn, | ||
| PrimaryGeneratedColumn, | ||
| UpdateDateColumn, | ||
| BeforeInsert, | ||
| BeforeUpdate, | ||
| } from 'typeorm'; | ||
| import { IHasUserId } from '@shared/base-entity/interface'; | ||
| import { User } from 'src/db/entities/User.entity'; | ||
| import { IsOptional } from 'class-validator'; | ||
| import { CrudValidationGroups } from '@dataui/crud'; | ||
| import { IsNotEmpty, IsUniqueCombination, MaxLength, IsNumber } from '@shared/utils/validation/class-validator-he'; | ||
| import { StringType, NumberType } from '@shared/utils/entity/class-transformer'; | ||
| import { fillDefaultYearValue } from "@shared/utils/entity/year.util"; | ||
|
|
||
| @Index('transportations_users_idx', ['userId'], {}) | ||
| @Index(['userId', 'key', 'year'], { unique: true }) | ||
| @Entity('transportations') | ||
| export class Transportation implements IHasUserId { | ||
| @BeforeInsert() | ||
| @BeforeUpdate() | ||
| async fillFields() { | ||
| fillDefaultYearValue(this); | ||
| } | ||
|
|
||
| @PrimaryGeneratedColumn({ type: 'int', name: 'id' }) | ||
| id: number; | ||
|
|
||
| @Column('int', { name: 'user_id' }) | ||
| userId: number; | ||
|
|
||
| @Column({ nullable: true }) | ||
| year: number; | ||
|
|
||
| @IsOptional({ groups: [CrudValidationGroups.UPDATE] }) | ||
| @NumberType | ||
| @IsNumber({ maxDecimalPlaces: 0 }, { always: true }) | ||
| @IsUniqueCombination(['userId', 'year'], [Transportation, User], { | ||
| always: true, | ||
| }) | ||
| @IsNotEmpty({ groups: [CrudValidationGroups.CREATE] }) | ||
| @Column('int', { name: 'key' }) | ||
| key: number; | ||
|
|
||
| @IsOptional({ groups: [CrudValidationGroups.UPDATE] }) | ||
| @StringType | ||
| @MaxLength(500, { always: true }) | ||
| @IsNotEmpty({ groups: [CrudValidationGroups.CREATE] }) | ||
| @IsOptional({ always: true }) | ||
| @StringType | ||
| @MaxLength(255, { always: true }) | ||
| @Column('varchar', { name: 'departure_time', nullable: true, length: 255 }) | ||
| departureTime: string | null; | ||
|
|
||
| @IsOptional({ always: true }) | ||
| @StringType | ||
| @MaxLength(1000, { always: true }) | ||
| @Column('varchar', { name: 'description', nullable: true, length: 1000 }) | ||
| description: string | null; | ||
|
|
||
| @CreateDateColumn({ name: 'created_at', type: 'timestamp' }) | ||
| createdAt: Date; | ||
|
|
||
| @UpdateDateColumn({ name: 'updated_at', type: 'timestamp' }) | ||
| updatedAt: Date; | ||
|
|
||
| @JoinColumn([{ name: 'user_id', referencedColumnName: 'id' }]) | ||
| user: User; | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. השינוי הזה לא באמת נצרך |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { BaseEntityModuleOptions } from '@shared/base-entity/interface'; | ||
| import { IHeader } from '@shared/utils/exporter/types'; | ||
| import { Transportation } from 'src/db/entities/Transportation.entity'; | ||
|
|
||
| function getConfig(): BaseEntityModuleOptions { | ||
| return { | ||
| entity: Transportation, | ||
| exporter: { | ||
| getExportHeaders(): IHeader[] { | ||
| return [ | ||
| { value: 'key', label: 'שילוט' }, | ||
| { value: 'year', label: 'שנה' }, | ||
| { value: 'departureTime', label: 'שעת יציאה' }, | ||
| { value: 'description', label: 'תיאור נסיעה' }, | ||
| ]; | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| export default getConfig(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
כדאי להוסיף פה fill default year
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ואז יצירת הסעה חדשה לא יצטרכו להכניס שנה?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
כן, וגם יהיה אפשר להוריד את זה מהמערך של הimporter, תראי איך זה בטבלאות אחרות
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
בשביל שזה יעבוד צריך לשים מעל זה @beforeCreate @beforeUpdate