Compare commits

..

162 Commits

Author SHA1 Message Date
Szilárd Dóró
7756103476 Merge pull request #1861 from nhost/changeset-release/main 2023-04-24 09:38:50 +02:00
github-actions[bot]
fef9456c12 chore: update versions 2023-04-23 19:36:24 +00:00
Szilárd Dóró
2d6d56f6b0 Merge pull request #1860 from nhost/fix/project-details
fix(dashboard): filter projects by workspace
2023-04-23 21:35:16 +02:00
Szilárd Dóró
f54be0fefd fix: don't break unit tests 2023-04-23 19:27:36 +02:00
Szilárd Dóró
4e76d388ab fix: remove unused query parameter 2023-04-23 16:42:33 +02:00
Szilárd Dóró
84b84ab785 fix: filter projects by workspace 2023-04-23 16:34:39 +02:00
Szilárd Dóró
899732f280 Merge pull request #1852 from nhost/changeset-release/main
chore: update versions
2023-04-21 13:40:09 +02:00
github-actions[bot]
037b566e39 chore: update versions 2023-04-21 11:23:53 +00:00
Szilárd Dóró
829f20c83c Merge pull request #1856 from nhost/renovate/vitejs-plugin-react-4.x
chore(deps): update dependency @vitejs/plugin-react to v4
2023-04-21 13:22:44 +02:00
Szilárd Dóró
f1b5a944a3 chore: add changeset 2023-04-21 11:42:44 +02:00
renovate[bot]
5ccb764ae5 chore(deps): update dependency @vitejs/plugin-react to v4 2023-04-21 09:38:43 +00:00
Szilárd Dóró
ef2b639734 Merge pull request #1839 from nhost/renovate/vueuse-core-10.x
fix(deps): update dependency @vueuse/core to v10
2023-04-21 11:36:00 +02:00
Szilárd Dóró
a5b895a827 chore: add changeset 2023-04-21 11:14:13 +02:00
renovate[bot]
b441b4bae2 fix(deps): update dependency @vueuse/core to v10 2023-04-21 09:02:30 +00:00
Szilárd Dóró
a6c67c1e4c Merge pull request #1836 from nhost/renovate/react-monorepo
chore(deps): update dependency @types/react to v18.0.37
2023-04-21 10:54:19 +02:00
Szilárd Dóró
7f1785ac0f chore: add changeset 2023-04-21 10:21:02 +02:00
renovate[bot]
ec74e7fe98 chore(deps): update dependency @types/react to v18.0.37 2023-04-19 12:53:55 +00:00
Szilárd Dóró
6713c198c6 Merge pull request #1833 from nhost/renovate/turbo-1.x
chore(deps): update dependency turbo to v1.9.3
2023-04-19 14:52:03 +02:00
renovate[bot]
35a6b9cf47 chore(deps): update dependency turbo to v1.9.3 2023-04-19 09:32:19 +00:00
Szilárd Dóró
79f97fad76 Merge pull request #1838 from nhost/renovate/graphql-request-6.x
fix(deps): update dependency graphql-request to v6
2023-04-19 11:29:16 +02:00
Szilárd Dóró
2faf79077d chore: add changeset 2023-04-19 11:07:46 +02:00
Szilárd Dóró
4972b6feb6 chore: sync versions, update codegen 2023-04-19 11:07:15 +02:00
Szilárd Dóró
23d5861c4c Merge pull request #1837 from rikardwissing/fix/wait-for-valid-token
Wait for valid token or sign out before establishing connection.
2023-04-19 09:31:56 +02:00
renovate[bot]
098ac5a71c fix(deps): update dependency graphql-request to v6 2023-04-18 18:54:27 +00:00
Nuno Pato
3a15329cfd Merge pull request #1849 from nhost/docs/add-compute-section
add compute section to the docs
2023-04-18 13:20:39 +00:00
Nuno Pato
c3e798aa1d asd 2023-04-18 13:15:40 +00:00
Szilárd Dóró
eec5e6a93d Merge pull request #1843 from nhost/changeset-release/main
chore: update versions
2023-04-18 15:10:41 +02:00
Nuno Pato
d964b689cd move compute resources to position 1 2023-04-18 09:37:28 +00:00
Nuno Pato
1e080c1af5 add compute section to the docs 2023-04-18 09:35:01 +00:00
github-actions[bot]
177bba7ec0 chore: update versions 2023-04-18 07:27:56 +00:00
Szilárd Dóró
a593b45dc2 Merge pull request #1845 from nhost/chore/dashboard-update-nomenclature-compute
chore: dashboard: update nomenclature for compute
2023-04-18 09:24:46 +02:00
Szilárd Dóró
b384fb8bd8 chore: merge changesets 2023-04-17 20:58:38 +02:00
Nuno Pato
abd8620ded "Resources" -> "Compute" 2023-04-17 16:58:45 +00:00
Szilárd Dóró
e62ccdcaae Merge pull request #1844 from nhost/fix/resource-memory-limit
fix(dashboard): use correct vCPUs and memory after reset
2023-04-17 14:17:49 +02:00
Szilárd Dóró
46d01b09d6 chore: use constants 2023-04-17 13:45:59 +02:00
Szilárd Dóró
ff74e712f8 fix: use correct vCPUs and memory after reset 2023-04-17 13:38:47 +02:00
Szilárd Dóró
770794ccad Merge pull request #1709 from nhost/feat/resource-sliders
feat(dashboard): Resource Sliders
2023-04-17 13:03:04 +02:00
Szilárd Dóró
aa80d1795d chore: update initial resource ratio 2023-04-17 09:28:17 +02:00
Szilárd Dóró
eaa7720c65 fix: fix tests 2023-04-17 09:17:34 +02:00
Szilárd Dóró
7f447d1182 fix: don't break the initial UI 2023-04-17 08:43:23 +02:00
Szilárd Dóró
5d3dd84762 Merge branch 'main' into feat/resource-sliders 2023-04-17 08:36:55 +02:00
Szilárd Dóró
c625317342 Merge pull request #1841 from nhost/changeset-release/main
chore: update versions
2023-04-17 08:36:12 +02:00
Rikard Wissing
117398f5dc Add changeset 2023-04-16 15:00:50 +01:00
Rikard Wissing
4e421eb4bd Refactor a bit 2023-04-16 14:55:51 +01:00
Rikard Wissing
771447b089 Remove log 2023-04-16 14:52:35 +01:00
github-actions[bot]
8ab75a4146 chore: update versions 2023-04-14 09:54:44 +00:00
Szilárd Dóró
607f465616 Merge pull request #1840 from nhost/chore/use-dialog-hook
chore(dashboard): unify payment dialog management
2023-04-14 11:50:15 +02:00
Szilárd Dóró
668c877130 chore: add changeset 2023-04-14 11:17:32 +02:00
Szilárd Dóró
4bd870eb96 chore: relocate BillingPaymentMethodForm 2023-04-14 11:15:58 +02:00
Szilárd Dóró
39b3161d91 fix: use up-to-date card information 2023-04-14 10:31:27 +02:00
Szilárd Dóró
ae090a6585 chore: unify modal management for payments 2023-04-13 16:53:30 +02:00
Rikard Wissing
be4831ae62 Update integrations/apollo/src/index.ts
Co-authored-by: Szilárd Dóró <doroszilard@gmail.com>
2023-04-13 15:10:14 +02:00
Szilárd Dóró
4fb0c18c32 Merge branch 'main' into feat/resource-sliders 2023-04-13 14:56:03 +02:00
Szilárd Dóró
22cdd7f8d7 Merge pull request #1834 from nhost/changeset-release/main
chore: update versions
2023-04-13 14:38:10 +02:00
github-actions[bot]
f3a91a1f76 chore: update versions 2023-04-13 11:09:10 +00:00
Szilárd Dóró
1e9b92fcf8 Merge pull request #1835 from nhost/chore/remove-user-context
chore(dashboard): cleanup unused code
2023-04-13 13:07:30 +02:00
Szilárd Dóró
6cc56066c2 chore: update changeset 2023-04-13 11:44:38 +02:00
Rikard Wissing
99e80cea44 Wait for valid token 2023-04-12 23:45:38 +02:00
Szilárd Dóró
f2f1c01e3b chore: refactor memory steps 2023-04-12 17:43:44 +02:00
Szilárd Dóró
2c0f98e85c Merge branch 'main' into feat/resource-sliders 2023-04-12 14:43:12 +02:00
Szilárd Dóró
a3ad84925c chore: cleanup additional GraphQL operations 2023-04-12 14:36:11 +02:00
Szilárd Dóró
b8611b6a1c chore: cleanup unused GraphQL operations 2023-04-12 14:25:41 +02:00
Szilárd Dóró
a0e3030005 chore: cleanup UIContext 2023-04-12 14:01:41 +02:00
Szilárd Dóró
0cf1f1d938 Merge branch 'main' into chore/remove-user-context 2023-04-12 13:32:25 +02:00
Szilárd Dóró
88f026066f Merge pull request #1830 from rikardwissing/patch-1
Add generateLinks instead of link and onError args
2023-04-12 13:26:13 +02:00
Szilárd Dóró
185bef878d fix: accommodate dashboard test 2023-04-12 11:56:03 +02:00
Szilárd Dóró
a1c7b00e74 chore: add changeset 2023-04-12 11:55:29 +02:00
Szilárd Dóró
6da4562e79 chore: format code 2023-04-12 11:55:22 +02:00
Szilárd Dóró
e44cfcb2f2 Merge branch 'patch-1' of https://github.com/rikardwissing/nhost into pr/1830 2023-04-12 11:50:32 +02:00
Rikard Wissing
23fabaf8a6 Check for undefined 2023-04-12 11:48:48 +02:00
Szilárd Dóró
f4dca9836f fix: block UI when user is not available 2023-04-12 11:34:47 +02:00
Szilárd Dóró
f2704ea149 chore: improve query refetch 2023-04-12 11:30:34 +02:00
Szilárd Dóró
dd1b053212 fix: don't break provisioning page 2023-04-12 10:46:37 +02:00
Szilárd Dóró
d4ccc65655 chore: add changeset 2023-04-12 10:41:23 +02:00
Szilárd Dóró
2c2570fc82 chore: cleanup unused hooks 2023-04-12 10:40:49 +02:00
Rikard Wissing
a60f26966b Update integrations/apollo/src/index.ts
Co-authored-by: Szilárd Dóró <doroszilard@gmail.com>
2023-04-12 09:52:19 +02:00
Rikard Wissing
a988de2d61 Update integrations/apollo/src/index.ts
Co-authored-by: Szilárd Dóró <doroszilard@gmail.com>
2023-04-12 09:51:58 +02:00
Rikard Wissing
de54ca460e Update integrations/apollo/src/index.ts
Co-authored-by: Szilárd Dóró <doroszilard@gmail.com>
2023-04-12 09:51:48 +02:00
Szilárd Dóró
afdffab743 Merge pull request #1831 from nhost/fix/functions-response
fix(nhost-js): don't suppress error messages
2023-04-12 09:46:02 +02:00
Szilárd Dóró
4c61520397 chore: add changeset 2023-04-12 09:09:09 +02:00
Szilárd Dóró
f02cd444d5 fix: don't break builds 2023-04-11 17:38:10 +02:00
Szilárd Dóró
7f45a51aca fix: don't break build 2023-04-11 17:30:21 +02:00
Szilárd Dóró
08e70b9df9 fix: don't suppress error messages 2023-04-11 17:21:40 +02:00
Szilárd Dóró
32f92489a4 Merge pull request #1829 from nhost/changeset-release/main
chore: update versions
2023-04-11 15:58:09 +02:00
Szilárd Dóró
20a83362ee fix: don't break builds 2023-04-11 15:28:23 +02:00
Szilárd Dóró
20b800c3e4 Merge branch 'main' into feat/resource-sliders 2023-04-11 15:24:28 +02:00
github-actions[bot]
94c9cd151a chore: update versions 2023-04-11 13:13:16 +00:00
Szilárd Dóró
0e9eb18052 Merge pull request #1827 from nhost/renovate/react-monorepo
chore(deps): update dependency @types/react to v18.0.34
2023-04-11 15:11:46 +02:00
Szilárd Dóró
bfaa5b4c4a Merge branch 'main' into pr/1830 2023-04-11 14:57:39 +02:00
Szilárd Dóró
52ec6fe70c Merge pull request #1826 from nhost/renovate/glob-10.x
fix(deps): update dependency glob to v10
2023-04-11 14:45:48 +02:00
Szilárd Dóró
43b1b1442c chore: sync @types/react and @types/react-dom 2023-04-11 14:45:26 +02:00
Szilárd Dóró
b06239cc14 chore: add changeset 2023-04-11 14:30:35 +02:00
renovate[bot]
73dde87a65 fix(deps): update dependency glob to v10 2023-04-11 10:58:36 +00:00
renovate[bot]
7e7d810b74 chore(deps): update dependency @types/react to v18.0.34 2023-04-11 10:58:08 +00:00
Szilárd Dóró
b6b2403562 Merge pull request #1825 from nhost/renovate/rimraf-5.x
chore(deps): update dependency rimraf to v5
2023-04-11 12:54:11 +02:00
Szilárd Dóró
9a1f095a45 chore: add changeset 2023-04-11 12:13:55 +02:00
Rikard Wissing
a1a00b33ad Make backwards compatible
There is a behavioral change because of how customLink was implemented before. But I think this is the intended behavior.
2023-04-11 11:49:24 +02:00
renovate[bot]
a3b1ffe77c chore(deps): update dependency rimraf to v5 2023-04-11 09:42:50 +00:00
Szilárd Dóró
4f22ab3a99 Merge pull request #1816 from nhost/chore/current-project-hook
chore(dashboard): cleanup home page
2023-04-11 11:39:55 +02:00
Rikard Wissing
a269f4ca3f Add generateLinks instead of link and onError args
Breaking change, but makes it more versatile.
Not tested
2023-04-11 11:16:15 +02:00
Szilárd Dóró
411cb65ba4 chore: add changeset 2023-04-11 11:14:35 +02:00
Szilárd Dóró
f691c1f753 Merge pull request #1824 from nhost/renovate/vitest-monorepo
chore(deps): update vitest monorepo to ^0.30.0
2023-04-11 10:33:09 +02:00
Szilárd Dóró
b299cfc943 chore: add changeset 2023-04-11 08:38:55 +02:00
renovate[bot]
6157680963 chore(deps): update vitest monorepo to ^0.30.0 2023-04-09 15:40:35 +00:00
Szilárd Dóró
1d4bdfa88b fix integration tests 2023-04-06 18:43:10 +02:00
Szilárd Dóró
2755fc43b9 fix linter error 2023-04-06 17:18:01 +02:00
Szilárd Dóró
0c80d141aa fix: don't break integration tests 2023-04-06 16:55:31 +02:00
Szilárd Dóró
f285883c88 chore: improve integration tests 2023-04-06 16:48:29 +02:00
Szilárd Dóró
39f9a325d3 chore: delete old useCurrentWorkspaceAndApplication hook 2023-04-06 16:26:52 +02:00
Szilárd Dóró
e8f66e346f chore: migrate more components to new hook 2023-04-06 16:16:39 +02:00
Szilárd Dóró
98c0535fc9 chore: migrate more components to new hook 2023-04-06 15:55:49 +02:00
Szilárd Dóró
7a61c2e976 chore: migrate more components to new hook 2023-04-06 15:49:14 +02:00
Szilárd Dóró
a15a4db210 fix: revert locale related changes 2023-04-06 15:25:38 +02:00
Szilárd Dóró
11fcb8c72f Merge branch 'main' into chore/current-project-hook 2023-04-06 15:18:08 +02:00
Szilárd Dóró
93910f27e1 chore: partially migrate components to useCurrentWorkspaceAndProject 2023-04-05 16:00:09 +02:00
Szilárd Dóró
04e2d19dda fix: fix issue plaguing sign outs for a while now 2023-04-05 14:21:11 +02:00
Szilárd Dóró
a2175f6df7 chore: cleanup unused files 2023-04-05 13:54:50 +02:00
Szilárd Dóró
18d415a8fd feat: rework project list 2023-04-05 12:54:20 +02:00
Szilárd Dóró
baaa510309 fix: add price to GQL 2023-03-31 15:28:59 +02:00
Szilárd Dóró
a84aa5ad68 Merge branch 'main' into feat/resource-sliders 2023-03-31 15:19:09 +02:00
Szilárd Dóró
4191b933c9 Merge branch 'main' into feat/resource-sliders 2023-03-24 10:57:01 +01:00
Szilárd Dóró
cf2264ce1d Merge branch 'main' into feat/resource-sliders 2023-03-20 16:25:34 +01:00
Szilárd Dóró
02dd9dd8c0 Merge branch 'main' into feat/resource-sliders 2023-03-20 12:41:38 +01:00
Szilárd Dóró
d4ff25df0f fix: adjust warning color 2023-03-10 14:19:10 +01:00
Szilárd Dóró
3d74374780 fix: update codegen 2023-03-09 10:22:43 +01:00
Szilárd Dóró
7063af678c Merge remote-tracking branch 'origin/main' into feat/resource-sliders 2023-03-09 10:14:33 +01:00
Szilárd Dóró
2b44a1cf27 chore: add tests, fix flaky tests
- fix a UI glitch where values jumped after reset
2023-03-08 16:33:02 +01:00
Szilárd Dóró
c4f60b3645 feat: fetch plan independently 2023-03-08 15:44:30 +01:00
Szilárd Dóró
f86f658aa5 feat: improve upgrade / downgrade experience 2023-03-08 13:54:35 +01:00
Szilárd Dóró
bd02bd3f3e fix: cpu -> vcpu and selected -> available 2023-03-08 13:41:50 +01:00
Szilárd Dóró
a133faa797 chore: added submission tests 2023-03-08 11:24:17 +01:00
Szilárd Dóró
bb0269691d Merge remote-tracking branch 'origin/main' into feat/resource-sliders 2023-03-08 10:23:48 +01:00
Szilárd Dóró
8d6171d22d chore: move test-related stuff 2023-03-07 17:23:09 +01:00
Szilárd Dóró
fff178d79f fix: fix unit tests 2023-03-07 16:59:15 +01:00
Szilárd Dóró
5e5e454ae7 chore: remove inputs from total resources 2023-03-07 16:34:40 +01:00
Szilárd Dóró
ce005f6d9e Merge remote-tracking branch 'origin/main' into feat/resource-sliders 2023-03-07 15:37:42 +01:00
Szilárd Dóró
85889ee882 chore: add changeset 2023-03-07 10:23:33 +01:00
Szilárd Dóró
351873059e fix: use correct colors in light mode 2023-03-07 10:09:00 +01:00
Szilárd Dóró
8ccfc10522 fix: fix inner slider behaviour 2023-03-07 10:05:25 +01:00
Szilárd Dóró
82b02ca70b feat: improve slider appearance 2023-03-07 09:12:28 +01:00
Szilárd Dóró
14fc132040 fix: show footer when downgrading 2023-03-06 17:02:54 +01:00
Szilárd Dóró
a35da349ed fix: fix tests and prevent error when plan is missing 2023-03-06 16:48:43 +01:00
Szilárd Dóró
302e1d9d33 feat: retrieve plan info from the project 2023-03-06 16:18:42 +01:00
Szilárd Dóró
0db40184e8 fix: show values correctly after saving resources 2023-03-06 15:38:07 +01:00
Szilárd Dóró
d38649494e chore: added tests 2023-03-06 15:14:30 +01:00
Szilárd Dóró
5f22f1b5e5 chore: restructure to support tests
- added network requests to retrieve computation info
2023-03-06 14:13:48 +01:00
Szilárd Dóró
494f93a4bf chore: change terminology RAM -> Memory 2023-03-06 10:28:40 +01:00
Szilárd Dóró
84c8af232c fix: don't nest p in p 2023-03-03 16:54:21 +01:00
Szilárd Dóró
7f101d54da feat: add pricing placeholders 2023-03-03 16:53:28 +01:00
Szilárd Dóró
75b497412e fix: reset error, fix RAM label 2023-03-03 16:16:09 +01:00
Szilárd Dóró
5bd774afbb chore: improve readability 2023-03-03 16:11:54 +01:00
Szilárd Dóró
cdfe203fe4 Merge remote-tracking branch 'origin/main' into feat/resource-sliders 2023-03-03 15:37:45 +01:00
Szilárd Dóró
4c7d32e944 fix: resource labels 2023-03-03 15:35:17 +01:00
Szilárd Dóró
447c622fc0 fix: remove unnecessary inputs from services 2023-03-03 15:33:01 +01:00
Szilárd Dóró
03f22aed72 chore: improved resource constants 2023-03-03 15:21:15 +01:00
Szilárd Dóró
ede5abf2ac fix: use correct width for inner slider rail 2023-03-03 15:09:33 +01:00
Szilárd Dóró
0bdd1d0e0c fix: fixed top slider vlaidation 2023-03-03 14:19:08 +01:00
Szilárd Dóró
61de7b21fd feat: improve slider rails 2023-03-03 14:00:57 +01:00
Szilárd Dóró
4b6ead1b17 feat: add validation to top slider 2023-03-03 13:18:57 +01:00
Szilárd Dóró
0b193e6310 feat: create form fragments 2023-03-03 12:15:29 +01:00
Szilárd Dóró
b21a5403fe feat: add sections for services, improve slider 2023-03-03 11:15:01 +01:00
Szilárd Dóró
e8320be941 feat: initial Resource page code 2023-03-02 16:23:23 +01:00
311 changed files with 7908 additions and 10538 deletions

View File

@@ -81,7 +81,7 @@ module.exports = {
},
{
group: ['@testing-library/react*'],
message: 'Please use @/utils/testUtils instead.',
message: 'Please use @/tests/testUtils instead.',
},
],
},

View File

@@ -1,5 +1,51 @@
# @nhost/dashboard
## 0.15.2
### Patch Changes
- 84b84ab7: fix(projects): filter projects by workspace
## 0.15.1
### Patch Changes
- 2faf7907: chore(deps): bump `graphql-request` to v6
- f1b5a944: chore(deps): bump `@vitejs/plugin-react` to v4
- 7f1785ac: chore(deps): bump `@types/react` to v18.0.37
- @nhost/react-apollo@5.0.19
## 0.15.0
### Minor Changes
- 85889ee8: feat(dashboard): add Compute management to the settings
## 0.14.8
### Patch Changes
- 668c8771: chore(dialogs): unify dialog management of payment dialogs
## 0.14.7
### Patch Changes
- d4ccc656: chore: cleanup unused code
- @nhost/react-apollo@5.0.18
- @nhost/nextjs@1.13.21
## 0.14.6
### Patch Changes
- b299cfc9: chore(deps): bump `vitest` to v0.30.0
- 411cb65b: chore(projects): refactor workspace and project hooks
- 43b1b144: chore(deps): bump `@types/react` to v18.0.34 and `@types/react-dom` to v18.0.11
- Updated dependencies [43b1b144]
- @nhost/react-apollo@5.0.17
- @nhost/nextjs@1.13.20
## 0.14.5
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/dashboard",
"version": "0.14.5",
"version": "0.15.2",
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
@@ -8,7 +8,7 @@
"build": "next build --no-lint",
"analyze": "ANALYZE=true pnpm build --no-lint",
"start": "next start",
"lint": "next lint --max-warnings 2",
"lint": "next lint --max-warnings 0",
"test": "vitest",
"codegen": "graphql-codegen --config graphql.config.yaml --errors-only",
"nhost:dev": "nhost dev -d",
@@ -51,7 +51,7 @@
"generate-password": "^1.7.0",
"graphiql": "^2.4.0",
"graphql": "^16.6.0",
"graphql-request": "^4.3.0",
"graphql-request": "^6.0.0",
"graphql-tag": "^2.12.6",
"graphql-ws": "^5.11.2",
"just-kebab-case": "^4.1.1",
@@ -105,15 +105,15 @@
"@types/lodash.debounce": "^4.0.7",
"@types/node": "^16.11.7",
"@types/pluralize": "^0.0.29",
"@types/react": "18.0.33",
"@types/react": "18.0.37",
"@types/react-dom": "18.0.11",
"@types/react-table": "^7.7.12",
"@types/testing-library__jest-dom": "^5.14.5",
"@types/validator": "^13.7.10",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@vitejs/plugin-react": "^3.0.0",
"@vitest/coverage-c8": "^0.29.0",
"@vitejs/plugin-react": "^4.0.0",
"@vitest/coverage-c8": "^0.30.0",
"autoprefixer": "^10.4.13",
"babel-loader": "^8.3.0",
"babel-plugin-transform-remove-console": "^6.9.4",
@@ -147,7 +147,7 @@
"tsconfig-paths-webpack-plugin": "^4.0.0",
"vite": "^4.0.2",
"vite-tsconfig-paths": "^4.0.3",
"vitest": "^0.29.0",
"vitest": "^0.30.0",
"webpack": "^5.75.0"
},
"browserslist": {

View File

@@ -1,6 +1,6 @@
import FeedbackForm from '@/components/common/FeedbackForm';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useInterval } from '@/hooks/useInterval';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Button from '@/ui/v2/Button';
import { Dropdown } from '@/ui/v2/Dropdown';
@@ -33,7 +33,7 @@ export function AppLoader({
date,
restoring,
}: AppLoaderProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
let timeElapsedSinceEventCreation: number;
@@ -41,11 +41,11 @@ export function AppLoader({
timeElapsedSinceEventCreation = getRelativeDateByApplicationState(date);
} else if (unpause) {
timeElapsedSinceEventCreation = getRelativeDateByApplicationState(
currentApplication.appStates[0].createdAt,
currentProject.appStates[0].createdAt,
);
} else {
timeElapsedSinceEventCreation = getRelativeDateByApplicationState(
currentApplication.createdAt,
currentProject.createdAt,
);
}
@@ -63,9 +63,9 @@ export function AppLoader({
<div className="grid grid-flow-row gap-2">
<div className="grid grid-flow-row gap-1">
<Text variant="h3" component="h1">
{restoring && `Restoring ${currentApplication.name} from backup`}
{!restoring && unpause && `Unpausing ${currentApplication.name}`}
{!restoring && !unpause && `Provisioning ${currentApplication.name}`}
{restoring && `Restoring ${currentProject.name} from backup`}
{!restoring && unpause && `Unpausing ${currentProject.name}`}
{!restoring && !unpause && `Provisioning ${currentProject.name}`}
</Text>
<Text>This normally takes around 2 minutes</Text>
</div>

View File

@@ -2,7 +2,7 @@ import FeedbackForm from '@/components/common/FeedbackForm';
import Container from '@/components/layout/Container';
import { useAppCreatedAt } from '@/hooks/useAppCreatedAt';
import { useCurrentDate } from '@/hooks/useCurrentDate';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { ApplicationState } from '@/types/application';
import { ApplicationStatus } from '@/types/application';
import { Modal } from '@/ui/Modal';
@@ -31,8 +31,7 @@ import { RemoveApplicationModal } from './RemoveApplicationModal';
import { StagingMetadata } from './StagingMetadata';
export default function ApplicationErrored() {
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject();
const [changingApplicationStateLoading, setChangingApplicationStateLoading] =
useState(false);
@@ -43,7 +42,8 @@ export default function ApplicationErrored() {
// state, but we want to query again to double-check that we have the latest state
// of the application. @GC.
const { data, loading, error } = useGetApplicationStateQuery({
variables: { appId: currentApplication.id },
variables: { appId: currentProject?.id },
skip: !currentProject,
});
const previousState = data?.app?.appStates
@@ -56,8 +56,8 @@ export default function ApplicationErrored() {
const client = useApolloClient();
const { currentDate } = useCurrentDate();
const user = useUserData();
const isOwner = currentWorkspace.members.some(
({ userId, type }) => userId === user?.id && type === 'owner',
const isOwner = currentWorkspace.workspaceMembers.some(
({ id, type }) => id === user?.id && type === 'owner',
);
const { appCreatedAt } = useAppCreatedAt();
@@ -69,15 +69,15 @@ export default function ApplicationErrored() {
try {
await deleteApplication({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
},
});
triggerToast(`${currentApplication.name} deleted`);
triggerToast(`${currentProject?.name} deleted`);
} catch (e) {
triggerToast(`Error deleting ${currentApplication.name}`);
triggerToast(`Error deleting ${currentProject?.name}`);
discordAnnounce(
`Error deleting app: ${currentApplication.name} (${user.email})`,
`Error deleting app: ${currentProject?.name} (${user.email})`,
);
return;
}
@@ -85,19 +85,19 @@ export default function ApplicationErrored() {
await insertApp({
variables: {
app: {
name: currentApplication.name,
slug: currentApplication.slug,
planId: currentApplication.plan.id,
name: currentProject.name,
slug: currentProject.slug,
planId: currentProject.plan.id,
workspaceId: currentWorkspace.id,
regionId: currentApplication.region.id,
regionId: currentProject.region.id,
},
},
});
discordAnnounce(`Recreating: ${currentApplication.name} (${user.email})`);
triggerToast(`Recreating ${currentApplication.name} `);
discordAnnounce(`Recreating: ${currentProject?.name} (${user.email})`);
triggerToast(`Recreating ${currentProject?.name} `);
await updateOwnCache(client);
} catch (e) {
triggerToast(`Error trying to recreate: ${currentApplication.name}`);
triggerToast(`Error trying to recreate: ${currentProject?.name}`);
}
}
@@ -106,18 +106,18 @@ export default function ApplicationErrored() {
try {
await updateApplication({
variables: {
appId: currentApplication.id,
appId: currentProject?.id,
app: {
desiredState: ApplicationStatus.Live,
},
},
});
triggerToast(`${currentApplication.name} set to awake.`);
triggerToast(`${currentProject?.name} set to awake.`);
} catch (e) {
triggerToast(`Error trying to awake ${currentApplication.name}`);
triggerToast(`Error trying to awake ${currentProject?.name}`);
discordAnnounce(
`Error trying to awake app: ${currentApplication.name} (${user.email})`,
`Error trying to awake app: ${currentProject?.name} (${user.email})`,
);
}
}
@@ -175,8 +175,8 @@ export default function ApplicationErrored() {
// which instead of deleting just an application, it deletes and recreates.
handler={recreateApplication}
close={() => setShowRecreateModal(false)}
title={`Recreate project ${currentApplication.name}?`}
description={`The project ${currentApplication.name} will be removed and then re-created. All data will be lost and there will be no way to
title={`Recreate project ${currentProject.name}?`}
description={`The project ${currentProject?.name} will be removed and then re-created. All data will be lost and there will be no way to
recover the app once it has been deleted.`}
/>
</Modal>
@@ -187,8 +187,8 @@ export default function ApplicationErrored() {
>
<RemoveApplicationModal
close={() => setShowDeleteModal(false)}
title={`Remove project ${currentApplication.name}?`}
description={`The project ${currentApplication.name} will be removed. All data will be lost and there will be no way to
title={`Remove project ${currentProject.name}?`}
description={`The project ${currentProject?.name} will be removed. All data will be lost and there will be no way to
recover the app once it has been deleted.`}
/>
</Modal>

View File

@@ -1,8 +1,8 @@
import {
GetOneUserDocument,
GetAllWorkspacesAndProjectsDocument,
useDeleteApplicationMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import Button from '@/ui/v2/Button';
import ArrowRightIcon from '@/ui/v2/icons/ArrowRightIcon';
import Link from '@/ui/v2/Link';
@@ -10,14 +10,15 @@ import Text from '@/ui/v2/Text';
import { copy } from '@/utils/copy';
import { getApplicationStatusString } from '@/utils/helpers';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { formatDistance } from 'date-fns';
import { useRouter } from 'next/router';
import { toast } from 'react-hot-toast';
export default function ApplicationInfo() {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [deleteApplication] = useDeleteApplicationMutation({
refetchQueries: [GetOneUserDocument],
refetchQueries: [GetAllWorkspacesAndProjectsDocument],
});
const router = useRouter();
@@ -26,7 +27,7 @@ export default function ApplicationInfo() {
await toast.promise(
deleteApplication({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
},
}),
{
@@ -36,6 +37,7 @@ export default function ApplicationInfo() {
'An error occurred while deleting the project. Please try again.',
),
},
getToastStyleProps(),
);
await router.push('/');
@@ -51,10 +53,10 @@ export default function ApplicationInfo() {
<Button
variant="borderless"
onClick={() => copy(currentApplication.id, 'Application ID')}
onClick={() => copy(currentProject.id, 'Application ID')}
className="py-1 text-xs"
>
{currentApplication.id}
{currentProject.id}
</Button>
</div>
@@ -65,27 +67,27 @@ export default function ApplicationInfo() {
variant="borderless"
onClick={() =>
copy(
currentApplication.desiredState.toString(),
currentProject.desiredState.toString(),
'Application Desired State',
)
}
className="py-1 text-xs"
>
{getApplicationStatusString(currentApplication.desiredState)}
{getApplicationStatusString(currentProject.desiredState)}
</Button>
</div>
<div className="grid grid-flow-row gap-0.5">
<Text variant="subtitle2">Region:</Text>
<Text variant="subtitle1">{currentApplication.region.city}</Text>
<Text variant="subtitle1">{currentProject.region.city}</Text>
</div>
<div className="grid grid-flow-row gap-0.5">
<Text variant="subtitle2">Created:</Text>
<Text variant="subtitle1">
{formatDistance(new Date(currentApplication.createdAt), new Date(), {
{formatDistance(new Date(currentProject.createdAt), new Date(), {
addSuffix: true,
})}
</Text>
@@ -93,7 +95,7 @@ export default function ApplicationInfo() {
<div className="grid grid-flow-row gap-2">
<Link
href={`https://staging.nhost.run/console/data/default/schema/public/tables/app_state_history/browse?filter=app_id%3B%24eq%3B${currentApplication.id}`}
href={`https://staging.nhost.run/console/data/default/schema/public/tables/app_state_history/browse?filter=app_id%3B%24eq%3B${currentProject.id}`}
target="_blank"
rel="noreferrer noopener"
className="grid grid-flow-col items-center justify-center gap-1 p-2"

View File

@@ -4,7 +4,6 @@ import Container from '@/components/layout/Container';
import OverviewDeployments from '@/components/overview/OverviewDeployments';
import OverviewDocumentation from '@/components/overview/OverviewDocumentation';
import OverviewMetrics from '@/components/overview/OverviewMetrics/OverviewMetrics';
import OverviewMigration from '@/components/overview/OverviewMigration';
import OverviewProjectInfo from '@/components/overview/OverviewProjectInfo';
import OverviewRepository from '@/components/overview/OverviewRepository';
import OverviewTopBar from '@/components/overview/OverviewTopBar';
@@ -12,7 +11,6 @@ import OverviewUsage from '@/components/overview/OverviewUsage';
import { features } from '@/components/overview/features';
import { frameworks } from '@/components/overview/frameworks';
import useIsPlatform from '@/hooks/common/useIsPlatform';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { Alert } from '@/ui/Alert';
import Divider from '@/ui/v2/Divider';
@@ -27,10 +25,6 @@ export default function ApplicationLive({
errorMessage,
}: ApplicationLiveProps) {
const isPlatform = useIsPlatform();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const isProjectUsingRDS = currentApplication?.featureFlags.some(
(feature) => feature.name === 'fleetcontrol_use_rds',
);
if (!isPlatform) {
return (
@@ -98,12 +92,6 @@ export default function ApplicationLive({
</div>
<div className="grid grid-flow-row content-start gap-8 lg:col-span-1 lg:gap-12">
{isProjectUsingRDS && (
<>
<OverviewMigration />
<Divider />
</>
)}
<OverviewProjectInfo />
<Divider />
<OverviewRepository />

View File

@@ -1,206 +0,0 @@
import { useDialog } from '@/components/common/DialogProvider';
import Container from '@/components/layout/Container';
import ProjectStatusInfo from '@/components/project/ProjectStatusInfo';
import useProjectRedirectWhenReady from '@/hooks/common/useProjectRedirectWhenReady';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useInterval } from '@/hooks/useInterval';
import { ApplicationStatus } from '@/types/application';
import { Alert } from '@/ui/Alert';
import Button from '@/ui/v2/Button';
import Link from '@/ui/v2/Link';
import Text from '@/ui/v2/Text';
import { discordAnnounce } from '@/utils/discordAnnounce';
import { triggerToast } from '@/utils/toast';
import {
useInsertFeatureFlagMutation,
useUpdateApplicationMutation,
} from '@/utils/__generated__/graphql';
import { useUserEmail } from '@nhost/nextjs';
import { useEffect, useState } from 'react';
/**
* Number of minutes to wait before enabling the "Cancel Migration" button.
*/
const MIGRATION_CANCEL_TIMEOUT_MINUTES = 15;
function MigrationDialog() {
const { closeAlertDialog } = useDialog();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const [countdownTimer, setCountdownTimer] = useState(-1);
const minutes = Math.floor(countdownTimer / 60);
const seconds = Math.floor(countdownTimer % 60);
const countdownActive = countdownTimer > 0;
useEffect(() => {
if (typeof window === 'undefined') {
return;
}
const rawTimestamp = localStorage.getItem(
`migration-${currentApplication?.id}`,
);
if (!rawTimestamp) {
return;
}
const timestamp = new Date(rawTimestamp);
const timeDifference =
timestamp.getTime() +
1000 * 60 * MIGRATION_CANCEL_TIMEOUT_MINUTES -
Date.now();
if (timeDifference < 0) {
setCountdownTimer(0);
return;
}
setCountdownTimer(timeDifference / 1000);
}, [currentApplication?.id]);
useInterval(
() =>
setCountdownTimer((prev) => {
if (prev === 0) {
return 0;
}
return prev - 1;
}),
1000,
);
useEffect(() => {
if (countdownTimer !== 0 || typeof window === 'undefined') {
return;
}
localStorage.removeItem(`migration-${currentApplication.id}`);
}, [countdownTimer, currentApplication.id]);
const [updateApplication] = useUpdateApplicationMutation({
refetchQueries: ['getOneUser'],
});
const [insertFeatureFlag] = useInsertFeatureFlagMutation();
const userEmail = useUserEmail();
async function handleCancelMigration() {
try {
await updateApplication({
variables: {
appId: currentApplication.id,
app: {
desiredState: ApplicationStatus.Live,
},
},
});
await insertFeatureFlag({
variables: {
flag: {
appId: currentApplication.id,
name: 'fleetcontrol_use_rds',
value: 'console',
description: 'Use RDS',
},
},
});
triggerToast(`${currentApplication.name} migration cancelled.`);
} catch (e) {
triggerToast(`Error trying to migrate ${currentApplication.name}`);
await discordAnnounce(
`Error trying to migrate app: ${currentApplication.subdomain} (${userEmail})`,
);
} finally {
closeAlertDialog();
}
}
return (
<div className="grid grid-flow-row gap-2 px-6">
<Text>
Cancelling this migration will revert your project to use the shared
Postgres instance.
</Text>
{!countdownActive && (
<Alert severity="warning" className="px-3 text-left">
Reach out to us at{' '}
<Link
underline="none"
target="_blank"
className="hover:underline focus:underline focus:outline-none"
href="https://discord.com/channels/552499021260914688/1029043079946182676"
>
#migratedb
</Link>{' '}
if you think the migration should have finished by now.
</Alert>
)}
<div className="grid grid-flow-row gap-2 pb-1">
<Button onClick={closeAlertDialog}>Continue Migration</Button>
<Button
onClick={handleCancelMigration}
variant="outlined"
color="secondary"
disabled={countdownActive}
>
{countdownActive
? `Cancel in ${String(minutes).padStart(2, '0')}:${String(
seconds,
).padStart(2, '0')}`
: 'Cancel Migration'}
</Button>
</div>
</div>
);
}
export default function ApplicationMigrating() {
const { openAlertDialog } = useDialog();
useProjectRedirectWhenReady({ pollInterval: 10000 });
return (
<Container className="flex flex-col gap-6">
<ProjectStatusInfo
className="mx-auto max-w-sm"
title="Migration in progress"
description="Your project is being migrated to use a dedicated and more performant Postgres instance."
imageProps={{
src: '/assets/migrating.svg',
alt: 'Application Migrating',
}}
/>
<Button
variant="borderless"
color="error"
className="mx-auto"
onClick={() =>
openAlertDialog({
title: 'Cancel Migration',
payload: <MigrationDialog />,
props: {
titleProps: {
className: 'px-6',
},
PaperProps: {
className: 'py-6 px-0 max-w-sm w-full',
},
hidePrimaryAction: true,
hideSecondaryAction: true,
},
})
}
>
Cancel Migration
</Button>
</Container>
);
}

View File

@@ -4,11 +4,11 @@ import { StagingMetadata } from '@/components/applications/StagingMetadata';
import { useDialog } from '@/components/common/DialogProvider';
import Container from '@/components/layout/Container';
import {
GetOneUserDocument,
GetAllWorkspacesAndProjectsDocument,
useGetFreeAndActiveProjectsQuery,
useUnpauseApplicationMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { Modal } from '@/ui';
import { Alert } from '@/ui/Alert';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
@@ -25,22 +25,26 @@ import { toast } from 'react-hot-toast';
import { RemoveApplicationModal } from './RemoveApplicationModal';
export default function ApplicationPaused() {
const { openAlertDialog } = useDialog();
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { id } = useUserData();
const isOwner = currentWorkspace.members.some(
({ userId, type }) => userId === id && type === 'owner',
const { openDialog } = useDialog();
const {
currentWorkspace,
currentProject,
refetch: refetchWorkspaceAndProject,
} = useCurrentWorkspaceAndProject();
const user = useUserData();
const isOwner = currentWorkspace.workspaceMembers.some(
({ id, type }) => id === user?.id && type === 'owner',
);
const [showDeletingModal, setShowDeletingModal] = useState(false);
const [unpauseApplication, { loading: changingApplicationStateLoading }] =
useUnpauseApplicationMutation({
refetchQueries: [GetOneUserDocument],
refetchQueries: [GetAllWorkspacesAndProjectsDocument],
});
const { data, loading } = useGetFreeAndActiveProjectsQuery({
variables: { userId: id },
variables: { userId: user?.id },
fetchPolicy: 'cache-and-network',
skip: !user,
});
const numberOfFreeAndLiveProjects = data?.freeAndActiveProjects.length || 0;
@@ -49,7 +53,7 @@ export default function ApplicationPaused() {
async function handleTriggerUnpausing() {
try {
await toast.promise(
unpauseApplication({ variables: { appId: currentApplication.id } }),
unpauseApplication({ variables: { appId: currentProject.id } }),
{
loading: 'Starting the project...',
success: `The project has been started successfully.`,
@@ -69,6 +73,8 @@ export default function ApplicationPaused() {
},
getToastStyleProps(),
);
await refetchWorkspaceAndProject();
} catch {
// Note: The toast will handle the error.
}
@@ -86,8 +92,8 @@ export default function ApplicationPaused() {
>
<RemoveApplicationModal
close={() => setShowDeletingModal(false)}
title={`Remove project ${currentApplication.name}?`}
description={`The project ${currentApplication.name} will be removed. All data will be lost and there will be no way to
title={`Remove project ${currentProject.name}?`}
description={`The project ${currentProject.name} will be removed. All data will be lost and there will be no way to
recover the app once it has been deleted.`}
/>
</Modal>
@@ -104,7 +110,7 @@ export default function ApplicationPaused() {
<Box className="grid grid-flow-row gap-1">
<Text variant="h3" component="h1">
{currentApplication.name} is sleeping
{currentProject.name} is sleeping
</Text>
<Text>
@@ -117,14 +123,10 @@ export default function ApplicationPaused() {
<Button
className="mx-auto w-full max-w-[280px]"
onClick={() => {
openAlertDialog({
title: 'Upgrade your plan.',
payload: <ChangePlanModal />,
openDialog({
component: <ChangePlanModal />,
props: {
PaperProps: { className: 'p-0' },
hidePrimaryAction: true,
hideSecondaryAction: true,
hideTitle: true,
maxWidth: 'lg',
},
});
@@ -148,7 +150,7 @@ export default function ApplicationPaused() {
<Alert severity="warning" className="mx-auto max-w-xs text-left">
Note: Only one free project can be active at any given time.
Please pause your active free project before unpausing{' '}
{currentApplication.name}.
{currentProject.name}.
</Alert>
)}

View File

@@ -1,17 +1,17 @@
import Container from '@/components/layout/Container';
import { useCheckProvisioning } from '@/hooks/useCheckProvisioning';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { ApplicationStatus } from '@/types/application';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Text from '@/ui/v2/Text';
import Image from 'next/image';
import ApplicationInfo from './ApplicationInfo';
import { AppLoader } from './AppLoader';
import ApplicationInfo from './ApplicationInfo';
import { StagingMetadata } from './StagingMetadata';
export default function ApplicationProvisioning() {
const currentApplicationState = useCheckProvisioning();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const currentProjectState = useCheckProvisioning();
const { currentProject } = useCurrentWorkspaceAndProject();
return (
<Container className="mx-auto mt-8 grid max-w-sm grid-flow-row gap-4 text-center">
@@ -24,16 +24,16 @@ export default function ApplicationProvisioning() {
/>
</div>
{currentApplicationState.state === ApplicationStatus.Empty ? (
{currentProjectState.state === ApplicationStatus.Empty ? (
<div className="grid grid-flow-row gap-1">
<Text variant="h3" component="h1">
Setting Up {currentApplication.name}
Setting Up {currentProject.name}
</Text>
<Text>This normally takes around 2 minutes</Text>
<ActivityIndicator className="mx-auto" />
</div>
) : (
<AppLoader startLoader date={currentApplicationState.createdAt} />
<AppLoader startLoader date={currentProjectState.createdAt} />
)}
<StagingMetadata>

View File

@@ -1,17 +1,17 @@
import Container from '@/components/layout/Container';
import { useCheckProvisioning } from '@/hooks/useCheckProvisioning';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { ApplicationStatus } from '@/types/application';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Text from '@/ui/v2/Text';
import Image from 'next/image';
import ApplicationInfo from './ApplicationInfo';
import { AppLoader } from './AppLoader';
import ApplicationInfo from './ApplicationInfo';
import { StagingMetadata } from './StagingMetadata';
export default function ApplicationRestoring() {
const currentApplicationState = useCheckProvisioning();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const currentProjectState = useCheckProvisioning();
const { currentProject } = useCurrentWorkspaceAndProject();
return (
<Container className="mx-auto mt-8 grid max-w-sm grid-flow-row gap-4 text-center">
@@ -23,10 +23,10 @@ export default function ApplicationRestoring() {
height={72}
/>
</div>
{currentApplicationState.state === ApplicationStatus.Empty ? (
{currentProjectState.state === ApplicationStatus.Empty ? (
<div className="grid grid-flow-row gap-1">
<Text variant="h3" component="h1">
Setting Up {currentApplication.name}
Setting Up {currentProject.name}
</Text>
<Text>This normally takes around 2 minutes</Text>
@@ -34,11 +34,7 @@ export default function ApplicationRestoring() {
<ActivityIndicator className="mx-auto" />
</div>
) : (
<AppLoader
startLoader
restoring
date={currentApplicationState.createdAt}
/>
<AppLoader startLoader restoring date={currentProjectState.createdAt} />
)}
<StagingMetadata>
<ApplicationInfo />

View File

@@ -1,6 +1,6 @@
import FeedbackForm from '@/components/common/FeedbackForm';
import Container from '@/components/layout/Container';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { Modal } from '@/ui/Modal';
import Button from '@/ui/v2/Button';
import { Dropdown } from '@/ui/v2/Dropdown';
@@ -13,12 +13,11 @@ import { RemoveApplicationModal } from './RemoveApplicationModal';
import { StagingMetadata } from './StagingMetadata';
export default function ApplicationUnknown() {
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject();
const [showDeleteModal, setShowDeleteModal] = useState(false);
const user = useUserData();
const isOwner = currentWorkspace.members.some(
({ userId, type }) => userId === user?.id && type === 'owner',
const isOwner = currentWorkspace.workspaceMembers.some(
({ id, type }) => id === user?.id && type === 'owner',
);
return (
@@ -29,8 +28,8 @@ export default function ApplicationUnknown() {
>
<RemoveApplicationModal
close={() => setShowDeleteModal(false)}
title={`Remove project ${currentApplication.name}?`}
description={`The project ${currentApplication.name} will be removed. All data will be lost and there will be no way to
title={`Remove project ${currentProject.name}?`}
description={`The project ${currentProject.name} will be removed. All data will be lost and there will be no way to
recover the app once it has been deleted.`}
/>
</Modal>

View File

@@ -1,25 +1,25 @@
import { BillingPaymentMethodForm } from '@/components/billing-payment-method/BillingPaymentMethodForm';
import { useDialog } from '@/components/common/DialogProvider';
import { useUI } from '@/context/UIContext';
import { BillingPaymentMethodForm } from '@/components/workspace/BillingPaymentMethodForm';
import {
refetchGetApplicationPlanQuery,
useGetAppPlanAndGlobalPlansQuery,
useGetPaymentMethodsQuery,
useUpdateAppMutation,
useUpdateApplicationMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { Modal } from '@/ui/Modal';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import Checkbox from '@/ui/v2/Checkbox';
import { BaseDialog } from '@/ui/v2/Dialog';
import Text from '@/ui/v2/Text';
import { planDescriptions } from '@/utils/planDescriptions';
import { triggerToast } from '@/utils/toast';
import { useTheme } from '@mui/material';
import getServerError from '@/utils/settings/getServerError/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import Image from 'next/image';
import { useRouter } from 'next/router';
import { useState } from 'react';
import { toast } from 'react-hot-toast';
function Plan({
planName,
@@ -66,21 +66,23 @@ function Plan({
}
export function ChangePlanModalWithData({ app, plans, close }: any) {
const theme = useTheme();
const [selectedPlanId, setSelectedPlanId] = useState('');
const { closeAlertDialog } = useDialog();
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const {
currentWorkspace,
currentProject,
refetch: refetchWorkspaceAndProject,
} = useCurrentWorkspaceAndProject();
// get workspace payment methods
const { data } = useGetPaymentMethodsQuery({
variables: {
workspaceId: currentWorkspace.id,
workspaceId: currentWorkspace?.id,
},
skip: !currentWorkspace,
});
const { openPaymentModal, closePaymentModal, paymentModal } = useUI();
const [showPaymentModal, setShowPaymentModal] = useState(false);
const paymentMethodAvailable = data?.paymentMethods.length > 0;
const currentPlan = plans.find((plan) => plan.id === app.plan.id);
@@ -88,38 +90,44 @@ export function ChangePlanModalWithData({ app, plans, close }: any) {
const isDowngrade = currentPlan.price > selectedPlan?.price;
// graphql mutations
const [updateApp] = useUpdateAppMutation({
const [updateApp] = useUpdateApplicationMutation({
refetchQueries: [
refetchGetApplicationPlanQuery({
workspace: currentWorkspace.slug,
slug: currentApplication.slug,
slug: currentProject.slug,
}),
],
});
// function handlers
const handleUpdateAppPlan = async () => {
await updateApp({
variables: {
id: app.id,
app: {
planId: selectedPlan.id,
try {
await toast.promise(
updateApp({
variables: {
appId: app.id,
app: {
planId: selectedPlan.id,
},
},
}),
{
loading: 'Updating plan...',
success: `Plan has been updated successfully to ${selectedPlan.name}.`,
error: getServerError(
'An error occurred while updating the plan. Please try again.',
),
},
},
});
getToastStyleProps(),
);
if (isDowngrade) {
if (close) {
close();
}
await refetchWorkspaceAndProject();
close?.();
closeAlertDialog();
setShowPaymentModal(false);
} catch (error) {
// Note: Error is handled by the toast.
}
triggerToast(
`${currentApplication.name} plan changed to ${selectedPlan.name}.`,
);
};
const handleChangePlanClick = async () => {
@@ -128,33 +136,30 @@ export function ChangePlanModalWithData({ app, plans, close }: any) {
}
if (!paymentMethodAvailable) {
openPaymentModal();
setShowPaymentModal(true);
return;
}
await handleUpdateAppPlan();
if (close) {
close();
}
setShowPaymentModal(false);
close?.();
closeAlertDialog();
};
return (
<Box className="w-full max-w-xl rounded-lg p-6 text-left">
<Modal
showModal={paymentModal}
close={closePaymentModal}
dialogStyle={{ zIndex: theme.zIndex.modal + 1 }}
<BaseDialog
open={showPaymentModal}
onClose={() => setShowPaymentModal(false)}
>
<BillingPaymentMethodForm
close={closePaymentModal}
onPaymentMethodAdded={handleUpdateAppPlan}
workspaceId={currentWorkspace.id}
/>
</Modal>
</BaseDialog>
<div className="flex flex-col">
<div className="mx-auto">
<Image
@@ -217,14 +222,12 @@ export function ChangePlanModalWithData({ app, plans, close }: any) {
export interface ChangePlanModalProps {
/**
* Function to close the modal if mounted on parent component.
*
* @deprecated Implement modal by using `openAlertDialog` hook instead.
* Function to close the modal.
*/
close?: () => void;
onCancel?: () => void;
}
export function ChangePlanModal({ close }: ChangePlanModalProps) {
export function ChangePlanModal({ onCancel }: ChangePlanModalProps) {
const {
query: { workspaceSlug, appSlug },
} = useRouter();
@@ -250,5 +253,5 @@ export function ChangePlanModal({ close }: ChangePlanModalProps) {
const { apps, plans } = data;
const app = apps[0];
return <ChangePlanModalWithData app={app} plans={plans} close={close} />;
return <ChangePlanModalWithData app={app} plans={plans} close={onCancel} />;
}

View File

@@ -1,6 +1,6 @@
import { LoadingScreen } from '@/components/common/LoadingScreen';
import useIsPlatform from '@/hooks/common/useIsPlatform';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import IconButton from '@/ui/v2/IconButton';
@@ -20,11 +20,11 @@ interface HasuraDataProps {
}
export function HasuraData({ close }: HasuraDataProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const isPlatform = useIsPlatform();
const projectAdminSecret = currentApplication?.config?.hasura.adminSecret;
const projectAdminSecret = currentProject?.config?.hasura.adminSecret;
if (!currentApplication?.subdomain || !projectAdminSecret) {
if (!currentProject?.subdomain || !projectAdminSecret) {
return <LoadingScreen />;
}
@@ -32,8 +32,8 @@ export function HasuraData({ close }: HasuraDataProps) {
process.env.NEXT_PUBLIC_ENV === 'dev' || !isPlatform
? `${getHasuraConsoleServiceUrl()}`
: generateAppServiceUrl(
currentApplication?.subdomain,
currentApplication?.region.awsName,
currentProject?.subdomain,
currentProject?.region.awsName,
'hasura',
defaultLocalBackendSlugs,
{ ...defaultRemoteBackendSlugs, hasura: '/console' },

View File

@@ -1,15 +1,15 @@
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import Checkbox from '@/ui/v2/Checkbox';
import Divider from '@/ui/v2/Divider';
import Text from '@/ui/v2/Text';
import { discordAnnounce } from '@/utils/discordAnnounce';
import { triggerToast } from '@/utils/toast';
import {
GetOneUserDocument,
GetAllWorkspacesAndProjectsDocument,
useDeleteApplicationMutation,
} from '@/utils/__generated__/graphql';
import { discordAnnounce } from '@/utils/discordAnnounce';
import { triggerToast } from '@/utils/toast';
import router from 'next/router';
import { useState } from 'react';
import { twMerge } from 'tailwind-merge';
@@ -46,14 +46,14 @@ export function RemoveApplicationModal({
className,
}: RemoveApplicationModalProps) {
const [deleteApplication] = useDeleteApplicationMutation({
refetchQueries: [GetOneUserDocument],
refetchQueries: [GetAllWorkspacesAndProjectsDocument],
});
const [loadingRemove, setLoadingRemove] = useState(false);
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [remove, setRemove] = useState(false);
const [remove2, setRemove2] = useState(false);
const appName = currentApplication?.name;
const appName = currentProject?.name;
async function handleClick() {
setLoadingRemove(true);
@@ -70,7 +70,7 @@ export function RemoveApplicationModal({
try {
await deleteApplication({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
},
});
} catch (error) {
@@ -78,7 +78,7 @@ export function RemoveApplicationModal({
}
close();
await router.push('/');
triggerToast(`${currentApplication.name} deleted`);
triggerToast(`${currentProject.name} deleted`);
}
return (

View File

@@ -1,165 +0,0 @@
import DeploymentStatusMessage from '@/components/deployments/DeploymentStatusMessage';
import { FindOldApps } from '@/components/home';
import type { UserData } from '@/hooks/useGetAllUserWorkspacesAndApplications';
import type { ApplicationState } from '@/types/application';
import { ApplicationStatus } from '@/types/application';
import StateBadge from '@/ui/StateBadge';
import type { DeploymentStatus } from '@/ui/StatusCircle';
import { StatusCircle } from '@/ui/StatusCircle';
import Divider from '@/ui/v2/Divider';
import Link from '@/ui/v2/Link';
import List from '@/ui/v2/List';
import { ListItem } from '@/ui/v2/ListItem';
import { getApplicationStatusString } from '@/utils/helpers';
import Image from 'next/image';
import NavLink from 'next/link';
import { Fragment } from 'react';
export function checkStatusOfTheApplication(
stateHistory: ApplicationState[] | [],
) {
if (stateHistory.length === 0) {
return ApplicationStatus.Empty;
}
if (stateHistory[0].stateId === undefined) {
return ApplicationStatus.Empty;
}
return stateHistory[0].stateId;
}
export function RenderWorkspacesWithApps({
userData,
query,
}: {
userData: UserData | null;
query: string;
}) {
return (
<div>
{userData?.workspaces
.filter((workspace) =>
workspace.applications.map((app) =>
app.name.toLowerCase().includes(query.toLowerCase()),
),
)
.sort((w1, w2) =>
// sort alphabetical order (A-Z)
w1.name.localeCompare(w2.name),
)
.map((workspace) => {
// early exit if no applications are available
if (workspace.applications.length === 0) {
return null;
}
const workspaceProjects = workspace.applications
.filter((app) =>
app.name.toLowerCase().includes(query.toLowerCase()),
)
.sort((appA, appB) => {
// sort apps based on either:
// 1. When the app was recently deployed, if there is any deployments available
// 2. When the app was created
const appASort =
appA.deployments.length > 0
? new Date(appA.deployments[0].deploymentEndedAt)
: new Date(appA.createdAt);
const appBSort =
appB.deployments.length > 0
? new Date(appB.deployments[0].deploymentEndedAt)
: new Date(appB.createdAt);
if (appASort > appBSort) {
return -1;
}
return 1;
});
return (
<div key={workspace.slug} className="my-8">
<NavLink href={`/${workspace.slug}`} passHref>
<Link
href={`${workspace.slug}`}
className="mb-1.5 block font-medium"
underline="none"
sx={{ color: 'text.primary' }}
>
{workspace.name}
</Link>
</NavLink>
<List className="grid grid-flow-row border-y">
{workspaceProjects.map((app, index) => {
const [latestDeployment] = app.deployments;
return (
<Fragment key={app.slug}>
<ListItem.Root
secondaryAction={
<div className="grid grid-flow-col gap-px">
{latestDeployment && (
<div className="mr-2 flex self-center align-middle">
<StatusCircle
status={
latestDeployment.deploymentStatus as DeploymentStatus
}
/>
</div>
)}
<StateBadge
state={checkStatusOfTheApplication(app.appStates)}
desiredState={app.desiredState}
title={getApplicationStatusString(
checkStatusOfTheApplication(app.appStates),
)}
/>
</div>
}
>
<NavLink
href={`${workspace?.slug}/${app.slug}`}
passHref
>
<ListItem.Button className="rounded-none">
<ListItem.Avatar>
<div className="h-10 w-10 overflow-hidden rounded-lg">
<Image
src="/logos/new.svg"
alt="Nhost Logo"
width={40}
height={40}
/>
</div>
</ListItem.Avatar>
<ListItem.Text
primary={app.name}
secondary={
<DeploymentStatusMessage
appCreatedAt={app.createdAt}
deployment={latestDeployment}
/>
}
/>
</ListItem.Button>
</NavLink>
</ListItem.Root>
{index < workspaceProjects.length - 1 && (
<Divider component="li" />
)}
</Fragment>
);
})}
</List>
</div>
);
})}
<FindOldApps />
</div>
);
}

View File

@@ -1,10 +1,10 @@
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import Checkbox from '@/ui/v2/Checkbox';
import Text from '@/ui/v2/Text';
import { triggerToast } from '@/utils/toast';
import { useRestoreApplicationDatabaseMutation } from '@/utils/__generated__/graphql';
import { triggerToast } from '@/utils/toast';
import { formatISO9075 } from 'date-fns';
import { useState } from 'react';
@@ -28,7 +28,7 @@ export function RestoreBackupModal({
const [isSure, setIsSure] = useState(false);
const [mutationIsCompleted, setMutationIsCompleted] = useState(false);
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [restoreApplicationDatabase, { loading }] =
useRestoreApplicationDatabaseMutation();
@@ -39,7 +39,7 @@ export function RestoreBackupModal({
await restoreApplicationDatabase({
variables: {
backupId,
appId: currentApplication.id,
appId: currentProject.id,
},
});
} catch (error) {
@@ -53,9 +53,9 @@ export function RestoreBackupModal({
if (mutationIsCompleted) {
return (
<Box className="w-modal p-6 rounded-lg">
<Box className="w-modal rounded-lg p-6">
<div className="flex flex-col">
<Text className="text-center font-medium text-lg">
<Text className="text-center text-lg font-medium">
The backup has been restored successfully.
</Text>
@@ -68,7 +68,7 @@ export function RestoreBackupModal({
}
return (
<Box className="w-modal px-6 py-6 text-left rounded-lg">
<Box className="w-modal rounded-lg px-6 py-6 text-left">
<div className="flex flex-col">
<Text className="text-center text-lg font-medium">
Restore Database Backup

View File

@@ -19,7 +19,7 @@ export function UnlockFeatureByUpgrading({
className,
...props
}: UnlockFeatureByUpgradingProps) {
const { openAlertDialog } = useDialog();
const { openDialog } = useDialog();
return (
<div className={twMerge('flex', className)} {...props}>
@@ -29,14 +29,10 @@ export function UnlockFeatureByUpgrading({
<Button
variant="borderless"
onClick={() => {
openAlertDialog({
title: 'Upgrade your plan.',
payload: <ChangePlanModal />,
openDialog({
component: <ChangePlanModal />,
props: {
PaperProps: { className: 'p-0 max-w-xl w-full' },
hidePrimaryAction: true,
hideSecondaryAction: true,
hideTitle: true,
},
});
}}

View File

@@ -1,5 +1,5 @@
import type { ConnectGithubModalState } from '@/components/applications/ConnectGithubModal';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { FormProvider, useForm } from 'react-hook-form';
import { EditRepositorySettingsModal } from './EditRepositorySettingsModal';
@@ -21,13 +21,13 @@ export function EditRepositorySettings({
selectedRepoId,
handleSelectAnotherRepository,
}: EditRepositorySettingsProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const form = useForm<EditRepositorySettingsFormData>({
reValidateMode: 'onSubmit',
defaultValues: {
productionBranch: currentApplication.repositoryProductionBranch || 'main',
repoBaseFolder: currentApplication.nhostBaseFolder,
productionBranch: currentProject?.repositoryProductionBranch || 'main',
repoBaseFolder: currentProject?.nhostBaseFolder,
},
});

View File

@@ -2,8 +2,8 @@ import type { EditRepositorySettingsFormData } from '@/components/applications/g
import { useDialog } from '@/components/common/DialogProvider';
import ErrorBoundaryFallback from '@/components/common/ErrorBoundaryFallback';
import GithubIcon from '@/components/icons/GithubIcon';
import { useUpdateAppMutation } from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useUpdateApplicationMutation } from '@/generated/graphql';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import Button from '@/ui/v2/Button';
import Text from '@/ui/v2/Text';
import { discordAnnounce } from '@/utils/discordAnnounce';
@@ -27,9 +27,9 @@ export function EditRepositorySettingsModal({
const isNotCompleted = !watch('productionBranch') || !watch('repoBaseFolder');
const { closeAlertDialog } = useDialog();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateApp, { loading }] = useUpdateAppMutation();
const [updateApp, { loading }] = useUpdateApplicationMutation();
const client = useApolloClient();
@@ -37,10 +37,10 @@ export function EditRepositorySettingsModal({
data: EditRepositorySettingsFormData,
) => {
try {
if (!currentApplication.githubRepository || selectedRepoId) {
if (!currentProject.githubRepository || selectedRepoId) {
await updateApp({
variables: {
id: currentApplication.id,
appId: currentProject.id,
app: {
githubRepositoryId: selectedRepoId,
repositoryProductionBranch: data.productionBranch,
@@ -51,7 +51,7 @@ export function EditRepositorySettingsModal({
} else {
await updateApp({
variables: {
id: currentApplication.id,
appId: currentProject.id,
app: {
repositoryProductionBranch: data.productionBranch,
nhostBaseFolder: data.repoBaseFolder,
@@ -69,7 +69,7 @@ export function EditRepositorySettingsModal({
triggerToast('GitHub repository settings successfully updated.');
} catch (error) {
await discordAnnounce(
`Error while trying to edit repository GitHub integration: ${currentApplication.slug}.`,
`Error while trying to edit repository GitHub integration: ${currentProject.slug}.`,
);
throw error;
}

View File

@@ -1,5 +1,5 @@
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useRemoteApplicationGQLClient } from '@/hooks/useRemoteApplicationGQLClient';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Option from '@/ui/v2/Option';
import Select from '@/ui/v2/Select';
@@ -19,12 +19,12 @@ export interface UserSelectProps {
}
export function UserSelect({ onUserChange, ...props }: UserSelectProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const userApplicationClient = useRemoteApplicationGQLClient();
const { data, loading, error } = useRemoteAppGetUsersCustomQuery({
client: userApplicationClient,
variables: { where: {}, limit: 250, offset: 0 },
skip: !currentApplication,
skip: !currentProject,
});
if (loading) {

View File

@@ -1,6 +1,6 @@
import NavLink from '@/components/common/NavLink';
import useIsPlatform from '@/hooks/common/useIsPlatform';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { BoxProps } from '@/ui/v2/Box';
import Box from '@/ui/v2/Box';
import Text from '@/ui/v2/Text';
@@ -10,8 +10,7 @@ export interface BreadcrumbsProps extends BoxProps {}
export default function Breadcrumbs({ className, ...props }: BreadcrumbsProps) {
const isPlatform = useIsPlatform();
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject();
if (!isPlatform) {
return (
@@ -61,16 +60,16 @@ export default function Breadcrumbs({ className, ...props }: BreadcrumbsProps) {
</>
)}
{currentApplication && (
{currentProject && (
<>
<Text color="disabled">/</Text>
<NavLink
href={`/${currentWorkspace.slug}/${currentApplication.slug}`}
href={`/${currentWorkspace.slug}/${currentProject.slug}`}
className="truncate text-[13px] hover:underline sm:text-sm"
sx={{ color: 'text.primary' }}
>
{currentApplication.name}
{currentProject.name}
</NavLink>
</>
)}

View File

@@ -1,4 +1,4 @@
import { render, screen } from '@/utils/testUtils';
import { render, screen } from '@/tests/testUtils';
import type { Column } from 'react-table';
import { expect, test } from 'vitest';
import DataGrid from './DataGrid';

View File

@@ -3,7 +3,7 @@ import { FileIcon } from '@/components/icons/FileIcon';
import PDFPreview from '@/components/icons/PDFPreview';
import VideoPreview from '@/components/icons/VideoPreview';
import { useAppClient } from '@/hooks/useAppClient';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { Modal } from '@/ui/Modal';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Box from '@/ui/v2/Box';
@@ -166,7 +166,7 @@ export default function DataGridPreviewCell<TData extends object>({
value: { fetchBlob, id, mimeType, alt, blob },
fallbackPreview = null,
}: DataGridPreviewCellProps<TData>) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const appClient = useAppClient();
const { objectUrl, loading, error } = useBlob({ fetchBlob, blob, mimeType });
const [showModal, setShowModal] = useState(false);
@@ -205,7 +205,7 @@ export default function DataGridPreviewCell<TData extends object>({
}
const { presignedUrl } = await appClient.storage
.setAdminSecret(currentApplication.config?.hasura.adminSecret)
.setAdminSecret(currentProject?.config?.hasura.adminSecret)
.getPresignedUrl({ fileId: id });
if (!presignedUrl) {

View File

@@ -22,7 +22,7 @@ export interface OpenDialogOptions {
/**
* Title of the dialog.
*/
title: ReactNode;
title?: ReactNode;
/**
* Component to render inside the dialog skeleton.
*/

View File

@@ -1,3 +1,4 @@
export * from './DialogContext';
export { default as DialogContext } from './DialogContext';
export { default as DialogProvider } from './DialogProvider';
export { default as useDialog } from './useDialog';

View File

@@ -3,7 +3,6 @@ import FeedbackForm from '@/components/common/FeedbackForm';
import NavLink from '@/components/common/NavLink';
import ThemeSwitcher from '@/components/common/ThemeSwitcher';
import { Nav } from '@/components/dashboard/Nav';
import { useUserDataContext } from '@/context/workspace1-context';
import useIsPlatform from '@/hooks/common/useIsPlatform';
import useProjectRoutes from '@/hooks/common/useProjectRoutes';
import { useNavigationVisible } from '@/hooks/useNavigationVisible';
@@ -19,6 +18,7 @@ import List from '@/ui/v2/List';
import type { ListItemButtonProps } from '@/ui/v2/ListItem';
import { ListItem } from '@/ui/v2/ListItem';
import Text from '@/ui/v2/Text';
import { useApolloClient } from '@apollo/client';
import { useSignOut } from '@nhost/nextjs';
import getConfig from 'next/config';
import { useRouter } from 'next/router';
@@ -88,7 +88,7 @@ export default function MobileNav({ className, ...props }: MobileNavProps) {
const [menuOpen, setMenuOpen] = useState(false);
const [showChangePasswordModal, setShowChangePasswordModal] = useState(false);
const { signOut } = useSignOut();
const { setUserContext } = useUserDataContext();
const apolloClient = useApolloClient();
const router = useRouter();
const { publicRuntimeConfig } = getConfig();
@@ -236,7 +236,7 @@ export default function MobileNav({ className, ...props }: MobileNavProps) {
setShowChangePasswordModal(true);
}}
>
Change password
Change Password
</ListItem.Button>
</ListItem.Root>
@@ -248,13 +248,13 @@ export default function MobileNav({ className, ...props }: MobileNavProps) {
color="secondary"
className="justify-start border-none px-2 py-2.5 text-[16px]"
onClick={async () => {
setUserContext({ workspaces: [] });
setMenuOpen(false);
await apolloClient.clearStore();
await signOut();
await router.push('/signin');
}}
>
Sign out
Sign Out
</ListItem.Button>
</ListItem.Root>
</List>

View File

@@ -7,9 +7,8 @@ import Button from '@/ui/v2/Button';
import { Dropdown, useDropdown } from '@/ui/v2/Dropdown';
import PowerIcon from '@/ui/v2/icons/PowerIcon';
import Text from '@/ui/v2/Text';
import { nhost } from '@/utils/nhost';
import { useApolloClient } from '@apollo/client';
import { useUserData } from '@nhost/nextjs';
import { useSignOut, useUserData } from '@nhost/nextjs';
import getConfig from 'next/config';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
@@ -22,8 +21,9 @@ function AccountMenuContent({
onChangePasswordClick,
}: AccountMenuContentProps) {
const user = useUserData();
const { signOut } = useSignOut();
const router = useRouter();
const client = useApolloClient();
const apolloClient = useApolloClient();
const { handleClose } = useDropdown();
const { publicRuntimeConfig } = getConfig();
@@ -37,12 +37,10 @@ function AccountMenuContent({
/>
<Text variant="h3" component="h2" className="text-center">
{nhost.auth.getUser()?.displayName}
{user?.displayName}
</Text>
<Text className="text-center font-medium">
{nhost.auth.getUser()?.email}
</Text>
<Text className="text-center font-medium">{user?.email}</Text>
</div>
<div className="grid grid-flow-row gap-2">
@@ -57,17 +55,13 @@ function AccountMenuContent({
Change Password
</Button>
<Button color="error" disabled>
Remove Account
</Button>
<Button
variant="outlined"
color="secondary"
onClick={async () => {
await nhost.auth.signOut();
router.push('/signin');
await client.resetStore();
await apolloClient.clearStore();
await signOut();
await router.push('/signin');
}}
endIcon={<PowerIcon className="mr-1 h-4 w-4" />}
>

View File

@@ -1,13 +0,0 @@
import type { ReactNode } from 'react';
interface ContainerIndexApplicationsProps {
children?: ReactNode | ReactNode[];
}
export function ContainerIndexApplications({
children,
}: ContainerIndexApplicationsProps) {
return <div className="flex flex-col font-display md:w-app">{children}</div>;
}
export default ContainerIndexApplications;

View File

@@ -22,6 +22,13 @@ export function CountrySelector({ value, onChange }: CountrySelectorProps) {
value={value || null}
onChange={(_event, inputValue) => onChange(inputValue as string)}
placeholder="Select Country"
slotProps={{
listbox: { className: 'min-w-0 w-full' },
popper: {
disablePortal: false,
className: 'z-[10000] w-[270px] w-full',
},
}}
>
{countries?.map((country) => (
<Option key={country.name} value={country.code}>

View File

@@ -1,55 +0,0 @@
import { useWorkspaceContext } from '@/context/workspace-context';
import { useUserDataContext } from '@/context/workspace1-context';
import Button from '@/ui/v2/Button';
import Text from '@/ui/v2/Text';
import { darken } from '@mui/system';
import Link from 'next/link';
export function NoApplications() {
const { userContext } = useUserDataContext();
const { workspaceContext } = useWorkspaceContext();
return (
<div className="noapps mt-4 h-80 rounded-md text-center font-display font-normal">
<div className="pt-12">
<Text
className="text-center text-2xl font-semibold"
sx={{ color: 'common.white' }}
>
Welcome to Nhost!
</Text>
<Text className="mt-2" sx={{ color: 'common.white' }}>
Let&apos;s set up your first backend - the Nhost way.
</Text>
<div className="inline-block pt-10">
<Link href="/new" passHref>
<Button
sx={{
backgroundColor: (theme) =>
`${theme.palette.common.white} !important`,
color: (theme) => `${theme.palette.common.black} !important`,
'&:hover': {
backgroundColor: (theme) =>
`${darken(theme.palette.common.white, 0.1)} !important`,
},
}}
disabled={
!workspaceContext.id && userContext.workspaces.length === 0
}
>
Create Your First Project
</Button>
</Link>
</div>
<div>
<Text className="mt-9 opacity-40" sx={{ color: 'common.white' }}>
Looking for your old projects? They&apos;re still on
console.nhost.io during this beta.
</Text>
</div>
</div>
</div>
);
}
export default NoApplications;

View File

@@ -1,8 +1,8 @@
import Form from '@/components/common/Form';
import hasuraMetadataQuery from '@/tests/msw/mocks/rest/hasuraMetadataQuery';
import tableQuery from '@/tests/msw/mocks/rest/tableQuery';
import Button from '@/ui/v2/Button';
import Text from '@/ui/v2/Text';
import hasuraMetadataQuery from '@/utils/msw/mocks/rest/hasuraMetadataQuery';
import tableQuery from '@/utils/msw/mocks/rest/tableQuery';
import type { ComponentMeta, ComponentStory } from '@storybook/react';
import { useState } from 'react';
import { FormProvider, useForm } from 'react-hook-form';

View File

@@ -1,7 +1,7 @@
import permissionVariablesQuery from '@/utils/msw/mocks/graphql/permissionVariablesQuery';
import hasuraMetadataQuery from '@/utils/msw/mocks/rest/hasuraMetadataQuery';
import tableQuery from '@/utils/msw/mocks/rest/tableQuery';
import { render, screen } from '@/utils/testUtils';
import permissionVariablesQuery from '@/tests/msw/mocks/graphql/permissionVariablesQuery';
import hasuraMetadataQuery from '@/tests/msw/mocks/rest/hasuraMetadataQuery';
import tableQuery from '@/tests/msw/mocks/rest/tableQuery';
import { render, screen } from '@/tests/testUtils';
import { setupServer } from 'msw/node';
import { test, vi } from 'vitest';
import ColumnAutocomplete from './ColumnAutocomplete';

View File

@@ -13,8 +13,8 @@ import useDeleteColumnWithToastMutation from '@/hooks/dataBrowser/useDeleteColum
import useTableQuery from '@/hooks/dataBrowser/useTableQuery';
import type { UpdateRecordVariables } from '@/hooks/dataBrowser/useUpdateRecordMutation';
import useUpdateRecordWithToastMutation from '@/hooks/dataBrowser/useUpdateRecordMutation/useUpdateRecordWithToastMutation';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import useTablePath from '@/hooks/useTablePath';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type {
DataBrowserGridColumn,
NormalizedQueryDataRow,
@@ -163,8 +163,8 @@ export default function DataBrowserGrid({
const isSchemaEditable = !isSchemaLocked(schemaSlug as string);
const { openDrawer, openAlertDialog } = useDialog();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const isGitHubConnected = !!currentApplication?.githubRepository;
const { currentProject } = useCurrentWorkspaceAndProject();
const isGitHubConnected = !!currentProject?.githubRepository;
const limit = 25;
const [currentOffset, setCurrentOffset] = useState<number | null>(

View File

@@ -2,8 +2,8 @@ import type { DataGridPaginationProps } from '@/components/common/DataGridPagina
import DataGridPagination from '@/components/common/DataGridPagination';
import { useDialog } from '@/components/common/DialogProvider';
import useDeleteRecordMutation from '@/hooks/dataBrowser/useDeleteRecordMutation';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import useDataGridConfig from '@/hooks/useDataGridConfig';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { DataBrowserGridColumn } from '@/types/dataBrowser';
import type { BoxProps } from '@/ui/v2/Box';
import Box from '@/ui/v2/Box';
@@ -50,8 +50,8 @@ export default function DataBrowserGridControls({
onInsertColumnClick,
...props
}: DataBrowserGridControlsProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const isGitHubConnected = !!currentApplication?.githubRepository;
const { currentProject } = useCurrentWorkspaceAndProject();
const isGitHubConnected = !!currentProject?.githubRepository;
const queryClient = useQueryClient();
const { openAlertDialog } = useDialog();

View File

@@ -6,7 +6,7 @@ import RetryableErrorBoundary from '@/components/common/RetryableErrorBoundary';
import useIsPlatform from '@/hooks/common/useIsPlatform';
import useDatabaseQuery from '@/hooks/dataBrowser/useDatabaseQuery';
import useDeleteTableWithToastMutation from '@/hooks/dataBrowser/useDeleteTableMutation/useDeleteTableWithToastMutation';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import FloatingActionButton from '@/ui/FloatingActionButton';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Backdrop from '@/ui/v2/Backdrop';
@@ -74,8 +74,8 @@ function DataBrowserSidebarContent({
}: Pick<DataBrowserSidebarProps, 'onSidebarItemClick'>) {
const queryClient = useQueryClient();
const { openDrawer, openAlertDialog } = useDialog();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const isGitHubConnected = !!currentApplication?.githubRepository;
const { currentProject } = useCurrentWorkspaceAndProject();
const isGitHubConnected = !!currentProject?.githubRepository;
const router = useRouter();
const {
@@ -516,7 +516,7 @@ export default function DataBrowserSidebar({
...props
}: DataBrowserSidebarProps) {
const isPlatform = useIsPlatform();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [expanded, setExpanded] = useState(false);
@@ -547,7 +547,7 @@ export default function DataBrowserSidebar({
document.removeEventListener('keydown', closeSidebarWhenEscapeIsPressed);
}, []);
if (isPlatform && !currentApplication?.config?.hasura.adminSecret) {
if (isPlatform && !currentProject?.config?.hasura.adminSecret) {
return null;
}

View File

@@ -1,8 +1,8 @@
import { useDialog } from '@/components/common/DialogProvider';
import useMetadataQuery from '@/hooks/dataBrowser/useMetadataQuery';
import useTableQuery from '@/hooks/dataBrowser/useTableQuery';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useRemoteApplicationGQLClient } from '@/hooks/useRemoteApplicationGQLClient';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { DialogFormProps } from '@/types/common';
import type {
DatabaseAccessLevel,
@@ -13,9 +13,6 @@ import { Alert } from '@/ui/Alert';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import FullPermissionIcon from '@/ui/v2/icons/FullPermissionIcon';
import NoPermissionIcon from '@/ui/v2/icons/NoPermissionIcon';
import PartialPermissionIcon from '@/ui/v2/icons/PartialPermissionIcon';
import Link from '@/ui/v2/Link';
import Table from '@/ui/v2/Table';
import TableBody from '@/ui/v2/TableBody';
@@ -24,6 +21,9 @@ import TableContainer from '@/ui/v2/TableContainer';
import TableHead from '@/ui/v2/TableHead';
import TableRow from '@/ui/v2/TableRow';
import Text from '@/ui/v2/Text';
import FullPermissionIcon from '@/ui/v2/icons/FullPermissionIcon';
import NoPermissionIcon from '@/ui/v2/icons/NoPermissionIcon';
import PartialPermissionIcon from '@/ui/v2/icons/PartialPermissionIcon';
import { useGetRemoteAppRolesQuery } from '@/utils/__generated__/graphql';
import NavLink from 'next/link';
import { useState } from 'react';
@@ -61,8 +61,7 @@ export default function EditPermissionsForm({
const [action, setAction] = useState<DatabaseAction>();
const { closeDrawerWithDirtyGuard } = useDialog();
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject();
const client = useRemoteApplicationGQLClient();
const {
@@ -330,7 +329,7 @@ export default function EditPermissionsForm({
<Alert className="text-left">
Please go to the{' '}
<NavLink
href={`/${currentWorkspace.slug}/${currentApplication.slug}/settings/roles-and-permissions`}
href={`/${currentWorkspace.slug}/${currentProject.slug}/settings/roles-and-permissions`}
passHref
>
<Link

View File

@@ -1,18 +1,18 @@
import ControlledSelect from '@/components/common/ControlledSelect';
import type { RolePermissionEditorFormValues } from '@/components/dataBrowser/EditPermissionsForm/RolePermissionEditorForm';
import useTableQuery from '@/hooks/dataBrowser/useTableQuery';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Autocomplete from '@/ui/v2/Autocomplete';
import Button from '@/ui/v2/Button';
import IconButton from '@/ui/v2/IconButton';
import PlusIcon from '@/ui/v2/icons/PlusIcon';
import XIcon from '@/ui/v2/icons/XIcon';
import InputLabel from '@/ui/v2/InputLabel';
import Option from '@/ui/v2/Option';
import Text from '@/ui/v2/Text';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import PlusIcon from '@/ui/v2/icons/PlusIcon';
import XIcon from '@/ui/v2/icons/XIcon';
import { useGetRolesPermissionsQuery } from '@/utils/__generated__/graphql';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import { useTheme } from '@mui/material';
import clsx from 'clsx';
import { useFieldArray, useFormContext, useWatch } from 'react-hook-form';
@@ -50,10 +50,10 @@ export default function ColumnPresetsSection({
error: tableError,
} = useTableQuery([`default.${schema}.${table}`], { schema, table });
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data: permissionVariablesData } = useGetRolesPermissionsQuery({
variables: { appId: currentApplication?.id },
skip: !currentApplication?.id,
variables: { appId: currentProject?.id },
skip: !currentProject?.id,
});
const {
setValue,

View File

@@ -1,10 +1,10 @@
import Form from '@/components/common/Form';
import permissionVariablesQuery from '@/tests/msw/mocks/graphql/permissionVariablesQuery';
import hasuraMetadataQuery from '@/tests/msw/mocks/rest/hasuraMetadataQuery';
import tableQuery from '@/tests/msw/mocks/rest/tableQuery';
import type { RuleGroup } from '@/types/dataBrowser';
import Button from '@/ui/v2/Button';
import Text from '@/ui/v2/Text';
import permissionVariablesQuery from '@/utils/msw/mocks/graphql/permissionVariablesQuery';
import hasuraMetadataQuery from '@/utils/msw/mocks/rest/hasuraMetadataQuery';
import tableQuery from '@/utils/msw/mocks/rest/tableQuery';
import type { ComponentMeta, ComponentStory } from '@storybook/react';
import { useState } from 'react';
import { FormProvider, useForm } from 'react-hook-form';

View File

@@ -1,12 +1,12 @@
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { Rule, RuleGroup } from '@/types/dataBrowser';
import { Alert } from '@/ui/Alert';
import type { BoxProps } from '@/ui/v2/Box';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import PlusIcon from '@/ui/v2/icons/PlusIcon';
import Link from '@/ui/v2/Link';
import Text from '@/ui/v2/Text';
import PlusIcon from '@/ui/v2/icons/PlusIcon';
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl';
import { useMemo } from 'react';
import { useFieldArray, useFormContext } from 'react-hook-form';
@@ -69,7 +69,7 @@ export default function RuleGroupEditor({
sx,
...props
}: RuleGroupEditorProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const form = useFormContext();
const { control, getValues } = form;
@@ -127,7 +127,7 @@ export default function RuleGroupEditor({
depth > 6 && { backgroundColor: 'secondary.800' },
]}
>
<div className="grid grid-flow-row gap-4 lg:gap-2 py-4">
<div className="grid grid-flow-row gap-4 py-4 lg:gap-2">
{(rules as (Rule & { id: string })[]).map((rule, ruleIndex) => (
<div className="grid grid-cols-[70px_1fr] gap-2" key={rule.id}>
<div>
@@ -188,13 +188,13 @@ export default function RuleGroupEditor({
<Text>
This rule group contains one or more objects (e.g: _exists) that
are not supported by our dashboard yet.{' '}
{currentApplication && (
{currentProject && (
<span>
Please{' '}
<Link
href={`${generateAppServiceUrl(
currentApplication.subdomain,
currentApplication.region?.awsName,
currentProject.subdomain,
currentProject.region?.awsName,
'hasura',
)}/console/data/default/schema/${schema}/tables/${table}/permissions`}
underline="hover"
@@ -212,8 +212,8 @@ export default function RuleGroupEditor({
</div>
{!disabled && (
<div className="grid grid-flow-row lg:grid-flow-col lg:justify-between gap-2 pb-2">
<div className="grid grid-flow-row lg:grid-flow-col gap-2 lg:justify-start">
<div className="grid grid-flow-row gap-2 pb-2 lg:grid-flow-col lg:justify-between">
<div className="grid grid-flow-row gap-2 lg:grid-flow-col lg:justify-start">
<Button
startIcon={<PlusIcon />}
variant="borderless"

View File

@@ -3,15 +3,15 @@ import ControlledSelect from '@/components/common/ControlledSelect';
import ReadOnlyToggle from '@/components/common/ReadOnlyToggle';
import type { ColumnAutocompleteProps } from '@/components/dataBrowser/ColumnAutocomplete';
import ColumnAutocomplete from '@/components/dataBrowser/ColumnAutocomplete';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { HasuraOperator } from '@/types/dataBrowser';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import type { AutocompleteOption } from '@/ui/v2/Autocomplete';
import type { InputProps } from '@/ui/v2/Input';
import { inputClasses } from '@/ui/v2/Input';
import Option from '@/ui/v2/Option';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import { useGetRolesPermissionsQuery } from '@/utils/__generated__/graphql';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import { useController, useFormContext, useWatch } from 'react-hook-form';
import useRuleGroupEditor from './useRuleGroupEditor';
@@ -96,7 +96,7 @@ export default function RuleValueInput({
helperText,
}: RuleValueInputProps) {
const { schema, table, disabled } = useRuleGroupEditor();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { setValue } = useFormContext();
const inputName = `${name}.value`;
const operator: HasuraOperator = useWatch({ name: `${name}.operator` });
@@ -118,8 +118,8 @@ export default function RuleValueInput({
loading,
error: customClaimsError,
} = useGetRolesPermissionsQuery({
variables: { appId: currentApplication?.id },
skip: !isHasuraInput || !currentApplication?.id,
variables: { appId: currentProject?.id },
skip: !isHasuraInput || !currentProject?.id,
});
if (operator === '_is_null') {

View File

@@ -1,19 +1,19 @@
import NavLink from '@/components/common/NavLink';
import AppDeploymentDuration from '@/components/deployments/AppDeploymentDuration';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { Avatar } from '@/ui/Avatar';
import type { DeploymentStatus } from '@/ui/StatusCircle';
import { StatusCircle } from '@/ui/StatusCircle';
import Button from '@/ui/v2/Button';
import Chip from '@/ui/v2/Chip';
import ArrowCounterclockwiseIcon from '@/ui/v2/icons/ArrowCounterclockwiseIcon';
import ChevronRightIcon from '@/ui/v2/icons/ChevronRightIcon';
import { ListItem } from '@/ui/v2/ListItem';
import Tooltip from '@/ui/v2/Tooltip';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import ArrowCounterclockwiseIcon from '@/ui/v2/icons/ArrowCounterclockwiseIcon';
import ChevronRightIcon from '@/ui/v2/icons/ChevronRightIcon';
import type { DeploymentRowFragment } from '@/utils/__generated__/graphql';
import { useInsertDeploymentMutation } from '@/utils/__generated__/graphql';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { formatDistanceToNowStrict, parseISO } from 'date-fns';
import { toast } from 'react-hot-toast';
import { twMerge } from 'tailwind-merge';
@@ -44,8 +44,7 @@ export default function DeploymentListItem({
showRedeploy,
disableRedeploy,
}: DeploymentListItemProps) {
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject();
const relativeDateOfDeployment = deployment.deploymentStartedAt
? formatDistanceToNowStrict(parseISO(deployment.deploymentStartedAt), {
@@ -61,7 +60,7 @@ export default function DeploymentListItem({
<ListItem.Button
className="grid grid-flow-col items-center justify-between gap-2 rounded-none p-2"
component={NavLink}
href={`/${currentWorkspace.slug}/${currentApplication.slug}/deployments/${deployment.id}`}
href={`/${currentWorkspace.slug}/${currentProject.slug}/deployments/${deployment.id}`}
aria-label={commitMessage || 'No commit message'}
>
<div className="grid grid-flow-col items-center justify-center gap-2 self-center">
@@ -108,7 +107,7 @@ export default function DeploymentListItem({
const insertDeploymentPromise = insertDeployment({
variables: {
object: {
appId: currentApplication?.id,
appId: currentProject?.id,
commitMessage: deployment.commitMessage,
commitSHA: deployment.commitSHA,
commitUserAvatarUrl: deployment.commitUserAvatarUrl,

View File

@@ -1,5 +1,5 @@
import { render, screen } from '@/tests/testUtils';
import type { Deployment } from '@/types/application';
import { render, screen } from '@/utils/testUtils';
import { test, vi } from 'vitest';
import DeploymentStatusMessage from './DeploymentStatusMessage';

View File

@@ -9,13 +9,13 @@ import FilesDataGridControls from '@/components/files/FilesDataGridControls';
import { FileIcon } from '@/components/icons/FileIcon';
import { useAppClient } from '@/hooks/useAppClient';
import useBuckets from '@/hooks/useBuckets';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import useFiles from '@/hooks/useFiles';
import useFilesAggregate from '@/hooks/useFilesAggregate';
import { getHasuraAdminSecret } from '@/utils/env';
import { showLoadingToast, triggerToast } from '@/utils/toast';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { Files } from '@/utils/__generated__/graphql';
import { Order_By as OrderBy } from '@/utils/__generated__/graphql';
import { getHasuraAdminSecret } from '@/utils/env';
import { showLoadingToast, triggerToast } from '@/utils/toast';
import debounce from 'lodash.debounce';
import { useRouter } from 'next/router';
import type { ChangeEvent } from 'react';
@@ -31,7 +31,7 @@ export type FilesDataGridProps = Partial<DataGridProps<StoredFile>>;
export default function FilesDataGrid(props: FilesDataGridProps) {
const router = useRouter();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const appClient = useAppClient();
const [searchString, setSearchString] = useState<string | null>(null);
const [currentOffset, setCurrentOffset] = useState<number | null>(
@@ -263,7 +263,7 @@ export default function FilesDataGrid(props: FilesDataGridProps) {
.setAdminSecret(
process.env.NEXT_PUBLIC_ENV === 'dev'
? getHasuraAdminSecret()
: currentApplication.config?.hasura.adminSecret,
: currentProject.config?.hasura.adminSecret,
)
.upload({
file,

View File

@@ -2,8 +2,8 @@ import type { DataGridPaginationProps } from '@/components/common/DataGridPagina
import DataGridPagination from '@/components/common/DataGridPagination';
import { useDialog } from '@/components/common/DialogProvider';
import { useAppClient } from '@/hooks/useAppClient';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import useDataGridConfig from '@/hooks/useDataGridConfig';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { FileUploadButtonProps } from '@/ui/FileUploadButton';
import FileUploadButton from '@/ui/FileUploadButton';
import type { BoxProps } from '@/ui/v2/Box';
@@ -12,9 +12,9 @@ import Button from '@/ui/v2/Button';
import Chip from '@/ui/v2/Chip';
import type { InputProps } from '@/ui/v2/Input';
import Input from '@/ui/v2/Input';
import type { Files } from '@/utils/__generated__/graphql';
import { getHasuraAdminSecret } from '@/utils/env';
import { triggerToast } from '@/utils/toast';
import type { Files } from '@/utils/__generated__/graphql';
import type { PropsWithoutRef } from 'react';
import { useState } from 'react';
import type { Row } from 'react-table';
@@ -38,7 +38,7 @@ export default function FilesDataGridControls({
...props
}: FilesDataGridControlsProps) {
const { openAlertDialog } = useDialog();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const appClient = useAppClient();
const [deleteLoading, setDeleteLoading] = useState(false);
@@ -73,7 +73,7 @@ export default function FilesDataGridControls({
const storageWithAdminSecret = appClient.storage.setAdminSecret(
process.env.NEXT_PUBLIC_ENV === 'dev'
? getHasuraAdminSecret()
: currentApplication.config?.hasura.adminSecret,
: currentProject.config?.hasura.adminSecret,
);
// note: this is not an optimal solution, but we don't have a better way

View File

@@ -1,14 +0,0 @@
import { RenderWorkspacesWithApps } from '@/components/applications/RenderWorkspacesWithApps';
import type { UserData } from '@/hooks/useGetAllUserWorkspacesAndApplications';
export function AllWorkspacesApplications({
userData,
query,
}: {
userData: UserData | null;
query: string;
}) {
return <RenderWorkspacesWithApps query={query} userData={userData} />;
}
export default AllWorkspacesApplications;

View File

@@ -1,47 +0,0 @@
import { LoadingScreen } from '@/components/common/LoadingScreen';
import { ContainerIndexApplications } from '@/components/dashboard/ContainerIndexApplications';
import { NoApplications } from '@/components/dashboard/NoApplications';
import { AllWorkspacesApplications } from '@/components/home/AllWorkspaceApplications';
import { IndexHeaderApps } from '@/components/home/IndexHeaderApps';
import { useUserDataContext } from '@/context/workspace1-context';
import { useCheckApplications } from '@/hooks/useCheckApplications';
import type { UserData } from '@/hooks/useGetAllUserWorkspacesAndApplications';
import { useEffect, useState } from 'react';
export function Applications() {
const [filtered, setFiltered] = useState<UserData | null>(null);
const [query, setQuery] = useState('');
const { userContext } = useUserDataContext();
useEffect(() => {
setFiltered(userContext);
}, [userContext]);
const { loading, error, noApplications } = useCheckApplications();
if (loading) {
return <LoadingScreen />;
}
if (error) {
throw error;
}
if (noApplications) {
return (
<ContainerIndexApplications>
<NoApplications />
</ContainerIndexApplications>
);
}
return (
<ContainerIndexApplications>
<IndexHeaderApps query={query} setQuery={setQuery} />
<AllWorkspacesApplications query={query} userData={filtered} />
</ContainerIndexApplications>
);
}
export default Applications;

View File

@@ -3,14 +3,14 @@ import Form from '@/components/common/Form';
import type { DialogFormProps } from '@/types/common';
import Button from '@/ui/v2/Button';
import Input from '@/ui/v2/Input';
import { slugifyString } from '@/utils/helpers';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import {
refetchGetOneUserQuery,
GetAllWorkspacesAndProjectsDocument,
useInsertWorkspaceMutation,
useUpdateWorkspaceMutation,
} from '@/utils/__generated__/graphql';
import { slugifyString } from '@/utils/helpers';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { yupResolver } from '@hookform/resolvers/yup';
import { useUserData } from '@nhost/nextjs';
import { useRouter } from 'next/router';
@@ -85,11 +85,7 @@ export default function EditWorkspaceNameForm({
const currentUser = useUserData();
const [insertWorkspace, { client }] = useInsertWorkspaceMutation();
const [updateWorkspaceName] = useUpdateWorkspaceMutation({
refetchQueries: [
refetchGetOneUserQuery({
userId: currentUser.id,
}),
],
refetchQueries: [GetAllWorkspacesAndProjectsDocument],
awaitRefetchQueries: true,
ignoreResults: true,
});
@@ -196,7 +192,7 @@ export default function EditWorkspaceNameForm({
}
await client.refetchQueries({
include: ['getOneUser'],
include: [GetAllWorkspacesAndProjectsDocument],
});
// The form has been submitted, it's not dirty anymore

View File

@@ -1,3 +1,2 @@
export * from './EditWorkspaceNameForm';
export { default } from './EditWorkspaceNameForm';
export { default as EditWorkspaceNameForm } from './EditWorkspaceNameForm';

View File

@@ -1,25 +0,0 @@
import Link from '@/ui/v2/Link';
import Text from '@/ui/v2/Text';
export function FindOldApps() {
return (
<div className="mt-4">
<Text className="font-medium" color="secondary">
Looking for your old apps? They&apos;re still on{' '}
<span className="pb-0.25">
<Link
href="https://console.nhost.io"
target="_blank"
rel="noreferrer"
underline="hover"
>
console.nhost.io
</Link>
</span>{' '}
during this beta.
</Text>
</div>
);
}
export default FindOldApps;

View File

@@ -1,51 +0,0 @@
import { useUI } from '@/context/UIContext';
import Button from '@/ui/v2/Button';
import PlusCircleIcon from '@/ui/v2/icons/PlusCircleIcon';
import SearchIcon from '@/ui/v2/icons/SearchIcon';
import Input from '@/ui/v2/Input';
import Text from '@/ui/v2/Text';
import Link from 'next/link';
interface IndexHeaderAppsProps {
query?: any;
setQuery?: any;
}
export function IndexHeaderApps({ query, setQuery }: IndexHeaderAppsProps) {
const { maintenanceActive } = useUI();
return (
<div className="mx-auto mb-6 grid w-full grid-flow-col place-content-between items-center py-2">
<Text variant="h2" component="h1" className="hidden md:block">
My Projects
</Text>
<Input
placeholder="Find Project"
startAdornment={
<SearchIcon
className="ml-2 -mr-1 h-4 w-4 shrink-0"
sx={{ color: 'text.disabled' }}
/>
}
value={query}
onChange={(event) => {
setQuery(event.target.value);
}}
/>
<Link href="/new" passHref>
<Button
variant="outlined"
color="secondary"
startIcon={<PlusCircleIcon />}
disabled={maintenanceActive}
>
New Project
</Button>
</Link>
</div>
);
}
export default IndexHeaderApps;

View File

@@ -1,4 +1,8 @@
import { useGetWorkspaceMemberInvitesToManageQuery } from '@/generated/graphql';
import {
GetAllWorkspacesAndProjectsDocument,
GetWorkspaceMemberInvitesToManageDocument,
useGetWorkspaceMemberInvitesToManageQuery,
} from '@/generated/graphql';
import useIsPlatform from '@/hooks/common/useIsPlatform';
import { useSubmitState } from '@/hooks/useSubmitState';
import Box from '@/ui/v2/Box';
@@ -29,7 +33,7 @@ export function InviteAnnounce() {
variables: {
userId: user?.id,
},
skip: !isPlatform,
skip: !isPlatform || !user,
});
useEffect(() => {
@@ -114,7 +118,10 @@ export function InviteAnnounce() {
// just refetch all data
await client.refetchQueries({
include: ['getOneUser', 'getWorkspaceMemberInvitesToManage'],
include: [
GetAllWorkspacesAndProjectsDocument,
GetWorkspaceMemberInvitesToManageDocument,
],
});
setIgnoreState({

View File

@@ -1,27 +0,0 @@
import { Resource } from '@/components/home/Resource';
import Text from '@/ui/v2/Text';
export default function Resources() {
return (
<div>
<Text color="disabled">Resources</Text>
<div className="mt-4 flex flex-col space-y-1">
<Resource
text="Documentation"
logo="Question"
link="https://docs.nhost.io"
/>
<Resource
text="Javascript Client"
logo="js"
link="https://docs.nhost.io/reference/javascript/"
/>
<Resource
text="Nhost CLI"
logo="CLI"
link="https://docs.nhost.io/platform/cli"
/>
</div>
</div>
);
}

View File

@@ -1,5 +1,5 @@
import { useInsertFeedbackOneMutation } from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { Avatar } from '@/ui/Avatar';
import Button from '@/ui/v2/Button';
import Input from '@/ui/v2/Input';
@@ -8,7 +8,7 @@ import { useUserData } from '@nhost/nextjs';
import * as React from 'react';
export function SendFeedback({ setFeedbackSent, feedback, setFeedback }: any) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [insertFeedback, { loading }] = useInsertFeedbackOneMutation();
const user = useUserData();
@@ -16,7 +16,7 @@ export function SendFeedback({ setFeedbackSent, feedback, setFeedback }: any) {
e.preventDefault();
const feedbackWithProjectInfo = [
currentApplication && `Project ID: ${currentApplication.id}`,
currentProject && `Project ID: ${currentProject.id}`,
typeof window !== 'undefined' && `URL: ${window.location.href}`,
feedback,
]

View File

@@ -1,56 +0,0 @@
import { Resources } from '@/components/home';
import GithubIcon from '@/components/icons/GithubIcon';
import { WorkspaceSection } from '@/components/workspace/WorkspaceSection';
import Button from '@/ui/v2/Button';
import Image from 'next/image';
import Link from 'next/link';
export default function Sidebar() {
return (
<div className="mt-2 grid w-full grid-flow-row content-start gap-8 md:ml-10 md:grid md:w-workspaceSidebar">
<WorkspaceSection />
<Resources />
<div className="grid grid-flow-row gap-2">
<Link
href="https://github.com/nhost/nhost"
passHref
target="_blank"
rel="noreferrer noopener"
>
<Button
className="grid grid-flow-col gap-1"
variant="outlined"
color="secondary"
startIcon={<GithubIcon />}
>
Star us on GitHub
</Button>
</Link>
<Link
href="https://discord.com/invite/9V7Qb2U"
passHref
target="_blank"
rel="noreferrer noopener"
>
<Button
className="grid grid-flow-col gap-1"
variant="outlined"
color="secondary"
aria-labelledby="discord-button-label"
>
<Image
src="/assets/brands/discord.svg"
alt="Discord Logo"
width={24}
height={24}
/>
<span id="discord-button-label">Join Discord</span>
</Button>
</Link>
</div>
</div>
);
}

View File

@@ -0,0 +1,165 @@
import { useDialog } from '@/components/common/DialogProvider';
import { EditWorkspaceNameForm } from '@/components/home/EditWorkspaceNameForm';
import { Resource } from '@/components/home/Resource';
import GithubIcon from '@/components/icons/GithubIcon';
import type { Workspace } from '@/types/application';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import type { BoxProps } from '@/ui/v2/Box';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import List from '@/ui/v2/List';
import { ListItem } from '@/ui/v2/ListItem';
import Text from '@/ui/v2/Text';
import PlusCircleIcon from '@/ui/v2/icons/PlusCircleIcon';
import Image from 'next/image';
import NavLink from 'next/link';
import { twMerge } from 'tailwind-merge';
export interface SidebarProps extends BoxProps {
/**
* List of workspaces to be displayed.
*/
workspaces: Workspace[];
}
export default function Sidebar({
className,
workspaces,
...props
}: SidebarProps) {
const { openDialog } = useDialog();
return (
<Box
component="aside"
className={twMerge(
'grid w-full grid-flow-row content-start gap-8 md:grid',
className,
)}
{...props}
>
<section className="grid grid-flow-row gap-2">
<Text color="secondary">My Workspaces</Text>
{workspaces.length > 0 ? (
<List className="grid grid-flow-row gap-2">
{workspaces.map(({ id, name, slug }) => (
<ListItem.Root key={id}>
<NavLink href={`/${slug}`} passHref>
<ListItem.Button
dense
aria-label={`View ${name}`}
className="!p-1"
>
<ListItem.Avatar className="h-8 w-8">
<div className="inline-block h-8 w-8 overflow-hidden rounded-lg">
<Image
src="/logos/new.svg"
alt="Nhost Logo"
width={32}
height={32}
/>
</div>
</ListItem.Avatar>
<ListItem.Text primary={name} />
</ListItem.Button>
</NavLink>
</ListItem.Root>
))}
</List>
) : (
<ActivityIndicator
label="Creating your first workspace..."
className="py-1"
/>
)}
<Button
variant="borderless"
color="secondary"
startIcon={<PlusCircleIcon />}
className="justify-self-start"
onClick={() => {
openDialog({
title: (
<span className="grid grid-flow-row">
<span>New Workspace</span>
<Text variant="subtitle1" component="span">
Invite team members to workspaces to work collaboratively.
</Text>
</span>
),
component: <EditWorkspaceNameForm />,
});
}}
>
New Workspace
</Button>
</section>
<section className="grid grid-flow-row gap-2">
<Text color="secondary">Resources</Text>
<div className="grid grid-flow-row gap-2">
<Resource
text="Documentation"
logo="Question"
link="https://docs.nhost.io"
/>
<Resource
text="JavaScript Client"
logo="js"
link="https://docs.nhost.io/reference/javascript/"
/>
<Resource
text="Nhost CLI"
logo="CLI"
link="https://docs.nhost.io/platform/cli"
/>
</div>
</section>
<section className="grid grid-flow-row gap-2">
<NavLink
href="https://github.com/nhost/nhost"
passHref
target="_blank"
rel="noreferrer noopener"
>
<Button
className="grid grid-flow-col gap-1"
variant="outlined"
color="secondary"
startIcon={<GithubIcon />}
>
Star us on GitHub
</Button>
</NavLink>
<NavLink
href="https://discord.com/invite/9V7Qb2U"
passHref
target="_blank"
rel="noreferrer noopener"
>
<Button
className="grid grid-flow-col gap-1"
variant="outlined"
color="secondary"
aria-labelledby="discord-button-label"
>
<Image
src="/assets/brands/discord.svg"
alt="Discord Logo"
width={24}
height={24}
/>
<span id="discord-button-label">Join Discord</span>
</Button>
</NavLink>
</section>
</Box>
);
}

View File

@@ -0,0 +1 @@
export { default as Sidebar } from './Sidebar';

View File

@@ -0,0 +1,225 @@
import DeploymentStatusMessage from '@/components/deployments/DeploymentStatusMessage';
import { useUI } from '@/context/UIContext';
import type { ApplicationState, Workspace } from '@/types/application';
import { ApplicationStatus } from '@/types/application';
import StateBadge from '@/ui/StateBadge';
import type { DeploymentStatus } from '@/ui/StatusCircle';
import { StatusCircle } from '@/ui/StatusCircle';
import type { BoxProps } from '@/ui/v2/Box';
import Box from '@/ui/v2/Box';
import type { ButtonProps } from '@/ui/v2/Button';
import Button from '@/ui/v2/Button';
import type { InputProps } from '@/ui/v2/Input';
import Input from '@/ui/v2/Input';
import Link from '@/ui/v2/Link';
import List from '@/ui/v2/List';
import { ListItem } from '@/ui/v2/ListItem';
import Text from '@/ui/v2/Text';
import PlusCircleIcon from '@/ui/v2/icons/PlusCircleIcon';
import SearchIcon from '@/ui/v2/icons/SearchIcon';
import { getApplicationStatusString } from '@/utils/helpers';
import { Divider } from '@mui/material';
import debounce from 'lodash.debounce';
import Image from 'next/image';
import NavLink from 'next/link';
import type { ChangeEvent, PropsWithoutRef } from 'react';
import { Fragment, useState } from 'react';
import { twMerge } from 'tailwind-merge';
export interface WorkspaceAndProjectListProps extends BoxProps {
/**
* List of workspaces to be displayed.
*/
workspaces: Workspace[];
/**
* Props to be passed to individual slots.
*/
slotProps?: {
root?: BoxProps;
header?: BoxProps;
search?: PropsWithoutRef<InputProps>;
button?: PropsWithoutRef<ButtonProps>;
};
}
function checkStatusOfTheApplication(stateHistory: ApplicationState[] | []) {
if (stateHistory.length === 0) {
return ApplicationStatus.Empty;
}
if (stateHistory[0].stateId === undefined) {
return ApplicationStatus.Empty;
}
return stateHistory[0].stateId;
}
export default function WorkspaceAndProjectList({
workspaces,
className,
slotProps = {},
...props
}: WorkspaceAndProjectListProps) {
const [query, setQuery] = useState('');
const { maintenanceActive } = useUI();
const handleQueryChange = debounce((event: ChangeEvent<HTMLInputElement>) => {
slotProps?.search?.onChange?.(event);
setQuery(event.target.value);
}, 500);
const filteredWorkspaces = workspaces
.map((workspace) => ({
...workspace,
projects: workspace.projects.filter((project) =>
project.name.toLowerCase().includes(query.toLowerCase()),
),
}))
.filter((workspace) => workspace.projects.length > 0);
return (
<Box
{...props}
{...slotProps.root}
className={twMerge(
'grid grid-flow-row content-start gap-4',
className,
slotProps.root?.className,
)}
>
<Box
{...slotProps.header}
className={twMerge(
'grid grid-flow-col place-content-between items-center',
slotProps.header?.className,
)}
>
<Text variant="h2" component="h1" className="hidden md:block">
My Projects
</Text>
<Input
placeholder="Find Project"
startAdornment={
<SearchIcon
className="ml-2 -mr-1 h-4 w-4 shrink-0"
sx={{ color: 'text.disabled' }}
/>
}
{...slotProps.search}
onChange={handleQueryChange}
/>
<NavLink href="/new" passHref>
<Button
variant="outlined"
color="secondary"
startIcon={<PlusCircleIcon />}
disabled={maintenanceActive}
{...slotProps.button}
>
New Project
</Button>
</NavLink>
</Box>
<Box className="my-8 grid grid-flow-row gap-8">
{filteredWorkspaces.map((workspace) => (
<div key={workspace.slug}>
<NavLink href={`/${workspace.slug}`} passHref>
<Link
href={`${workspace.slug}`}
className="mb-1.5 block font-medium"
underline="none"
sx={{ color: 'text.primary' }}
>
{workspace.name}
</Link>
</NavLink>
<List className="grid grid-flow-row border-y">
{workspace.projects.map((project, index) => {
const [latestDeployment] = project.deployments;
return (
<Fragment key={project.slug}>
<ListItem.Root
secondaryAction={
<div className="grid grid-flow-col gap-px">
{latestDeployment && (
<div className="mr-2 flex self-center align-middle">
<StatusCircle
status={
latestDeployment.deploymentStatus as DeploymentStatus
}
/>
</div>
)}
<StateBadge
state={checkStatusOfTheApplication(
project.appStates,
)}
desiredState={project.desiredState}
title={getApplicationStatusString(
checkStatusOfTheApplication(project.appStates),
)}
/>
</div>
}
>
<NavLink
href={`${workspace?.slug}/${project.slug}`}
passHref
>
<ListItem.Button className="rounded-none">
<ListItem.Avatar>
<div className="h-10 w-10 overflow-hidden rounded-lg">
<Image
src="/logos/new.svg"
alt="Nhost Logo"
width={40}
height={40}
/>
</div>
</ListItem.Avatar>
<ListItem.Text
primary={project.name}
secondary={
<DeploymentStatusMessage
appCreatedAt={project.createdAt}
deployment={latestDeployment}
/>
}
/>
</ListItem.Button>
</NavLink>
</ListItem.Root>
{index < workspace.projects.length - 1 && (
<Divider component="li" role="listitem" />
)}
</Fragment>
);
})}
</List>
</div>
))}
</Box>
<Text className="font-medium" color="secondary">
Looking for your old apps? They&apos;re still on{' '}
<Link
href="https://console.nhost.io"
target="_blank"
rel="noreferrer"
underline="always"
>
console.nhost.io
</Link>{' '}
during this beta.
</Text>
</Box>
);
}

View File

@@ -0,0 +1,2 @@
export * from './WorkspaceAndProjectList';
export { default as WorkspaceAndProjectList } from './WorkspaceAndProjectList';

View File

@@ -1,3 +0,0 @@
export { FindOldApps } from './FindOldApps';
export { IndexHeaderApps } from './IndexHeaderApps';
export { default as Resources } from './Resources';

View File

@@ -4,11 +4,8 @@ import type { AuthenticatedLayoutProps } from '@/components/layout/Authenticated
import AuthenticatedLayout from '@/components/layout/AuthenticatedLayout';
import useIsPlatform from '@/hooks/common/useIsPlatform';
import useProjectRoutes from '@/hooks/common/useProjectRoutes';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useGetAllUserWorkspacesAndApplications } from '@/hooks/useGetAllUserWorkspacesAndApplications';
import { useNavigationVisible } from '@/hooks/useNavigationVisible';
import useNotFoundRedirect from '@/hooks/useNotFoundRedirect';
import { useSetAppWorkspaceContextFromUserContext } from '@/hooks/useSetAppWorkspaceContextFromUserContext';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { BoxProps } from '@/ui/v2/Box';
import Box from '@/ui/v2/Box';
@@ -31,14 +28,7 @@ function ProjectLayoutContent({
...mainContainerProps
} = {},
}: ProjectLayoutProps) {
// TODO: This will be removed once we migrated every occurrence to
// useCurrentWorkspaceAndProject()
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { currentProject, loading, error } = useCurrentWorkspaceAndProject({
fetchPolicy: 'network-only',
});
const { currentProject, loading, error } = useCurrentWorkspaceAndProject();
const router = useRouter();
const shouldDisplayNav = useNavigationVisible();
@@ -56,8 +46,6 @@ function ProjectLayoutContent({
),
);
useGetAllUserWorkspacesAndApplications(false);
useSetAppWorkspaceContextFromUserContext();
useNotFoundRedirect();
useEffect(() => {
@@ -70,7 +58,7 @@ function ProjectLayoutContent({
}
}, [isPlatform, isRestrictedPath, router]);
if (!currentWorkspace || !currentApplication || isRestrictedPath || loading) {
if (isRestrictedPath || loading) {
return <LoadingScreen />;
}

View File

@@ -4,7 +4,6 @@ import type { BaseLayoutProps } from '@/components/layout/BaseLayout';
import BaseLayout from '@/components/layout/BaseLayout';
import Container from '@/components/layout/Container';
import useIsPlatform from '@/hooks/common/useIsPlatform';
import { useCleanWorkspaceContext } from '@/hooks/use-cleanWorkspaceContext';
import Box from '@/ui/v2/Box';
import ThemeProvider from '@/ui/v2/ThemeProvider';
import GlobalStyles from '@mui/material/GlobalStyles';
@@ -22,7 +21,6 @@ export default function UnauthenticatedLayout({
const router = useRouter();
const isPlatform = useIsPlatform();
const { isAuthenticated, isLoading } = useAuthenticationStatus();
useCleanWorkspaceContext();
useEffect(() => {
if (!isPlatform || (!isLoading && isAuthenticated)) {

View File

@@ -1,5 +1,5 @@
import LogsDatePicker from '@/components/logs/LogsDatePicker';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { AvailableLogsServices, LogsCustomInterval } from '@/types/logs';
import type { BoxProps } from '@/ui/v2/Box';
import Box from '@/ui/v2/Box';
@@ -127,8 +127,8 @@ export default function LogsHeader({
onServiceChange,
...props
}: LogsHeaderProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const applicationCreationDate = new Date(currentApplication.createdAt);
const { currentProject } = useCurrentWorkspaceAndProject();
const applicationCreationDate = new Date(currentProject.createdAt);
/**
* Will subtract the `customInterval` time in minutes from the current date.

View File

@@ -1,13 +1,9 @@
import { UserDataProvider } from '@/context/workspace1-context';
import type { Project } from '@/types/application';
import { ApplicationStatus } from '@/types/application';
import type { Workspace } from '@/types/workspace';
import nhostGraphQLLink from '@/utils/msw/mocks/graphql/nhostGraphQLLink';
import { render, screen, waitForElementToBeRemoved } from '@/utils/testUtils';
import { mockApplication, mockWorkspace } from '@/tests/mocks';
import { queryClient, render, screen } from '@/tests/testUtils';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { afterAll, beforeAll, vi } from 'vitest';
import OverviewDeployments from '.';
import OverviewDeployments from './OverviewDeployments';
vi.mock('next/router', () => ({
useRouter: vi.fn().mockReturnValue({
@@ -37,54 +33,10 @@ vi.mock('next/router', () => ({
}),
}));
const mockApplication: Project = {
id: '1',
name: 'Test Application',
slug: 'test-application',
appStates: [],
subdomain: '',
isProvisioned: true,
region: {
awsName: 'us-east-1',
city: 'New York',
countryCode: 'US',
id: '1',
},
createdAt: new Date().toISOString(),
deployments: [],
desiredState: ApplicationStatus.Live,
featureFlags: [],
providersUpdated: true,
githubRepository: { fullName: 'test/git-project' },
repositoryProductionBranch: null,
nhostBaseFolder: null,
plan: null,
config: {
hasura: {
adminSecret: 'nhost-admin-secret',
},
},
};
const mockWorkspace: Workspace = {
id: '1',
name: 'Test Workspace',
slug: 'test-workspace',
members: [],
applications: [mockApplication],
};
const server = setupServer(
rest.get('https://local.graphql.nhost.run/v1', (_req, res, ctx) =>
res(ctx.status(200)),
),
nhostGraphQLLink.operation(async (_req, res, ctx) =>
res(
ctx.data({
deployments: [],
}),
),
),
);
beforeAll(() => {
@@ -93,48 +45,89 @@ beforeAll(() => {
server.listen();
});
afterEach(() => server.resetHandlers());
afterEach(() => {
server.resetHandlers(
rest.get('https://local.graphql.nhost.run/v1', (_req, res, ctx) =>
res(ctx.status(200)),
),
);
queryClient.clear();
});
afterAll(() => {
server.close();
vi.restoreAllMocks();
});
test('should render an empty state when GitHub is not connected', () => {
render(
<UserDataProvider
initialWorkspaces={[
{
...mockWorkspace,
applications: [{ ...mockApplication, githubRepository: null }],
},
]}
>
<OverviewDeployments />
</UserDataProvider>,
test('should render an empty state when GitHub is not connected', async () => {
server.use(
rest.post('https://local.graphql.nhost.run/v1', async (req, res, ctx) => {
const { operationName } = await req.json();
if (operationName === 'GetWorkspaceAndProject') {
return res(
ctx.json({
data: {
workspaces: [
{
...mockWorkspace,
projects: [{ ...mockApplication, githubRepository: null }],
},
],
projects: [{ ...mockApplication, githubRepository: null }],
},
}),
);
}
return res(
ctx.json({
data: {
deployments: [],
},
}),
);
}),
);
expect(screen.getByText(/no deployments/i)).toBeInTheDocument();
render(<OverviewDeployments />);
expect(await screen.findByText(/no deployments/i)).toBeInTheDocument();
expect(
screen.getByRole('button', { name: /connect to github/i }),
await screen.findByRole('button', { name: /connect to github/i }),
).toBeInTheDocument();
});
test('should render an empty state when GitHub is connected, but there are no deployments', async () => {
render(
<UserDataProvider initialWorkspaces={[mockWorkspace]}>
<OverviewDeployments />
</UserDataProvider>,
server.use(
rest.post('https://local.graphql.nhost.run/v1', async (_req, res, ctx) => {
const { operationName } = await _req.json();
if (operationName === 'GetWorkspaceAndProject') {
return res(
ctx.json({
data: {
workspaces: [mockWorkspace],
projects: [mockApplication],
},
}),
);
}
return res(ctx.json({ data: { deployments: [] } }));
}),
);
expect(screen.getByText(/^deployments$/i)).toBeInTheDocument();
expect(screen.getByRole('link', { name: /view all/i })).toBeInTheDocument();
render(<OverviewDeployments />);
await waitForElementToBeRemoved(() => screen.queryByRole('progressbar'));
expect(await screen.findByText(/^deployments$/i)).toBeInTheDocument();
expect(
await screen.findByRole('link', { name: /view all/i }),
).toBeInTheDocument();
expect(screen.getByText(/no deployments/i)).toBeInTheDocument();
expect(screen.getByText(/test\/git-project/i)).toBeInTheDocument();
expect(screen.getByRole('link', { name: /edit/i })).toHaveAttribute(
expect(await screen.findByText(/no deployments/i)).toBeInTheDocument();
expect(await screen.findByText(/test\/git-project/i)).toBeInTheDocument();
expect(await screen.findByRole('link', { name: /edit/i })).toHaveAttribute(
'href',
'/test-workspace/test-application/settings/git',
);
@@ -142,103 +135,124 @@ test('should render an empty state when GitHub is connected, but there are no de
test('should render a list of deployments', async () => {
server.use(
nhostGraphQLLink.operation(async (req, res, ctx) => {
const requestPayload = await req.json();
rest.post('https://local.graphql.nhost.run/v1', async (_req, res, ctx) => {
const { operationName } = await _req.json();
if (requestPayload.operationName === 'ScheduledOrPendingDeploymentsSub') {
return res(ctx.data({ deployments: [] }));
if (operationName === 'ScheduledOrPendingDeploymentsSub') {
return res(ctx.json({ data: { deployments: [] } }));
}
return res(
ctx.data({
deployments: [
{
id: '1',
commitSHA: 'abc123',
deploymentStartedAt: '2021-08-01T00:00:00.000Z',
deploymentEndedAt: '2021-08-01T00:05:00.000Z',
deploymentStatus: 'DEPLOYED',
commitUserName: 'test.user',
commitUserAvatarUrl: 'http://images.example.com/avatar.png',
commitMessage: 'Test commit message',
},
],
}),
);
}),
);
render(
<UserDataProvider initialWorkspaces={[mockWorkspace]}>
<OverviewDeployments />
</UserDataProvider>,
);
await waitForElementToBeRemoved(() => screen.queryByRole('progressbar'));
expect(screen.getByText(/test commit message/i)).toBeInTheDocument();
expect(screen.getByLabelText(/avatar/i)).toHaveStyle(
'background-image: url(http://images.example.com/avatar.png)',
);
expect(
screen.getByRole('link', {
name: /test commit message/i,
}),
).toHaveAttribute('href', '/test-workspace/test-application/deployments/1');
expect(screen.getByText(/5m 0s/i)).toBeInTheDocument();
expect(screen.getByText(/live/i)).toBeInTheDocument();
expect(screen.getByRole('button', { name: /redeploy/i })).not.toBeDisabled();
});
test('should disable redeployments if a deployment is already in progress', async () => {
server.use(
nhostGraphQLLink.operation(async (req, res, ctx) => {
const requestPayload = await req.json();
if (requestPayload.operationName === 'ScheduledOrPendingDeploymentsSub') {
if (operationName === 'GetWorkspaceAndProject') {
return res(
ctx.data({
deployments: [
{
id: '2',
commitSHA: 'abc234',
deploymentStartedAt: '2021-08-02T00:00:00.000Z',
deploymentEndedAt: null,
deploymentStatus: 'PENDING',
commitUserName: 'test.user',
commitUserAvatarUrl: 'http://images.example.com/avatar.png',
commitMessage: 'Test commit message',
},
],
ctx.json({
data: {
workspaces: [mockWorkspace],
projects: [mockApplication],
},
}),
);
}
return res(
ctx.data({
deployments: [
{
id: '1',
commitSHA: 'abc123',
deploymentStartedAt: '2021-08-01T00:00:00.000Z',
deploymentEndedAt: '2021-08-01T00:05:00.000Z',
deploymentStatus: 'DEPLOYED',
commitUserName: 'test.user',
commitUserAvatarUrl: 'http://images.example.com/avatar.png',
commitMessage: 'Test commit message',
},
],
ctx.json({
data: {
deployments: [
{
id: '1',
commitSHA: 'abc123',
deploymentStartedAt: '2021-08-01T00:00:00.000Z',
deploymentEndedAt: '2021-08-01T00:05:00.000Z',
deploymentStatus: 'DEPLOYED',
commitUserName: 'test.user',
commitUserAvatarUrl: 'http://images.example.com/avatar.png',
commitMessage: 'Test commit message',
},
],
},
}),
);
}),
);
render(
<UserDataProvider initialWorkspaces={[mockWorkspace]}>
<OverviewDeployments />
</UserDataProvider>,
render(<OverviewDeployments />);
expect(await screen.findByText(/test commit message/i)).toBeInTheDocument();
expect(await screen.findByLabelText(/avatar/i)).toHaveStyle(
'background-image: url(http://images.example.com/avatar.png)',
);
expect(
await screen.findByRole('link', {
name: /test commit message/i,
}),
).toHaveAttribute('href', '/test-workspace/test-application/deployments/1');
expect(await screen.findByText(/5m 0s/i)).toBeInTheDocument();
expect(await screen.findByText(/live/i)).toBeInTheDocument();
expect(
await screen.findByRole('button', { name: /redeploy/i }),
).not.toBeDisabled();
});
test('should disable redeployments if a deployment is already in progress', async () => {
server.use(
rest.post('https://local.graphql.nhost.run/v1', async (req, res, ctx) => {
const { operationName } = await req.json();
if (operationName === 'ScheduledOrPendingDeploymentsSub') {
return res(
ctx.json({
data: {
deployments: [
{
id: '2',
commitSHA: 'abc234',
deploymentStartedAt: '2021-08-02T00:00:00.000Z',
deploymentEndedAt: null,
deploymentStatus: 'PENDING',
commitUserName: 'test.user',
commitUserAvatarUrl: 'http://images.example.com/avatar.png',
commitMessage: 'Test commit message',
},
],
},
}),
);
}
if (operationName === 'GetWorkspaceAndProject') {
return res(
ctx.json({
data: {
workspaces: [mockWorkspace],
projects: [mockApplication],
},
}),
);
}
return res(
ctx.json({
data: {
deployments: [
{
id: '1',
commitSHA: 'abc123',
deploymentStartedAt: '2021-08-01T00:00:00.000Z',
deploymentEndedAt: '2021-08-01T00:05:00.000Z',
deploymentStatus: 'DEPLOYED',
commitUserName: 'test.user',
commitUserAvatarUrl: 'http://images.example.com/avatar.png',
commitMessage: 'Test commit message',
},
],
},
}),
);
}),
);
await waitForElementToBeRemoved(() => screen.queryByRole('progressbar'));
expect(screen.getByRole('button', { name: /redeploy/i })).toBeDisabled();
render(<OverviewDeployments />);
expect(
await screen.findByRole('button', { name: /redeploy/i }),
).toBeDisabled();
});

View File

@@ -2,28 +2,26 @@ import useGitHubModal from '@/components/applications/github/useGitHubModal';
import DeploymentListItem from '@/components/deployments/DeploymentListItem';
import GithubIcon from '@/components/icons/GithubIcon';
import { useUI } from '@/context/UIContext';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import Divider from '@/ui/v2/Divider';
import ChevronRightIcon from '@/ui/v2/icons/ChevronRightIcon';
import RocketIcon from '@/ui/v2/icons/RocketIcon';
import List from '@/ui/v2/List';
import Text from '@/ui/v2/Text';
import { getLastLiveDeployment } from '@/utils/helpers';
import ChevronRightIcon from '@/ui/v2/icons/ChevronRightIcon';
import RocketIcon from '@/ui/v2/icons/RocketIcon';
import {
useGetDeploymentsSubSubscription,
useScheduledOrPendingDeploymentsSubSubscription,
} from '@/utils/__generated__/graphql';
import { getLastLiveDeployment } from '@/utils/helpers';
import NavLink from 'next/link';
import { Fragment } from 'react';
function OverviewDeploymentsTopBar() {
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { githubRepository } = currentApplication || {};
const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject();
const isGitHubConnected = !!currentProject?.githubRepository;
return (
<div className="grid grid-flow-col place-content-between items-center gap-2 pb-4">
@@ -32,10 +30,10 @@ function OverviewDeploymentsTopBar() {
</Text>
<NavLink
href={`/${currentWorkspace?.slug}/${currentApplication?.slug}/deployments`}
href={`/${currentWorkspace?.slug}/${currentProject?.slug}/deployments`}
passHref
>
<Button variant="borderless" disabled={!githubRepository}>
<Button variant="borderless" disabled={!isGitHubConnected}>
View all
<ChevronRightIcon className="ml-1 inline-block h-4 w-4" />
</Button>
@@ -45,11 +43,10 @@ function OverviewDeploymentsTopBar() {
}
function OverviewDeploymentList() {
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject();
const { data, loading } = useGetDeploymentsSubSubscription({
variables: {
id: currentApplication?.id,
id: currentProject?.id,
limit: 5,
offset: 0,
},
@@ -60,7 +57,7 @@ function OverviewDeploymentList() {
loading: scheduledOrPendingDeploymentsLoading,
} = useScheduledOrPendingDeploymentsSubSubscription({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
},
});
@@ -102,12 +99,12 @@ function OverviewDeploymentList() {
>
<GithubIcon className="h-4 w-4 self-center" />
<Text variant="body1" className="self-center font-normal">
{currentApplication?.githubRepository?.fullName}
{currentProject?.githubRepository?.fullName}
</Text>
</Box>
<NavLink
href={`/${currentWorkspace.slug}/${currentApplication.slug}/settings/git`}
href={`/${currentWorkspace.slug}/${currentProject.slug}/settings/git`}
passHref
>
<Button variant="borderless" size="small">
@@ -145,14 +142,17 @@ function OverviewDeploymentList() {
}
export default function OverviewDeployments() {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject, loading } = useCurrentWorkspaceAndProject();
const { openGitHubModal } = useGitHubModal();
const { maintenanceActive } = useUI();
const isGitHubConnected = !!currentProject?.githubRepository;
const { githubRepository } = currentApplication || {};
if (loading) {
return <ActivityIndicator label="Loading project info..." delay={1000} />;
}
// GitHub repo connected. Show deployments
if (githubRepository) {
if (isGitHubConnected) {
return (
<div className="flex flex-col">
<OverviewDeploymentsTopBar />

View File

@@ -1,141 +0,0 @@
import { useDialog } from '@/components/common/DialogProvider';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { ApplicationStatus } from '@/types/application';
import { Alert } from '@/ui/Alert';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import Chip from '@/ui/v2/Chip';
import Text from '@/ui/v2/Text';
import { triggerToast } from '@/utils/toast';
import { useUpdateApplicationMutation } from '@/utils/__generated__/graphql';
const migrationSteps = [
{
title: 'Your project will be paused',
},
{
title: 'Your database will be migrated to its own dedicated instance',
},
{
title: 'Your project will be resumed',
},
];
export default function OverviewMigration() {
const { openAlertDialog } = useDialog();
const [updateApplication] = useUpdateApplicationMutation({
refetchQueries: ['getOneUser'],
});
const { currentApplication } = useCurrentWorkspaceAndApplication();
return (
<div className="pb-12">
<div className="flex flex-col gap-2">
<Text variant="h3">
Migrate Database
<span className="relative -top-0.5 ml-2 self-center">
<Chip label="New" color="primary" size="small" />
</span>
</Text>
<Text variant="subtitle1" className="!font-medium">
Migrate your project&apos;s data to its own Postgres instance and get
root access to your database.
</Text>
</div>
<div className="mt-6 flex flex-row place-content-between rounded-lg">
<Button
variant="outlined"
color="secondary"
className="w-full border-1 hover:border-1"
onClick={() => {
openAlertDialog({
title: 'Migrate Database',
payload: (
<div className="flex flex-col gap-6 pb-8">
<Text>
Your project&apos;s data will be moved to a new and
dedicated Postgres instance with root access.
</Text>
<div className="flex flex-col gap-4">
<Text>Steps to migrate:</Text>
<div className="grid grid-rows-3 gap-4">
{migrationSteps.map((step, index) => (
<div key={step.title} className="col-span-1">
<div className="flex h-11 flex-row gap-3">
<div className="flex items-center">
<Box
className="flex h-8 w-8 flex-col items-center justify-center self-center rounded-md align-middle font-semibold"
sx={{ backgroundColor: 'grey.200' }}
>
<Text
component="span"
className="font-semibold"
color="secondary"
>
{index + 1}
</Text>
</Box>
</div>
<div className="flex w-[312px] items-center">
<Text>{step.title}</Text>
</div>
</div>
</div>
))}
</div>
</div>
<Alert className="text-left">
You can expect some downtime while we are moving your data
around. The time to migrate is dependent on your database
size.
</Alert>
</div>
),
props: {
contentProps: {
className: 'py-0',
},
PaperProps: {
className: 'max-w-[29.25rem] mx-auto p-6 rounded-lg',
},
primaryButtonText: 'Start Migration',
onPrimaryAction: async () => {
try {
await updateApplication({
variables: {
appId: currentApplication.id,
app: {
desiredState: ApplicationStatus.Migrating,
},
},
});
localStorage.setItem(
`migration-${currentApplication.id}`,
new Date().toISOString(),
);
triggerToast(`${currentApplication.name} set to migrate.`);
} catch (e) {
triggerToast(
`Error trying to migrate ${currentApplication.name}`,
);
}
},
actionsProps: {
className: 'flex flex-row-reverse place-content-between',
},
},
});
}}
>
Start Migrating
</Button>
</div>
</div>
);
}

View File

@@ -1 +0,0 @@
export { default } from './OverviewMigration';

View File

@@ -1,28 +1,27 @@
import GithubIcon from '@/components/icons/GithubIcon';
import { useUI } from '@/context/UIContext';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import Text from '@/ui/v2/Text';
import NavLink from 'next/link';
export default function OverviewRepository() {
const { currentWorkspace, currentApplication } =
useCurrentWorkspaceAndApplication();
const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject();
const { maintenanceActive } = useUI();
return (
<div>
<Text variant="h3">Repository</Text>
<Text variant="subtitle1" className="mt-2 !font-medium">
{!currentApplication.githubRepository
{!currentProject.githubRepository
? 'Connect your project with a GitHub repository to create your first deployment.'
: 'GitHub is connected.'}
</Text>
{!currentApplication.githubRepository ? (
{!currentProject.githubRepository ? (
<div className="mt-6 flex flex-row place-content-between rounded-lg">
<NavLink
href={`/${currentWorkspace.slug}/${currentApplication.slug}/settings/git`}
href={`/${currentWorkspace.slug}/${currentProject.slug}/settings/git`}
passHref
>
<Button
@@ -47,12 +46,12 @@ export default function OverviewRepository() {
>
<GithubIcon className="h-4 w-4 self-center" />
<Text variant="body1" className="self-center font-normal">
{currentApplication.githubRepository.fullName}
{currentProject.githubRepository.fullName}
</Text>
</Box>
<NavLink
href={`/${currentWorkspace.slug}/${currentApplication.slug}/settings/git`}
href={`/${currentWorkspace.slug}/${currentProject.slug}/settings/git`}
passHref
>
<Button

View File

@@ -15,7 +15,7 @@ export default function OverviewTopBar() {
const isPlatform = useIsPlatform();
const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject();
const isPro = !currentProject?.plan?.isFree;
const { openAlertDialog } = useDialog();
const { openDialog } = useDialog();
const { maintenanceActive } = useUI();
if (!isPlatform) {
@@ -92,14 +92,10 @@ export default function OverviewTopBar() {
variant="borderless"
className="mr-2"
onClick={() => {
openAlertDialog({
title: 'Upgrade your plan.',
payload: <ChangePlanModal />,
openDialog({
component: <ChangePlanModal />,
props: {
PaperProps: { className: 'p-0 max-w-xl w-full' },
hidePrimaryAction: true,
hideSecondaryAction: true,
hideTitle: true,
},
});
}}

View File

@@ -5,7 +5,7 @@ import {
useResetPostgresPasswordMutation,
useUpdateApplicationMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import Button from '@/ui/v2/Button';
import CopyIcon from '@/ui/v2/icons/CopyIcon';
import Input from '@/ui/v2/Input';
@@ -51,7 +51,7 @@ export default function ResetDatabasePasswordSettings() {
const [resetPostgresPasswordMutation] = useResetPostgresPasswordMutation();
const user = useUserData();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const handleGenerateRandomPassword = () => {
const newRandomDatabasePassword = generateRandomDatabasePassword();
@@ -65,13 +65,13 @@ export default function ResetDatabasePasswordSettings() {
try {
await resetPostgresPasswordMutation({
variables: {
appID: currentApplication.id,
appID: currentProject.id,
newPassword: values.databasePassword,
},
});
await updateApplication({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
app: {
postgresPassword: values.databasePassword,
},
@@ -81,14 +81,14 @@ export default function ResetDatabasePasswordSettings() {
form.reset(values);
triggerToast(
`The database password for ${currentApplication.name} has been updated successfully.`,
`The database password for ${currentProject.name} has been updated successfully.`,
);
} catch (e) {
triggerToast(
`An error occured while trying to update the database password for ${currentApplication.name}`,
`An error occured while trying to update the database password for ${currentProject.name}`,
);
await discordAnnounce(
`An error occurred while trying to update the database password: ${currentApplication.name} (${user.email}): ${e.message}`,
`An error occurred while trying to update the database password: ${currentProject.name} (${user.email}): ${e.message}`,
);
}
};

View File

@@ -39,12 +39,6 @@ export interface SettingsContainerProps
* @default 'https://docs.nhost.io/'
*/
docsLink?: string;
/**
* Props for the primary action.
*
* @deprecated Use `slotProps.submitButton` instead.
*/
primaryActionButtonProps?: ButtonProps;
/**
* Submit button text.
*
@@ -106,7 +100,6 @@ export default function SettingsContainer({
title,
description,
icon,
primaryActionButtonProps,
submitButtonText = 'Save',
className,
onEnabledChange,
@@ -188,18 +181,10 @@ export default function SettingsContainer({
)}
<Button
variant={
(submitButton || primaryActionButtonProps)?.disabled
? 'outlined'
: 'contained'
}
color={
(submitButton || primaryActionButtonProps)?.disabled
? 'secondary'
: 'primary'
}
variant={submitButton?.disabled ? 'outlined' : 'contained'}
color={submitButton?.disabled ? 'secondary' : 'primary'}
type="submit"
{...(submitButton || primaryActionButtonProps)}
{...submitButton}
>
{submitButtonText}
</Button>

View File

@@ -1,5 +1,5 @@
import NavLink from '@/components/common/NavLink';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import FloatingActionButton from '@/ui/FloatingActionButton';
import Backdrop from '@/ui/v2/Backdrop';
import type { BoxProps } from '@/ui/v2/Box';
@@ -63,11 +63,7 @@ export default function SettingsSidebar({
...props
}: SettingsSidebarProps) {
const [expanded, setExpanded] = useState(false);
const { currentApplication } = useCurrentWorkspaceAndApplication();
const isProjectUsingRDS = currentApplication?.featureFlags?.some(
(feature) => feature.name === 'fleetcontrol_use_rds',
);
const { currentProject } = useCurrentWorkspaceAndProject();
function toggleExpanded() {
setExpanded(!expanded);
@@ -92,7 +88,7 @@ export default function SettingsSidebar({
document.removeEventListener('keydown', closeSidebarWhenEscapeIsPressed);
}, []);
if (!currentApplication) {
if (!currentProject) {
return null;
}
@@ -132,7 +128,14 @@ export default function SettingsSidebar({
>
General
</SettingsNavLink>
{isK8SPostgresEnabledInCurrentEnvironment && !isProjectUsingRDS && (
<SettingsNavLink
href="/resources"
exact={false}
onClick={handleSelect}
>
Compute Resources
</SettingsNavLink>
{isK8SPostgresEnabledInCurrentEnvironment && (
<SettingsNavLink
href="/database"
exact={false}

View File

@@ -6,7 +6,7 @@ import {
useGetAuthenticationSettingsQuery,
useUpdateConfigMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Input from '@/ui/v2/Input';
import getServerError from '@/utils/settings/getServerError';
@@ -29,13 +29,13 @@ export type AllowedEmailSettingsFormValues = Yup.InferType<
export default function AllowedEmailDomainsSettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateConfig] = useUpdateConfigMutation({
refetchQueries: [GetAuthenticationSettingsDocument],
});
const { data, loading, error } = useGetAuthenticationSettingsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -75,7 +75,7 @@ export default function AllowedEmailDomainsSettings() {
) => {
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
config: {
auth: {
user: {

View File

@@ -6,7 +6,7 @@ import {
useGetAuthenticationSettingsQuery,
useUpdateConfigMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Input from '@/ui/v2/Input';
import getServerError from '@/utils/settings/getServerError';
@@ -26,13 +26,13 @@ export type AllowedRedirectURLFormValues = Yup.InferType<
export default function AllowedRedirectURLsSettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateConfig] = useUpdateConfigMutation({
refetchQueries: [GetAuthenticationSettingsDocument],
});
const { data, loading, error } = useGetAuthenticationSettingsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -67,7 +67,7 @@ export default function AllowedRedirectURLsSettings() {
) => {
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
config: {
auth: {
redirections: {

View File

@@ -6,7 +6,7 @@ import {
useGetAuthenticationSettingsQuery,
useUpdateConfigMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Input from '@/ui/v2/Input';
import getServerError from '@/utils/settings/getServerError';
@@ -27,13 +27,13 @@ export type BlockedEmailFormValues = Yup.InferType<typeof validationSchema>;
export default function BlockedEmailSettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateConfig] = useUpdateConfigMutation({
refetchQueries: [GetAuthenticationSettingsDocument],
});
const { data, loading, error } = useGetAuthenticationSettingsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -72,7 +72,7 @@ export default function BlockedEmailSettings() {
) => {
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
config: {
auth: {
user: {

View File

@@ -6,7 +6,7 @@ import {
useGetAuthenticationSettingsQuery,
useUpdateConfigMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Input from '@/ui/v2/Input';
import getServerError from '@/utils/settings/getServerError';
@@ -24,13 +24,13 @@ export type ClientURLFormValues = Yup.InferType<typeof validationSchema>;
export default function ClientURLSettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateConfig] = useUpdateConfigMutation({
refetchQueries: [GetAuthenticationSettingsDocument],
});
const { data, loading, error } = useGetAuthenticationSettingsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -63,7 +63,7 @@ export default function ClientURLSettings() {
const handleClientURLChange = async (values: ClientURLFormValues) => {
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
config: {
auth: {
redirections: {

View File

@@ -1,15 +1,15 @@
import Form from '@/components/common/Form';
import SettingsContainer from '@/components/settings/SettingsContainer';
import { useUI } from '@/context/UIContext';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import {
GetAuthenticationSettingsDocument,
useGetAuthenticationSettingsQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { FormProvider, useForm } from 'react-hook-form';
import { toast } from 'react-hot-toast';
import * as Yup from 'yup';
@@ -22,13 +22,13 @@ export type DisableNewUsersFormValues = Yup.InferType<typeof validationSchema>;
export default function DisableNewUsersSettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateConfig] = useUpdateConfigMutation({
refetchQueries: [GetAuthenticationSettingsDocument],
});
const { data, loading, error } = useGetAuthenticationSettingsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -60,7 +60,7 @@ export default function DisableNewUsersSettings() {
) => {
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
config: {
auth: {
signUp: {

View File

@@ -7,7 +7,7 @@ import {
useGetAuthenticationSettingsQuery,
useUpdateConfigMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Option from '@/ui/v2/Option';
import getServerError from '@/utils/settings/getServerError';
@@ -32,13 +32,13 @@ export type GravatarFormValues = Yup.InferType<typeof validationSchema>;
export default function GravatarSettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateConfig] = useUpdateConfigMutation({
refetchQueries: [GetAuthenticationSettingsDocument],
});
const { data, loading, error } = useGetAuthenticationSettingsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -78,7 +78,7 @@ export default function GravatarSettings() {
const handleGravatarSettingsChange = async (values: GravatarFormValues) => {
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
config: {
auth: {
user: {

View File

@@ -6,7 +6,7 @@ import {
useGetAuthenticationSettingsQuery,
useUpdateConfigMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Input from '@/ui/v2/Input';
import getServerError from '@/utils/settings/getServerError';
@@ -26,13 +26,13 @@ export type MFASettingsFormValues = Yup.InferType<typeof validationSchema>;
export default function MFASettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateConfig] = useUpdateConfigMutation({
refetchQueries: [GetAuthenticationSettingsDocument],
});
const { data, loading, error } = useGetAuthenticationSettingsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -67,7 +67,7 @@ export default function MFASettings() {
const handleMFASettingsChange = async (values: MFASettingsFormValues) => {
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication.id,
appId: currentProject.id,
config: {
auth: {
totp: values,

View File

@@ -5,15 +5,15 @@ import type {
import BaseEnvironmentVariableForm, {
baseEnvironmentVariableFormValidationSchema,
} from '@/components/settings/environmentVariables/BaseEnvironmentVariableForm';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import {
GetEnvironmentVariablesDocument,
useGetEnvironmentVariablesQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { yupResolver } from '@hookform/resolvers/yup';
import { FormProvider, useForm } from 'react-hook-form';
import toast from 'react-hot-toast';
@@ -39,10 +39,10 @@ export default function CreateEnvironmentVariableForm({
resolver: yupResolver(baseEnvironmentVariableFormValidationSchema),
});
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data, loading, error } = useGetEnvironmentVariablesQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -83,7 +83,7 @@ export default function CreateEnvironmentVariableForm({
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
config: {
global: {
environment: [

View File

@@ -5,16 +5,16 @@ import type {
import BaseEnvironmentVariableForm, {
baseEnvironmentVariableFormValidationSchema,
} from '@/components/settings/environmentVariables/BaseEnvironmentVariableForm';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { EnvironmentVariable } from '@/types/application';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import {
GetEnvironmentVariablesDocument,
useGetEnvironmentVariablesQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { yupResolver } from '@hookform/resolvers/yup';
import { FormProvider, useForm } from 'react-hook-form';
import toast from 'react-hot-toast';
@@ -46,10 +46,10 @@ export default function EditEnvironmentVariableForm({
resolver: yupResolver(baseEnvironmentVariableFormValidationSchema),
});
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data, loading, error } = useGetEnvironmentVariablesQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -95,7 +95,7 @@ export default function EditEnvironmentVariableForm({
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
config: {
global: {
environment: [

View File

@@ -1,14 +1,14 @@
import { useDialog } from '@/components/common/DialogProvider';
import Form from '@/components/common/Form';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { DialogFormProps } from '@/types/common';
import Button from '@/ui/v2/Button';
import Input from '@/ui/v2/Input';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import {
GetEnvironmentVariablesDocument,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { yupResolver } from '@hookform/resolvers/yup';
import { useEffect } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
@@ -64,7 +64,7 @@ export default function EditJwtSecretForm({
submitButtonText = 'Save',
location,
}: EditJwtSecretFormProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateConfig] = useUpdateConfigMutation({
refetchQueries: [GetEnvironmentVariablesDocument],
});
@@ -93,7 +93,7 @@ export default function EditJwtSecretForm({
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
config: {
hasura: {
jwtSecrets: isArray ? parsedJwtSecret : [parsedJwtSecret],

View File

@@ -1,9 +1,9 @@
import { useDialog } from '@/components/common/DialogProvider';
import SettingsContainer from '@/components/settings/SettingsContainer';
import CreateEnvironmentVariableForm from '@/components/settings/environmentVariables/CreateEnvironmentVariableForm';
import EditEnvironmentVariableForm from '@/components/settings/environmentVariables/EditEnvironmentVariableForm';
import SettingsContainer from '@/components/settings/SettingsContainer';
import { useUI } from '@/context/UIContext';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { EnvironmentVariable } from '@/types/application';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Box from '@/ui/v2/Box';
@@ -11,18 +11,18 @@ import Button from '@/ui/v2/Button';
import Divider from '@/ui/v2/Divider';
import { Dropdown } from '@/ui/v2/Dropdown';
import IconButton from '@/ui/v2/IconButton';
import DotsVerticalIcon from '@/ui/v2/icons/DotsVerticalIcon';
import PlusIcon from '@/ui/v2/icons/PlusIcon';
import List from '@/ui/v2/List';
import { ListItem } from '@/ui/v2/ListItem';
import Text from '@/ui/v2/Text';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import DotsVerticalIcon from '@/ui/v2/icons/DotsVerticalIcon';
import PlusIcon from '@/ui/v2/icons/PlusIcon';
import {
GetEnvironmentVariablesDocument,
useGetEnvironmentVariablesQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { Fragment } from 'react';
import toast from 'react-hot-toast';
import { twMerge } from 'tailwind-merge';
@@ -37,9 +37,9 @@ export interface EnvironmentVariableSettingsFormValues {
export default function EnvironmentVariableSettings() {
const { openDialog, openAlertDialog } = useDialog();
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data, loading, error } = useGetEnvironmentVariablesQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -77,7 +77,7 @@ export default function EnvironmentVariableSettings() {
async function handleDeleteVariable({ id }: EnvironmentVariable) {
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
config: {
global: {
environment: availableEnvironmentVariables

View File

@@ -1,21 +1,22 @@
import { useDialog } from '@/components/common/DialogProvider';
import InlineCode from '@/components/common/InlineCode';
import EditJwtSecretForm from '@/components/settings/environmentVariables/EditJwtSecretForm';
import SettingsContainer from '@/components/settings/SettingsContainer';
import EditJwtSecretForm from '@/components/settings/environmentVariables/EditJwtSecretForm';
import { useUI } from '@/context/UIContext';
import useIsPlatform from '@/hooks/common/useIsPlatform';
import { useAppClient } from '@/hooks/useAppClient';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import Divider from '@/ui/v2/Divider';
import IconButton from '@/ui/v2/IconButton';
import EyeIcon from '@/ui/v2/icons/EyeIcon';
import EyeOffIcon from '@/ui/v2/icons/EyeOffIcon';
import List from '@/ui/v2/List';
import { ListItem } from '@/ui/v2/ListItem';
import Text from '@/ui/v2/Text';
import EyeIcon from '@/ui/v2/icons/EyeIcon';
import EyeOffIcon from '@/ui/v2/icons/EyeOffIcon';
import { useGetEnvironmentVariablesQuery } from '@/utils/__generated__/graphql';
import generateAppServiceUrl, {
defaultLocalBackendSlugs,
defaultRemoteBackendSlugs,
@@ -23,7 +24,6 @@ import generateAppServiceUrl, {
import { getHasuraConsoleServiceUrl } from '@/utils/env';
import { generateRemoteAppUrl } from '@/utils/helpers';
import getJwtSecretsWithoutFalsyValues from '@/utils/settings/getJwtSecretsWithoutFalsyValues';
import { useGetEnvironmentVariablesQuery } from '@/utils/__generated__/graphql';
import { Fragment, useState } from 'react';
export default function SystemEnvironmentVariableSettings() {
@@ -32,9 +32,9 @@ export default function SystemEnvironmentVariableSettings() {
const { openDialog } = useDialog();
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data, loading, error } = useGetEnvironmentVariablesQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -101,18 +101,18 @@ export default function SystemEnvironmentVariableSettings() {
const systemEnvironmentVariables = [
{
key: 'NHOST_BACKEND_URL',
value: generateRemoteAppUrl(currentApplication.subdomain),
value: generateRemoteAppUrl(currentProject.subdomain),
},
{ key: 'NHOST_SUBDOMAIN', value: currentApplication.subdomain },
{ key: 'NHOST_REGION', value: currentApplication.region.awsName },
{ key: 'NHOST_SUBDOMAIN', value: currentProject.subdomain },
{ key: 'NHOST_REGION', value: currentProject.region.awsName },
{
key: 'NHOST_HASURA_URL',
value:
process.env.NEXT_PUBLIC_ENV === 'dev' || !isPlatform
? `${getHasuraConsoleServiceUrl()}/console`
: generateAppServiceUrl(
currentApplication?.subdomain,
currentApplication?.region.awsName,
currentProject?.subdomain,
currentProject?.region.awsName,
'hasura',
defaultLocalBackendSlugs,
{ ...defaultRemoteBackendSlugs, hasura: '/console' },

View File

@@ -2,8 +2,11 @@ import Form from '@/components/common/Form';
import InlineCode from '@/components/common/InlineCode';
import SettingsContainer from '@/components/settings/SettingsContainer';
import { useUI } from '@/context/UIContext';
import { useUpdateAppMutation } from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import {
GetAllWorkspacesAndProjectsDocument,
useUpdateApplicationMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { Alert } from '@/ui/Alert';
import Input from '@/ui/v2/Input';
import { discordAnnounce } from '@/utils/discordAnnounce';
@@ -23,14 +26,14 @@ export interface BaseDirectoryFormValues {
export default function BaseDirectorySettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const [updateApp] = useUpdateAppMutation();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateApp] = useUpdateApplicationMutation();
const client = useApolloClient();
const form = useForm<BaseDirectoryFormValues>({
reValidateMode: 'onSubmit',
defaultValues: {
nhostBaseFolder: currentApplication?.nhostBaseFolder,
nhostBaseFolder: currentProject?.nhostBaseFolder,
},
});
@@ -38,14 +41,14 @@ export default function BaseDirectorySettings() {
useEffect(() => {
reset(() => ({
nhostBaseFolder: currentApplication?.nhostBaseFolder,
nhostBaseFolder: currentProject?.nhostBaseFolder,
}));
}, [currentApplication?.nhostBaseFolder, reset]);
}, [currentProject?.nhostBaseFolder, reset]);
const handleBaseFolderChange = async (values: BaseDirectoryFormValues) => {
const updateAppMutation = updateApp({
variables: {
id: currentApplication.id,
appId: currentProject.id,
app: {
...values,
},
@@ -67,7 +70,9 @@ export default function BaseDirectorySettings() {
form.reset(values);
try {
await client.refetchQueries({ include: ['getOneUser'] });
await client.refetchQueries({
include: [GetAllWorkspacesAndProjectsDocument],
});
} catch (error) {
await discordAnnounce(
error.message || 'Error while trying to update application cache',
@@ -98,7 +103,7 @@ export default function BaseDirectorySettings() {
docsLink="https://docs.nhost.io/platform/github-integration#base-directory"
className="grid grid-flow-row lg:grid-cols-5"
>
{currentApplication?.githubRepository ? (
{currentProject?.githubRepository ? (
<Input
{...register('nhostBaseFolder')}
name="nhostBaseFolder"

View File

@@ -1,8 +1,11 @@
import Form from '@/components/common/Form';
import SettingsContainer from '@/components/settings/SettingsContainer';
import { useUI } from '@/context/UIContext';
import { useUpdateAppMutation } from '@/generated/graphql';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import {
GetAllWorkspacesAndProjectsDocument,
useUpdateApplicationMutation,
} from '@/generated/graphql';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { Alert } from '@/ui/Alert';
import Input from '@/ui/v2/Input';
import { discordAnnounce } from '@/utils/discordAnnounce';
@@ -22,15 +25,14 @@ export interface DeploymentBranchFormValues {
export default function DeploymentBranchSettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const [updateApp] = useUpdateAppMutation();
const { currentProject } = useCurrentWorkspaceAndProject();
const [updateApp] = useUpdateApplicationMutation();
const client = useApolloClient();
const form = useForm<DeploymentBranchFormValues>({
reValidateMode: 'onSubmit',
defaultValues: {
repositoryProductionBranch:
currentApplication?.repositoryProductionBranch,
repositoryProductionBranch: currentProject?.repositoryProductionBranch,
},
});
@@ -38,17 +40,16 @@ export default function DeploymentBranchSettings() {
useEffect(() => {
reset(() => ({
repositoryProductionBranch:
currentApplication?.repositoryProductionBranch,
repositoryProductionBranch: currentProject?.repositoryProductionBranch,
}));
}, [currentApplication?.repositoryProductionBranch, reset]);
}, [currentProject?.repositoryProductionBranch, reset]);
const handleDeploymentBranchChange = async (
values: DeploymentBranchFormValues,
) => {
const updateAppMutation = updateApp({
variables: {
id: currentApplication.id,
appId: currentProject.id,
app: {
...values,
},
@@ -70,7 +71,9 @@ export default function DeploymentBranchSettings() {
form.reset(values);
try {
await client.refetchQueries({ include: ['getOneUser'] });
await client.refetchQueries({
include: [GetAllWorkspacesAndProjectsDocument],
});
} catch (error) {
await discordAnnounce(
error.message || 'Error while trying to update application cache',
@@ -93,7 +96,7 @@ export default function DeploymentBranchSettings() {
docsLink="https://docs.nhost.io/platform/github-integration#deployment-branch"
className="grid grid-flow-row lg:grid-cols-5"
>
{currentApplication?.githubRepository ? (
{currentProject?.githubRepository ? (
<Input
{...register('repositoryProductionBranch')}
name="repositoryProductionBranch"

View File

@@ -5,15 +5,15 @@ import type {
import BasePermissionVariableForm, {
basePermissionVariableValidationSchema,
} from '@/components/settings/permissions/BasePermissionVariableForm';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import {
GetRolesPermissionsDocument,
useGetRolesPermissionsQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { yupResolver } from '@hookform/resolvers/yup';
import { FormProvider, useForm } from 'react-hook-form';
import toast from 'react-hot-toast';
@@ -30,10 +30,10 @@ export default function CreatePermissionVariableForm({
onSubmit,
...props
}: CreatePermissionVariableFormProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data, error, loading } = useGetRolesPermissionsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -89,7 +89,7 @@ export default function CreatePermissionVariableForm({
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
config: {
auth: {
session: {

View File

@@ -5,16 +5,16 @@ import type {
import BasePermissionVariableForm, {
basePermissionVariableValidationSchema,
} from '@/components/settings/permissions/BasePermissionVariableForm';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { PermissionVariable } from '@/types/application';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import {
GetRolesPermissionsDocument,
useGetRolesPermissionsQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { yupResolver } from '@hookform/resolvers/yup';
import { FormProvider, useForm } from 'react-hook-form';
import toast from 'react-hot-toast';
@@ -36,10 +36,10 @@ export default function EditPermissionVariableForm({
onSubmit,
...props
}: EditPermissionVariableFormProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data, error, loading } = useGetRolesPermissionsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -116,7 +116,7 @@ export default function EditPermissionVariableForm({
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
config: {
auth: {
session: {

View File

@@ -1,9 +1,9 @@
import { useDialog } from '@/components/common/DialogProvider';
import SettingsContainer from '@/components/settings/SettingsContainer';
import CreatePermissionVariableForm from '@/components/settings/permissions/CreatePermissionVariableForm';
import EditPermissionVariableForm from '@/components/settings/permissions/EditPermissionVariableForm';
import SettingsContainer from '@/components/settings/SettingsContainer';
import { useUI } from '@/context/UIContext';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { PermissionVariable } from '@/types/application';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Box from '@/ui/v2/Box';
@@ -11,32 +11,32 @@ import Button from '@/ui/v2/Button';
import Divider from '@/ui/v2/Divider';
import { Dropdown } from '@/ui/v2/Dropdown';
import IconButton from '@/ui/v2/IconButton';
import DotsVerticalIcon from '@/ui/v2/icons/DotsVerticalIcon';
import LockIcon from '@/ui/v2/icons/LockIcon';
import PlusIcon from '@/ui/v2/icons/PlusIcon';
import List from '@/ui/v2/List';
import { ListItem } from '@/ui/v2/ListItem';
import Text from '@/ui/v2/Text';
import Tooltip from '@/ui/v2/Tooltip';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import DotsVerticalIcon from '@/ui/v2/icons/DotsVerticalIcon';
import LockIcon from '@/ui/v2/icons/LockIcon';
import PlusIcon from '@/ui/v2/icons/PlusIcon';
import {
GetRolesPermissionsDocument,
useGetRolesPermissionsQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getAllPermissionVariables from '@/utils/settings/getAllPermissionVariables';
import getServerError from '@/utils/settings/getServerError';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { Fragment } from 'react';
import toast from 'react-hot-toast';
import { twMerge } from 'tailwind-merge';
export default function PermissionVariableSettings() {
const { maintenanceActive } = useUI();
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { openDialog, openAlertDialog } = useDialog();
const { data, loading, error } = useGetRolesPermissionsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -60,7 +60,7 @@ export default function PermissionVariableSettings() {
async function handleDeleteVariable({ id }: PermissionVariable) {
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
config: {
auth: {
session: {

View File

@@ -0,0 +1,106 @@
import { prettifyMemory } from '@/features/settings/resources/utils/prettifyMemory';
import { prettifyVCPU } from '@/features/settings/resources/utils/prettifyVCPU';
import useProPlan from '@/hooks/common/useProPlan';
import { Alert } from '@/ui/Alert';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import Divider from '@/ui/v2/Divider';
import Text from '@/ui/v2/Text';
import {
RESOURCE_VCPU_MULTIPLIER,
RESOURCE_VCPU_PRICE,
} from '@/utils/CONSTANTS';
export interface ResourcesConfirmationDialogProps {
/**
* Price of the new plan.
*/
updatedResources: {
vcpu: number;
memory: number;
};
/**
* Function to be called when the user clicks the cancel button.
*/
onCancel: () => void;
/**
* Function to be called when the user clicks the confirm button.
*/
onSubmit: () => Promise<void>;
}
export default function ResourcesConfirmationDialog({
updatedResources,
onCancel,
onSubmit,
}: ResourcesConfirmationDialogProps) {
const { data: proPlan, loading, error } = useProPlan();
const updatedPrice =
RESOURCE_VCPU_PRICE * (updatedResources.vcpu / RESOURCE_VCPU_MULTIPLIER);
if (!loading && !proPlan) {
return (
<Alert severity="error">
Couldn&apos;t load the plan for this project. Please try again.
</Alert>
);
}
if (error) {
throw error;
}
return (
<div className="grid grid-flow-row gap-6 px-6 pb-6">
{updatedResources.vcpu > 0 ? (
<Text className="text-center">
Please allow some time for the selected resources to take effect.
</Text>
) : (
<Text className="text-center">
By confirming this you will go back to the original amount of
resources of the {proPlan.name} plan.
</Text>
)}
<Box className="grid grid-flow-row gap-4">
<Box className="grid grid-flow-col justify-between gap-2">
<Text className="font-medium">{proPlan.name} Plan</Text>
<Text>${proPlan.price.toFixed(2)}/mo</Text>
</Box>
<Box className="grid grid-flow-col items-center justify-between gap-2">
<Box className="grid grid-flow-row gap-0.5">
<Text className="font-medium">Dedicated Resources</Text>
<Text className="text-xs" color="secondary">
{prettifyVCPU(updatedResources.vcpu)} vCPUs +{' '}
{prettifyMemory(updatedResources.memory)} of Memory
</Text>
</Box>
<Text>${updatedPrice.toFixed(2)}/mo</Text>
</Box>
<Divider />
<Box className="grid grid-flow-col justify-between gap-2">
<Text className="font-medium">Total</Text>
<Text>${(updatedPrice + proPlan.price).toFixed(2)}/mo</Text>
</Box>
</Box>
<Box className="grid grid-flow-row gap-2">
<Button
color={updatedResources.vcpu > 0 ? 'primary' : 'error'}
onClick={onSubmit}
autoFocus
>
Confirm
</Button>
<Button variant="borderless" color="secondary" onClick={onCancel}>
Cancel
</Button>
</Box>
</div>
);
}

View File

@@ -0,0 +1,2 @@
export * from './ResourcesConfirmationDialog';
export { default } from './ResourcesConfirmationDialog';

View File

@@ -0,0 +1,331 @@
import {
getProPlanOnlyQuery,
getWorkspaceAndProjectQuery,
} from '@/tests/msw/mocks/graphql/plansQuery';
import {
resourcesAvailableQuery,
resourcesUnavailableQuery,
resourcesUpdatedQuery,
} from '@/tests/msw/mocks/graphql/resourceSettingsQuery';
import updateConfigMutation from '@/tests/msw/mocks/graphql/updateConfigMutation';
import {
fireEvent,
render,
screen,
waitFor,
waitForElementToBeRemoved,
within,
} from '@/tests/testUtils';
import {
RESOURCE_MEMORY_MULTIPLIER,
RESOURCE_VCPU_MULTIPLIER,
} from '@/utils/CONSTANTS';
import userEvent from '@testing-library/user-event';
import { setupServer } from 'msw/node';
import { test, vi } from 'vitest';
import ResourcesForm from './ResourcesForm';
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
vi.mock('next/router', () => ({
useRouter: vi.fn().mockReturnValue({
basePath: '',
pathname: '/test-workspace/test-application',
route: '/[workspaceSlug]/[appSlug]',
asPath: '/test-workspace/test-application',
isLocaleDomain: false,
isReady: true,
isPreview: false,
query: {
workspaceSlug: 'test-workspace',
appSlug: 'test-application',
},
push: vi.fn(),
replace: vi.fn(),
reload: vi.fn(),
back: vi.fn(),
prefetch: vi.fn(),
beforePopState: vi.fn(),
events: {
on: vi.fn(),
off: vi.fn(),
emit: vi.fn(),
},
isFallback: false,
}),
}));
const server = setupServer(
resourcesAvailableQuery,
getProPlanOnlyQuery,
getWorkspaceAndProjectQuery,
);
beforeAll(() => {
process.env.NEXT_PUBLIC_NHOST_PLATFORM = 'true';
process.env.NEXT_PUBLIC_ENV = 'production';
server.listen();
});
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
// Note: Workaround based on https://github.com/testing-library/user-event/issues/871#issuecomment-1059317998
function changeSliderValue(slider: HTMLElement, value: number) {
fireEvent.input(slider, { target: { value } });
fireEvent.change(slider, { target: { value } });
}
test('should show an empty state message that the feature must be enabled if no data is available', async () => {
server.use(resourcesUnavailableQuery);
render(<ResourcesForm />);
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
expect(screen.getByText(/enable this feature/i)).toBeInTheDocument();
});
test('should show the sliders if the switch is enabled', async () => {
server.use(resourcesUnavailableQuery);
const user = userEvent.setup();
render(<ResourcesForm />);
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
expect(screen.getByText(/enable this feature/i)).toBeInTheDocument();
await user.click(screen.getByRole('checkbox'));
expect(screen.queryByText(/enable this feature/i)).not.toBeInTheDocument();
expect(screen.getAllByRole('slider')).toHaveLength(9);
});
test('should not show an empty state message if there is data available', async () => {
render(<ResourcesForm />);
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
await waitFor(() =>
expect(
screen.queryByRole('slider', { name: /total available vcpu/i }),
).toBeInTheDocument(),
);
expect(screen.queryByText(/enable this feature/i)).not.toBeInTheDocument();
expect(screen.getAllByRole('slider')).toHaveLength(9);
expect(screen.getByText(/^vcpus:/i)).toHaveTextContent(/vcpus: 8/i);
expect(screen.getByText(/^memory:/i)).toHaveTextContent(/memory: 16384 mib/i);
});
test('should show a warning message if not all the resources are allocated', async () => {
render(<ResourcesForm />);
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
changeSliderValue(
screen.getByRole('slider', {
name: /total available vcpu/i,
}),
9 * RESOURCE_VCPU_MULTIPLIER,
);
expect(screen.getByText(/^vcpus:/i)).toHaveTextContent(/vcpus: 9/i);
expect(screen.getByText(/^memory:/i)).toHaveTextContent(/memory: 18432 mib/i);
expect(
screen.getByText(/you now have 1 vcpus and 2048 mib of memory unused./i),
).toBeInTheDocument();
});
test('should update the price when the top slider is changed', async () => {
render(<ResourcesForm />);
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
expect(screen.queryByText(/\$200\.00\/mo/i)).not.toBeInTheDocument();
changeSliderValue(
screen.getByRole('slider', {
name: /total available vcpu/i,
}),
9 * RESOURCE_VCPU_MULTIPLIER,
);
expect(screen.getByText(/\$425\.00\/mo/i)).toBeInTheDocument();
// we display the final price in two places
expect(screen.getAllByText(/\$475\.00\/mo/i)).toHaveLength(2);
});
test('should show a validation error when the form is submitted when not everything is allocated', async () => {
const user = userEvent.setup();
render(<ResourcesForm />);
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
expect(screen.getByRole('button', { name: /save/i })).toBeDisabled();
changeSliderValue(
screen.getByRole('slider', {
name: /total available vcpu/i,
}),
9 * RESOURCE_VCPU_MULTIPLIER,
);
await user.click(screen.getByRole('button', { name: /save/i }));
expect(
screen.getAllByText(/you now have 1 vcpus and 2048 mib of memory unused./i),
).toHaveLength(2);
});
test('should show a confirmation dialog when the form is submitted', async () => {
server.use(updateConfigMutation);
const user = userEvent.setup();
render(<ResourcesForm />);
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
await waitFor(() =>
expect(
screen.queryByRole('slider', { name: /total available vcpu/i }),
).toBeInTheDocument(),
);
changeSliderValue(
screen.getByRole('slider', {
name: /total available vcpu/i,
}),
9 * RESOURCE_VCPU_MULTIPLIER,
);
changeSliderValue(
screen.getByRole('slider', { name: /database vcpu/i }),
2.25 * RESOURCE_VCPU_MULTIPLIER,
);
changeSliderValue(
screen.getByRole('slider', { name: /hasura graphql vcpu/i }),
2.25 * RESOURCE_VCPU_MULTIPLIER,
);
changeSliderValue(
screen.getByRole('slider', { name: /auth vcpu/i }),
2.25 * RESOURCE_VCPU_MULTIPLIER,
);
changeSliderValue(
screen.getByRole('slider', { name: /storage vcpu/i }),
2.25 * RESOURCE_VCPU_MULTIPLIER,
);
changeSliderValue(
screen.getByRole('slider', { name: /database memory/i }),
4.5 * RESOURCE_MEMORY_MULTIPLIER,
);
changeSliderValue(
screen.getByRole('slider', { name: /hasura graphql memory/i }),
4.5 * RESOURCE_MEMORY_MULTIPLIER,
);
changeSliderValue(
screen.getByRole('slider', { name: /auth memory/i }),
4.5 * RESOURCE_MEMORY_MULTIPLIER,
);
changeSliderValue(
screen.getByRole('slider', { name: /storage memory/i }),
4.5 * RESOURCE_MEMORY_MULTIPLIER,
);
await user.click(screen.getByRole('button', { name: /save/i }));
expect(await screen.findByRole('dialog')).toBeInTheDocument();
expect(
within(screen.getByRole('dialog')).getByRole('heading', {
name: /confirm dedicated resources/i,
}),
).toBeInTheDocument();
expect(
within(screen.getByRole('dialog')).getByText(
/9 vcpus \+ 18432 mib of memory/i,
{ exact: true },
),
).toBeInTheDocument();
expect(
within(screen.getByRole('dialog')).getByText(/\$475\.00\/mo/i, {
exact: true,
}),
).toBeInTheDocument();
// we need to mock the query again because the mutation updated the resources
// and we need to return the updated values
server.use(resourcesUpdatedQuery);
await user.click(screen.getByRole('button', { name: /confirm/i }));
await waitForElementToBeRemoved(() => screen.getByRole('dialog'));
expect(
await screen.findByText(/resources have been updated successfully./i),
).toBeInTheDocument();
expect(
screen.getByRole('slider', { name: /total available vcpu/i }),
).toHaveValue((9 * RESOURCE_VCPU_MULTIPLIER).toString());
expect(screen.getByRole('button', { name: /save/i })).toBeDisabled();
});
test('should display a red button when custom resources are disabled', async () => {
const user = userEvent.setup();
render(<ResourcesForm />);
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
await user.click(screen.getByRole('checkbox'));
expect(screen.getByText(/enable this feature/i)).toBeInTheDocument();
expect(screen.getByText(/total cost:/i)).toHaveTextContent(
/total cost: \$25\.00\/mo/i,
);
await user.click(screen.getByRole('button', { name: /save/i }));
expect(await screen.findByRole('dialog')).toBeInTheDocument();
expect(
screen.getByRole('heading', { name: /disable dedicated resources/i }),
).toBeInTheDocument();
expect(screen.getByRole('button', { name: /confirm/i })).toHaveStyle({
'background-color': '#f13154',
});
});
test('should hide the footer when custom resource allocation is disabled', async () => {
server.use(updateConfigMutation);
const user = userEvent.setup();
render(<ResourcesForm />);
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
await user.click(screen.getByRole('checkbox'));
await user.click(screen.getByRole('button', { name: /save/i }));
expect(await screen.findByRole('dialog')).toBeInTheDocument();
server.use(resourcesUnavailableQuery);
await user.click(screen.getByRole('button', { name: /confirm/i }));
await waitForElementToBeRemoved(() => screen.getByRole('dialog'));
expect(screen.queryByText(/total cost:/i)).not.toBeInTheDocument();
});

View File

@@ -0,0 +1,382 @@
import { useDialog } from '@/components/common/DialogProvider';
import Form from '@/components/common/Form';
import SettingsContainer from '@/components/settings/SettingsContainer';
import ResourcesConfirmationDialog from '@/components/settings/resources/ResourcesConfirmationDialog';
import ServiceResourcesFormFragment from '@/components/settings/resources/ServiceResourcesFormFragment';
import TotalResourcesFormFragment from '@/components/settings/resources/TotalResourcesFormFragment';
import { prettifyMemory } from '@/features/settings/resources/utils/prettifyMemory';
import { prettifyVCPU } from '@/features/settings/resources/utils/prettifyVCPU';
import type { ResourceSettingsFormValues } from '@/features/settings/resources/utils/resourceSettingsValidationSchema';
import { resourceSettingsValidationSchema } from '@/features/settings/resources/utils/resourceSettingsValidationSchema';
import useProPlan from '@/hooks/common/useProPlan';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import { Alert } from '@/ui/Alert';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import Box from '@/ui/v2/Box';
import Button from '@/ui/v2/Button';
import Divider from '@/ui/v2/Divider';
import Text from '@/ui/v2/Text';
import {
RESOURCE_VCPU_MULTIPLIER,
RESOURCE_VCPU_PRICE,
} from '@/utils/CONSTANTS';
import type { GetResourcesQuery } from '@/utils/__generated__/graphql';
import {
GetResourcesDocument,
useGetResourcesQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getServerError from '@/utils/settings/getServerError';
import getUnallocatedResources from '@/utils/settings/getUnallocatedResources';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { yupResolver } from '@hookform/resolvers/yup';
import { useState } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { toast } from 'react-hot-toast';
import { twMerge } from 'tailwind-merge';
function getInitialServiceResources(
data: GetResourcesQuery,
service: Exclude<keyof GetResourcesQuery['config'], '__typename'>,
) {
const { cpu, memory } = data?.config?.[service]?.resources?.compute || {};
return {
vcpu: cpu || 0,
memory: memory || 0,
};
}
export default function ResourcesForm() {
const [validationError, setValidationError] = useState<Error | null>(null);
const { openDialog, closeDialog } = useDialog();
const { currentProject } = useCurrentWorkspaceAndProject();
const {
data,
loading,
error: resourcesError,
} = useGetResourcesQuery({
variables: {
appId: currentProject?.id,
},
});
const {
data: proPlan,
loading: proPlanLoading,
error: proPlanError,
} = useProPlan();
const [updateConfig] = useUpdateConfigMutation({
refetchQueries: [GetResourcesDocument],
});
const initialDatabaseResources = getInitialServiceResources(data, 'postgres');
const initialHasuraResources = getInitialServiceResources(data, 'hasura');
const initialAuthResources = getInitialServiceResources(data, 'auth');
const initialStorageResources = getInitialServiceResources(data, 'storage');
const totalInitialVCPU =
initialDatabaseResources.vcpu +
initialHasuraResources.vcpu +
initialAuthResources.vcpu +
initialStorageResources.vcpu;
const totalInitialMemory =
initialDatabaseResources.memory +
initialHasuraResources.memory +
initialAuthResources.memory +
initialStorageResources.memory;
const form = useForm<ResourceSettingsFormValues>({
values: {
enabled: totalInitialVCPU > 0 && totalInitialMemory > 0,
totalAvailableVCPU: totalInitialVCPU || 2000,
totalAvailableMemory: totalInitialMemory || 4096,
hasuraVCPU: initialHasuraResources.vcpu || 500,
hasuraMemory: initialHasuraResources.memory || 1536,
databaseVCPU: initialDatabaseResources.vcpu || 1000,
databaseMemory: initialDatabaseResources.memory || 2048,
authVCPU: initialAuthResources.vcpu || 250,
authMemory: initialAuthResources.memory || 256,
storageVCPU: initialStorageResources.vcpu || 250,
storageMemory: initialStorageResources.memory || 256,
},
resolver: yupResolver(resourceSettingsValidationSchema),
});
if (!proPlan && !proPlanLoading) {
return (
<Alert severity="error">
Couldn&apos;t load the plan for this project. Please try again.
</Alert>
);
}
if (loading || proPlanLoading) {
return (
<ActivityIndicator
label="Loading resource settings..."
delay={1000}
className="mx-auto"
/>
);
}
const { watch, formState } = form;
const isDirty = Object.keys(formState.dirtyFields).length > 0;
const enabled = watch('enabled');
const totalAvailableVCPU = enabled ? watch('totalAvailableVCPU') : 0;
const initialPrice =
RESOURCE_VCPU_PRICE * (totalInitialVCPU / RESOURCE_VCPU_MULTIPLIER) +
proPlan.price;
const updatedPrice =
RESOURCE_VCPU_PRICE * (totalAvailableVCPU / RESOURCE_VCPU_MULTIPLIER) +
proPlan.price;
async function handleSubmit(formValues: ResourceSettingsFormValues) {
const updateConfigPromise = updateConfig({
variables: {
appId: currentProject?.id,
config: {
postgres: {
resources: enabled
? {
compute: {
cpu: formValues.databaseVCPU,
memory: formValues.databaseMemory,
},
replicas: 1,
}
: null,
},
hasura: {
resources: enabled
? {
compute: {
cpu: formValues.hasuraVCPU,
memory: formValues.hasuraMemory,
},
replicas: 1,
}
: null,
},
auth: {
resources: enabled
? {
compute: {
cpu: formValues.authVCPU,
memory: formValues.authMemory,
},
replicas: 1,
}
: null,
},
storage: {
resources: enabled
? {
compute: {
cpu: formValues.storageVCPU,
memory: formValues.storageMemory,
},
replicas: 1,
}
: null,
},
},
},
});
try {
await toast.promise(
updateConfigPromise,
{
loading: 'Updating resources...',
success: 'Resources have been updated successfully.',
error: getServerError(
'An error occurred while updating resources. Please try again.',
),
},
getToastStyleProps(),
);
if (!formValues.enabled) {
form.reset({
enabled: false,
totalAvailableVCPU: 2000,
totalAvailableMemory: 4096,
hasuraVCPU: 500,
hasuraMemory: 1536,
databaseVCPU: 1000,
databaseMemory: 2048,
authVCPU: 250,
authMemory: 256,
storageVCPU: 250,
storageMemory: 256,
});
} else {
form.reset(null, { keepValues: true, keepDirty: false });
}
} catch {
// Note: The error has already been handled by the toast.
}
}
function handleConfirm(formValues: ResourceSettingsFormValues) {
setValidationError(null);
const { vcpu: unallocatedVCPU, memory: unallocatedMemory } =
getUnallocatedResources(formValues);
const hasUnusedResources = unallocatedVCPU > 0 || unallocatedMemory > 0;
if (hasUnusedResources) {
const unusedResourceMessage = [
unallocatedVCPU > 0 ? `${prettifyVCPU(unallocatedVCPU)} vCPUs` : '',
unallocatedMemory > 0
? `${prettifyMemory(unallocatedMemory)} of Memory`
: '',
]
.filter(Boolean)
.join(' and ');
setValidationError(
new Error(
`You now have ${unusedResourceMessage} unused. Allocate it to any of the services before saving.`,
),
);
return;
}
openDialog({
title: enabled
? 'Confirm Dedicated Resources'
: 'Disable Dedicated Resources',
component: (
<ResourcesConfirmationDialog
updatedResources={{
vcpu: enabled ? formValues.totalAvailableVCPU : 0,
memory: enabled ? formValues.totalAvailableMemory : 0,
}}
onCancel={closeDialog}
onSubmit={async () => {
await handleSubmit(formValues);
}}
/>
),
props: {
titleProps: { className: 'justify-center pb-1' },
},
});
}
if (resourcesError || proPlanError) {
throw resourcesError || proPlanError;
}
return (
<FormProvider {...form}>
<Form onSubmit={handleConfirm}>
<SettingsContainer
title="Compute Resources"
description="See how much compute you have available and customise allocation on this page."
className="gap-0 px-0"
showSwitch
switchId="enabled"
slotProps={{
submitButton: {
disabled: !enabled || !isDirty,
loading: formState.isSubmitting,
},
// Note: We need a custom footer because of the pricing
// information
footer: { className: 'hidden', 'aria-hidden': true },
}}
>
{enabled ? (
<>
<TotalResourcesFormFragment initialPrice={initialPrice} />
<Divider />
<ServiceResourcesFormFragment
title="PostgreSQL Database"
description="Manage how much compute you need for the PostgreSQL Database."
cpuKey="databaseVCPU"
memoryKey="databaseMemory"
/>
<Divider />
<ServiceResourcesFormFragment
title="Hasura GraphQL"
description="Manage how much compute you need for the Hasura GraphQL API."
cpuKey="hasuraVCPU"
memoryKey="hasuraMemory"
/>
<Divider />
<ServiceResourcesFormFragment
title="Auth"
description="Manage how much compute you need for Auth."
cpuKey="authVCPU"
memoryKey="authMemory"
/>
<Divider />
<ServiceResourcesFormFragment
title="Storage"
description="Manage how much compute you need for Storage."
cpuKey="storageVCPU"
memoryKey="storageMemory"
/>
{validationError && (
<Box className="px-4 pb-4">
<Alert
severity="error"
className="flex flex-col gap-2 text-left"
>
<strong>
Please use all the available vCPUs and Memory
</strong>
<p>{validationError.message}</p>
</Alert>
</Box>
)}
</>
) : (
<Box className={twMerge('px-4', (enabled || isDirty) && 'pb-4')}>
<Alert className="text-left">
Enable this feature to access custom resource allocation for
your services.
</Alert>
</Box>
)}
{(enabled || isDirty) && (
<Box className="flex flex-row items-center justify-between border-t px-4 pt-4">
<span />
<Box className="flex flex-row items-center gap-4">
<Text>
Total cost:{' '}
<span className="font-medium">
${updatedPrice.toFixed(2)}/mo
</span>
</Text>
<Button
type="submit"
variant={isDirty ? 'contained' : 'outlined'}
color={isDirty ? 'primary' : 'secondary'}
disabled={!isDirty}
>
Save
</Button>
</Box>
</Box>
)}
</SettingsContainer>
</Form>
</FormProvider>
);
}

View File

@@ -0,0 +1 @@
export { default } from './ResourcesForm';

View File

@@ -0,0 +1,172 @@
import { prettifyMemory } from '@/features/settings/resources/utils/prettifyMemory';
import { prettifyVCPU } from '@/features/settings/resources/utils/prettifyVCPU';
import type { ResourceSettingsFormValues } from '@/features/settings/resources/utils/resourceSettingsValidationSchema';
import {
MAX_SERVICE_MEMORY,
MAX_SERVICE_VCPU,
MIN_SERVICE_MEMORY,
MIN_SERVICE_VCPU,
} from '@/features/settings/resources/utils/resourceSettingsValidationSchema';
import Box from '@/ui/v2/Box';
import Slider from '@/ui/v2/Slider';
import Text from '@/ui/v2/Text';
import { RESOURCE_MEMORY_STEP, RESOURCE_VCPU_STEP } from '@/utils/CONSTANTS';
import { useFormContext, useWatch } from 'react-hook-form';
export interface ServiceResourcesFormFragmentProps {
/**
* The title of the form fragment.
*/
title: string;
/**
* The description of the form fragment.
*/
description: string;
/**
* Form field name for CPU.
*/
cpuKey: Exclude<
keyof ResourceSettingsFormValues,
'enabled' | 'totalAvailableVCPU' | 'totalAvailableMemory'
>;
/**
* Form field name for Memory.
*/
memoryKey: Exclude<
keyof ResourceSettingsFormValues,
'enabled' | 'totalAvailableVCPU' | 'totalAvailableMemory'
>;
}
export default function ServiceResourcesFormFragment({
title,
description,
cpuKey,
memoryKey,
}: ServiceResourcesFormFragmentProps) {
const { setValue } = useFormContext<ResourceSettingsFormValues>();
const formValues = useWatch<ResourceSettingsFormValues>();
// Total allocated CPU for all resources
const totalAllocatedCPU = Object.keys(formValues)
.filter((key) => key.endsWith('CPU') && key !== 'totalAvailableVCPU')
.reduce((acc, key) => acc + formValues[key], 0);
// Total allocated memory for all resources
const totalAllocatedMemory = Object.keys(formValues)
.filter((key) => key.endsWith('Memory') && key !== 'totalAvailableMemory')
.reduce((acc, key) => acc + formValues[key], 0);
const remainingCPU = formValues.totalAvailableVCPU - totalAllocatedCPU;
const allowedCPU = remainingCPU + formValues[cpuKey];
const remainingMemory =
formValues.totalAvailableMemory - totalAllocatedMemory;
const allowedMemory = remainingMemory + formValues[memoryKey];
function handleCPUChange(value: string) {
const updatedCPU = parseFloat(value);
const exceedsAvailableCPU =
updatedCPU + (totalAllocatedCPU - formValues[cpuKey]) >
formValues.totalAvailableVCPU;
if (
Number.isNaN(updatedCPU) ||
exceedsAvailableCPU ||
updatedCPU < MIN_SERVICE_VCPU
) {
return;
}
setValue(cpuKey, updatedCPU, { shouldDirty: true });
}
function handleMemoryChange(value: string) {
const updatedMemory = parseFloat(value);
const exceedsAvailableMemory =
updatedMemory + (totalAllocatedMemory - formValues[memoryKey]) >
formValues.totalAvailableMemory;
if (
Number.isNaN(updatedMemory) ||
exceedsAvailableMemory ||
updatedMemory < MIN_SERVICE_MEMORY
) {
return;
}
setValue(memoryKey, updatedMemory, { shouldDirty: true });
}
return (
<Box className="grid grid-flow-row gap-4 p-4">
<Box className="grid grid-flow-row gap-2">
<Text variant="h3" className="font-semibold">
{title}
</Text>
<Text color="secondary">{description}</Text>
</Box>
<Box className="grid grid-flow-row gap-2">
<Box className="grid grid-flow-col items-center justify-between gap-2">
<Text>
Allocated vCPUs:{' '}
<span className="font-medium">
{prettifyVCPU(formValues[cpuKey])}
</span>
</Text>
{remainingCPU > 0 && formValues[cpuKey] < MAX_SERVICE_VCPU && (
<Text className="text-sm">
<span className="font-medium">
{prettifyVCPU(remainingCPU)} vCPUs
</span>{' '}
remaining
</Text>
)}
</Box>
<Slider
value={formValues[cpuKey]}
onChange={(_event, value) => handleCPUChange(value.toString())}
max={MAX_SERVICE_VCPU}
step={RESOURCE_VCPU_STEP}
allowed={allowedCPU}
aria-label={`${title} vCPU`}
marks
/>
</Box>
<Box className="grid grid-flow-row gap-2">
<Box className="grid grid-flow-col items-center justify-between gap-2">
<Text>
Allocated Memory:{' '}
<span className="font-medium">
{prettifyMemory(formValues[memoryKey])}
</span>
</Text>
{remainingMemory > 0 && formValues[memoryKey] < MAX_SERVICE_MEMORY && (
<Text className="text-sm">
<span className="font-medium">
{prettifyMemory(remainingMemory)} of Memory
</span>{' '}
remaining
</Text>
)}
</Box>
<Slider
value={formValues[memoryKey]}
onChange={(_event, value) => handleMemoryChange(value.toString())}
max={MAX_SERVICE_MEMORY}
step={RESOURCE_MEMORY_STEP}
allowed={allowedMemory}
aria-label={`${title} Memory`}
marks
/>
</Box>
</Box>
);
}

View File

@@ -0,0 +1,2 @@
export * from './ServiceResourcesFormFragment';
export { default } from './ServiceResourcesFormFragment';

View File

@@ -0,0 +1,184 @@
import { prettifyMemory } from '@/features/settings/resources/utils/prettifyMemory';
import { prettifyVCPU } from '@/features/settings/resources/utils/prettifyVCPU';
import type { ResourceSettingsFormValues } from '@/features/settings/resources/utils/resourceSettingsValidationSchema';
import {
MAX_TOTAL_VCPU,
MIN_TOTAL_MEMORY,
MIN_TOTAL_VCPU,
} from '@/features/settings/resources/utils/resourceSettingsValidationSchema';
import useProPlan from '@/hooks/common/useProPlan';
import { Alert } from '@/ui/Alert';
import Box from '@/ui/v2/Box';
import Slider, { sliderClasses } from '@/ui/v2/Slider';
import Text from '@/ui/v2/Text';
import ArrowRightIcon from '@/ui/v2/icons/ArrowRightIcon';
import {
RESOURCE_MEMORY_MULTIPLIER,
RESOURCE_VCPU_MEMORY_RATIO,
RESOURCE_VCPU_MULTIPLIER,
RESOURCE_VCPU_PRICE,
RESOURCE_VCPU_STEP,
} from '@/utils/CONSTANTS';
import getUnallocatedResources from '@/utils/settings/getUnallocatedResources';
import { alpha, styled } from '@mui/material';
import { useFormContext, useWatch } from 'react-hook-form';
export interface TotalResourcesFormFragmentProps {
/**
* The initial price of the resources.
*/
initialPrice: number;
}
const StyledAvailableCpuSlider = styled(Slider)(({ theme }) => ({
[`& .${sliderClasses.rail}`]: {
backgroundColor: alpha(theme.palette.primary.main, 0.15),
},
}));
export default function TotalResourcesFormFragment({
initialPrice,
}: TotalResourcesFormFragmentProps) {
const {
data: proPlan,
error: proPlanError,
loading: proPlanLoading,
} = useProPlan();
const { setValue } = useFormContext<ResourceSettingsFormValues>();
const formValues = useWatch<ResourceSettingsFormValues>();
if (!proPlan && !proPlanLoading) {
return (
<Alert severity="error">
Couldn&apos;t load the plan for this projectee. Please try again.
</Alert>
);
}
if (proPlanError) {
throw proPlanError;
}
const allocatedCPU =
formValues.databaseVCPU +
formValues.hasuraVCPU +
formValues.authVCPU +
formValues.storageVCPU;
const allocatedMemory =
formValues.databaseMemory +
formValues.hasuraMemory +
formValues.authMemory +
formValues.storageMemory;
const updatedPrice =
RESOURCE_VCPU_PRICE *
(formValues.totalAvailableVCPU / RESOURCE_VCPU_MULTIPLIER) +
proPlan.price;
const { vcpu: unallocatedVCPU, memory: unallocatedMemory } =
getUnallocatedResources(formValues);
const hasUnusedResources = unallocatedVCPU > 0 || unallocatedMemory > 0;
const unusedResourceMessage = [
unallocatedVCPU > 0 ? `${prettifyVCPU(unallocatedVCPU)} vCPUs` : '',
unallocatedMemory > 0
? `${prettifyMemory(unallocatedMemory)} of Memory`
: '',
]
.filter(Boolean)
.join(' and ');
function handleCPUChange(value: string) {
const updatedCPU = parseFloat(value);
const updatedMemory =
(updatedCPU / RESOURCE_VCPU_MULTIPLIER) *
RESOURCE_VCPU_MEMORY_RATIO *
RESOURCE_MEMORY_MULTIPLIER;
if (
Number.isNaN(updatedCPU) ||
updatedCPU < Math.max(MIN_TOTAL_VCPU, allocatedCPU) ||
updatedMemory < Math.max(MIN_TOTAL_MEMORY, allocatedMemory)
) {
return;
}
setValue('totalAvailableVCPU', updatedCPU, { shouldDirty: true });
setValue('totalAvailableMemory', updatedMemory, { shouldDirty: true });
}
return (
<Box className="px-4 pb-4">
<Box className="rounded-md border">
<Box className="flex flex-col gap-4 bg-transparent p-4">
<Box className="flex flex-row items-center justify-between gap-4">
<Text color="secondary">
Total available compute for your project:
</Text>
{initialPrice !== updatedPrice && (
<Text className="flex flex-row items-center justify-end gap-2">
<Text component="span" color="secondary">
${initialPrice.toFixed(2)}/mo
</Text>
<ArrowRightIcon />
<Text component="span" className="font-medium">
${updatedPrice.toFixed(2)}/mo
</Text>
</Text>
)}
</Box>
<Box className="flex flex-row items-center justify-start gap-4">
<Text color="secondary">
vCPUs:{' '}
<Text component="span" color="primary" className="font-medium">
{prettifyVCPU(formValues.totalAvailableVCPU)}
</Text>
</Text>
<Text color="secondary">
Memory:{' '}
<Text component="span" color="primary" className="font-medium">
{prettifyMemory(formValues.totalAvailableMemory)}
</Text>
</Text>
</Box>
<StyledAvailableCpuSlider
value={formValues.totalAvailableVCPU}
onChange={(_event, value) => handleCPUChange(value.toString())}
max={MAX_TOTAL_VCPU}
step={RESOURCE_VCPU_STEP}
aria-label="Total Available vCPU"
/>
</Box>
<Alert
severity={hasUnusedResources ? 'warning' : 'info'}
className="grid grid-flow-row gap-2 rounded-t-none rounded-b-[5px] text-left"
>
{hasUnusedResources ? (
<>
<strong>Please use all the available vCPUs and Memory</strong>
<p>
You now have {unusedResourceMessage} unused. Allocate it to any
of the services before saving.
</p>
</>
) : (
<>
<strong>You&apos;re All Set</strong>
<p>
You have successfully allocated all the available vCPUs and
Memory.
</p>
</>
)}
</Alert>
</Box>
</Box>
);
}

View File

@@ -0,0 +1 @@
export { default } from './TotalResourcesFormFragment';

View File

@@ -5,16 +5,16 @@ import type {
import BaseRoleForm, {
baseRoleFormValidationSchema,
} from '@/components/settings/roles/BaseRoleForm';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import getServerError from '@/utils/settings/getServerError';
import getUserRoles from '@/utils/settings/getUserRoles';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import {
GetRolesPermissionsDocument,
useGetRolesPermissionsQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getServerError from '@/utils/settings/getServerError';
import getUserRoles from '@/utils/settings/getUserRoles';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { yupResolver } from '@hookform/resolvers/yup';
import { FormProvider, useForm } from 'react-hook-form';
import toast from 'react-hot-toast';
@@ -31,9 +31,9 @@ export default function CreateRoleForm({
onSubmit,
...props
}: CreateRoleFormProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data, loading, error } = useGetRolesPermissionsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
const { allowed: allowedRoles } = data?.config?.auth?.user?.roles || {};
@@ -70,7 +70,7 @@ export default function CreateRoleForm({
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
config: {
auth: {
user: {

View File

@@ -5,17 +5,17 @@ import type {
import BaseRoleForm, {
baseRoleFormValidationSchema,
} from '@/components/settings/roles/BaseRoleForm';
import { useCurrentWorkspaceAndApplication } from '@/hooks/useCurrentWorkspaceAndApplication';
import { useCurrentWorkspaceAndProject } from '@/hooks/v2/useCurrentWorkspaceAndProject';
import type { Role } from '@/types/application';
import ActivityIndicator from '@/ui/v2/ActivityIndicator';
import getServerError from '@/utils/settings/getServerError';
import getUserRoles from '@/utils/settings/getUserRoles';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import {
GetRolesPermissionsDocument,
useGetRolesPermissionsQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import getServerError from '@/utils/settings/getServerError';
import getUserRoles from '@/utils/settings/getUserRoles';
import { getToastStyleProps } from '@/utils/settings/settingsConstants';
import { yupResolver } from '@hookform/resolvers/yup';
import { FormProvider, useForm } from 'react-hook-form';
import toast from 'react-hot-toast';
@@ -37,9 +37,9 @@ export default function EditRoleForm({
onSubmit,
...props
}: EditRoleFormProps) {
const { currentApplication } = useCurrentWorkspaceAndApplication();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data, loading, error } = useGetRolesPermissionsQuery({
variables: { appId: currentApplication?.id },
variables: { appId: currentProject?.id },
fetchPolicy: 'cache-only',
});
@@ -98,7 +98,7 @@ export default function EditRoleForm({
const updateConfigPromise = updateConfig({
variables: {
appId: currentApplication?.id,
appId: currentProject?.id,
config: {
auth: {
user: {

Some files were not shown because too many files have changed in this diff Show More