From ad38cb73c37ae63ac293bdfb6631895caeecd74e Mon Sep 17 00:00:00 2001 From: Leszek Date: Fri, 12 Jul 2024 13:45:26 +0200 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 8d3d056b86f68ccde922d12e0defae61499acc74 Author: Leszek Date: Fri Jul 12 12:34:21 2024 +0200 small code cleanup in submission modal commit 347684c0364e5e38be4a57b4ab88670469621937 Author: Leszek Date: Fri Jul 12 12:33:32 2024 +0200 fix submission modal not loading submission from next page commit d4d2a009a88cc83c2442fab9bcef1dc149140bb9 Author: Leszek Date: Thu Jul 11 10:19:14 2024 +0200 rename few properties for better clarity commit c65f33dfa03c26375c43d3f1846f608f320551cc Author: Leszek Date: Wed Jul 10 00:32:16 2024 +0200 cleanup and comment Submission Modal code also cleanup duplicated submission flow a bit commit 8eaae0283efc17d473b1bf314f28443386f891b1 Author: Leszek Date: Tue Jul 9 15:46:54 2024 +0200 use classnames util in KoboModal commit 417d66ffd71796f761c163b21ee2ea2e1ba0adfc Author: Leszek Date: Tue Jul 9 15:46:38 2024 +0200 small cleanup of KoboSelect styles commit 0d9546c0a293b8285208435727392c82ce596997 Author: Leszek Date: Tue Jul 9 15:46:17 2024 +0200 Move background audio handling into Submission Modal from Data Table to make it more independent commit d85bd1f44d2532e5543b24c065211b027f51ca6a Author: Leszek Date: Tue Jul 9 15:33:31 2024 +0200 remove unused types import commit 457c564093cb99165fb9a1ee85cd683ee09cd88f Author: Leszek Date: Tue Jul 9 15:33:13 2024 +0200 KoboDropdown name prop is not optional anymore commit a7b183933ad9c4504681c3818c8adef5366d2833 Merge: bac5130aa 368e75598 Author: RuthShryock <81720958+RuthShryock@users.noreply.github.com> Date: Mon Jul 8 11:07:11 2024 -0400 Merge pull request #4994 from kobotoolbox/nlp-usage-limit-block-frontend [TASK-461] Add modal(s) to NLP page when user is over limits commit bac5130aa07eb9e88d6a17cec8b39c1eae3d7d9b Merge: a8e4243e9 0e211554a Author: Philip Edwards Date: Thu Jul 4 11:48:09 2024 -0400 Merge pull request #4992 from kobotoolbox/react-18-upgrade Upgrade to React 18 commit 0e211554a65853c714cf1166f11bf531778e4dcd Author: Phil Edwards Date: Thu Jul 4 11:03:19 2024 -0400 Pin unused storybook dependency, removes EBADENGINE warning https://github.com/kobotoolbox/kpi/pull/4992#discussion_r1665821999 commit a8e4243e9abf01e06b1be227b54b516a565936cf Merge: fac7edfc8 71920e990 Author: Olivier Léger Date: Thu Jul 4 09:50:12 2024 -0400 Merge pull request #4988 from kobotoolbox/remove-constance-values-assigned-in-tests Refactor `constance` setting assignments in tests to use `override_config` commit 7d3da93cd4f2b53b511bd7a232b57132bc96cae6 Author: Leszek Date: Thu Jul 4 14:13:51 2024 +0200 fix edit library item button link commit 4b844aecc5c16a9c62263614a9647bc46e90dc75 Author: Leszek Date: Thu Jul 4 13:59:10 2024 +0200 fix _prepColumns on validation status change commit d1eec97db7e399bffbd1af6ae1344e1e5cd1754c Author: Leszek Date: Thu Jul 4 13:55:31 2024 +0200 fix _prepColumns on initial Data Table load commit 368e75598695272c0cf308884ac71977426527ac Author: James Kiger Date: Wed Jul 3 13:12:52 2024 -0400 Remove extra button styling commit fac7edfc8a36cbea0e7b409a5c8684dbbc5115b8 Merge: 167f66523 c234e4e22 Author: Philip Edwards Date: Wed Jul 3 12:42:11 2024 -0400 Merge pull request #4991 from kobotoolbox/organizations-error-anon-user Retrieve organization data only for logged-in users to prevent error messages commit 71920e9903476e185698103a4cfc8177498f3e7f Author: RuthShryock Date: Wed Jul 3 10:45:12 2024 -0400 keep direct imports at the top commit a2355d47055f25562fcc9d8136b7e87ba40ca460 Author: RuthShryock Date: Wed Jul 3 09:57:40 2024 -0400 fix formatting and use LazyJSONSerializable instead of json.dumps commit 8396b20d7f633b7b305e1a63a89a6ebdb2e5915d Author: Phil Edwards Date: Tue Jul 2 16:03:02 2024 -0400 Remove bonus console.log commit 3cfebca489845ca71f4d1d179f7bdaf5d4fe6cab Author: Phil Edwards Date: Tue Jul 2 13:08:44 2024 -0400 Pass tests that would fail locally after mocha / chai / deep-eql update commit 28eb4cb09ee031c0aba53c2555c0bcf7a517dedc Author: Phil Edwards Date: Tue Jul 2 11:21:06 2024 -0400 Install react-query v5 Pre-emptively install react-query, to make branch switching easier for upcoming PR reviews. commit 3631296cdc0b5705cfaf6781852d25561dbd258c Author: Phil Edwards Date: Mon Jul 1 17:36:55 2024 -0400 Use React's "automatic" runtime instead of "classic" - https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html - https://swc.rs/docs/configuration/compilation#jsctransformreactruntime > "Use `runtime: automatic` to use a JSX runtime module (e.g. `react/jsx-runtime` introduced in React 17)." (Note that with the new jsx transform, you can now use jsx/tsx in a file without importing React. TS knows this now, too. Feel free to take its suggestion.) (The $schema key added to .swcrc just adds better hints when editing the JSON config, it's unrelated to the runtime change.) commit df1d722547b8d708b929455f4e532a82f0d39192 Author: Phil Edwards Date: Mon Jul 1 17:24:11 2024 -0400 Remove react-hot-loader in favor of react-refresh - https://github.com/gaearon/react-hot-loader?tab=readme-ov-file#moving-towards-next-step - https://github.com/pmmmwh/react-refresh-webpack-plugin - using `swc-loader` > swc-loader will set the development option based on Webpack's mode > option. swc won't enable fast refresh when development is false. commit f49b04647fddaa3fd5a9634a38bbcc4ad2faceb1 Author: Phil Edwards Date: Mon Jul 1 17:15:42 2024 -0400 Bump several build-related packages commit 10bb3c0f62a62ce41cc54f3fb8fbf581eb194a34 Author: Phil Edwards Date: Mon Jul 1 12:11:13 2024 -0400 Validate 'change email' field If you click the 'change email' button without filling the email input, in prod it appears to do nothing; in dev there's a fullscreen error. We should probably show a toast in case of API error, but meanwhile I through in some light validation to disable the button until there's at least something in the text input. commit 30862c51042552eb24a9dc195e70a7a2b1aa779f Author: Phil Edwards Date: Fri Jun 28 14:43:46 2024 -0400 Opt-in to the React 18 root API https://react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis commit a008ee38a5f190704a4a2e30d808965fe9fc34fb Author: James Kiger Date: Tue Jul 2 08:20:34 2024 -0400 Use enum for usage limit types commit 2b4ac08aaed8e7888ffc81dca173e05dcbb5b3a5 Author: James Kiger Date: Tue Jul 2 07:08:40 2024 -0400 Minor corrections commit c234e4e22607e31367609944d6bf0f96783fcda7 Author: RuthShryock Date: Mon Jul 1 15:28:03 2024 -0400 don't get organization data if the user is not logged in commit 66c8b59ca85c0dab93d28a5cb38a07512565750f Author: Phil Edwards Date: Fri Jun 28 13:39:48 2024 -0400 Satisfy updated TS / react types. commit 5c7a8d1bb65b95f26c5be811d310a1f98044f704 Author: Phil Edwards Date: Thu Jun 27 18:15:20 2024 -0400 Update react to v18, allowing semver updates (Also update webpack-dev-server and autoprefixer while we're here) This commit does not fully build yet; need: - Fix emerging TS errors, from types updates - Make sure react-refresh, etc. works - Make sure all react-based libraries work - See about this EBADENGINE >=16.17.0 in Storybook's dependencies - …and more. Note the react-table override: v6 -> v7 or v8 is a substantial rewrite with no upgrade guide. My hope is that, as with reflux, it was forwards- compatible with react v18, and we can upgrade it later. A variety of deprecation warnings appear when you do a fresh install without package-lock.json. Here's how to view them again: rm -rf ./node_modules npm cache clean -f # superstitiously, to get resolved/integrity * npm install * (https://stackoverflow.com/a/75236714) commit d47f8cc6868f280ab498468d03c5c22c9a0d71ff Author: James Kiger Date: Mon Jul 1 10:51:17 2024 -0400 Styling commit cfb38da89534481fd887ac068a75808874e17579 Author: James Kiger Date: Mon Jul 1 08:48:09 2024 -0400 Clean up handling of seconds-to-minutes conversion for usage/limits commit d0305bacc97199fe41e93372a038e363fd385851 Author: RuthShryock Date: Fri Jun 28 17:23:36 2024 -0400 use override_config in test cases where config values are directly assigned commit 039566d44c77d59beaf1f68713acdbb4ef855869 Author: James Kiger Date: Fri Jun 28 13:47:54 2024 -0400 Add modal for blocking frontend nlp usage --- .swcrc | 3 +- hub/tests/test_admin_validators.py | 4 +- .../billingContextProvider.component.tsx | 4 + .../requireOrgOwner.component.tsx | 6 +- .../account/plans/billingButton.component.tsx | 4 +- jsapp/js/account/plans/plan.component.tsx | 4 +- .../security/email/emailSection.component.tsx | 4 + jsapp/js/account/stripe.types.ts | 7 + jsapp/js/account/usage/usage.component.tsx | 4 +- jsapp/js/account/usage/usageContainer.tsx | 4 +- .../account/usage/usageProjectBreakdown.tsx | 14 +- jsapp/js/account/usage/useUsage.hook.ts | 10 +- .../assetsTable/assetActionButtons.tsx | 3 +- jsapp/js/components/bigModal/bigModal.es6 | 1 - jsapp/js/components/common/koboDropdown.tsx | 14 +- jsapp/js/components/common/koboSelect.scss | 33 +- jsapp/js/components/common/tooltip.tsx | 1 + jsapp/js/components/modals/koboModal.tsx | 9 +- .../nlpUsageLimitBlockModal.component.tsx | 83 + .../nlpUsageLimitBlockModal.module.scss | 24 + .../transcript/stepConfig.component.tsx | 33 +- .../processing/transcript/transcript.utils.ts | 3 +- .../translations/stepConfig.component.tsx | 33 +- .../reports/reportTable.component.tsx | 5 +- .../submissions/submissionDataTable.scss | 22 +- .../submissions/submissionDataTable.tsx | 71 +- .../submissions/submissionModal.scss | 112 +- .../submissions/submissionModal.tsx | 798 +- .../submissions/submissionUtils.tests.es6 | 35 +- jsapp/js/components/submissions/table.tsx | 76 +- .../js/components/submissions/table.types.ts | 9 +- .../usageLimits/useExceedingLimits.hook.ts | 19 +- jsapp/js/main.es6 | 35 +- jsapp/js/pageState.store.ts | 4 + jsapp/js/router/requireAuth.tsx | 5 +- jsapp/js/utils.ts | 6 + kobo/apps/accounts/tests/test_current_user.py | 26 +- package-lock.json | 57331 +++++++--------- package.json | 107 +- tsconfig.json | 2 +- webpack/webpack.common.js | 19 +- 41 files changed, 27110 insertions(+), 31877 deletions(-) create mode 100644 jsapp/js/components/processing/nlpUsageLimitBlockModal/nlpUsageLimitBlockModal.component.tsx create mode 100644 jsapp/js/components/processing/nlpUsageLimitBlockModal/nlpUsageLimitBlockModal.module.scss diff --git a/.swcrc b/.swcrc index 298f73452a..120cb676a5 100644 --- a/.swcrc +++ b/.swcrc @@ -1,4 +1,5 @@ { + "$schema": "https://swc.rs/schema.json", "sourceMaps": true, "jsc": { "parser": { @@ -7,7 +8,7 @@ }, "transform": { "react": { - "runtime": "classic", + "runtime": "automatic", "refresh": true } } diff --git a/hub/tests/test_admin_validators.py b/hub/tests/test_admin_validators.py index 6f9c87d257..a5522bdef3 100644 --- a/hub/tests/test_admin_validators.py +++ b/hub/tests/test_admin_validators.py @@ -1,14 +1,14 @@ -from constance import config +from constance.test import override_config from django.contrib.auth.models import User from django.test import TestCase from hub.admin.extend_user import validate_superuser_auth from kobo.apps.accounts.mfa.models import MfaMethod +@override_config(SUPERUSER_AUTH_ENFORCEMENT=True) class ValidateSuperuserMfaTest(TestCase): def setUp(self): - config.SUPERUSER_AUTH_ENFORCEMENT = True self.superuser = User.objects.create_superuser( username='admin', password='adminpassword' ) diff --git a/jsapp/js/account/billingContextProvider.component.tsx b/jsapp/js/account/billingContextProvider.component.tsx index 77e9825dd2..f22c130fba 100644 --- a/jsapp/js/account/billingContextProvider.component.tsx +++ b/jsapp/js/account/billingContextProvider.component.tsx @@ -5,8 +5,12 @@ import { OrganizationContext, useOrganization, } from 'js/account/organizations/useOrganization.hook'; +import sessionStore from 'js/stores/session'; export const BillingContextProvider = (props: {children: ReactNode}) => { + if (!sessionStore.isLoggedIn) { + return <>{props.children}; + } const [organization, reloadOrg, orgStatus] = useOrganization(); const usage = useUsage(organization?.id); const products = useProducts(); diff --git a/jsapp/js/account/organizations/requireOrgOwner.component.tsx b/jsapp/js/account/organizations/requireOrgOwner.component.tsx index dd77f49886..927bfe23df 100644 --- a/jsapp/js/account/organizations/requireOrgOwner.component.tsx +++ b/jsapp/js/account/organizations/requireOrgOwner.component.tsx @@ -1,11 +1,11 @@ -import React, {ReactElement, Suspense, useContext, useEffect} from 'react'; -import {RouteObject, useNavigate} from 'react-router-dom'; +import React, {Suspense, useContext, useEffect} from 'react'; +import {useNavigate} from 'react-router-dom'; import {OrganizationContext} from 'js/account/organizations/useOrganization.hook'; import LoadingSpinner from 'js/components/common/loadingSpinner'; import {ACCOUNT_ROUTES} from 'js/account/routes.constants'; interface Props { - children: RouteObject[] | undefined | ReactElement; + children: React.ReactNode; redirect?: boolean; } diff --git a/jsapp/js/account/plans/billingButton.component.tsx b/jsapp/js/account/plans/billingButton.component.tsx index 642063303a..7ae766e852 100644 --- a/jsapp/js/account/plans/billingButton.component.tsx +++ b/jsapp/js/account/plans/billingButton.component.tsx @@ -2,7 +2,7 @@ import cx from 'classnames'; import type {ButtonProps} from 'js/components/common/button'; import Button from 'js/components/common/button'; import React from 'react'; -import {button} from './billingButton.module.scss'; +import styles from './billingButton.module.scss'; /** * The base button component that's used on the Plans/Add-ons pages. @@ -16,7 +16,7 @@ export default function BillingButton(props: Partial) { color='blue' size='l' {...props} - className={cx([button, props.className])} + className={cx([styles.button, props.className])} isFullWidth /> ); diff --git a/jsapp/js/account/plans/plan.component.tsx b/jsapp/js/account/plans/plan.component.tsx index 66b52fd4db..3cc822d39e 100644 --- a/jsapp/js/account/plans/plan.component.tsx +++ b/jsapp/js/account/plans/plan.component.tsx @@ -341,7 +341,7 @@ export default function Plan(props: PlanProps) { const getSubscribedProduct = useCallback(getSubscriptionsForProductId, []); const isSubscribedProduct = useCallback( - (product: SinglePricedProduct, quantity = null) => { + (product: SinglePricedProduct, quantity: number | undefined) => { if (!product.price?.unit_amount && !hasActiveSubscription) { return true; } @@ -356,7 +356,7 @@ export default function Plan(props: PlanProps) { (subscription: SubscriptionInfo) => subscription.items[0].price.id === product.price.id && hasManageableStatus(subscription) && - quantity && + quantity !== undefined && quantity === subscription.quantity ); } diff --git a/jsapp/js/account/security/email/emailSection.component.tsx b/jsapp/js/account/security/email/emailSection.component.tsx index 51a0a99ae7..8d4b4b7099 100644 --- a/jsapp/js/account/security/email/emailSection.component.tsx +++ b/jsapp/js/account/security/email/emailSection.component.tsx @@ -170,6 +170,7 @@ export default function EmailSection() { value={email.newEmail} placeholder={t('Type new email address')} onChange={onTextFieldChange.bind(onTextFieldChange)} + type='email' />