tiun 0.0.2.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.forgejo/workflows/codeberg-tests.yml +226 -0
- data/.gitignore +7 -3
- data/.prettierrc.json +5 -0
- data/.rubocop.yml +221 -0
- data/AGENTS.md +132 -0
- data/Appraisals +18 -0
- data/CONTRIBUTING.md +80 -0
- data/CONTRIBUTING.ru.md +326 -0
- data/Gemfile +20 -1
- data/README.md +52 -23
- data/README.ru.md +72 -0
- data/Rakefile +10 -4
- data/TODO +2 -6
- data/bin/console +4 -3
- data/config/cucumber.yml +1 -0
- data/cucumber.mjs +6 -0
- data/docs/backend.md +73 -0
- data/docs/backend.ru.md +73 -0
- data/docs/components/approved.md +39 -0
- data/docs/components/approved.ru.md +39 -0
- data/docs/components/attachment-field.md +7 -0
- data/docs/components/attachment-field.ru.md +8 -0
- data/docs/components/attachment.md +48 -0
- data/docs/components/attachment.ru.md +48 -0
- data/docs/components/avatar.md +39 -0
- data/docs/components/avatar.ru.md +37 -0
- data/docs/components/chip.md +119 -0
- data/docs/components/chip.ru.md +99 -0
- data/docs/components/configuration.md +137 -0
- data/docs/components/configuration.ru.md +138 -0
- data/docs/components/daylight.md +41 -0
- data/docs/components/daylight.ru.md +41 -0
- data/docs/components/defaults.md +148 -0
- data/docs/components/defaults.ru.md +149 -0
- data/docs/components/documents.md +64 -0
- data/docs/components/documents.ru.md +64 -0
- data/docs/components/external-form-fields.ru.md +137 -0
- data/docs/components/external-renderers.md +50 -0
- data/docs/components/external-renderers.ru.md +51 -0
- data/docs/components/feedback.md +76 -0
- data/docs/components/feedback.ru.md +76 -0
- data/docs/components/footer.md +49 -0
- data/docs/components/footer.ru.md +49 -0
- data/docs/components/forms.md +177 -0
- data/docs/components/forms.ru.md +177 -0
- data/docs/components/images.md +141 -0
- data/docs/components/images.ru.md +140 -0
- data/docs/components/index.md +140 -0
- data/docs/components/index.ru.md +140 -0
- data/docs/components/intro.md +150 -0
- data/docs/components/intro.ru.md +150 -0
- data/docs/components/login.md +602 -0
- data/docs/components/login.ru.md +604 -0
- data/docs/components/methods.md +59 -0
- data/docs/components/methods.ru.md +59 -0
- data/docs/components/player.md +72 -0
- data/docs/components/player.ru.md +69 -0
- data/docs/components/profile.md +84 -0
- data/docs/components/profile.ru.md +84 -0
- data/docs/components/record-manager.md +69 -0
- data/docs/components/record-manager.ru.md +69 -0
- data/docs/components/row-column.ru.md +51 -0
- data/docs/components/rtfer.md +76 -0
- data/docs/components/rtfer.ru.md +76 -0
- data/docs/components/schema-calendar.md +86 -0
- data/docs/components/schema-calendar.ru.md +84 -0
- data/docs/components/schema-records.md +168 -0
- data/docs/components/schema-records.ru.md +168 -0
- data/docs/components/signup.md +196 -0
- data/docs/components/signup.ru.md +196 -0
- data/docs/components/slug-flow.md +97 -0
- data/docs/components/slug-flow.ru.md +59 -0
- data/docs/components/stockee.md +21 -0
- data/docs/components/stockee.ru.md +21 -0
- data/docs/components/text-views.md +64 -0
- data/docs/components/text-views.ru.md +57 -0
- data/docs/components/theme.md +214 -0
- data/docs/components/theme.ru.md +214 -0
- data/docs/components/tooltip.md +37 -0
- data/docs/components/tooltip.ru.md +30 -0
- data/docs/components/validation.md +153 -0
- data/docs/components/validation.ru.md +154 -0
- data/docs/components.md +31 -0
- data/docs/components.ru.md +31 -0
- data/docs/controller-names.md +23 -0
- data/docs/controller-names.ru.md +23 -0
- data/docs/examples/dneslov-frontend.md +38 -0
- data/docs/examples/dneslov-frontend.ru.md +39 -0
- data/docs/examples/dneslov-frontend.yaml +266 -0
- data/docs/frontend.md +316 -0
- data/docs/frontend.ru.md +332 -0
- data/docs/migrations/component-configuration.md +48 -0
- data/docs/migrations/component-configuration.ru.md +40 -0
- data/docs/migrations/component-shell-proposal.md +108 -0
- data/docs/migrations/component-shell-proposal.ru.md +150 -0
- data/docs/migrations/theme-layout.md +83 -0
- data/docs/migrations/theme-layout.ru.md +97 -0
- data/docs/reference.md +45 -0
- data/docs/reference.ru.md +1763 -0
- data/docs/resources.md +348 -0
- data/docs/resources.ru.md +349 -0
- data/docs/tasks/DNE-542.md +11 -0
- data/docs/tasks/DNE-566.md +8 -0
- data/docs/tasks/chip-segments.md +54 -0
- data/docs/tasks/configured-profile.md +73 -0
- data/docs/tasks/frontend/auth-form.md +7 -0
- data/docs/tasks/frontend/avatar.md +5 -0
- data/docs/tasks/frontend/component-removal.md +11 -0
- data/docs/tasks/frontend/dynamic-field.md +6 -0
- data/docs/tasks/frontend/field-caption.md +38 -0
- data/docs/tasks/frontend/form-core.md +65 -0
- data/docs/tasks/frontend/form-field-context.md +16 -0
- data/docs/tasks/frontend/form-session-renewal.md +58 -0
- data/docs/tasks/frontend/frontend-components.md +7 -0
- data/docs/tasks/frontend/frontend-docs.md +6 -0
- data/docs/tasks/frontend/frontend-layout.md +13 -0
- data/docs/tasks/frontend/frontend-methods.md +15 -0
- data/docs/tasks/frontend/frontend-other.md +13 -0
- data/docs/tasks/frontend/frontend-services.md +7 -0
- data/docs/tasks/frontend/fusion.md +22 -0
- data/docs/tasks/frontend/heading-core.md +5 -0
- data/docs/tasks/frontend/i18n-scope.md +37 -0
- data/docs/tasks/frontend/index-runtime.md +48 -0
- data/docs/tasks/frontend/inline-form.md +7 -0
- data/docs/tasks/frontend/intro-core.md +11 -0
- data/docs/tasks/frontend/login.md +8 -0
- data/docs/tasks/frontend/menu-branch.md +5 -0
- data/docs/tasks/frontend/paginator.md +7 -0
- data/docs/tasks/frontend/records-core.md +35 -0
- data/docs/tasks/frontend/resource-source-core.md +12 -0
- data/docs/tasks/frontend/signup.md +8 -0
- data/docs/tasks/frontend/span-body.md +16 -0
- data/docs/tasks/frontend/text-commonee.md +48 -0
- data/docs/tasks/frontend/theme-field.md +31 -0
- data/docs/tasks/frontend/theme-menu.md +8 -0
- data/docs/tasks/frontend/theme-settings.md +10 -0
- data/docs/tasks/frontend/view-content-core.md +12 -0
- data/docs/tasks/frontend/view-source-core.md +12 -0
- data/docs/tasks/ruby-extension-compatibility.ru.md +74 -0
- data/docs/tasks/todo-code-climate.md +8 -0
- data/docs/tasks/todo-compatibility.md +50 -0
- data/docs/tasks/todo-reek.md +5 -0
- data/docs/tasks/todo-yard-inch.md +7 -0
- data/eslint.config.mjs +15 -0
- data/exe/tiun +1 -0
- data/gemfiles/rails_7_0.gemfile +16 -0
- data/gemfiles/rails_7_2.gemfile +17 -0
- data/lib/config/locale/browser.en.yml +43 -0
- data/lib/config/locale/browser.ru.yml +35 -0
- data/lib/config/locale/confirmation.en.yml +16 -0
- data/lib/config/locale/confirmation.ru.yml +16 -0
- data/lib/config/locale/errors.en.yml +57 -0
- data/lib/config/locale/errors.ru.yml +47 -0
- data/lib/config/locale/form_delay.en.yml +11 -0
- data/lib/config/locale/form_delay.ru.yml +11 -0
- data/lib/config/locale/recovery.en.yml +14 -0
- data/lib/config/locale/ru.yml +269 -6
- data/lib/config/routes.rb +5 -11
- data/lib/tasks/tiun/translations.rake +12 -0
- data/lib/tiun/actor/validate.rb +3 -2
- data/lib/tiun/actor.rb +13 -10
- data/lib/tiun/api_not_found.rb +16 -0
- data/lib/tiun/attributes.rb +8 -7
- data/lib/tiun/auth/attribute_models.rb +32 -0
- data/lib/tiun/auth/controller/discord.rb +26 -0
- data/lib/tiun/auth/controller/facebook.rb +62 -0
- data/lib/tiun/auth/controller/github.rb +37 -0
- data/lib/tiun/auth/controller/kakao.rb +33 -0
- data/lib/tiun/auth/controller/oauth.rb +167 -0
- data/lib/tiun/auth/controller/ok.rb +8 -0
- data/lib/tiun/auth/controller/telegram.rb +188 -0
- data/lib/tiun/auth/controller/vk.rb +85 -0
- data/lib/tiun/auth/controller/wechat.rb +58 -0
- data/lib/tiun/auth/controller/weibo.rb +28 -0
- data/lib/tiun/auth/controller.rb +467 -150
- data/lib/tiun/auth/json_session.rb +19 -0
- data/lib/tiun/auth/token_identity.rb +46 -0
- data/lib/tiun/auth/user_identity.rb +27 -0
- data/lib/tiun/auth/views/oauth_address.html.erb +23 -0
- data/lib/tiun/auth.rb +184 -45
- data/lib/tiun/carrier_wave_store.rb +59 -0
- data/lib/tiun/cli.rb +52 -32
- data/lib/tiun/concern/resources.rb +85 -0
- data/lib/tiun/config_source.rb +52 -0
- data/lib/tiun/content_range.rb +123 -0
- data/lib/tiun/context/merge.rb +117 -0
- data/lib/tiun/context.rb +39 -0
- data/lib/tiun/controller/auth/identity.rb +260 -0
- data/lib/tiun/controller/auth/registration.rb +46 -0
- data/lib/tiun/controller/auth.rb +198 -0
- data/lib/tiun/controller/auto.rb.erb +10 -0
- data/lib/tiun/controller/base/actions.rb +156 -0
- data/lib/tiun/controller/base/assignment.rb +101 -0
- data/lib/tiun/controller/base/parameters.rb +198 -0
- data/lib/tiun/controller/base/params.rb +166 -0
- data/lib/tiun/controller/base/records.rb +107 -0
- data/lib/tiun/controller/base/representation.rb +108 -0
- data/lib/tiun/controller/base/scopes.rb +132 -0
- data/lib/tiun/controller/base.rb +52 -0
- data/lib/tiun/controller/component_assets.rb +96 -0
- data/lib/tiun/controller/meta.rb +248 -0
- data/lib/tiun/controller/translations.rb +22 -0
- data/lib/tiun/controller.rb +13 -0
- data/lib/tiun/core/boot.rb +210 -0
- data/lib/tiun/core/contexts.rb +53 -0
- data/lib/tiun/core/controller_contexts.rb +42 -0
- data/lib/tiun/core/defaults.rb +215 -0
- data/lib/tiun/core/evaluation.rb +105 -0
- data/lib/tiun/core/field_attributes.rb +78 -0
- data/lib/tiun/core/files.rb +153 -0
- data/lib/tiun/core/generation.rb +234 -0
- data/lib/tiun/core/methods.rb +104 -0
- data/lib/tiun/core/names.rb +140 -0
- data/lib/tiun/core/registry.rb +97 -0
- data/lib/tiun/core/reloading.rb +77 -0
- data/lib/tiun/core/resources.rb +308 -0
- data/lib/tiun/core/routing/forward.rb +206 -0
- data/lib/tiun/core/routing.rb +323 -0
- data/lib/tiun/core/types.rb +88 -0
- data/lib/tiun/core.rb +26 -0
- data/lib/tiun/core_helper.rb +85 -13
- data/lib/tiun/engine.rb +64 -20
- data/lib/tiun/error_handling.rb +121 -0
- data/lib/tiun/hooks.rb +131 -0
- data/lib/tiun/mailer/confirmation.rb +45 -0
- data/lib/tiun/mailer/recovery.rb +16 -0
- data/lib/tiun/migration.rb +72 -50
- data/lib/tiun/mixins.rb +128 -19
- data/lib/tiun/model/account/identity.rb +93 -0
- data/lib/tiun/model/account.rb +256 -7
- data/lib/tiun/model/auth/bcrypt.rb +47 -0
- data/lib/tiun/model/auth.rb +164 -36
- data/lib/tiun/model/auto.rb.erb +12 -0
- data/lib/tiun/model/me.rb +214 -0
- data/lib/tiun/model/settings.rb +193 -0
- data/lib/tiun/model/token/recovery.rb +48 -0
- data/lib/tiun/model/token.rb +37 -3
- data/lib/tiun/model.rb +82 -69
- data/lib/tiun/notification/service.rb +18 -0
- data/lib/tiun/notification.rb +6 -0
- data/lib/tiun/policy/default.rb +7 -0
- data/lib/tiun/policy.rb +84 -8
- data/lib/tiun/proceed/allowed_errors.rb +217 -0
- data/lib/tiun/proceed/auth.rb +50 -0
- data/lib/tiun/proceed/description.rb +89 -0
- data/lib/tiun/proceed/enums.rb +225 -0
- data/lib/tiun/proceed/hooks.rb +51 -0
- data/lib/tiun/proceed/pass_over_paths.rb +40 -0
- data/lib/tiun/proceed/policy.rb +172 -0
- data/lib/tiun/proceed/registration.rb +69 -0
- data/lib/tiun/proceed/schemas/component_nodes.rb +436 -0
- data/lib/tiun/proceed/schemas/constants.rb +117 -0
- data/lib/tiun/proceed/schemas/content.rb +68 -0
- data/lib/tiun/proceed/schemas/definitions.rb +181 -0
- data/lib/tiun/proceed/schemas/dictionary.rb +144 -0
- data/lib/tiun/proceed/schemas/fields.rb +182 -0
- data/lib/tiun/proceed/schemas/models.rb +50 -0
- data/lib/tiun/proceed/schemas/spans.rb +87 -0
- data/lib/tiun/proceed/schemas/values.rb +94 -0
- data/lib/tiun/proceed/schemas/view_paths.rb +86 -0
- data/lib/tiun/proceed/schemas/view_readiness.rb +51 -0
- data/lib/tiun/proceed/schemas/views.rb +192 -0
- data/lib/tiun/proceed/schemas.rb +137 -0
- data/lib/tiun/proceed/services.rb +79 -0
- data/lib/tiun/proceed/token_lifetimes.rb +49 -0
- data/lib/tiun/proceed/translations.rb +45 -0
- data/lib/tiun/proceed/versions.rb +315 -0
- data/lib/tiun/proceed.rb +23 -0
- data/lib/tiun/router.rb +40 -0
- data/lib/tiun/routes/mounts.rb +280 -0
- data/lib/tiun/routes.rb +150 -0
- data/lib/tiun/service/auto.rb.erb +5 -0
- data/lib/tiun/service/email_confirmation.rb +108 -0
- data/lib/tiun/service/job.rb +16 -0
- data/lib/tiun/service.rb +82 -0
- data/lib/tiun/services/translation.rb +297 -0
- data/lib/tiun/themes.rb +98 -0
- data/lib/tiun/translations/database.rb +72 -0
- data/lib/tiun/translations.rb +279 -0
- data/lib/tiun/version.rb +3 -3
- data/lib/tiun.rb +79 -486
- data/package-lock.json +4836 -0
- data/package.json +103 -0
- data/scripts/build-application.mjs +39 -0
- data/scripts/build-css.mjs +21 -0
- data/scripts/ci-badges.mjs +54 -0
- data/scripts/ci-badges.test.mjs +46 -0
- data/scripts/ci-coverage.mjs +26 -0
- data/scripts/ci-quality.mjs +80 -0
- data/scripts/ci-quality.sh +21 -0
- data/scripts/ci-quality.test.mjs +59 -0
- data/scripts/clean.mjs +3 -0
- data/scripts/publish-ci-badges.sh +45 -0
- data/src/auth/configuration.ts +50 -0
- data/src/browser/contracts.js +7 -0
- data/src/browser/mount.d.ts +26 -0
- data/src/browser/mount.jsx +1 -0
- data/src/browser/styles.js +17 -0
- data/src/browser/tiun.scss +23 -0
- data/src/browser/tiun.ts +1 -0
- data/src/calendar/configuration.ts +98 -0
- data/src/components/Avatar.tsx +45 -0
- data/src/components/Calendar.tsx +441 -0
- data/src/components/CatchWrapper.tsx +55 -0
- data/src/components/Chip.tsx +267 -0
- data/src/components/Column.tsx +13 -0
- data/src/components/Component.tsx +1042 -0
- data/src/components/Enum.tsx +142 -0
- data/src/components/Figure.tsx +11 -0
- data/src/components/FlexText.tsx +101 -0
- data/src/components/Footer.tsx +13 -0
- data/src/components/Grid.tsx +36 -0
- data/src/components/Heading.tsx +64 -0
- data/src/components/Image.tsx +179 -0
- data/src/components/Index.tsx +560 -0
- data/src/components/Intro.tsx +536 -0
- data/src/components/Loader.tsx +118 -0
- data/src/components/Lorem.tsx +385 -0
- data/src/components/Markdown.d.ts +17 -0
- data/src/components/Markdown.jsx +118 -0
- data/src/components/Menu.tsx +50 -0
- data/src/components/Modal.tsx +150 -0
- data/src/components/Paginator.tsx +271 -0
- data/src/components/Player.tsx +269 -0
- data/src/components/Records.tsx +1090 -0
- data/src/components/Row.tsx +193 -0
- data/src/components/Span.tsx +122 -0
- data/src/components/Step.tsx +19 -0
- data/src/components/Stockee.tsx +50 -0
- data/src/components/Toast.tsx +125 -0
- data/src/components/Tooltip.tsx +214 -0
- data/src/components/View.tsx +278 -0
- data/src/components/_palette.scss +26 -0
- data/src/components/calendar-browser.scss +143 -0
- data/src/components/calendar.scss +217 -0
- data/src/components/chip-browser.scss +270 -0
- data/src/components/chips.scss +95 -0
- data/src/components/column.scss +4 -0
- data/src/components/dashboard-browser.scss +81 -0
- data/src/components/dashboard.scss +117 -0
- data/src/components/description-browser.scss +112 -0
- data/src/components/document.scss +43 -0
- data/src/components/enum-browser.scss +33 -0
- data/src/components/enums.scss +56 -0
- data/src/components/footer.scss +51 -0
- data/src/components/form/ActionButton.tsx +66 -0
- data/src/components/form/Attachment.tsx +200 -0
- data/src/components/form/Block.tsx +55 -0
- data/src/components/form/BooleanBox.tsx +58 -0
- data/src/components/form/Collection.tsx +89 -0
- data/src/components/form/DynamicInput.tsx +806 -0
- data/src/components/form/ErrorSpan.tsx +17 -0
- data/src/components/form/ExternalField.tsx +554 -0
- data/src/components/form/FieldCaption.tsx +35 -0
- data/src/components/form/Form.tsx +407 -0
- data/src/components/form/HiddenField.tsx +10 -0
- data/src/components/form/JsonEditor.tsx +443 -0
- data/src/components/form/Login.tsx +387 -0
- data/src/components/form/NumberField.tsx +75 -0
- data/src/components/form/Pressee.tsx +101 -0
- data/src/components/form/RtferField.tsx +94 -0
- data/src/components/form/SelectField.tsx +73 -0
- data/src/components/form/SlugFlow.tsx +296 -0
- data/src/components/form/TextArea.tsx +5 -0
- data/src/components/form/TextField.tsx +6 -0
- data/src/components/form/Wye.tsx +67 -0
- data/src/components/form/auth.scss +280 -0
- data/src/components/form/changes.ts +239 -0
- data/src/components/form/context.ts +31 -0
- data/src/components/form/createForm.tsx +109 -0
- data/src/components/form/dynamic-field.scss +20 -0
- data/src/components/form/dynamicMatching.ts +44 -0
- data/src/components/form/form-browser.scss +106 -0
- data/src/components/form/forms.scss +1571 -0
- data/src/components/form/formsLib.ts +76 -0
- data/src/components/form/identity.ts +10 -0
- data/src/components/form/input.scss +37 -0
- data/src/components/form/layout.ts +72 -0
- data/src/components/form/login-browser.scss +30 -0
- data/src/components/form/render.tsx +94 -0
- data/src/components/form/resourceFields.ts +87 -0
- data/src/components/form/types.ts +216 -0
- data/src/components/form/values.ts +266 -0
- data/src/components/image.scss +70 -0
- data/src/components/intro-browser.scss +106 -0
- data/src/components/intro.scss +158 -0
- data/src/components/loader.scss +86 -0
- data/src/components/menu.scss +24 -0
- data/src/components/player.scss +48 -0
- data/src/components/records-browser.scss +62 -0
- data/src/components/records.scss +185 -0
- data/src/components/row.scss +31 -0
- data/src/components/stockee.scss +26 -0
- data/src/components/theme-palettes/compat.scss +15 -0
- data/src/components/theme-palettes/dark.scss +238 -0
- data/src/components/theme-palettes/light.scss +21 -0
- data/src/components/theme.scss +34 -0
- data/src/components/tiun_core.scss +9 -0
- data/src/components/toast.scss +63 -0
- data/src/components/tooltip.scss +22 -0
- data/src/components/view-browser.scss +321 -0
- data/src/components/view-controls.scss +385 -0
- data/src/concern/application.ts +57 -0
- data/src/concern/calendarViewProps.ts +28 -0
- data/src/concern/chipViewProps.ts +60 -0
- data/src/concern/documentHead.ts +66 -0
- data/src/concern/i18n.ts +70 -0
- data/src/concern/resourceRequest.ts +25 -0
- data/src/concern/schemaText.ts +6 -0
- data/src/concern/slugFlowProps.ts +76 -0
- data/src/concern/spanOptions.ts +37 -0
- data/src/concern/spansViewProps.tsx +116 -0
- data/src/concern/useFormAccess.ts +324 -0
- data/src/concern/useRecordsResource.ts +62 -0
- data/src/config/application.ts +57 -0
- data/src/config/componentDefaults.ts +106 -0
- data/src/config/components.ts +436 -0
- data/src/config/names.ts +72 -0
- data/src/config/records.ts +34 -0
- data/src/decorators/buttonBehaviours.tsx +46 -0
- data/src/decorators/configuration.ts +104 -0
- data/src/decorators/validation.ts +52 -0
- data/src/decorators/withAppearance.tsx +45 -0
- data/src/decorators/withCaption.tsx +21 -0
- data/src/decorators/withChildren.tsx +31 -0
- data/src/decorators/withClose.scss +37 -0
- data/src/decorators/withClose.tsx +44 -0
- data/src/decorators/withColumn.tsx +111 -0
- data/src/decorators/withDiscordAuth.tsx +4 -0
- data/src/decorators/withExternalAuth.tsx +50 -0
- data/src/decorators/withFacebookAuth.tsx +4 -0
- data/src/decorators/withField.tsx +94 -0
- data/src/decorators/withForm.tsx +371 -0
- data/src/decorators/withGithubAuth.tsx +4 -0
- data/src/decorators/withKakaoAuth.tsx +4 -0
- data/src/decorators/withMenuBranch.scss +45 -0
- data/src/decorators/withMenuBranch.tsx +109 -0
- data/src/decorators/withOkAuth.tsx +4 -0
- data/src/decorators/withPlayerList.tsx +77 -0
- data/src/decorators/withQuickLinkMark.ts +57 -0
- data/src/decorators/withRecordForm.tsx +561 -0
- data/src/decorators/withRequestActivity.scss +7 -0
- data/src/decorators/withRequestActivity.tsx +21 -0
- data/src/decorators/withRouter.tsx +395 -0
- data/src/decorators/withRouterLink.tsx +54 -0
- data/src/decorators/withTelegramAuth.tsx +4 -0
- data/src/decorators/withTextControl.tsx +194 -0
- data/src/decorators/withUnique.scss +39 -0
- data/src/decorators/withUnique.tsx +172 -0
- data/src/decorators/withUnsavedChanges.scss +39 -0
- data/src/decorators/withUnsavedChanges.tsx +312 -0
- data/src/decorators/withValidation.ts +38 -0
- data/src/decorators/withVkAuth.tsx +4 -0
- data/src/decorators/withWechatAuth.tsx +4 -0
- data/src/decorators/withWeiboAuth.tsx +4 -0
- data/src/intro/config.ts +72 -0
- data/src/intro/position.ts +70 -0
- data/src/layout/units.ts +21 -0
- data/src/records/types.ts +67 -0
- data/src/routing/nativePaths.ts +16 -0
- data/src/routing/routes.ts +337 -0
- data/src/schema/Schema.ts +2044 -0
- data/src/schema/dates.ts +17 -0
- data/src/schema.ts +274 -0
- data/src/services/Meta.ts +64 -0
- data/src/services/Resource.ts +480 -0
- data/src/services/Stock.ts +156 -0
- data/src/services/browser/requestActivity.d.ts +7 -0
- data/src/services/browser/requestActivity.js +119 -0
- data/src/services/browser/slugColor.js +13 -0
- data/src/services/calendar/clock.ts +169 -0
- data/src/services/calendar/dates.ts +127 -0
- data/src/services/calendar/daylight.ts +328 -0
- data/src/services/calendar/useCalendarDaylight.ts +76 -0
- data/src/services/calendar/utcTimeSource.ts +41 -0
- data/src/services/enumLookup.ts +96 -0
- data/src/services/form/blankCondition.ts +61 -0
- data/src/services/form/hoardValidation.ts +84 -0
- data/src/services/i18n/I18n.ts +227 -0
- data/src/services/i18n/messages.ts +185 -0
- data/src/services/load.ts +60 -0
- data/src/services/methods/aboutData.d.ts +9 -0
- data/src/services/methods/aboutData.js +32 -0
- data/src/services/methods/calendarChoices.d.ts +1 -0
- data/src/services/methods/calendarChoices.js +9 -0
- data/src/services/methods/eventDates.ts +96 -0
- data/src/services/methods/forms.ts +22 -0
- data/src/services/methods/mount.jsx +34 -0
- data/src/services/methods/paschal.ts +45 -0
- data/src/services/methods/prepared.ts +193 -0
- data/src/services/methods/query.ts +30 -0
- data/src/services/methods/registry.ts +22 -0
- data/src/services/methods/resolveReadResource.ts +57 -0
- data/src/services/methods.ts +156 -0
- data/src/services/records/range.ts +39 -0
- data/src/services/records/resource.ts +90 -0
- data/src/services/records/useRecordPages.ts +286 -0
- data/src/services/session/renewal.ts +457 -0
- data/src/services/textLink.ts +11 -0
- data/src/services/timer.ts +25 -0
- data/src/services/useAppearance.ts +507 -0
- data/src/services/useSwitch.ts +152 -0
- data/src/theme/cache.ts +88 -0
- data/src/theme/configuration.ts +275 -0
- data/src/theme/context.ts +48 -0
- data/src/theme/resource.ts +106 -0
- data/tiun.gemspec +53 -45
- data/tools/rubocop/compact_block_braces.rb +39 -0
- data/tools/rubocop/i18n_decorators.rb +15 -0
- data/tools/rubocop/spacing.rb +96 -0
- data/tsconfig.build.json +26 -0
- data/tsconfig.json +27 -0
- metadata +628 -72
- data/.rspec +0 -3
- data/.travis.yml +0 -7
- data/lib/tiun/autocontroller.rb.erb +0 -20
- data/lib/tiun/autolistserializer.rb.erb +0 -9
- data/lib/tiun/automodel.rb.erb +0 -10
- data/lib/tiun/autoserializer.rb.erb +0 -9
- data/lib/tiun/base.rb +0 -405
- data/lib/tiun/core_controller.rb +0 -6
- data/lib/tiun/list_serializer.rb +0 -20
- data/lib/tiun/meta_controller.rb +0 -13
- data/lib/tiun/serializer.rb +0 -31
- /data/lib/tiun/{automigration.rb.erb → migration/auto.rb.erb} +0 -0
- /data/lib/tiun/{autopolicy.rb.erb → policy/auto.rb.erb} +0 -0
|
@@ -0,0 +1,1090 @@
|
|
|
1
|
+
/* eslint-disable max-lines -- The records module owns rendering and its resource-backed entry. */
|
|
2
|
+
import { ApplicationContextCore, type ApplicationState } from "../concern/application.js";
|
|
3
|
+
import React, {
|
|
4
|
+
type CSSProperties,
|
|
5
|
+
type KeyboardEvent,
|
|
6
|
+
type MouseEvent,
|
|
7
|
+
type ReactElement,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
useCallback,
|
|
10
|
+
useContext,
|
|
11
|
+
useEffect,
|
|
12
|
+
useLayoutEffect,
|
|
13
|
+
useMemo,
|
|
14
|
+
useRef,
|
|
15
|
+
useState,
|
|
16
|
+
} from "react";
|
|
17
|
+
import { Component, type ComponentProps } from "./Component.js";
|
|
18
|
+
import { Loader, type LoaderRequestState } from "./Loader.js";
|
|
19
|
+
import { type PendingRecordEdit, type StoredRecord, recordFormCommand } from "../decorators/withRecordForm.js";
|
|
20
|
+
import type { RecordKey, RecordsProps } from "../records/types.js";
|
|
21
|
+
import { Row, recordColumnText, recordTextLimit, rowHeading } from "./Row.js";
|
|
22
|
+
import {
|
|
23
|
+
declaredAttributes,
|
|
24
|
+
resourceAllowed,
|
|
25
|
+
resourceTypes,
|
|
26
|
+
resourceUpdateMethod,
|
|
27
|
+
restoreAttributes,
|
|
28
|
+
} from "../services/Resource.js";
|
|
29
|
+
import { recordOperation, recordPath } from "../services/records/resource.js";
|
|
30
|
+
import { remLength, rootRem, toRem } from "../layout/units.js";
|
|
31
|
+
import type { ComponentDefinition } from "../config/components.js";
|
|
32
|
+
import { Form } from "./form/Form.js";
|
|
33
|
+
import type { FormData } from "./form/types.js";
|
|
34
|
+
import { Paginator } from "./Paginator.js";
|
|
35
|
+
import { Stock } from "../services/Stock.js";
|
|
36
|
+
import { Stockee } from "./Stockee.js";
|
|
37
|
+
import { Toast } from "./Toast.js";
|
|
38
|
+
import { asString } from "../concern/schemaText.js";
|
|
39
|
+
import { object } from "../config/application.js";
|
|
40
|
+
import { useConfirmationPosition } from "../decorators/withUnsavedChanges.js";
|
|
41
|
+
import { useI18n } from "../concern/i18n.js";
|
|
42
|
+
import { writeResource } from "../concern/resourceRequest.js";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Отображает записи в таблице, сетке, стеке или раскрываемом списке.
|
|
46
|
+
* @param props Записи, поля, раскладка, действия и настройки догрузки коллекции.
|
|
47
|
+
* @returns Разметка коллекции либо null для скрытого пустого списка.
|
|
48
|
+
*/
|
|
49
|
+
export function Records<T>({
|
|
50
|
+
view = "table",
|
|
51
|
+
row_flow_kind = "table",
|
|
52
|
+
gap = 0.5,
|
|
53
|
+
width: itemWidth = 10,
|
|
54
|
+
...props
|
|
55
|
+
}: RecordsProps<T>): ReactElement | null {
|
|
56
|
+
const { t } = useI18n(),
|
|
57
|
+
columns = props.columns ?? [],
|
|
58
|
+
containerRef = useRef<HTMLDivElement>(null),
|
|
59
|
+
[layout, setLayout] = useState<{
|
|
60
|
+
height: number;
|
|
61
|
+
positions: { left: number; top: number; width: number }[];
|
|
62
|
+
waitingForImages: boolean;
|
|
63
|
+
}>({ height: 0, positions: [], waitingForImages: false }),
|
|
64
|
+
[expanded, setExpanded] = useState<ReadonlySet<RecordKey>>(() => new Set(props.defaultExpandedKeys)),
|
|
65
|
+
defaults = JSON.stringify(props.defaultExpandedKeys ?? []);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
setExpanded(new Set(props.defaultExpandedKeys));
|
|
69
|
+
}, [defaults]);
|
|
70
|
+
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
|
+
const root = containerRef.current;
|
|
73
|
+
if (view !== "stack" || !root) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Measures the stack using the actual heights of its records.
|
|
79
|
+
* - Skips gaps for records that occupy no space.
|
|
80
|
+
* - Pauses automatic pagination while hidden images are loading.
|
|
81
|
+
* No arguments.
|
|
82
|
+
* @returns Nothing. Updates layout and loading state from the current DOM.
|
|
83
|
+
*/
|
|
84
|
+
const measure = (): void => {
|
|
85
|
+
const available = root.clientWidth,
|
|
86
|
+
baseRem = rootRem(root),
|
|
87
|
+
columnGap = gap * baseRem,
|
|
88
|
+
columnWidth = Math.min(itemWidth * baseRem, available || itemWidth * baseRem),
|
|
89
|
+
columnsThatFit = Math.max(1, Math.floor((available + columnGap) / (columnWidth + columnGap))),
|
|
90
|
+
heights = Array.from({ length: columnsThatFit }, () => 0),
|
|
91
|
+
offset = Math.max(0, (available - columnsThatFit * columnWidth - (columnsThatFit - 1) * columnGap) / 2),
|
|
92
|
+
positions = Array.from(root.children, (child) => {
|
|
93
|
+
const column = heights.indexOf(Math.min(...heights)),
|
|
94
|
+
element = child as HTMLElement,
|
|
95
|
+
top = heights[column]!;
|
|
96
|
+
element.style.width = toRem(columnWidth, root);
|
|
97
|
+
const { height } = element.getBoundingClientRect();
|
|
98
|
+
if (height > 0) {
|
|
99
|
+
heights[column] = top + height + columnGap;
|
|
100
|
+
}
|
|
101
|
+
return { left: offset + column * (columnWidth + columnGap), top, width: columnWidth };
|
|
102
|
+
}),
|
|
103
|
+
placement = {
|
|
104
|
+
height: Math.max(0, Math.max(...heights) - columnGap),
|
|
105
|
+
positions,
|
|
106
|
+
waitingForImages:
|
|
107
|
+
root.querySelector(
|
|
108
|
+
':is(.tiun-image-quiet, [data-image-reserve])[data-image-state="loading"] img:not([loading="lazy"])',
|
|
109
|
+
) !== null,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
setLayout((previous) => (JSON.stringify(previous) === JSON.stringify(placement) ? previous : placement));
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
measure();
|
|
116
|
+
const observer = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(measure);
|
|
117
|
+
observer?.observe(root);
|
|
118
|
+
observer?.observe(root.ownerDocument.documentElement);
|
|
119
|
+
const mutationObserver = root.ownerDocument.defaultView?.MutationObserver,
|
|
120
|
+
attributeObserver = mutationObserver ? new mutationObserver(measure) : undefined;
|
|
121
|
+
attributeObserver?.observe(root.ownerDocument.documentElement, {
|
|
122
|
+
attributeFilter: ["style", "class"],
|
|
123
|
+
attributes: true,
|
|
124
|
+
});
|
|
125
|
+
attributeObserver?.observe(root, {
|
|
126
|
+
attributeFilter: ["data-image-state"],
|
|
127
|
+
attributes: true,
|
|
128
|
+
childList: true,
|
|
129
|
+
subtree: true,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
Array.from(root.children).forEach((child) => observer?.observe(child));
|
|
133
|
+
|
|
134
|
+
root.addEventListener("load", measure, true);
|
|
135
|
+
window.addEventListener("resize", measure);
|
|
136
|
+
return () => {
|
|
137
|
+
observer?.disconnect();
|
|
138
|
+
attributeObserver?.disconnect();
|
|
139
|
+
root.removeEventListener("load", measure, true);
|
|
140
|
+
window.removeEventListener("resize", measure);
|
|
141
|
+
};
|
|
142
|
+
}, [view, props.items, itemWidth, gap]);
|
|
143
|
+
|
|
144
|
+
const rendering = {
|
|
145
|
+
...(props.render_kind ? { render_kind: props.render_kind } : {}),
|
|
146
|
+
...(props.render_with ? { render_with: props.render_with } : {}),
|
|
147
|
+
},
|
|
148
|
+
row = (item: T): React.ReactNode =>
|
|
149
|
+
props.renderHeader ? (
|
|
150
|
+
props.renderHeader(item)
|
|
151
|
+
) : (
|
|
152
|
+
<Row
|
|
153
|
+
{...rendering}
|
|
154
|
+
value={item}
|
|
155
|
+
columns={columns}
|
|
156
|
+
flow_kind={row_flow_kind}
|
|
157
|
+
{...(props.renderActions ? { renderActions: props.renderActions } : {})}
|
|
158
|
+
/>
|
|
159
|
+
),
|
|
160
|
+
rowClass = (item: T) =>
|
|
161
|
+
typeof props.rowClassName === "function" ? props.rowClassName(item) : (props.rowClassName ?? "");
|
|
162
|
+
|
|
163
|
+
function toggle(key: RecordKey): void {
|
|
164
|
+
setExpanded((previous) => {
|
|
165
|
+
const next = props.accordion === false ? new Set(previous) : new Set<RecordKey>();
|
|
166
|
+
if (!previous.has(key)) {
|
|
167
|
+
next.add(key);
|
|
168
|
+
} else {
|
|
169
|
+
next.delete(key);
|
|
170
|
+
}
|
|
171
|
+
return next;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const interactive = (target: EventTarget | null) =>
|
|
176
|
+
(target as Element | null)?.closest?.("a,button,input,select,textarea");
|
|
177
|
+
|
|
178
|
+
if (!props.items.length && !props.loading && !props.error && !props.hasMore && props.hideIfEmpty) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
return (
|
|
182
|
+
<div
|
|
183
|
+
id={props.id}
|
|
184
|
+
className={`tiun-records ${props.className ?? ""}`}
|
|
185
|
+
data-view={view}
|
|
186
|
+
aria-busy={Boolean(props.loading)}
|
|
187
|
+
>
|
|
188
|
+
{view === "table" ? (
|
|
189
|
+
<table className="tiun-record-table striped">
|
|
190
|
+
{row_flow_kind === "table" && (
|
|
191
|
+
<thead>
|
|
192
|
+
<tr>
|
|
193
|
+
{columns.map((column) => (
|
|
194
|
+
<th
|
|
195
|
+
key={column.key}
|
|
196
|
+
className="tiun-record-table-text"
|
|
197
|
+
data-tiun-column={column.key}
|
|
198
|
+
style={{ width: remLength(column.width) }}
|
|
199
|
+
>
|
|
200
|
+
{recordColumnText(column.title)}
|
|
201
|
+
</th>
|
|
202
|
+
))}
|
|
203
|
+
{props.renderActions && (
|
|
204
|
+
<th className="actions tiun-record-table-text" scope="col">
|
|
205
|
+
{recordColumnText(props.i18n?.actions ?? t("tiun.components.records.action_title"))}
|
|
206
|
+
</th>
|
|
207
|
+
)}
|
|
208
|
+
</tr>
|
|
209
|
+
</thead>
|
|
210
|
+
)}
|
|
211
|
+
<tbody>
|
|
212
|
+
{props.items.map((item) =>
|
|
213
|
+
props.renderHeader ? (
|
|
214
|
+
<tr key={props.getKey(item)}>
|
|
215
|
+
<td colSpan={Math.max(1, columns.length)}>{row(item)}</td>
|
|
216
|
+
</tr>
|
|
217
|
+
) : (
|
|
218
|
+
<Row
|
|
219
|
+
{...rendering}
|
|
220
|
+
key={props.getKey(item)}
|
|
221
|
+
as="tr"
|
|
222
|
+
value={item}
|
|
223
|
+
columns={columns}
|
|
224
|
+
flow_kind={row_flow_kind}
|
|
225
|
+
className={rowClass(item)}
|
|
226
|
+
{...(props.renderActions ? { renderActions: props.renderActions } : {})}
|
|
227
|
+
/>
|
|
228
|
+
),
|
|
229
|
+
)}
|
|
230
|
+
</tbody>
|
|
231
|
+
</table>
|
|
232
|
+
) : view === "collapsible" ? (
|
|
233
|
+
<ul className="tiun-record-list collapsible collection">
|
|
234
|
+
{props.items.map((item) => {
|
|
235
|
+
const entryKey = props.getKey(item),
|
|
236
|
+
entryPanel = props.renderBody?.(item),
|
|
237
|
+
isToggleEnabled = props.canExpand ? props.canExpand(item) : Boolean(entryPanel),
|
|
238
|
+
onClick = (event: MouseEvent<HTMLElement>): void => {
|
|
239
|
+
if (isToggleEnabled && !interactive(event.target)) {
|
|
240
|
+
toggle(entryKey);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
onKeyDown = (event: KeyboardEvent<HTMLElement>): void => {
|
|
244
|
+
if (
|
|
245
|
+
isToggleEnabled &&
|
|
246
|
+
event.target === event.currentTarget &&
|
|
247
|
+
["Enter", " "].includes(event.key)
|
|
248
|
+
) {
|
|
249
|
+
event.preventDefault();
|
|
250
|
+
toggle(entryKey);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
open = isToggleEnabled && expanded.has(entryKey);
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<li key={entryKey} className={`${rowClass(item)} ${open ? "active" : ""}`}>
|
|
257
|
+
<div
|
|
258
|
+
className={`collapsible-header ${props.headerClassName ?? ""}`}
|
|
259
|
+
role={isToggleEnabled ? "button" : undefined}
|
|
260
|
+
tabIndex={isToggleEnabled ? 0 : undefined}
|
|
261
|
+
aria-expanded={isToggleEnabled ? open : undefined}
|
|
262
|
+
onClick={onClick}
|
|
263
|
+
onKeyDown={onKeyDown}
|
|
264
|
+
>
|
|
265
|
+
{row(item)}
|
|
266
|
+
</div>
|
|
267
|
+
{entryPanel != null && (
|
|
268
|
+
<div
|
|
269
|
+
className={`tiun-record-body collapsible-body ${props.bodyClassName ?? ""}`}
|
|
270
|
+
hidden={!open}
|
|
271
|
+
>
|
|
272
|
+
{entryPanel}
|
|
273
|
+
</div>
|
|
274
|
+
)}
|
|
275
|
+
</li>
|
|
276
|
+
);
|
|
277
|
+
})}
|
|
278
|
+
</ul>
|
|
279
|
+
) : (
|
|
280
|
+
<div
|
|
281
|
+
ref={containerRef}
|
|
282
|
+
className={`tiun-record-${view}`}
|
|
283
|
+
style={
|
|
284
|
+
{
|
|
285
|
+
"--tiun-record-width": `${itemWidth}rem`,
|
|
286
|
+
gap: `${gap}rem`,
|
|
287
|
+
...(view === "stack" ? { height: toRem(layout.height, containerRef.current) } : {}),
|
|
288
|
+
} as CSSProperties
|
|
289
|
+
}
|
|
290
|
+
>
|
|
291
|
+
{props.items.map((item, index) => (
|
|
292
|
+
<div
|
|
293
|
+
key={props.getKey(item)}
|
|
294
|
+
className={rowClass(item)}
|
|
295
|
+
style={
|
|
296
|
+
view === "stack"
|
|
297
|
+
? {
|
|
298
|
+
left: toRem(layout.positions[index]?.left ?? 0, containerRef.current),
|
|
299
|
+
position: "absolute",
|
|
300
|
+
top: toRem(layout.positions[index]?.top ?? 0, containerRef.current),
|
|
301
|
+
width: toRem(layout.positions[index]?.width ?? 0, containerRef.current),
|
|
302
|
+
}
|
|
303
|
+
: undefined
|
|
304
|
+
}
|
|
305
|
+
>
|
|
306
|
+
{row(item)}
|
|
307
|
+
</div>
|
|
308
|
+
))}
|
|
309
|
+
</div>
|
|
310
|
+
)}
|
|
311
|
+
{/* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- A false or empty React error has no feedback. */}
|
|
312
|
+
{!props.items.length && props.loading !== true && !props.error && (
|
|
313
|
+
<>
|
|
314
|
+
{props.renderEmpty?.()}
|
|
315
|
+
{!props.renderEmpty && <p>{props.i18n?.empty ?? t("tiun.components.records.empty")}</p>}
|
|
316
|
+
</>
|
|
317
|
+
)}
|
|
318
|
+
<Paginator
|
|
319
|
+
{...props.pagination}
|
|
320
|
+
kind={props.pagination?.kind ?? (props.manualFetch ? "button" : "hidden")}
|
|
321
|
+
loading={props.loading === true || (view === "stack" && layout.waitingForImages)}
|
|
322
|
+
error={props.error}
|
|
323
|
+
hasMore={props.hasMore ?? false}
|
|
324
|
+
fetchFunc={props.onFetchNext}
|
|
325
|
+
onRetry={props.onRetry}
|
|
326
|
+
renderLoadMore={props.renderLoadMore}
|
|
327
|
+
i18n={props.i18n}
|
|
328
|
+
/>
|
|
329
|
+
</div>
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
interface RecordActionsProps {
|
|
334
|
+
readonly canEdit: boolean;
|
|
335
|
+
readonly editLoading: boolean;
|
|
336
|
+
readonly canRemove: boolean;
|
|
337
|
+
readonly summary: string;
|
|
338
|
+
readonly label: (name: string) => string;
|
|
339
|
+
readonly edit: () => void;
|
|
340
|
+
readonly remove: () => Promise<void>;
|
|
341
|
+
readonly restore?: (() => Promise<void>) | undefined;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Builds the deletion label from configured fields of the current row.
|
|
346
|
+
* - Each list item contributes one part. A nested list supplies ordered alternatives for that part.
|
|
347
|
+
* - Empty fields and numeric identifiers contribute no text.
|
|
348
|
+
* @param record {Data} Record as returned by the list resource.
|
|
349
|
+
* @param fields {unknown} Field path or list of parts from the Records configuration.
|
|
350
|
+
* @returns {string} The displayed label, or an empty string for an unnamed record.
|
|
351
|
+
*/
|
|
352
|
+
function recordRemoveLabel(record: Data, fields: unknown): string {
|
|
353
|
+
const parts = Array.isArray(fields) ? fields : [fields ?? ["title", "short_name"]];
|
|
354
|
+
return parts
|
|
355
|
+
.flatMap((part: unknown): string[] => {
|
|
356
|
+
const alternatives = Array.isArray(part) ? part : [part];
|
|
357
|
+
for (const field of alternatives) {
|
|
358
|
+
if (typeof field !== "string") continue;
|
|
359
|
+
const value = field
|
|
360
|
+
.split(".")
|
|
361
|
+
.reduce<unknown>((entry, key) => (object(entry) ? entry[key] : undefined), record);
|
|
362
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
363
|
+
if (text && !/^\d+$/u.test(text)) return [text];
|
|
364
|
+
}
|
|
365
|
+
return [];
|
|
366
|
+
})
|
|
367
|
+
.join(" · ");
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Renders edit and removal controls for a row.
|
|
372
|
+
* - The confirmation places the question beside the buttons when there is room.
|
|
373
|
+
* - A deleted row offers restoration at the same position as the delete button.
|
|
374
|
+
* - A comet takes the place of the active button during any request.
|
|
375
|
+
* @param props {RecordActionsProps} Permissions, loading state, translated labels and request handlers.
|
|
376
|
+
* @returns {React.JSX.Element} The row actions and their feedback.
|
|
377
|
+
*/
|
|
378
|
+
export function RecordActions(props: RecordActionsProps) {
|
|
379
|
+
const [confirming, setConfirming] = useState(false),
|
|
380
|
+
[busy, setBusy] = useState(false),
|
|
381
|
+
[failure, setFailure] = useState(false),
|
|
382
|
+
confirmationRef = useRef<HTMLDivElement>(null),
|
|
383
|
+
/** Runs the current row mutation. Takes no arguments and resolves when the request settles. */
|
|
384
|
+
mutate = async (): Promise<void> => {
|
|
385
|
+
setConfirming(false);
|
|
386
|
+
setBusy(true);
|
|
387
|
+
setFailure(false);
|
|
388
|
+
try {
|
|
389
|
+
await (props.restore ?? props.remove)();
|
|
390
|
+
} catch {
|
|
391
|
+
setFailure(true);
|
|
392
|
+
} finally {
|
|
393
|
+
setBusy(false);
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
question = props.summary
|
|
397
|
+
? props.label("remove.question").replace(/%default/gu, () => props.summary)
|
|
398
|
+
: props.label("remove.unnamed_question"),
|
|
399
|
+
removeRef = useRef<HTMLButtonElement>(null);
|
|
400
|
+
useConfirmationPosition(removeRef, confirmationRef, { caption: question, open: confirming });
|
|
401
|
+
let action: "restore" | "remove" = "remove",
|
|
402
|
+
editIcon = <Stockee asset={Stock.edit} />,
|
|
403
|
+
removeIcon = <Stockee asset={Stock.delete} />;
|
|
404
|
+
if (props.restore) {
|
|
405
|
+
action = "restore";
|
|
406
|
+
removeIcon = <Stockee asset={Stock.collectionRestore} />;
|
|
407
|
+
}
|
|
408
|
+
if (props.editLoading) {
|
|
409
|
+
editIcon = <Loader size={1.5} decorative />;
|
|
410
|
+
}
|
|
411
|
+
if (busy) {
|
|
412
|
+
removeIcon = <Loader size={1.5} decorative />;
|
|
413
|
+
}
|
|
414
|
+
return (
|
|
415
|
+
<div className="actions">
|
|
416
|
+
{props.canEdit && (
|
|
417
|
+
<button
|
|
418
|
+
type="button"
|
|
419
|
+
className="btn-flat"
|
|
420
|
+
aria-label={props.label("actions.edit")}
|
|
421
|
+
aria-busy={props.editLoading}
|
|
422
|
+
disabled={props.editLoading || busy}
|
|
423
|
+
onClick={props.edit}
|
|
424
|
+
>
|
|
425
|
+
{editIcon}
|
|
426
|
+
</button>
|
|
427
|
+
)}
|
|
428
|
+
{props.canRemove && (
|
|
429
|
+
<button
|
|
430
|
+
type="button"
|
|
431
|
+
className="btn-flat"
|
|
432
|
+
aria-label={props.label(`actions.${action}`)}
|
|
433
|
+
ref={removeRef}
|
|
434
|
+
aria-busy={busy}
|
|
435
|
+
disabled={busy}
|
|
436
|
+
onClick={() => {
|
|
437
|
+
if (props.restore) {
|
|
438
|
+
// eslint-disable-next-line no-void -- The action handles request errors internally.
|
|
439
|
+
void mutate();
|
|
440
|
+
} else {
|
|
441
|
+
setConfirming(true);
|
|
442
|
+
}
|
|
443
|
+
}}
|
|
444
|
+
>
|
|
445
|
+
{removeIcon}
|
|
446
|
+
</button>
|
|
447
|
+
)}
|
|
448
|
+
{confirming && (
|
|
449
|
+
<div
|
|
450
|
+
ref={confirmationRef}
|
|
451
|
+
popover="manual"
|
|
452
|
+
className="tiun-record-confirm"
|
|
453
|
+
role="alertdialog"
|
|
454
|
+
aria-label={props.label("remove.title")}
|
|
455
|
+
>
|
|
456
|
+
<span>{question}</span>
|
|
457
|
+
<div className="tiun-record-confirm-actions">
|
|
458
|
+
<button
|
|
459
|
+
type="button"
|
|
460
|
+
onClick={() => {
|
|
461
|
+
// eslint-disable-next-line no-void -- The action handles request errors itself.
|
|
462
|
+
void mutate();
|
|
463
|
+
}}
|
|
464
|
+
>
|
|
465
|
+
{props.label("yes")}
|
|
466
|
+
</button>
|
|
467
|
+
<button
|
|
468
|
+
type="button"
|
|
469
|
+
onClick={() => {
|
|
470
|
+
setConfirming(false);
|
|
471
|
+
}}
|
|
472
|
+
>
|
|
473
|
+
{props.label("actions.cancel")}
|
|
474
|
+
</button>
|
|
475
|
+
</div>
|
|
476
|
+
</div>
|
|
477
|
+
)}
|
|
478
|
+
{failure && <Toast tone="error" message={props.label(`errors.${action}`)} />}
|
|
479
|
+
</div>
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
type Data = Readonly<Record<string, unknown>>;
|
|
484
|
+
|
|
485
|
+
interface DeletedRecord {
|
|
486
|
+
readonly data: FormData & { readonly id: string | number };
|
|
487
|
+
readonly position: number;
|
|
488
|
+
readonly query: string;
|
|
489
|
+
readonly owner: string;
|
|
490
|
+
readonly row: Data;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Holds pager controls until the mounted Loader publishes its first state.
|
|
495
|
+
* @returns Nothing. Initial markup has no paging action to perform.
|
|
496
|
+
*/
|
|
497
|
+
const idlePageAction = (): void => {
|
|
498
|
+
// No request exists before the Loader is mounted.
|
|
499
|
+
},
|
|
500
|
+
// eslint-disable-next-line sort-vars -- Keep the paging callback with its documentation.
|
|
501
|
+
firstRecordPosition = 0,
|
|
502
|
+
restoreReplaceCount = 0;
|
|
503
|
+
|
|
504
|
+
// eslint-disable-next-line one-var -- Pager defaults are independent of restored row positions.
|
|
505
|
+
const idlePages: LoaderRequestState = {
|
|
506
|
+
contentRange: undefined,
|
|
507
|
+
error: "",
|
|
508
|
+
fetchNext: idlePageAction,
|
|
509
|
+
hasMore: false,
|
|
510
|
+
loading: false,
|
|
511
|
+
reload: idlePageAction,
|
|
512
|
+
rewind: idlePageAction,
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Binds the list query to its configured child Loader.
|
|
517
|
+
* @param props Records definition, rendering context, selected resource and its Loader inputs.
|
|
518
|
+
* @returns The child Loader with the Records content.
|
|
519
|
+
*/
|
|
520
|
+
export function RecordsWithLoader({
|
|
521
|
+
resource,
|
|
522
|
+
loaderProps,
|
|
523
|
+
revision,
|
|
524
|
+
state,
|
|
525
|
+
stored,
|
|
526
|
+
...props
|
|
527
|
+
}: ComponentProps & {
|
|
528
|
+
readonly definition: ComponentDefinition;
|
|
529
|
+
readonly resource: string | undefined;
|
|
530
|
+
readonly revision: number;
|
|
531
|
+
readonly stored: StoredRecord | undefined;
|
|
532
|
+
readonly pendingEdit: PendingRecordEdit | undefined;
|
|
533
|
+
readonly loaderProps: Data;
|
|
534
|
+
readonly configuredRow: ComponentDefinition | undefined;
|
|
535
|
+
}) {
|
|
536
|
+
const { schema, definition: node } = props,
|
|
537
|
+
[query, setQuery] = useState(""),
|
|
538
|
+
activeQuery = useRef(query),
|
|
539
|
+
[displayedQuery, setDisplayedQuery] = useState(query),
|
|
540
|
+
acceptedQuery = useRef(query),
|
|
541
|
+
[searchDraft, setSearchDraft] = useState(""),
|
|
542
|
+
[items, setItems] = useState<readonly unknown[]>([]),
|
|
543
|
+
[currentWrite, setCurrentWrite] = useState<StoredRecord>(),
|
|
544
|
+
[requestState, setRequestState] = useState(idlePages),
|
|
545
|
+
searchData = useMemo(() => ({ q: searchDraft }), [searchDraft]),
|
|
546
|
+
searchPagination = node.pagination as Data | undefined,
|
|
547
|
+
searchResultsPerPage = typeof searchPagination?.per === "number" ? searchPagination.per : 25;
|
|
548
|
+
const isMetadataPending = state === "loading";
|
|
549
|
+
activeQuery.current = query;
|
|
550
|
+
const { filter, ...parameters } = loaderProps;
|
|
551
|
+
useEffect(() => {
|
|
552
|
+
setCurrentWrite(stored);
|
|
553
|
+
}, [stored]);
|
|
554
|
+
if (filter !== undefined && !object(filter)) {
|
|
555
|
+
throw new TypeError(schema.i18n.t("tiun.errors.application.configuration"));
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Applies an accepted page to the records owned by this list.
|
|
559
|
+
* - Replaces the displayed search and its local edits when its response is accepted.
|
|
560
|
+
* @param page Records returned by Loader.
|
|
561
|
+
* @param replace Whether the page replaces the old list.
|
|
562
|
+
* @returns Nothing.
|
|
563
|
+
*/
|
|
564
|
+
const receive = useCallback((page: readonly unknown[], replace: boolean): void => {
|
|
565
|
+
if (replace && activeQuery.current !== acceptedQuery.current) {
|
|
566
|
+
acceptedQuery.current = activeQuery.current;
|
|
567
|
+
setDisplayedQuery(acceptedQuery.current);
|
|
568
|
+
setCurrentWrite(undefined);
|
|
569
|
+
}
|
|
570
|
+
setItems((previous) => (replace ? page : previous.concat(page)));
|
|
571
|
+
}, []);
|
|
572
|
+
return (
|
|
573
|
+
<>
|
|
574
|
+
<RecordsContent
|
|
575
|
+
{...props}
|
|
576
|
+
items={items}
|
|
577
|
+
pages={requestState}
|
|
578
|
+
isMetadataPending={isMetadataPending}
|
|
579
|
+
resource={resource}
|
|
580
|
+
pageSize={searchResultsPerPage}
|
|
581
|
+
query={displayedQuery}
|
|
582
|
+
searchData={searchData}
|
|
583
|
+
onSearch={(value) => {
|
|
584
|
+
setQuery(value);
|
|
585
|
+
}}
|
|
586
|
+
onSearchDraft={setSearchDraft}
|
|
587
|
+
currentWrite={currentWrite}
|
|
588
|
+
onClearWrite={() => setCurrentWrite(undefined)}
|
|
589
|
+
onRemove={(key, keyOf) => {
|
|
590
|
+
if (activeQuery.current !== query) return;
|
|
591
|
+
if (items.some((row) => keyOf(row) === key)) requestState.rewind();
|
|
592
|
+
setItems((previous) => previous.filter((row) => keyOf(row) !== key));
|
|
593
|
+
}}
|
|
594
|
+
onRestore={({ key, keyOf, position, row }) => {
|
|
595
|
+
if (activeQuery.current !== query) return;
|
|
596
|
+
setItems((previous) => {
|
|
597
|
+
const rows = previous.filter((item) => keyOf(item) !== key);
|
|
598
|
+
rows.splice(position, restoreReplaceCount, row);
|
|
599
|
+
return rows;
|
|
600
|
+
});
|
|
601
|
+
}}
|
|
602
|
+
/>
|
|
603
|
+
<Loader
|
|
604
|
+
request={{
|
|
605
|
+
meta: schema.metadata,
|
|
606
|
+
node,
|
|
607
|
+
resource: isMetadataPending ? undefined : resource,
|
|
608
|
+
pageSize: searchResultsPerPage,
|
|
609
|
+
query,
|
|
610
|
+
revision,
|
|
611
|
+
parameters,
|
|
612
|
+
filters: filter ?? {},
|
|
613
|
+
}}
|
|
614
|
+
onPage={receive}
|
|
615
|
+
onRequestState={setRequestState}
|
|
616
|
+
/>
|
|
617
|
+
</>
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Aligns list controls with the collection and binds them to the Loader's callbacks.
|
|
623
|
+
* - While metadata loads, renders the empty table and locks the search form.
|
|
624
|
+
* @param props Records configuration, current pages and interaction callbacks.
|
|
625
|
+
* @returns The configured list, including search and feedback in the paging controls.
|
|
626
|
+
*/
|
|
627
|
+
function RecordsContent({
|
|
628
|
+
schema,
|
|
629
|
+
definition: node,
|
|
630
|
+
data,
|
|
631
|
+
onCommand,
|
|
632
|
+
ancestors = [],
|
|
633
|
+
items,
|
|
634
|
+
pages,
|
|
635
|
+
isMetadataPending,
|
|
636
|
+
resource,
|
|
637
|
+
configuredRow,
|
|
638
|
+
pageSize,
|
|
639
|
+
query,
|
|
640
|
+
searchData,
|
|
641
|
+
onSearch,
|
|
642
|
+
onSearchDraft,
|
|
643
|
+
currentWrite,
|
|
644
|
+
onClearWrite,
|
|
645
|
+
onRemove,
|
|
646
|
+
onRestore,
|
|
647
|
+
pendingEdit,
|
|
648
|
+
...input
|
|
649
|
+
}: ComponentProps & {
|
|
650
|
+
readonly definition: ComponentDefinition;
|
|
651
|
+
readonly configuredRow: ComponentDefinition | undefined;
|
|
652
|
+
readonly items: readonly unknown[];
|
|
653
|
+
readonly pages: LoaderRequestState;
|
|
654
|
+
readonly isMetadataPending: boolean;
|
|
655
|
+
readonly resource: string | undefined;
|
|
656
|
+
readonly pageSize: number;
|
|
657
|
+
readonly query: string;
|
|
658
|
+
readonly searchData: FormData;
|
|
659
|
+
readonly onSearch: (query: string) => void;
|
|
660
|
+
readonly onSearchDraft: (query: string) => void;
|
|
661
|
+
readonly currentWrite: StoredRecord | undefined;
|
|
662
|
+
readonly onClearWrite: () => void;
|
|
663
|
+
readonly onRemove: (key: string, keyOf: (record: unknown) => string) => void;
|
|
664
|
+
readonly onRestore: (restored: {
|
|
665
|
+
readonly key: string;
|
|
666
|
+
readonly keyOf: (record: unknown) => string;
|
|
667
|
+
readonly position: number;
|
|
668
|
+
readonly row: Data;
|
|
669
|
+
}) => void;
|
|
670
|
+
readonly pendingEdit: PendingRecordEdit | undefined;
|
|
671
|
+
}) {
|
|
672
|
+
const textOptions: { recordTextLength?: number } = {};
|
|
673
|
+
if (node.view === "table") {
|
|
674
|
+
textOptions.recordTextLength = recordTextLimit;
|
|
675
|
+
}
|
|
676
|
+
// eslint-disable-next-line one-var, @typescript-eslint/no-unsafe-type-assertion -- Read the application after setting the column options. Standalone Records has no Index.
|
|
677
|
+
const application = useContext(ApplicationContextCore) as ApplicationState | null,
|
|
678
|
+
[deleted, setDeleted] = useState<ReadonlyMap<string, DeletedRecord>>(() => new Map()),
|
|
679
|
+
owner = String(application?.user?.id ?? application?.user?.uid ?? ""),
|
|
680
|
+
readable = resourceAllowed(schema.metadata, resource, "get"),
|
|
681
|
+
pagination = (node.pagination ?? {}) as Data,
|
|
682
|
+
recordComponent = node.element as ComponentDefinition | undefined,
|
|
683
|
+
recordDefinition = recordComponent?.of ? schema.componentDefinitions[recordComponent.of] : undefined,
|
|
684
|
+
resolvedRow = configuredRow ?? (recordDefinition ? { ...recordDefinition, ...recordComponent } : recordComponent),
|
|
685
|
+
resolvedRowHeaders = Array.isArray(resolvedRow?.headers) ? resolvedRow.headers : undefined,
|
|
686
|
+
rowColumns = (resolvedRow?.children ?? []).map((child) => {
|
|
687
|
+
const header = resolvedRowHeaders?.find((item: ComponentDefinition) => item.name === child.name),
|
|
688
|
+
headerDefinition =
|
|
689
|
+
header && header.caption === undefined && header.text === undefined && header.children === undefined
|
|
690
|
+
? { ...header, caption: `:tiun.components.${node.name}.row.${child.name}` }
|
|
691
|
+
: header;
|
|
692
|
+
return {
|
|
693
|
+
key: child.name,
|
|
694
|
+
head_to: rowHeading(schema.configuredComponent(child).node.headTo),
|
|
695
|
+
render: (record: unknown) => (
|
|
696
|
+
<Component
|
|
697
|
+
schema={schema}
|
|
698
|
+
definition={child}
|
|
699
|
+
data={record}
|
|
700
|
+
{...input}
|
|
701
|
+
{...textOptions}
|
|
702
|
+
onCommand={onCommand}
|
|
703
|
+
ancestors={ancestors}
|
|
704
|
+
/>
|
|
705
|
+
),
|
|
706
|
+
title: resolvedRowHeaders ? (
|
|
707
|
+
<Component
|
|
708
|
+
schema={schema}
|
|
709
|
+
definition={headerDefinition}
|
|
710
|
+
data={data}
|
|
711
|
+
{...input}
|
|
712
|
+
{...textOptions}
|
|
713
|
+
onCommand={onCommand}
|
|
714
|
+
ancestors={ancestors}
|
|
715
|
+
/>
|
|
716
|
+
) : child.title === undefined ? undefined : (
|
|
717
|
+
(schema.binding(child.title, data) as ReactNode)
|
|
718
|
+
),
|
|
719
|
+
};
|
|
720
|
+
}),
|
|
721
|
+
isLoading = isMetadataPending || pages.loading,
|
|
722
|
+
status = pages.error ? "error" : isLoading ? "loading" : items.length === 0 ? "empty" : undefined,
|
|
723
|
+
statusLoader = typeof node.loader === "string" ? schema.componentDefinitions[node.loader] : undefined,
|
|
724
|
+
statusNeedsFeedback =
|
|
725
|
+
status &&
|
|
726
|
+
status !== "loading" &&
|
|
727
|
+
statusLoader &&
|
|
728
|
+
(statusLoader.of !== "loader" || statusLoader.children?.some((child) => child.name === status)),
|
|
729
|
+
tableCommand = (name: string, record?: unknown): void => {
|
|
730
|
+
if (name === `${node.name}.reload`) {
|
|
731
|
+
onClearWrite();
|
|
732
|
+
pages.reload();
|
|
733
|
+
} else {
|
|
734
|
+
onCommand?.(name, record);
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
tableRecordKey = (record: unknown): string => String(schema.uid(resolvedRow?.uid ?? "$id", record)),
|
|
738
|
+
tableRecordView = (record: unknown): ReactNode =>
|
|
739
|
+
resolvedRow ? (
|
|
740
|
+
<Component
|
|
741
|
+
schema={schema}
|
|
742
|
+
definition={{ ...resolvedRow, name: resolvedRow.name ?? `${node.name}_row` }}
|
|
743
|
+
data={record}
|
|
744
|
+
{...input}
|
|
745
|
+
onCommand={tableCommand}
|
|
746
|
+
ancestors={ancestors}
|
|
747
|
+
/>
|
|
748
|
+
) : null,
|
|
749
|
+
updateActions = recordComponent?.actions as Data | undefined,
|
|
750
|
+
updateFormName =
|
|
751
|
+
typeof node.form === "string"
|
|
752
|
+
? node.form
|
|
753
|
+
: typeof updateActions?.edit === "string"
|
|
754
|
+
? updateActions.edit
|
|
755
|
+
: undefined,
|
|
756
|
+
updateFormTemplate = updateFormName ? schema.componentDefinitions[updateFormName] : undefined,
|
|
757
|
+
updateFormView = updateFormTemplate && schema.configuredComponent(updateFormTemplate).node,
|
|
758
|
+
updateResources = updateFormView?.resources as Data | undefined,
|
|
759
|
+
updateSource = typeof updateResources?.access === "string" ? updateResources.access : undefined,
|
|
760
|
+
writeAllowed = Boolean(
|
|
761
|
+
updateFormView?.of === "form" &&
|
|
762
|
+
Array.isArray(updateFormView.allow) &&
|
|
763
|
+
updateFormView.allow.includes("get") &&
|
|
764
|
+
updateSource &&
|
|
765
|
+
resourceAllowed(schema.metadata, updateSource, "get") &&
|
|
766
|
+
resourceUpdateMethod(schema.metadata, updateSource, updateFormView.allow),
|
|
767
|
+
);
|
|
768
|
+
const actions = node.actions as Data | undefined,
|
|
769
|
+
removeResource =
|
|
770
|
+
typeof actions?.remove === "string"
|
|
771
|
+
? actions.remove
|
|
772
|
+
: typeof updateActions?.remove === "string"
|
|
773
|
+
? updateActions.remove
|
|
774
|
+
: undefined,
|
|
775
|
+
canRemove = resourceAllowed(schema.metadata, removeResource, "delete");
|
|
776
|
+
|
|
777
|
+
const buttons = node.buttons as Data | undefined;
|
|
778
|
+
const searchName = typeof node.searchForm === "string" ? node.searchForm : undefined;
|
|
779
|
+
const search = searchName ? schema.formFields(searchName) : undefined;
|
|
780
|
+
const create = buttons?.new as Data | undefined;
|
|
781
|
+
// eslint-disable-next-line one-var -- Resolve the configured command after selecting the creation button.
|
|
782
|
+
const actionMatch = recordFormCommand.exec(asString(create?.onClick) ?? "")?.groups;
|
|
783
|
+
let createDefinition = updateFormTemplate,
|
|
784
|
+
newFormName = updateFormName,
|
|
785
|
+
written: StoredRecord | undefined;
|
|
786
|
+
if (actionMatch?.action === "new") {
|
|
787
|
+
createDefinition = schema.componentDefinitions[actionMatch.form ?? ""];
|
|
788
|
+
newFormName = actionMatch.form ?? updateFormName;
|
|
789
|
+
}
|
|
790
|
+
if (
|
|
791
|
+
(currentWrite?.isNew === true && currentWrite.form === newFormName) ||
|
|
792
|
+
(currentWrite?.isNew === false && currentWrite.form === updateFormName)
|
|
793
|
+
) {
|
|
794
|
+
written = currentWrite;
|
|
795
|
+
}
|
|
796
|
+
const writtenKey = written && schema.uid(resolvedRow?.uid ?? "$id", written.data);
|
|
797
|
+
let visibleItems = canRemove ? Array.from(new Map(items.map((row) => [tableRecordKey(row), row])).values()) : items;
|
|
798
|
+
if (written && writtenKey !== undefined && writtenKey !== null) {
|
|
799
|
+
const key = String(writtenKey);
|
|
800
|
+
visibleItems = written.isNew
|
|
801
|
+
? [written.data, ...visibleItems.filter((record) => tableRecordKey(record) !== key)]
|
|
802
|
+
: visibleItems.map((record) => (tableRecordKey(record) === key ? written.data : record));
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const createForm = createDefinition && schema.configuredComponent(createDefinition).node;
|
|
806
|
+
const createResources = createForm?.resources as Data | undefined;
|
|
807
|
+
const createResource = typeof createResources?.create === "string" ? createResources.create : undefined;
|
|
808
|
+
const createAllowed =
|
|
809
|
+
!createForm ||
|
|
810
|
+
createForm.of !== "form" ||
|
|
811
|
+
Boolean(
|
|
812
|
+
Array.isArray(createForm.allow) &&
|
|
813
|
+
createForm.allow.includes("post") &&
|
|
814
|
+
createResource &&
|
|
815
|
+
resourceAllowed(schema.metadata, createResource, "post"),
|
|
816
|
+
);
|
|
817
|
+
// eslint-disable-next-line one-var -- This resource is available only for an allowed form creation.
|
|
818
|
+
let restoreOperation: ReturnType<typeof recordOperation> | undefined;
|
|
819
|
+
if (createAllowed && typeof createResource === "string" && createForm?.of === "form") {
|
|
820
|
+
restoreOperation = recordOperation(schema.metadata, createResource, "post");
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Deletes the selected record and keeps its snapshot for restoration.
|
|
825
|
+
* - The matching form cache is invalidated only after a successful delete.
|
|
826
|
+
* - The row stays in place when it can be restored. The next explicit page accounts for deletion.
|
|
827
|
+
* @param row {Data} The displayed record with its resource identity.
|
|
828
|
+
* @returns {Promise<void>} Completes when the deletion is accepted.
|
|
829
|
+
*/
|
|
830
|
+
// eslint-disable-next-line one-var, max-statements -- Keep the delete, captured snapshot and cache invalidation in request order.
|
|
831
|
+
const remove = async (row: Data): Promise<void> => {
|
|
832
|
+
if (typeof removeResource !== "string" || !canRemove) {
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
const identity = row.id ?? row.uid,
|
|
836
|
+
operation = recordOperation(schema.metadata, removeResource, "delete");
|
|
837
|
+
if (typeof identity !== "string" && typeof identity !== "number") {
|
|
838
|
+
throw new TypeError(schema.i18n.t("tiun.components.records.errors.identity"));
|
|
839
|
+
}
|
|
840
|
+
let readPath: string | undefined;
|
|
841
|
+
if (updateFormView) {
|
|
842
|
+
readPath = schema.formRead(updateFormView, identity);
|
|
843
|
+
}
|
|
844
|
+
// eslint-disable-next-line one-var -- The cache key depends on the resolved form.
|
|
845
|
+
const cache = application?.recordCache,
|
|
846
|
+
saved = cache?.get(readPath ?? ""),
|
|
847
|
+
{ data: removed } = await writeResource({ method: operation.method, url: recordPath(operation, identity) });
|
|
848
|
+
if (typeof readPath === "string") {
|
|
849
|
+
cache?.delete(readPath);
|
|
850
|
+
}
|
|
851
|
+
const key = tableRecordKey(row);
|
|
852
|
+
if (restoreOperation && (object(removed) || saved)) {
|
|
853
|
+
const position = Math.max(firstRecordPosition, visibleItems.indexOf(row)),
|
|
854
|
+
snapshot = { ...row, ...saved, ...(object(removed) && removed), id: identity } as DeletedRecord["data"];
|
|
855
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- React supplies the previous map containing form arrays.
|
|
856
|
+
setDeleted((previous) => new Map(previous).set(key, { data: snapshot, owner, position, query, row }));
|
|
857
|
+
}
|
|
858
|
+
onRemove(key, tableRecordKey);
|
|
859
|
+
onClearWrite();
|
|
860
|
+
},
|
|
861
|
+
/**
|
|
862
|
+
* Replaces a deleted placeholder when its record has been recreated.
|
|
863
|
+
* @param key {string} The deleted row's identity in the rendered list.
|
|
864
|
+
* @param entry {DeletedRecord} The displayed row and position.
|
|
865
|
+
* @param value {unknown} The response of the creation resource.
|
|
866
|
+
* @returns {void} Replaces the row locally.
|
|
867
|
+
*/
|
|
868
|
+
// eslint-disable-next-line sort-vars, @typescript-eslint/prefer-readonly-parameter-types -- Keep the restore callbacks beside deletion. The form data contains mutable JSON arrays.
|
|
869
|
+
finishRestore = (key: string, entry: DeletedRecord, value: unknown): void => {
|
|
870
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- The selected form snapshot can contain JSON arrays.
|
|
871
|
+
setDeleted((previous) => {
|
|
872
|
+
const next = new Map(previous);
|
|
873
|
+
next.delete(key);
|
|
874
|
+
return next;
|
|
875
|
+
});
|
|
876
|
+
onRestore({
|
|
877
|
+
key,
|
|
878
|
+
keyOf: tableRecordKey,
|
|
879
|
+
position: entry.position,
|
|
880
|
+
row: { ...entry.row, ...(object(value) && value) },
|
|
881
|
+
});
|
|
882
|
+
onClearWrite();
|
|
883
|
+
},
|
|
884
|
+
/**
|
|
885
|
+
* Sends the deleted record to the existing creation resource.
|
|
886
|
+
* @param key {string} The deleted row's identity in the rendered list.
|
|
887
|
+
* @param entry {DeletedRecord} The data captured when the record was deleted.
|
|
888
|
+
* @returns {Promise<void>} Completes after successful creation and replacement of the row.
|
|
889
|
+
*/
|
|
890
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- The restore snapshot includes editable JSON arrays.
|
|
891
|
+
restore = async (key: string, entry: DeletedRecord): Promise<void> => {
|
|
892
|
+
if (!restoreOperation) {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
const attributes = restoreAttributes(
|
|
896
|
+
declaredAttributes(entry.data, restoreOperation, resourceTypes(schema.metadata)),
|
|
897
|
+
);
|
|
898
|
+
let requestData: Data = attributes;
|
|
899
|
+
if (typeof restoreOperation.root === "string" && restoreOperation.root !== "") {
|
|
900
|
+
requestData = { [restoreOperation.root]: attributes };
|
|
901
|
+
}
|
|
902
|
+
// eslint-disable-next-line one-var -- Send the request after applying its configured root.
|
|
903
|
+
const { data: restored } = await writeResource({
|
|
904
|
+
data: requestData,
|
|
905
|
+
method: restoreOperation.method,
|
|
906
|
+
url: recordPath(restoreOperation, entry.data.id, createResources?.params),
|
|
907
|
+
});
|
|
908
|
+
finishRestore(key, entry, restored);
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
if (deleted.size) {
|
|
912
|
+
const rows = [...visibleItems];
|
|
913
|
+
for (const [key, entry] of [...deleted].sort(
|
|
914
|
+
(
|
|
915
|
+
[, left]: readonly [string, { readonly position: number }],
|
|
916
|
+
[, right]: readonly [string, { readonly position: number }],
|
|
917
|
+
) => left.position - right.position,
|
|
918
|
+
)) {
|
|
919
|
+
if (entry.owner === owner && entry.query === query && !rows.some((row) => tableRecordKey(row) === key)) {
|
|
920
|
+
rows.splice(entry.position, restoreReplaceCount, entry.row);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
visibleItems = rows;
|
|
924
|
+
}
|
|
925
|
+
if (!isMetadataPending && resource && !readable)
|
|
926
|
+
return <Toast tone="error" message={schema.i18n.t("tiun.defaults.errors.403.name")} />;
|
|
927
|
+
const className = typeof node.className === "string" ? node.className : "";
|
|
928
|
+
const createControl =
|
|
929
|
+
!isMetadataPending && create && createAllowed ? (
|
|
930
|
+
<Component
|
|
931
|
+
schema={schema}
|
|
932
|
+
definition={{ name: "new", of: "pressee", ...create }}
|
|
933
|
+
data={data}
|
|
934
|
+
{...input}
|
|
935
|
+
onCommand={tableCommand}
|
|
936
|
+
ancestors={ancestors}
|
|
937
|
+
/>
|
|
938
|
+
) : !isMetadataPending && !create && updateFormName && createAllowed ? (
|
|
939
|
+
<button type="button" className="btn" onClick={() => onCommand?.(`${updateFormName}.new`)}>
|
|
940
|
+
{schema.i18n.t("tiun.components.records.actions.new")}
|
|
941
|
+
</button>
|
|
942
|
+
) : null;
|
|
943
|
+
return (
|
|
944
|
+
<>
|
|
945
|
+
{(search || createControl) && (
|
|
946
|
+
<div className={`tiun-records-toolbar ${className}`.trim()}>
|
|
947
|
+
{search && (
|
|
948
|
+
<Form
|
|
949
|
+
data={searchData}
|
|
950
|
+
disabled={isMetadataPending}
|
|
951
|
+
meta={search}
|
|
952
|
+
remoteName="filters"
|
|
953
|
+
remoteNames=""
|
|
954
|
+
onDataChange={(values) => {
|
|
955
|
+
onSearchDraft(String(values.q ?? ""));
|
|
956
|
+
}}
|
|
957
|
+
onSubmitData={async (values) => {
|
|
958
|
+
const value = String(values.q ?? "");
|
|
959
|
+
onSearchDraft(value);
|
|
960
|
+
onSearch(value.trim());
|
|
961
|
+
return values;
|
|
962
|
+
}}
|
|
963
|
+
/>
|
|
964
|
+
)}
|
|
965
|
+
{createControl}
|
|
966
|
+
</div>
|
|
967
|
+
)}
|
|
968
|
+
<Records
|
|
969
|
+
items={visibleItems}
|
|
970
|
+
getKey={tableRecordKey}
|
|
971
|
+
columns={rowColumns}
|
|
972
|
+
{...(typeof node.id === "string" ? { id: node.id } : {})}
|
|
973
|
+
{...(typeof node.width === "number" ? { width: node.width } : {})}
|
|
974
|
+
{...(typeof node.gap === "number" ? { gap: node.gap } : {})}
|
|
975
|
+
{...(node.view === "table" ? {} : { renderHeader: tableRecordView })}
|
|
976
|
+
{...(writeAllowed || canRemove
|
|
977
|
+
? {
|
|
978
|
+
/**
|
|
979
|
+
* Renders the actions allowed for a row in the current session.
|
|
980
|
+
* @param record {unknown} The displayed item or its restored copy.
|
|
981
|
+
* @returns {ReactNode} Row actions, or null when there is no record.
|
|
982
|
+
*/
|
|
983
|
+
// eslint-disable-next-line max-statements, max-lines-per-function -- The row shares one selection across edit, delete and restore buttons.
|
|
984
|
+
renderActions: (record: unknown): ReactNode => {
|
|
985
|
+
if (!object(record)) {
|
|
986
|
+
return null;
|
|
987
|
+
}
|
|
988
|
+
const key = tableRecordKey(record),
|
|
989
|
+
snapshot = deleted.get(key);
|
|
990
|
+
let entry: DeletedRecord | undefined, restoreRecord: RecordActionsProps["restore"];
|
|
991
|
+
if (snapshot?.owner === owner && snapshot.query === query) {
|
|
992
|
+
entry = snapshot;
|
|
993
|
+
}
|
|
994
|
+
if (entry && restoreOperation) {
|
|
995
|
+
const deletedRecord = entry;
|
|
996
|
+
/** Recreates the selected record. Takes no arguments and resolves after the request. */
|
|
997
|
+
restoreRecord = async (): Promise<void> => {
|
|
998
|
+
await restore(key, deletedRecord);
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
return (
|
|
1002
|
+
<RecordActions
|
|
1003
|
+
canEdit={writeAllowed && (!entry || Boolean(restoreOperation))}
|
|
1004
|
+
editLoading={Boolean(
|
|
1005
|
+
pendingEdit &&
|
|
1006
|
+
pendingEdit.form === updateFormTemplate?.name &&
|
|
1007
|
+
object(record) &&
|
|
1008
|
+
pendingEdit.id === record.id,
|
|
1009
|
+
)}
|
|
1010
|
+
canRemove={canRemove && (!entry || Boolean(restoreOperation))}
|
|
1011
|
+
summary={recordRemoveLabel(record, node.removeLabel)}
|
|
1012
|
+
label={(name) => schema.i18n.t(`tiun.components.records.${name}`)}
|
|
1013
|
+
edit={() => {
|
|
1014
|
+
if (entry && createDefinition) {
|
|
1015
|
+
onCommand?.(`${createDefinition.name}.restore`, {
|
|
1016
|
+
data: entry.data,
|
|
1017
|
+
onStored: (value: unknown) => {
|
|
1018
|
+
finishRestore(key, entry, value);
|
|
1019
|
+
},
|
|
1020
|
+
});
|
|
1021
|
+
} else if (typeof updateFormName === "string" && updateFormName !== "") {
|
|
1022
|
+
onCommand?.(`${updateFormName}.edit`, record);
|
|
1023
|
+
}
|
|
1024
|
+
}}
|
|
1025
|
+
remove={async (): Promise<void> => {
|
|
1026
|
+
await remove(record);
|
|
1027
|
+
}}
|
|
1028
|
+
restore={restoreRecord}
|
|
1029
|
+
/>
|
|
1030
|
+
);
|
|
1031
|
+
},
|
|
1032
|
+
}
|
|
1033
|
+
: {})}
|
|
1034
|
+
className={className}
|
|
1035
|
+
headerClassName={typeof node.headerClassName === "string" ? node.headerClassName : ""}
|
|
1036
|
+
bodyClassName={typeof node.bodyClassName === "string" ? node.bodyClassName : ""}
|
|
1037
|
+
view={
|
|
1038
|
+
node.view === "stack"
|
|
1039
|
+
? "stack"
|
|
1040
|
+
: node.view === "table"
|
|
1041
|
+
? "table"
|
|
1042
|
+
: node.view === "grid"
|
|
1043
|
+
? "grid"
|
|
1044
|
+
: "collapsible"
|
|
1045
|
+
}
|
|
1046
|
+
hasMore={pages.hasMore}
|
|
1047
|
+
onFetchNext={pages.fetchNext}
|
|
1048
|
+
loading={isLoading}
|
|
1049
|
+
error={pages.error}
|
|
1050
|
+
onRetry={pages.fetchNext}
|
|
1051
|
+
{...(statusNeedsFeedback ? { renderEmpty: () => null } : {})}
|
|
1052
|
+
pagination={{
|
|
1053
|
+
kind: pagination.kind === "button" ? "button" : "hidden",
|
|
1054
|
+
pageSize,
|
|
1055
|
+
renderCounter: false,
|
|
1056
|
+
renderFeedback: !statusNeedsFeedback,
|
|
1057
|
+
...(status === "loading" && statusLoader
|
|
1058
|
+
? {
|
|
1059
|
+
loadingFeedback: (
|
|
1060
|
+
<Component
|
|
1061
|
+
schema={schema}
|
|
1062
|
+
definition={statusLoader}
|
|
1063
|
+
data={data}
|
|
1064
|
+
{...input}
|
|
1065
|
+
state="loading"
|
|
1066
|
+
onCommand={tableCommand}
|
|
1067
|
+
ancestors={ancestors}
|
|
1068
|
+
/>
|
|
1069
|
+
),
|
|
1070
|
+
}
|
|
1071
|
+
: {}),
|
|
1072
|
+
...(typeof pagination.autoloadUpto === "number" ? { autoloadUpto: pagination.autoloadUpto } : {}),
|
|
1073
|
+
contentRange: pages.contentRange,
|
|
1074
|
+
rangeUnit: pagination.rangeUnit === "pages" ? "pages" : "records",
|
|
1075
|
+
}}
|
|
1076
|
+
/>
|
|
1077
|
+
{statusNeedsFeedback && (
|
|
1078
|
+
<Component
|
|
1079
|
+
schema={schema}
|
|
1080
|
+
definition={statusLoader}
|
|
1081
|
+
data={data}
|
|
1082
|
+
{...input}
|
|
1083
|
+
state={status}
|
|
1084
|
+
onCommand={tableCommand}
|
|
1085
|
+
ancestors={ancestors}
|
|
1086
|
+
/>
|
|
1087
|
+
)}
|
|
1088
|
+
</>
|
|
1089
|
+
);
|
|
1090
|
+
}
|