Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into klink/eng-549-accou…
Browse files Browse the repository at this point in the history
…nt-refinement-account-attributes

# Conflicts:
#	www/src/components/account/Groups.js
#	www/src/components/account/MoreMenu.js
#	www/src/components/account/Roles.js
#	www/src/components/account/ServiceAccounts.js
  • Loading branch information
dogmar committed Aug 29, 2022
2 parents 3525eb2 + af7c73a commit 0e18a6c
Show file tree
Hide file tree
Showing 29 changed files with 259 additions and 240 deletions.
9 changes: 9 additions & 0 deletions apps/graphql/lib/graphql/schema/base/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ defmodule GraphQl.Schema.Helpers do
end
end
end

def lazy_dataloader(key, resolver) do
fn
%{^key => %Ecto.Association.NotLoaded{}} = s, args, ctx ->
func = dataloader(resolver)
func.(s, args, ctx)
%{^key => v}, _, _ -> {:ok, v}
end
end
end
2 changes: 1 addition & 1 deletion apps/graphql/lib/graphql/schema/recipe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ defmodule GraphQl.Schema.Recipe do
field :restricted, :boolean
field :tests, list_of(:recipe_test)
field :repository, :repository, resolve: dataloader(Repository)
field :recipe_sections, list_of(:recipe_section)
field :recipe_sections, list_of(:recipe_section), resolve: lazy_dataloader(:recipe_sections, Recipe)
field :recipe_dependencies, list_of(:recipe)

timestamps()
Expand Down
58 changes: 49 additions & 9 deletions apps/graphql/test/queries/recipe_queries_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,33 @@ defmodule GraphQl.RecipeQueriesTest do

assert message == "one of repositoryId or repositoryName are required"
end

test "it won't blow up when sideloading sections" do
recipe = insert(:recipe)
section = insert(:recipe_section, recipe: recipe)
insert(:recipe_item, recipe_section: section, chart: build(:chart, repository: section.repository))

{:ok, %{data: %{"recipes" => %{"edges" => [%{"node" => r}]}}}} = run_query("""
query Recipes($id: ID!) {
recipes(repositoryId: $id, first: 5) {
edges {
node {
recipeSections { id }
}
}
}
}
""", %{"id" => recipe.repository.id}, %{current_user: insert(:user)})

assert hd(r["recipeSections"])["id"] == section.id
end
end

describe "recipe" do
test "It will fetch a recipe" do
recipe = insert(:recipe)
section = insert(:recipe_section, recipe: recipe)
%{sections: [section | _] = sections, dependencies: deps} = provision_recipe(recipe)
item = insert(:recipe_item, recipe_section: section, chart: build(:chart, repository: section.repository))
dep = insert(:recipe_dependency, recipe: recipe, index: 1)
dep2 = insert(:recipe_dependency, recipe: dep.dependent_recipe, index: 1)
dep3 = insert(:recipe_dependency, recipe: recipe, index: 2)

{:ok, %{data: %{"recipe" => found}}} = run_query("""
query Recipe($id: ID!) {
Expand All @@ -100,14 +117,13 @@ defmodule GraphQl.RecipeQueriesTest do

assert found["id"] == recipe.id

found_section = hd(found["recipeSections"])
assert found_section["id"] == section.id
assert Enum.map(found["recipeSections"], & &1["id"]) == Enum.map(sections, & &1.id)

found_item = hd(found_section["recipeItems"])
assert found_item["id"] == item.id
found_section = Enum.find(found["recipeSections"], & &1["id"] == section.id)
found_item = Enum.find(found_section["recipeItems"], & &1["id"] == item.id)
assert found_item["chart"]["id"] == item.chart.id

assert Enum.map([dep, dep2, dep3], & &1.dependent_recipe)
assert Enum.map(deps, & &1.dependent_recipe)
|> ids_equal(found["recipeDependencies"])
end

Expand Down Expand Up @@ -180,4 +196,28 @@ defmodule GraphQl.RecipeQueriesTest do
|> ids_equal(stacks)
end
end

defp provision_recipe(recipe) do
%{repository: repo0} = section0 = insert(:recipe_section, recipe: recipe)
insert(:recipe_item, recipe_section: section0, chart: build(:chart))

[%{dependent_recipe: level_1_1}, %{dependent_recipe: level_1_2}] = dependencies = for i <- 1..2,
do: insert(:recipe_dependency, recipe: recipe, index: i)
%{repository: repo} = section = insert(:recipe_section, recipe: level_1_1)
%{repository: repo2} = section2 = insert(:recipe_section, recipe: level_1_2)
insert(:recipe_item, recipe_section: section, chart: insert(:chart, dependencies: %{dependencies: [
%{type: :terraform, repo: repo.name, name: "name"},
%{type: :helm, repo: repo0.name, name: "zero"},
]}))
insert(:recipe_item, recipe_section: section2, terraform: insert(:terraform, dependencies: %{dependencies: [
%{type: :helm, repo: repo.name, name: "another-name"},
]}))
%{dependent_recipe: level_2_1} = dep = insert(:recipe_dependency, recipe: level_1_1, index: 1)
section3 = insert(:recipe_section, recipe: level_2_1)
insert(:recipe_item, recipe_section: section3, chart: insert(:chart, dependencies: %{dependencies: [
%{type: :helm, repo: repo2.name, name: "name"},
]}))

%{sections: [section0, section, section2, section3], dependencies: [dep | dependencies]}
end
end
2 changes: 1 addition & 1 deletion bin/webflow_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def webflow_dump():
diffed_update(
wf,
'62dff22f0b55da4ddc21ef80',
[r['node'] for r in repos['data']['repositories']['edges']],
[r['node'] for r in repos['data']['repositories']['edges'] if r['node']['name'] not in BLACKLIST],
lambda x: x['name'],
repo_data
)
Expand Down
9 changes: 2 additions & 7 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,16 @@
{
"matchManagers": ["npm"],
"addLabels": [
"dependencies",
"frontend"
]
},
{
"matchManagers": ["mix"],
"addLabels": [
"dependencies",
"backend"
]
}
],
"lockFileMaintenance": {
"enabled": true
},
"separateMinorPatch": true,
"dependencyDashboardApproval": true
"labels": ["dependencies"],
"separateMinorPatch": true
}
2 changes: 1 addition & 1 deletion www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"moment": "2.29.4",
"phoenix": "1.6.11",
"pluralsh-absinthe-socket-apollo-link": "0.2.0",
"pluralsh-design-system": "1.187.0",
"pluralsh-design-system": "1.190.0",
"prop-types": "15.8.1",
"query-string": "7.1.1",
"randomcolor": "0.6.2",
Expand Down
12 changes: 10 additions & 2 deletions www/src/components/Plural.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
} from 'react-router-dom'
import { StripeProvider } from 'react-stripe-elements'

import { Toast } from 'pluralsh-design-system'

import { growthbook } from '../helpers/growthbook'

import ApplicationLayout from './layout/ApplicationLayout'
Expand Down Expand Up @@ -59,7 +61,6 @@ import PackageUpdateQueue from './repos/common/PackageUpdateQueue'
import PackageDependencies from './repos/common/PackageDependencies'
import ImagePullMetrics from './repos/common/ImagePullMetrics'
import ImageVulnerabilities from './repos/common/ImageVulnerabilities'
import { SuccessToast } from './utils/Toasts'

function EditBilling(props) {
return (
Expand Down Expand Up @@ -113,7 +114,14 @@ function TestBanner() {
}, [])

if (growthbook.isOn('growthbook-test') && enable) {
return <SuccessToast>Growthbook Test!</SuccessToast>
return (
<Toast
severity="success"
marginBottom="medium"
marginRight="xxxxlarge"
>Growthbook Test!
</Toast>
)
}

return null
Expand Down
2 changes: 1 addition & 1 deletion www/src/components/account/Groups.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useMutation, useQuery } from '@apollo/client'
import { EmptyState } from 'components/utils/EmptyState'
import { Box } from 'grommet'
import { Flex } from 'honorable'
import { isEmpty } from 'lodash'
import {
Button,
EmptyState,
GlobeIcon,
Input,
Modal,
Expand Down
4 changes: 1 addition & 3 deletions www/src/components/account/MoreMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export function MoreMenu({ children }) {
align={{ top: 'bottom' }}
onClickOutside={() => setOpen(false)}
>
<Menu>
{children}
</Menu>
<Menu>{children}</Menu>
</Drop>
)}
</>
Expand Down
10 changes: 7 additions & 3 deletions www/src/components/account/Roles.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { useMutation, useQuery } from '@apollo/client'
import { EmptyState } from 'components/utils/EmptyState'
import { Box } from 'grommet'
import { Flex } from 'honorable'
import { isEmpty } from 'lodash'
import { Input, PageTitle, SearchIcon } from 'pluralsh-design-system'
import {
EmptyState,
Flex,
Input,
PageTitle,
SearchIcon,
} from 'pluralsh-design-system'
import { useContext, useState } from 'react'

import {
Expand Down
3 changes: 1 addition & 2 deletions www/src/components/account/ServiceAccounts.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useQuery } from '@apollo/client'
import { EmptyState } from 'components/utils/EmptyState'
import { Box } from 'grommet'
import { Flex, Input } from 'honorable'
import { isEmpty } from 'lodash'
import { PageTitle, SearchIcon } from 'pluralsh-design-system'
import { EmptyState, PageTitle, SearchIcon } from 'pluralsh-design-system'
import { useCallback, useState } from 'react'

import {
Expand Down
33 changes: 25 additions & 8 deletions www/src/components/account/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { Box } from 'grommet'
import {
Avatar, Button, MenuItem, Span,
} from 'honorable'
import { BotIcon } from 'pluralsh-design-system'
import { BotIcon, GraphQLToast } from 'pluralsh-design-system'
import { useContext, useState } from 'react'

import { fetchToken, setPreviousUserData, setToken } from '../../helpers/authentication'
import {
fetchToken,
setPreviousUserData,
setToken,
} from '../../helpers/authentication'

import { canEdit } from '../accounts/EditAccount'
import { EDIT_USER, IMPERSONATE_SERVICE_ACCOUNT } from '../accounts/queries'
Expand All @@ -15,7 +19,6 @@ import { CurrentUserContext } from '../login/CurrentUser'

import { Provider } from '../repos/misc'
import { DELETE_USER } from '../users/queries'
import { GraphQlToast } from '../utils/Toasts'

import { Confirm } from './Confirm'
import { EditServiceAccount } from './CreateServiceAccount'
Expand Down Expand Up @@ -56,7 +59,8 @@ export function Chip({ text, color }) {
<Span
color={color || 'action-link-inline'}
fontWeight="bold"
>{text}
>
{text}
</Span>
</Box>
)
Expand All @@ -77,8 +81,14 @@ function UserEdit({ user, update }) {
return (
<>
<MoreMenu>
<MenuItem onClick={() => mutation({ variables: { attributes: { roles: { admin: !isAdmin } } } })}>
<Span color="text-light">{isAdmin ? 'Remove admin role' : 'Add admin role'}</Span>
<MenuItem
onClick={() => mutation({
variables: { attributes: { roles: { admin: !isAdmin } } },
})}
>
<Span color="text-light">
{isAdmin ? 'Remove admin role' : 'Add admin role'}
</Span>
</MenuItem>
<MenuItem onClick={() => setConfirm(true)}>
<Span color="text-error">Delete user</Span>
Expand Down Expand Up @@ -144,7 +154,12 @@ export function ServiceAccount({ user, update }) {
const editable = canEdit(me, account) || hasRbac(me, Permissions.USERS)
const [mutation, { error }] = useMutation(IMPERSONATE_SERVICE_ACCOUNT, {
variables: { id: user.id },
update: (_cache, { data: { impersonateServiceAccount: { jwt } } }) => {
update: (_cache,
{
data: {
impersonateServiceAccount: { jwt },
},
}) => {
setPreviousUserData({
me,
jwt: fetchToken(),
Expand Down Expand Up @@ -194,7 +209,9 @@ export function ServiceAccount({ user, update }) {
</Box>
</Box>
{error && (
<GraphQlToast
<GraphQLToast
marginBottom="medium"
marginRight="xxxxlarge"
error={error}
header="Failed to impersonate"
/>
Expand Down
31 changes: 14 additions & 17 deletions www/src/components/clusters/Clusters.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useQuery } from '@apollo/client'
import { EmptyState } from 'components/utils/EmptyState'
import { Box } from 'grommet'
import {
A, Br, Flex, Span,
} from 'honorable'
import { Button, LoopingLogo } from 'pluralsh-design-system'
import { Button, EmptyState, LoopingLogo } from 'pluralsh-design-system'
import { ReactElement, useEffect, useState } from 'react'
import { Link } from 'react-router-dom'

Expand Down Expand Up @@ -80,24 +79,23 @@ export function Clusters(): ReactElement | null {
<Box margin={{ top: '152px' }}>
<EmptyState
message="Looks like you don't have any clusters registered yet."
description={(
<Span>
Clusters are registered here once you've installed and deployed Plural
<Br />Console. If you need support installing it, read our&nbsp;
<A
inline
href="https://docs.plural.sh/getting-started/getting-started"
target="_blank"
rel="noopener noreferrer"
>
quickstart guide
</A>.
</Span>
)}
>
<Span>
Clusters are registered here once you've installed and deployed Plural
<Br />Console. If you need support installing it, read our&nbsp;
<A
inline
href="https://docs.plural.sh/getting-started/getting-started"
target="_blank"
rel="noopener noreferrer"
>
quickstart guide
</A>.
</Span>
<Button
as={Link}
to="/repository/a051a0bf-61b5-4ab5-813d-2c541c83a979"
marginTop="medium"
>
Install Plural Console
</Button>
Expand Down Expand Up @@ -135,4 +133,3 @@ export function Clusters(): ReactElement | null {
</QueueContext.Provider>
)
}

2 changes: 1 addition & 1 deletion www/src/components/clusters/ClustersSidecar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function ClustersSidecar(): ReactElement {
>
<Button
secondary
endIcon={<ArrowTopRightIcon size={24} />}
endIcon={<ArrowTopRightIcon />}
as={A}
target="_blank"
href={`https://${queue.domain}`}
Expand Down
2 changes: 1 addition & 1 deletion www/src/components/clusters/ConsoleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function ConsoleButton({ q = {}, text, ...props }) {
target="_blank"
href={`https://${q.domain}`}
textDecoration="none"
endIcon={<ArrowTopRightIcon size={16} />}
endIcon={<ArrowTopRightIcon />}
{...props}
>
{text || 'View in Console'}
Expand Down
Loading

0 comments on commit 0e18a6c

Please sign in to comment.