Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update codebase to use API classes #122

Closed
wants to merge 154 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
17fd4d3
wip: update type definitions and parsing logic for config values
Parkreiner Apr 1, 2024
a95a44b
refactor: update some code for clarity
Parkreiner Apr 1, 2024
18e80f0
fix: update property names in top-level config
Parkreiner Apr 1, 2024
3cfc7c5
wip: commit progress on link update
Parkreiner Apr 1, 2024
ec1e794
chore: finish updates for CreateWorkspaceLink
Parkreiner Apr 1, 2024
50ad128
chore: add new test case for disabled state
Parkreiner Apr 1, 2024
bbcdaf7
fix: cleanup markup and text for EntityDataReminder
Parkreiner Apr 1, 2024
730e979
chore: add readEntityData as context value
Parkreiner Apr 1, 2024
cd804f6
refactor: rename DataEntityReminder to ReminderAcoordionItem
Parkreiner Apr 1, 2024
9e541c2
chore: extract core accordion item logic to parent
Parkreiner Apr 1, 2024
f445df4
chore: finish initial version of ReminderAccordion
Parkreiner Apr 1, 2024
f841d1a
wip: commit test stubs for ReminderAccordion
Parkreiner Apr 1, 2024
98a94c8
chore: rename isReadingEntityData prop
Parkreiner Apr 1, 2024
d2ac1ac
chore: update mock context values in tests
Parkreiner Apr 1, 2024
b415ce5
wip: commit test stub for hiding cta button when there is no repo URL
Parkreiner Apr 1, 2024
604c7a4
chore: hide CTA button when there is no repo URL
Parkreiner Apr 1, 2024
8635663
chore: rename AccordionItem to Disclosure
Parkreiner Apr 2, 2024
233d255
chore: update tests for Disclosure
Parkreiner Apr 2, 2024
badd8ee
chore: remove needless hasAssertions calls
Parkreiner Apr 2, 2024
e87e41e
fix: update conditional logic for ReminderAccordion
Parkreiner Apr 2, 2024
52a2731
fix: more accordion bug fixes
Parkreiner Apr 2, 2024
c45e132
chore: finish another test case
Parkreiner Apr 2, 2024
0680934
chore: add another accordion test case
Parkreiner Apr 2, 2024
7ba9fce
refactor: rename props for clarity
Parkreiner Apr 2, 2024
14c4d86
refactor: simplify condition for entity reminder
Parkreiner Apr 2, 2024
8f5081e
refactor: update prop for Disclosure
Parkreiner Apr 2, 2024
11b7b81
chore: finish all tests for accordion
Parkreiner Apr 2, 2024
cb2664e
refactor: update type definition for mock config
Parkreiner Apr 2, 2024
41d6f20
refactor: polish up accordion tests
Parkreiner Apr 2, 2024
b3b83f0
chore: finish up all tests
Parkreiner Apr 2, 2024
b6c8dec
fix: add missing property to mock setup to help compiler pass
Parkreiner Apr 2, 2024
ff531b8
refactor: move isReadingEntityData property to workspaces config
Parkreiner Apr 2, 2024
352352f
fix: add overflow-y and max height behavior to accordion
Parkreiner Apr 2, 2024
53ba23e
chore: polish styling for accordion
Parkreiner Apr 2, 2024
90d6f9d
fix: add reminder accordion as exported plugin component
Parkreiner Apr 2, 2024
400c1b8
refactor: split API errors into separate file
Parkreiner Apr 3, 2024
0458d1e
refactor: consolidate workspace status logic (for now)
Parkreiner Apr 3, 2024
9351270
refactor: finish splitting API file into smaller pieces
Parkreiner Apr 3, 2024
7c0c074
fix: add refetch interval when some workspaces are pending
Parkreiner Apr 3, 2024
0f44f2d
refactor: update casing on file
Parkreiner Apr 3, 2024
dc1e951
refactor: co-locate window refetch check better
Parkreiner Apr 3, 2024
40d0f7a
wip: commit current progress on auth refactor
Parkreiner Apr 3, 2024
cb9f812
Merge branch 'main' into mes/api-refactor
Parkreiner Apr 4, 2024
9c0345a
wip: commit current progress on API factory refactor
Parkreiner Apr 5, 2024
1191b9d
Merge branch 'mes/api-refactor' of github.com:coder/backstage-plugins…
Parkreiner Apr 5, 2024
4be3d07
refactor: move snapshot logic into separate class
Parkreiner Apr 5, 2024
6ea77cb
refactor: move files around
Parkreiner Apr 5, 2024
e3ed733
refactor: clean up makeArbitraryCall definition
Parkreiner Apr 5, 2024
93b9e59
fix: make state snapshot types more specific
Parkreiner Apr 5, 2024
60e6b17
refactor: update CoderProvider
Parkreiner Apr 5, 2024
4689044
refactor: move query options
Parkreiner Apr 5, 2024
6e4762f
refactor: finish updating queryOptions to use coderClient
Parkreiner Apr 5, 2024
3a3a971
refactor: delete useBackstageEndpoints
Parkreiner Apr 5, 2024
12251f1
fix: update api endpoint logic to account for discovery API better
Parkreiner Apr 5, 2024
88a1145
refactor: more cleanup
Parkreiner Apr 5, 2024
67cdda6
fix: update logic for state snapshot comparison
Parkreiner Apr 5, 2024
d10e0fb
chore: add wip version of arbitrary API calls
Parkreiner Apr 5, 2024
830f05a
refactor: clean up StateSnapshotManager
Parkreiner Apr 5, 2024
e86646a
chore: add both API ref factories to plugin definition
Parkreiner Apr 5, 2024
788b6b7
fix: broaden type of config
Parkreiner Apr 5, 2024
1ae5dc7
fix: update import for auth hook
Parkreiner Apr 8, 2024
9fbc3e7
refactor: centralize Coder auth API ref
Parkreiner Apr 8, 2024
d5e25e8
fix: make sure API calls go to correct proxy path
Parkreiner Apr 8, 2024
d6afb82
fix: fix unlink token functionality
Parkreiner Apr 8, 2024
73f4877
fix: ensure localStorage token is cleared correctly"
Parkreiner Apr 8, 2024
4422254
chore: add first test case for StateSnapshotManager
Parkreiner Apr 8, 2024
e95fee5
chore: finish tests for main snapshot manager class
Parkreiner Apr 8, 2024
cbacea4
chore: finish all tests for StateSnapshotManager
Parkreiner Apr 8, 2024
866904d
docs: clean up comments for clarity
Parkreiner Apr 8, 2024
6c94331
refactor: simplify auth discrimination logic
Parkreiner Apr 8, 2024
7e774cb
refactor: clean up useCoderTokenAuth for clarity
Parkreiner Apr 9, 2024
fa3b027
refactor: centralize API ref ID logic
Parkreiner Apr 9, 2024
b13ab31
refactor: update auth hook for clarity again
Parkreiner Apr 9, 2024
1691457
refactor: consolidate test setup helper logic
Parkreiner Apr 9, 2024
a8f43a5
refactor: clean up mock Backstage functions again
Parkreiner Apr 9, 2024
4721d33
fix: ensure Auth doesn't blow up on mount
Parkreiner Apr 9, 2024
a49627d
fix: get all CoderProvider tests passing
Parkreiner Apr 9, 2024
6817641
fix: update initial test setup for useCoderWorkspacesQuery
Parkreiner Apr 9, 2024
f12626f
refactor: finish redesign of CoderTokenAuth
Parkreiner Apr 10, 2024
3a558d6
chore: update imports
Parkreiner Apr 10, 2024
cd519a6
refactor: update type definitions for core Auth definition
Parkreiner Apr 10, 2024
36609cd
refactor: extract useCoderClient into separate file
Parkreiner Apr 10, 2024
c7b34e1
refactor: narrow number of required methods on auth
Parkreiner Apr 10, 2024
ac3bbf6
wip: commit progress on CoderClient update
Parkreiner Apr 10, 2024
921fa9e
wip: commit more progress on client
Parkreiner Apr 10, 2024
13ba1ff
refactor: update BackstateHttpError to be aware of Axios
Parkreiner Apr 10, 2024
ad7f3cd
fix: remove rough edges from useCoderClient
Parkreiner Apr 10, 2024
1ceb237
fix: let CoderTokenAuth propagate errors
Parkreiner Apr 10, 2024
b8b7579
wip: remove all error lines from CoderClient refactor
Parkreiner Apr 10, 2024
33408a3
refactor: reorganize properties on useCoderClient
Parkreiner Apr 10, 2024
546800e
fix: update queryOptions to be aware of CoderClient
Parkreiner Apr 10, 2024
f4f65f2
fix: revamp Auth API to avoid nasty nested catch blocks
Parkreiner Apr 10, 2024
a568c5b
fix: improve logic for detecting changes
Parkreiner Apr 10, 2024
89de483
refactor: clean up auth code
Parkreiner Apr 10, 2024
1e1b22d
fix: make sure that main workspaces request has remapped URLs
Parkreiner Apr 11, 2024
5d3810e
refactor: hide auth implementation details better from end-user hooks
Parkreiner Apr 11, 2024
d1e3f55
docs: add comment about how CoderClient class works"
Parkreiner Apr 11, 2024
d4a6d62
chore: finish initial version of axios logic
Parkreiner Apr 11, 2024
d054874
refactor: update code to reduce chaos
Parkreiner Apr 11, 2024
6931eec
refactor: update main components to use SDK types
Parkreiner Apr 11, 2024
8726458
refactor: clean up CoderClient one last time and add comments
Parkreiner Apr 11, 2024
336c23d
fix: update how paths are generated
Parkreiner Apr 12, 2024
5a89be3
docs: add comment about edge case for SnateSnapshotManager
Parkreiner Apr 12, 2024
30782cb
docs: make comment more clear
Parkreiner Apr 12, 2024
6b13e5b
refactor: rename method for clarity
Parkreiner Apr 12, 2024
ffb291e
fix: swap in fake Coder SDK
Parkreiner Apr 15, 2024
61bbf33
fix: make sure API requests go through fake SDK axios instance
Parkreiner Apr 15, 2024
e2c1a6e
Merge branch 'main' into mes/api-refactor
Parkreiner Apr 16, 2024
052a762
fix: make sure auth setter has no memory leaks
Parkreiner Apr 16, 2024
5d6950b
refactor: rename variable for clarity
Parkreiner Apr 16, 2024
661dd9a
fix: make variable more consistently typed
Parkreiner Apr 16, 2024
889862d
refactor: rename type definition for clarity
Parkreiner Apr 16, 2024
9d83dae
fix: update queryOptions imports to account for removing Coder SDK
Parkreiner Apr 16, 2024
3390fbd
fix: remove pseudo-SDK
Parkreiner Apr 16, 2024
56098f2
fix: update factory definition to account for IdentityApi
Parkreiner Apr 16, 2024
ffd41a4
fix: temporarily remove IdentityApi
Parkreiner Apr 16, 2024
a94e5d5
fix: make sure workspaces query is only enabled when user is auth'd
Parkreiner Apr 16, 2024
026831b
fix: make sure that assets state is brought in correctly
Parkreiner Apr 16, 2024
de8947a
fix: make sure background refetches happen more accurately
Parkreiner Apr 16, 2024
8b87496
fix: remove Coder SDK type imports everywhere
Parkreiner Apr 16, 2024
89ff7c3
fix: update proxy path for Coder API requests
Parkreiner Apr 16, 2024
b2627f3
fix: delete coder-mirror
Parkreiner Apr 16, 2024
28e46c5
fix: remove typo in query options input type
Parkreiner Apr 16, 2024
e947379
fix: remove needless promise
Parkreiner Apr 17, 2024
322f0f8
fix: update mock server to account for new dummy request
Parkreiner Apr 17, 2024
a9e3037
fix: update failing tests for CoderProvider
Parkreiner Apr 17, 2024
0673eec
fix: update type import for test
Parkreiner Apr 17, 2024
c23a252
fix: update another type import
Parkreiner Apr 17, 2024
fa18aea
chore: make mock localStorage
Parkreiner Apr 17, 2024
a316b89
wip: commit progress on CoderTokenAuth
Parkreiner Apr 17, 2024
47f2af8
fix: update state setter to account for empty tokens
Parkreiner Apr 17, 2024
992d98e
wip: commit current test progress
Parkreiner Apr 17, 2024
6ad14dc
wip: finish majority of token auth tests
Parkreiner Apr 17, 2024
dd2fd51
chore: finalize CoderTokenAuth tests
Parkreiner Apr 17, 2024
6a672d6
docs: update names of test cases for clarity
Parkreiner Apr 17, 2024
4b64d77
refactor: make time dependencies easier to manage
Parkreiner Apr 18, 2024
3fda9f0
fix: add types to Backstage error class
Parkreiner Apr 18, 2024
f2d8716
Merge branch 'main' into mes/api-refactor
Parkreiner Apr 19, 2024
edde14a
fix: add IdentityApi to CoderClient class definition
Parkreiner Apr 19, 2024
0ae3a1b
refactor: clean up type parameters
Parkreiner Apr 19, 2024
0b47f29
wip: commit progress on CoderClient tests
Parkreiner Apr 19, 2024
fc778c7
wip: add all test cases for coder client
Parkreiner Apr 19, 2024
14baf98
refactor: clean up up Axios code for clarity and make sure values sta…
Parkreiner Apr 19, 2024
5620d8b
fix: turn session token logic into default middleware
Parkreiner Apr 19, 2024
579ad88
wip: commit progress on failing, non-isolated tests
Parkreiner Apr 19, 2024
e5f4393
fix: update issue with auth state changes not propagating to coder cl…
Parkreiner Apr 19, 2024
b032f18
fix: make sure client can clean up after itself after tests
Parkreiner Apr 19, 2024
723207a
refactor: simplify cleanup process for using CoderClient in tests
Parkreiner Apr 22, 2024
c8aaf60
fix: add support for aborting all pending requests on cleanup
Parkreiner Apr 22, 2024
323fcf2
refactor: consolidate ad-hoc coder client hook calls
Parkreiner Apr 23, 2024
6b5f7c9
refactor: rename internal property to make it less discoverable
Parkreiner Apr 23, 2024
4659647
refactor: make internals even less discoverable
Parkreiner Apr 23, 2024
e26b4a8
refactor: make internals less clunky
Parkreiner Apr 23, 2024
54c5a2a
docs: improve private message clarity
Parkreiner Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/backstage-plugin-coder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.61",
"@tanstack/react-query": "4.36.1",
"axios": "^1.6.8",
"dayjs": "^1.11.10",
"ua-parser-js": "^1.0.37",
"use-sync-external-store": "^1.2.0",
"valibot": "^0.28.1"
},
"peerDependencies": {
Expand All @@ -54,6 +58,7 @@
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.0.0",
"@types/ua-parser-js": "^0.7.39",
"msw": "^1.0.0"
},
"files": [
Expand Down
318 changes: 0 additions & 318 deletions plugins/backstage-plugin-coder/src/api.ts

This file was deleted.

60 changes: 60 additions & 0 deletions plugins/backstage-plugin-coder/src/api/Auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @file Defines shared values and types used among any custom Coder auth
* implementations for the frontend.
*/
import { createApiRef } from '@backstage/core-plugin-api';
import { CODER_API_REF_ID_PREFIX } from '../typesConstants';

type AuthSubscriptionPayload = Readonly<{
token: string;
isTokenValid: boolean;
}>;

export type AuthSubscriptionCallback<
TSubscriptionPayload extends AuthSubscriptionPayload = AuthSubscriptionPayload,
> = (payload: TSubscriptionPayload) => void;

export type AuthValidatorDispatch = (newStatus: boolean) => void;

/**
* Shared set of properties among all Coder auth implementations
*/
export type CoderAuthApi<
TPayload extends AuthSubscriptionPayload = AuthSubscriptionPayload,
> = TPayload & {
/**
* Gives back a "state setter" that lets a different class dispatch a new auth
* status to the auth class implementation.
*
* Use this to send the new status you think the auth should have. The auth
* will decide whether it will let the dispatch go through and update state.
*/
getAuthStateSetter: () => AuthValidatorDispatch;

/**
* Subscribes an external system to auth changes.
*
* Returns an pre-wired unsubscribe callback to remove fuss of needing to hold
* onto the original callback if it's not directly needed anymore
*/
subscribe: (callback: AuthSubscriptionCallback<TPayload>) => () => void;

/**
* Lets an external system unsubscribe from auth changes.
*/
unsubscribe: (callback: AuthSubscriptionCallback<TPayload>) => void;

/**
* Lets an external system get a fully immutable snapshot of the current auth
* state.
*/
getStateSnapshot: () => AuthSubscriptionPayload;
};

/**
* A single, shared auth API ref that can be used with any of the CoderAuth
* API classes (CoderTokenAuth, eventually CoderOAuth, etc.)
*/
export const coderAuthApiRef = createApiRef<CoderAuthApi>({
id: `${CODER_API_REF_ID_PREFIX}.auth`,
});
Loading
Loading