-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ayush/2075' of github.com:quadratichq/quadratic into ai…
…-prompt-logging
- Loading branch information
Showing
31 changed files
with
799 additions
and
106 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 |
---|---|---|
@@ -1,15 +1,36 @@ | ||
import getActiveTeam from '@/dashboard/shared/getActiveTeam'; | ||
import { apiClient } from '@/shared/api/apiClient'; | ||
import { ROUTES } from '@/shared/constants/routes'; | ||
import { ROUTES, SEARCH_PARAMS } from '@/shared/constants/routes'; | ||
import { LoaderFunctionArgs, redirect } from 'react-router-dom'; | ||
|
||
export const loader = async ({ request }: LoaderFunctionArgs) => { | ||
const url = new URL(request.url); | ||
const prompt = url.searchParams.get('prompt'); | ||
|
||
// Get the active team | ||
const { teams } = await apiClient.teams.list(); | ||
const { teamUuid } = await getActiveTeam(teams, undefined); | ||
|
||
const redirectUrl = ROUTES.CREATE_FILE(teamUuid, { prompt, private: true }); | ||
// Ensure the active team is _writeable_. If it's not, redirect them to the dashboard. | ||
// (They may have write access to another team, but not the 'active' one.) | ||
const team = teams.find(({ team }) => team.uuid === teamUuid); | ||
if (!team?.userMakingRequest.teamPermissions.includes('TEAM_EDIT')) { | ||
return redirect( | ||
`/?${SEARCH_PARAMS.SNACKBAR_MSG.KEY}=${encodeURIComponent('Failed to create file. You can only view this team.')}` | ||
); | ||
} | ||
|
||
// Are they trying to duplicate an example file? Do that. | ||
const example = url.searchParams.get('example'); | ||
if (example) { | ||
return redirect(ROUTES.CREATE_FILE_EXAMPLE(teamUuid, example)); | ||
} | ||
|
||
// Otherwise, start a new file by redirecting them to the file creation route | ||
const redirectUrl = ROUTES.CREATE_FILE(teamUuid, { | ||
// Are they creating a new file with a prompt? | ||
prompt: url.searchParams.get('prompt'), | ||
// Creating via this route is _always_ private | ||
private: true, | ||
}); | ||
return redirect(redirectUrl); | ||
}; |
This file contains 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 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 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 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 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 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 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 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.