-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(weave): Add mods page and menu item only for wandb admins (#3279)
* Basic UI for mods * Pass along purl for wild demo purposes * Mod demo updates * Wire up secret setting, add mod visual indicator * gradient similar to streamlit * Added secret types * Fix mutation types * Use the wandb api host for our iframe * Wire up backend host * Make mods page scroll properly * Only show mods to admins * Fix TSC errors * Fix project sidebar deps * Fix bungled merge * Add grace period for startup * Try some debugging, increase retries * Fix formatting * Fix trailing newline * Enabling container logging * Use wget instead of curl as we dont have it in the container anymore * Fix shadow variable lint error
- Loading branch information
Showing
7 changed files
with
550 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* This is a GraphQL approach to querying viewer information. | ||
* There is a query engine based approach in useViewerUserInfo.ts. | ||
*/ | ||
|
||
import { | ||
gql, | ||
TypedDocumentNode, | ||
useApolloClient, | ||
useMutation, | ||
} from '@apollo/client'; | ||
import {useEffect, useState} from 'react'; | ||
|
||
const SECRETS_QUERY = gql` | ||
query secrets($entityName: String!) { | ||
entity(name: $entityName) { | ||
id | ||
secrets { | ||
entityId | ||
name | ||
createdAt | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const SECRETS_MUTATION = gql` | ||
mutation insertSecret( | ||
$entityName: String! | ||
$secretName: String! | ||
$secretValue: String! | ||
) { | ||
insertSecret( | ||
input: { | ||
entityName: $entityName | ||
secretName: $secretName | ||
secretValue: $secretValue | ||
} | ||
) { | ||
success | ||
} | ||
} | ||
` as TypedDocumentNode<InsertSecretResponse, InsertSecretVariables>; | ||
|
||
type SecretResponseLoading = { | ||
loading: true; | ||
entityId: string; | ||
secrets: string[]; | ||
}; | ||
type SecretResponseSuccess = { | ||
loading: false; | ||
entityId: string; | ||
secrets: string[]; | ||
}; | ||
type SecretResponse = SecretResponseLoading | SecretResponseSuccess; | ||
|
||
export const useSecrets = ({ | ||
entityName, | ||
}: { | ||
entityName: string; | ||
}): SecretResponse => { | ||
const [response, setResponse] = useState<SecretResponse>({ | ||
loading: true, | ||
entityId: '', | ||
secrets: [], | ||
}); | ||
|
||
const apolloClient = useApolloClient(); | ||
|
||
useEffect(() => { | ||
let mounted = true; | ||
apolloClient | ||
.query({query: SECRETS_QUERY as any, variables: {entityName}}) | ||
.then(result => { | ||
if (!mounted) { | ||
return; | ||
} | ||
const secretPayloads = result.data.entity?.secrets ?? []; | ||
if (!secretPayloads) { | ||
setResponse({ | ||
loading: false, | ||
entityId: '', | ||
secrets: [], | ||
}); | ||
return; | ||
} | ||
const secrets = secretPayloads.map((secret: any) => secret.name).sort(); | ||
setResponse({ | ||
loading: false, | ||
entityId: result.data.entity?.id ?? '', | ||
secrets, | ||
}); | ||
}); | ||
return () => { | ||
mounted = false; | ||
}; | ||
}, [apolloClient, entityName]); | ||
|
||
return response; | ||
}; | ||
|
||
interface InsertSecretResponse { | ||
insertSecret: { | ||
success: boolean; | ||
}; | ||
} | ||
|
||
type InsertSecretVariables = { | ||
entityName: string; | ||
secretName: string; | ||
secretValue: string; | ||
}; | ||
|
||
export const useInsertSecret = () => { | ||
const [insertSecret] = useMutation< | ||
InsertSecretResponse, | ||
InsertSecretVariables | ||
>(SECRETS_MUTATION); | ||
|
||
return insertSecret; | ||
}; |
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.