From 05f0bc967ec2d7438b4c790fe9d6efbef2906360 Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Tue, 12 Jan 2021 17:03:18 -0500 Subject: [PATCH] Turn hash into type Fixes #3542 --- api/src/database/seeds/run.ts | 2 + api/src/services/fields.ts | 2 + api/src/services/specifications.ts | 3 + api/src/types/field.ts | 1 + api/src/utils/get-local-type.ts | 1 + app/src/interfaces/hash/index.ts | 2 +- app/src/lang/translations/en-US.yaml | 76 ++++++++----------- .../field-detail/components/schema.vue | 4 + .../routes/data-model/field-detail/store.ts | 3 + app/src/types/fields.ts | 1 + .../get-default-interface-for-type.ts | 1 + app/src/utils/get-js-type.ts | 2 +- 12 files changed, 51 insertions(+), 47 deletions(-) diff --git a/api/src/database/seeds/run.ts b/api/src/database/seeds/run.ts index efaedd1ec7..319d07b5d6 100644 --- a/api/src/database/seeds/run.ts +++ b/api/src/database/seeds/run.ts @@ -51,6 +51,8 @@ export default async function runSeed(database: Knex) { column = tableBuilder.increments(); } else if (columnInfo.type === 'csv') { column = tableBuilder.string(columnName); + } else if (columnInfo.type === 'hash') { + column = tableBuilder.string(columnName, 255); } else { column = tableBuilder[columnInfo.type!](columnName); } diff --git a/api/src/services/fields.ts b/api/src/services/fields.ts index 99617baff9..ebb31e1dd4 100644 --- a/api/src/services/fields.ts +++ b/api/src/services/fields.ts @@ -331,6 +331,8 @@ export class FieldsService { column = table[type](field.field, field.schema?.numeric_precision || 10, field.schema?.numeric_scale || 5); } else if (field.type === 'csv') { column = table.string(field.field); + } else if (field.type === 'hash') { + column = table.string(field.field, 255); } else { column = table[field.type](field.field); } diff --git a/api/src/services/specifications.ts b/api/src/services/specifications.ts index 7000380414..e6146e1405 100644 --- a/api/src/services/specifications.ts +++ b/api/src/services/specifications.ts @@ -526,5 +526,8 @@ class OASService implements SpecificationSubService { type: 'string', }, }, + hash: { + type: 'string', + }, }; } diff --git a/api/src/types/field.ts b/api/src/types/field.ts index 7a80308335..ca5a34bfd8 100644 --- a/api/src/types/field.ts +++ b/api/src/types/field.ts @@ -15,6 +15,7 @@ export const types = [ 'timestamp', 'binary', 'uuid', + 'hash', 'csv', ] as const; diff --git a/api/src/utils/get-local-type.ts b/api/src/utils/get-local-type.ts index 458093da4d..8acfcf3b81 100644 --- a/api/src/utils/get-local-type.ts +++ b/api/src/utils/get-local-type.ts @@ -92,6 +92,7 @@ export default function getLocalType( } if (field?.special?.includes('json')) return 'json'; + if (field?.special?.includes('hash')) return 'hash'; if (field?.special?.includes('csv')) return 'csv'; if (field?.special?.includes('uuid')) return 'uuid'; diff --git a/app/src/interfaces/hash/index.ts b/app/src/interfaces/hash/index.ts index 56a9a0d6a7..ac57e035ec 100644 --- a/app/src/interfaces/hash/index.ts +++ b/app/src/interfaces/hash/index.ts @@ -7,7 +7,7 @@ export default defineInterface(({ i18n }) => ({ description: i18n.t('interfaces.hash.description'), icon: 'fingerprint', component: InterfaceHash, - types: ['string'], + types: ['hash'], options: [ { field: 'placeholder', diff --git a/app/src/lang/translations/en-US.yaml b/app/src/lang/translations/en-US.yaml index 5d0511a8db..1f1c3d8677 100644 --- a/app/src/lang/translations/en-US.yaml +++ b/app/src/lang/translations/en-US.yaml @@ -31,8 +31,7 @@ rename_bookmark: Rename Bookmark update_bookmark: Update Bookmark delete_bookmark: Delete Bookmark delete_bookmark_copy: >- - Are you sure you want to delete the "{bookmark}" bookmark? This action cannot - be undone. + Are you sure you want to delete the "{bookmark}" bookmark? This action cannot be undone. logoutReason: SIGN_OUT: Signed out SESSION_EXPIRED: Session expired @@ -49,8 +48,8 @@ os_totalmem: OS Memory archive: Archive archive_confirm: Are you sure you want to archive this item? archive_confirm_count: >- - No Items Selected | Are you sure you want to archive this item? | Are you sure - you want to archive these {count} items? + No Items Selected | Are you sure you want to archive this item? | Are you sure you want to archive these {count} + items? reset_system_permissions: Reset System Permissions reset_system_permissions_copy: Reset all all system permissions to their defaults unarchive: Unarchive @@ -135,6 +134,7 @@ text: Text time: Time timestamp: Timestamp uuid: UUID +hash: Hash not_available_for_type: Not Available for this Type create_translations: Create Translations auto_generate: Auto-Generate @@ -142,9 +142,8 @@ this_will_auto_setup_fields_relations: This will automatically setup all require click_here: Click here to_manually_setup_translations: to manually setup translations. click_to_manage_translated_fields: >- - There are no translated fields yet. Click here to create them. | There is one - translated field. Click here to manage it. | There are {count} translated - fields. Click here to manage them. + There are no translated fields yet. Click here to create them. | There is one translated field. Click here to manage + it. | There are {count} translated fields. Click here to manage them. fields_group: Fields Group configure_m2o: Configure your Many-to-One Relationship... configure_o2m: Configure your One-to-Many Relationship... @@ -407,8 +406,8 @@ update_collection_success: Updated Collection delete_collection_success: Deleted Collection start_end_of_count_items: '{start}-{end} of {count} items' delete_collection_are_you_sure: >- - Are you sure you want to delete this collection? This will delete the - collection and all items in it. This action is permanent. + Are you sure you want to delete this collection? This will delete the collection and all items in it. This action is + permanent. collections_shown: Collections Shown visible_collections: Visible Collections hidden_collections: Hidden Collections @@ -570,47 +569,38 @@ discard_changes: Discard Changes keep_editing: Keep Editing page_help_collections_overview: '**Collections Overview** — Lists of all collections you have access to.' page_help_collections_collection: >- - **Browse Items** — Lists all {collection} items you have access to. Customize - layout, filters, and sorting to tailor your view, and even save bookmarks of - these different configurations for quick access. + **Browse Items** — Lists all {collection} items you have access to. Customize layout, filters, and sorting to tailor + your view, and even save bookmarks of these different configurations for quick access. page_help_collections_item: >- - **Item Detail** — A form for viewing and managing this item. This sidebar also - contains a full history of revisions, and embedded comments. + **Item Detail** — A form for viewing and managing this item. This sidebar also contains a full history of revisions, + and embedded comments. page_help_activity_collection: >- - **Browse Activity** — A comprehensive listing of all your user's system and - content activity. + **Browse Activity** — A comprehensive listing of all your user's system and content activity. page_help_docs_global: >- - **Documentation Overview** — Docs tailored specifically to this project's - version and schema. + **Documentation Overview** — Docs tailored specifically to this project's version and schema. page_help_files_collection: >- - **File Library** — Lists all file assets uploaded to this project. Customize - layout, filters, and sorting to tailor your view, and even save bookmarks of - these different configurations for quick access. + **File Library** — Lists all file assets uploaded to this project. Customize layout, filters, and sorting to tailor + your view, and even save bookmarks of these different configurations for quick access. page_help_files_item: >- - **File Detail** — A form for managing file metadata, editing the original - asset, and updating access settings. -page_help_settings_project: '**Project Settings** — Your project''s global configuration options.' + **File Detail** — A form for managing file metadata, editing the original asset, and updating access settings. +page_help_settings_project: "**Project Settings** — Your project's global configuration options." page_help_settings_datamodel_collections: >- - **Data Model: Collections** — Lists all collections available. This includes - visible, hidden, and system collections, as well as unmanaged database tables - that can be added. + **Data Model: Collections** — Lists all collections available. This includes visible, hidden, and system collections, + as well as unmanaged database tables that can be added. page_help_settings_datamodel_fields: >- - **Data Model: Collection** — A form for managing this collection and its - fields. + **Data Model: Collection** — A form for managing this collection and its fields. page_help_settings_roles_collection: '**Browse Roles** — Lists the Admin, Public and custom User Roles.' -page_help_settings_roles_item: '**Role Detail** — Manage a role''s permissions and other settings.' +page_help_settings_roles_item: "**Role Detail** — Manage a role's permissions and other settings." page_help_settings_presets_collection: >- - **Browse Presets** — Lists all presets in the project, including: user, role, - and global bookmarks, as well as default views. + **Browse Presets** — Lists all presets in the project, including: user, role, and global bookmarks, as well as default + views. page_help_settings_presets_item: >- - **Preset Detail** — A form for managing bookmarks and default collection - presets. + **Preset Detail** — A form for managing bookmarks and default collection presets. page_help_settings_webhooks_collection: '**Browse Webhooks** — Lists all webhooks within the project.' page_help_settings_webhooks_item: '**Webhook Detail** — A form for creating and managing project webhooks.' page_help_users_collection: '**User Directory** — Lists all system users within this project.' page_help_users_item: >- - **User Detail** — Manage your account information, or view the details of - other users. + **User Detail** — Manage your account information, or view the details of other users. activity_feed: Activity Feed add_new: Add New create_new: Create New @@ -618,9 +608,8 @@ all: All none: None no_layout_collection_selected_yet: No layout/collection selected yet batch_delete_confirm: >- - No items have been selected | Are you sure you want to delete this item? This - action can not be undone. | Are you sure you want to delete these {count} - items? This action can not be undone. + No items have been selected | Are you sure you want to delete this item? This action can not be undone. | Are you sure + you want to delete these {count} items? This action can not be undone. cancel: Cancel collection: Collection collections: Collections @@ -713,18 +702,15 @@ save_current_datetime: Save Current Date/Time comment: Comment continue: Continue continue_as: >- - {name} is currently authenticated. If you recognize this account, press - continue. + {name} is currently authenticated. If you recognize this account, press continue. editing_role: '{role} Role' creating_webhook: Creating Webhook default: Default delete: Delete delete_are_you_sure: >- - This action is permanent and can not be undone. Are you sure you would like to - proceed? + This action is permanent and can not be undone. Are you sure you would like to proceed? delete_field_are_you_sure: >- - Are you sure you want to delete the field "{field}"? This action can not be - undone. + Are you sure you want to delete the field "{field}"? This action can not be undone. description: Description done: Done duplicate: Duplicate diff --git a/app/src/modules/settings/routes/data-model/field-detail/components/schema.vue b/app/src/modules/settings/routes/data-model/field-detail/components/schema.vue index 190b33d004..5d06fe1298 100644 --- a/app/src/modules/settings/routes/data-model/field-detail/components/schema.vue +++ b/app/src/modules/settings/routes/data-model/field-detail/components/schema.vue @@ -212,6 +212,10 @@ export const fieldTypes = [ text: i18n.t('uuid'), value: 'uuid', }, + { + text: i18n.t('hash'), + value: 'hash', + }, ]; export default defineComponent({ diff --git a/app/src/modules/settings/routes/data-model/field-detail/store.ts b/app/src/modules/settings/routes/data-model/field-detail/store.ts index 46f7f5e989..4648e8c8e1 100644 --- a/app/src/modules/settings/routes/data-model/field-detail/store.ts +++ b/app/src/modules/settings/routes/data-model/field-detail/store.ts @@ -880,6 +880,9 @@ function initLocalStore(collection: string, field: string, type: typeof localTyp case 'uuid': state.fieldData.meta.special = ['uuid']; break; + case 'hash': + state.fieldData.meta.special = ['hash']; + break; case 'json': state.fieldData.meta.special = ['json']; break; diff --git a/app/src/types/fields.ts b/app/src/types/fields.ts index fd08915dec..88a3cd9125 100644 --- a/app/src/types/fields.ts +++ b/app/src/types/fields.ts @@ -23,6 +23,7 @@ export const types = [ 'timestamp', 'binary', 'uuid', + 'hash', 'csv', 'unknown', ] as const; diff --git a/app/src/utils/get-default-interface-for-type/get-default-interface-for-type.ts b/app/src/utils/get-default-interface-for-type/get-default-interface-for-type.ts index fab195e6c0..ae9970f4cb 100644 --- a/app/src/utils/get-default-interface-for-type/get-default-interface-for-type.ts +++ b/app/src/utils/get-default-interface-for-type/get-default-interface-for-type.ts @@ -18,6 +18,7 @@ const defaultInterfaceMap: Record = { uuid: 'text-input', unknown: 'text-input', csv: 'tags', + hash: 'hash', }; /** diff --git a/app/src/utils/get-js-type.ts b/app/src/utils/get-js-type.ts index aed687ef92..34d3901e4f 100644 --- a/app/src/utils/get-js-type.ts +++ b/app/src/utils/get-js-type.ts @@ -2,7 +2,7 @@ import { types } from '@/types'; export function getJSType(type: typeof types[number]) { if (['bigInteger', 'integer', 'float', 'decimal'].includes(type)) return 'number'; - if (['string', 'text', 'uuid'].includes(type)) return 'string'; + if (['string', 'text', 'uuid', 'hash'].includes(type)) return 'string'; if (['boolean'].includes(type)) return 'boolean'; if (['time', 'timestamp', 'date', 'dateTime'].includes(type)) return 'string'; if (['json', 'csv'].includes(type)) return 'object';