Skip to content

Commit

Permalink
hide "Set as default" when it is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskus committed Aug 7, 2024
1 parent 412f648 commit bfa140d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
19 changes: 16 additions & 3 deletions catalog/app/containers/Admin/UsersAndRoles/Roles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,14 @@ function Edit({ role, close }: EditProps) {
interface SettingsMenuProps {
role: Role
openDialog: Dialogs.Dialogs['open']
isDefaultRoleSettingDisabled: boolean
}

function SettingsMenu({ role, openDialog }: SettingsMenuProps) {
function SettingsMenu({
role,
openDialog,
isDefaultRoleSettingDisabled,
}: SettingsMenuProps) {

Check warning on line 650 in catalog/app/containers/Admin/UsersAndRoles/Roles.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Admin/UsersAndRoles/Roles.tsx#L647-L650

Added lines #L647 - L650 were not covered by tests
const openDeleteDialog = React.useCallback(() => {
openDialog(({ close }) => <Delete {...{ role, close }} />)
}, [openDialog, role])
Expand Down Expand Up @@ -681,8 +686,11 @@ function SettingsMenu({ role, openDialog }: SettingsMenuProps) {
<M.Icon>more_vert</M.Icon>
</M.IconButton>
</M.Tooltip>

<M.Menu anchorEl={anchorEl} keepMounted open={!!anchorEl} onClose={handleClose}>
<M.MenuItem onClick={handleMakeDefault}>Set as default</M.MenuItem>
{!isDefaultRoleSettingDisabled && (
<M.MenuItem onClick={handleMakeDefault}>Set as default</M.MenuItem>

Check warning on line 692 in catalog/app/containers/Admin/UsersAndRoles/Roles.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Admin/UsersAndRoles/Roles.tsx#L692

Added line #L692 was not covered by tests
)}
<M.MenuItem onClick={handleDelete}>Delete</M.MenuItem>
</M.Menu>
</>
Expand All @@ -693,6 +701,7 @@ export default function Roles() {
const data = GQL.useQueryS(ROLES_QUERY)
const rows = data.roles
const defaultRoleId = data.defaultRole?.id
const isDefaultRoleSettingDisabled = !!data.admin?.isDefaultRoleSettingDisabled

const filtering = Table.useFiltering({
rows,
Expand Down Expand Up @@ -759,7 +768,11 @@ export default function Roles() {
))}
<M.TableCell align="right" padding="none">
<Table.InlineActions actions={inlineActions(i)}>
<SettingsMenu role={i} openDialog={dialogs.open} />
<SettingsMenu
role={i}
openDialog={dialogs.open}
isDefaultRoleSettingDisabled={isDefaultRoleSettingDisabled}
/>
</Table.InlineActions>
</M.TableCell>
</M.TableRow>
Expand Down
17 changes: 17 additions & 0 deletions catalog/app/containers/Admin/UsersAndRoles/gql/Roles.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export type containers_Admin_UsersAndRoles_gql_RolesQueryVariables = Types.Exact
export type containers_Admin_UsersAndRoles_gql_RolesQuery = {
readonly __typename: 'Query'
} & {
readonly admin: { readonly __typename: 'AdminQueries' } & Pick<
Types.AdminQueries,
'isDefaultRoleSettingDisabled'
>
readonly roles: ReadonlyArray<
| ({ readonly __typename: 'UnmanagedRole' } & RoleSelection_UnmanagedRole_Fragment)
| ({ readonly __typename: 'ManagedRole' } & RoleSelection_ManagedRole_Fragment)
Expand All @@ -35,6 +39,19 @@ export const containers_Admin_UsersAndRoles_gql_RolesDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'admin' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'isDefaultRoleSettingDisabled' },
},
],
},
},
{
kind: 'Field',
name: { kind: 'Name', value: 'roles' },
Expand Down
3 changes: 3 additions & 0 deletions catalog/app/containers/Admin/UsersAndRoles/gql/Roles.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# import RoleSelection from "./RoleSelection.graphql"

query {
admin {
isDefaultRoleSettingDisabled
}
roles {
...RoleSelection
}
Expand Down

0 comments on commit bfa140d

Please sign in to comment.