-
Notifications
You must be signed in to change notification settings - Fork 894
chore(site): migrate a few services to react-query used in the DashboardProvider #9667
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7560d99
Refactor build info
BrunoQuaresma d34f4cf
Refactor entitlements
BrunoQuaresma fc932a6
Improve verbiage
BrunoQuaresma bda22ea
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma f9ea677
Refactor to use factory
BrunoQuaresma 85c5198
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma a75c079
Use mutate async
BrunoQuaresma 4ec38be
Migrate experiments to react-query
BrunoQuaresma daf251a
Remove entitlements service
BrunoQuaresma 7bef76c
Improve error handling
BrunoQuaresma 8183a34
Add storybook
BrunoQuaresma e94af69
Remove appearance service
BrunoQuaresma 6b31d04
Fix stories
BrunoQuaresma ec57777
Fix preview
BrunoQuaresma 2a1d764
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma e7611c6
Fix MockAppereance
BrunoQuaresma 617d5ca
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma 43c48c3
Fix MockAppereance
BrunoQuaresma 3b47005
Abstract get metadata as json
BrunoQuaresma 16c08b8
Minor fixes
BrunoQuaresma 58123fc
Fix test
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { QueryClient } from "@tanstack/react-query"; | ||
import * as API from "api/api"; | ||
import { AppearanceConfig } from "api/typesGenerated"; | ||
|
||
export const appearance = () => { | ||
return { | ||
queryKey: ["appearance"], | ||
queryFn: fetchAppearance, | ||
}; | ||
}; | ||
|
||
export const updateAppearance = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: API.updateAppearance, | ||
onSuccess: (newConfig: AppearanceConfig) => { | ||
queryClient.setQueryData(["appearance"], newConfig); | ||
}, | ||
}; | ||
}; | ||
|
||
const fetchAppearance = () => { | ||
const appearance = document.querySelector("meta[property=appearance]"); | ||
if (appearance) { | ||
const rawContent = appearance.getAttribute("content"); | ||
try { | ||
return JSON.parse(rawContent as string); | ||
} catch (ex) { | ||
// Ignore this and fetch as normal! | ||
} | ||
} | ||
|
||
return API.getAppearance(); | ||
}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as API from "api/api"; | ||
|
||
export const buildInfo = () => { | ||
return { | ||
queryKey: ["buildInfo"], | ||
queryFn: fetchBuildInfo, | ||
}; | ||
}; | ||
|
||
const fetchBuildInfo = async () => { | ||
// Build info is injected by the Coder server into the HTML document. | ||
const buildInfo = document.querySelector("meta[property=build-info]"); | ||
if (buildInfo) { | ||
const rawContent = buildInfo.getAttribute("content"); | ||
try { | ||
return JSON.parse(rawContent as string); | ||
} catch (e) { | ||
console.warn("Failed to parse build info from document", e); | ||
} | ||
} | ||
|
||
return API.getBuildInfo(); | ||
}; | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { QueryClient } from "@tanstack/react-query"; | ||
import * as API from "api/api"; | ||
|
||
const ENTITLEMENTS_QUERY_KEY = ["entitlements"]; | ||
|
||
export const entitlements = () => { | ||
return { | ||
queryKey: ENTITLEMENTS_QUERY_KEY, | ||
queryFn: fetchEntitlements, | ||
}; | ||
}; | ||
|
||
export const refreshEntitlements = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: API.refreshEntitlements, | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries({ | ||
queryKey: ENTITLEMENTS_QUERY_KEY, | ||
}); | ||
}, | ||
}; | ||
}; | ||
|
||
const fetchEntitlements = () => { | ||
// Entitlements is injected by the Coder server into the HTML document. | ||
const entitlements = document.querySelector("meta[property=entitlements]"); | ||
if (entitlements) { | ||
const rawContent = entitlements.getAttribute("content"); | ||
try { | ||
return JSON.parse(rawContent as string); | ||
} catch (e) { | ||
console.warn("Failed to parse entitlements from document", e); | ||
} | ||
} | ||
|
||
return API.getEntitlements(); | ||
}; | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as API from "api/api"; | ||
|
||
export const experiments = () => { | ||
return { | ||
queryKey: ["experiments"], | ||
queryFn: fetchExperiments, | ||
}; | ||
}; | ||
|
||
const fetchExperiments = async () => { | ||
// Experiments is injected by the Coder server into the HTML document. | ||
const experiments = document.querySelector("meta[property=experiments]"); | ||
if (experiments) { | ||
const rawContent = experiments.getAttribute("content"); | ||
try { | ||
return JSON.parse(rawContent as string); | ||
} catch (e) { | ||
console.warn("Failed to parse experiments from document", e); | ||
} | ||
} | ||
|
||
return API.getExperiments(); | ||
}; | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.