Skip to content
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

fix: [M3-7862] - Fix display of TagsPanel in read-only entities #10275

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/manager/src/components/TagCell/TagDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TagsPanel } from 'src/components/TagsPanel/TagsPanel';
export type OpenTagDrawer = (id: number, label: string, tags: string[]) => void;

export interface TagDrawerProps {
entityID: number;
disabled?: boolean;
entityLabel: string;
onClose: () => void;
open: boolean;
Expand All @@ -15,11 +15,11 @@ export interface TagDrawerProps {
}

const TagDrawer = (props: TagDrawerProps) => {
const { entityID, entityLabel, onClose, open, tags, updateTags } = props;
const { disabled, entityLabel, onClose, open, tags, updateTags } = props;

return (
<Drawer onClose={onClose} open={open} title={`Tags (${entityLabel})`}>
<TagsPanel entityId={entityID} tags={tags} updateTags={updateTags} />
<TagsPanel disabled={disabled} tags={tags} updateTags={updateTags} />
</Drawer>
);
};
Expand Down
21 changes: 5 additions & 16 deletions packages/manager/src/components/TagsPanel/TagsPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useQueryClient } from '@tanstack/react-query';
import * as React from 'react';

import {
StyledPlusIcon,
Expand All @@ -9,7 +9,6 @@ import { CircleProgress } from 'src/components/CircleProgress';
import Select from 'src/components/EnhancedSelect/Select';
import { Tag } from 'src/components/Tag/Tag';
import { Typography } from 'src/components/Typography';
import { useIsResourceRestricted } from 'src/hooks/useIsResourceRestricted';
import { useProfile } from 'src/queries/profile';
import { updateTagsSuggestionsData, useTagSuggestions } from 'src/queries/tags';
import { getErrorStringOrDefault } from 'src/utilities/errorUtils';
Expand All @@ -34,10 +33,6 @@ export interface TagsPanelProps {
* If true, the input will be disabled and no tags can be added or removed.
*/
disabled?: boolean;
/**
* The ID of the entity to which the tags belong.
*/
entityId: number;
/**
* The tags to display.
*/
Expand All @@ -50,7 +45,7 @@ export interface TagsPanelProps {

export const TagsPanel = (props: TagsPanelProps) => {
const { classes, cx } = useStyles();
const { disabled, entityId, tags, updateTags } = props;
const { disabled, tags, updateTags } = props;

const queryClient = useQueryClient();

Expand All @@ -66,12 +61,6 @@ export const TagsPanel = (props: TagsPanelProps) => {
isLoading: userTagsLoading,
} = useTagSuggestions(!profile?.restricted);

const isLinodesGrantReadOnly = useIsResourceRestricted({
grantLevel: 'read_only',
grantType: 'linode',
id: entityId,
});

const tagsToSuggest = React.useMemo<Item[] | undefined>(
Comment on lines -69 to -74
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to call this hook in each respective component instead of cluttering TagsPanel with unrelated logic.

() =>
userTags
Expand Down Expand Up @@ -176,7 +165,7 @@ export const TagsPanel = (props: TagsPanelProps) => {
className={classes.selectTag}
creatable
createOptionPosition="first"
disabled={disabled || isLinodesGrantReadOnly}
disabled={disabled}
escapeClearsValue
hideLabel
isLoading={userTagsLoading}
Expand All @@ -195,7 +184,7 @@ export const TagsPanel = (props: TagsPanelProps) => {
>
<StyledTagButton
buttonType="outlined"
disabled={disabled || isLinodesGrantReadOnly}
disabled={disabled}
endIcon={<StyledPlusIcon disabled={disabled} />}
onClick={toggleTagInput}
>
Expand All @@ -217,7 +206,7 @@ export const TagsPanel = (props: TagsPanelProps) => {
[classes.tag]: true,
})}
colorVariant="lightBlue"
disabled={disabled || isLinodesGrantReadOnly}
disabled={disabled}
key={`tag-item-${thisTag}`}
label={thisTag}
maxLength={30}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Grid from '@mui/material/Unstable_Grid2';
import { styled } from '@mui/material/styles';
import Grid from '@mui/material/Unstable_Grid2';
import * as React from 'react';
import { useHistory, useLocation, useParams } from 'react-router-dom';

Expand All @@ -10,6 +10,7 @@ import { Notice } from 'src/components/Notice/Notice';
import { Paper } from 'src/components/Paper';
import { TagsPanel } from 'src/components/TagsPanel/TagsPanel';
import { Typography } from 'src/components/Typography';
import { useIsResourceRestricted } from 'src/hooks/useIsResourceRestricted';
import {
useDomainQuery,
useDomainRecordsQuery,
Expand All @@ -36,6 +37,12 @@ export const DomainDetail = () => {
refetch: refetchRecords,
} = useDomainRecordsQuery(domainId);

const isDomainReadOnly = useIsResourceRestricted({
grantLevel: 'read_only',
grantType: 'domain',
id: domainId,
});

const [updateError, setUpdateError] = React.useState<string | undefined>();

const handleLabelChange = (label: string) => {
Expand Down Expand Up @@ -124,7 +131,7 @@ export const DomainDetail = () => {
Tags
</StyledTypography>
<TagsPanel
entityId={domain.id}
disabled={isDomainReadOnly}
tags={domain.tags}
updateTags={handleUpdateTags}
/>
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like restricted users can't view Kubernetes clusters at all, so the logic in this file may have no effect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the read-only logic isn't doing anything for LKE, we should remove the code IMO. Or if API will support it in the future, add a @todo placeholder about it and comment the grant-related code out

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { KubernetesCluster } from '@linode/api-v4/lib/kubernetes';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import Grid from '@mui/material/Unstable_Grid2';
import { Theme } from '@mui/material/styles';
import Grid from '@mui/material/Unstable_Grid2';
import { useSnackbar } from 'notistack';
import * as React from 'react';
import { makeStyles } from 'tss-react/mui';
Expand All @@ -13,6 +13,7 @@ import { ConfirmationDialog } from 'src/components/ConfirmationDialog/Confirmati
import { Paper } from 'src/components/Paper';
import { TagsPanel } from 'src/components/TagsPanel/TagsPanel';
import KubeClusterSpecs from 'src/features/Kubernetes/KubernetesClusterDetail/KubeClusterSpecs';
import { useIsResourceRestricted } from 'src/hooks/useIsResourceRestricted';
import {
useKubernetesClusterMutation,
useKubernetesDashboardQuery,
Expand Down Expand Up @@ -121,6 +122,12 @@ export const KubeSummaryPanel = (props: Props) => {
mutateAsync: resetKubeConfig,
} = useResetKubeConfigMutation();

const isClusterReadOnly = useIsResourceRestricted({
grantLevel: 'read_only',
grantType: 'linode',
id: cluster.id,
});

const [
resetKubeConfigDialogOpen,
setResetKubeConfigDialogOpen,
Expand Down Expand Up @@ -198,7 +205,7 @@ export const KubeSummaryPanel = (props: Props) => {
</Grid>
<Grid className={classes.tags}>
<TagsPanel
entityId={cluster.id}
disabled={isClusterReadOnly}
tags={cluster.tags}
updateTags={handleUpdateTags}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { useAccountManagement } from 'src/hooks/useAccountManagement';
import { useEditableLabelState } from 'src/hooks/useEditableLabelState';
import { useFlags } from 'src/hooks/useFlags';
import { useIsResourceRestricted } from 'src/hooks/useIsResourceRestricted';
import {
useLinodeQuery,
useLinodeUpdateMutation,
Expand Down Expand Up @@ -75,6 +76,12 @@ const LinodeDetailHeader = () => {
account?.capabilities ?? []
);

const isLinodesGrantReadOnly = useIsResourceRestricted({
grantLevel: 'read_only',
grantType: 'linode',
id: matchedLinodeId,
});

const [powerAction, setPowerAction] = React.useState<Action>('Reboot');
const [powerDialogOpen, setPowerDialogOpen] = React.useState(false);
const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(
Expand Down Expand Up @@ -293,7 +300,7 @@ const LinodeDetailHeader = () => {
open={isUpgradeVolumesDialogOpen}
/>
<TagDrawer
entityID={linode.id}
disabled={isLinodesGrantReadOnly}
entityLabel={linode.label}
onClose={closeTagDrawer}
open={tagDrawer.open}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Grid from '@mui/material/Unstable_Grid2';
import { keyframes, styled } from '@mui/material/styles';
import Grid from '@mui/material/Unstable_Grid2';
import * as React from 'react';

import { TagDrawer, TagDrawerProps } from 'src/components/TagCell/TagDrawer';
import { Typography } from 'src/components/Typography';
import { LinodeEntityDetail } from 'src/features/Linodes/LinodeEntityDetail';
import { useIsResourceRestricted } from 'src/hooks/useIsResourceRestricted';
import { useLinodeUpdateMutation } from 'src/queries/linodes/linodes';
import { useProfile } from 'src/queries/profile';

Expand All @@ -14,7 +15,7 @@ export const CardView = (props: RenderLinodesProps) => {
const { data: profile } = useProfile();

const [tagDrawer, setTagDrawer] = React.useState<
Omit<TagDrawerProps, 'onClose' | 'updateTags'>
Omit<TagDrawerProps, 'onClose' | 'updateTags'> & { entityID: number }
>({
entityID: 0,
entityLabel: '',
Expand All @@ -26,6 +27,12 @@ export const CardView = (props: RenderLinodesProps) => {
tagDrawer.entityID
);

const isLinodesGrantReadOnly = useIsResourceRestricted({
grantLevel: 'read_only',
grantType: 'linode',
id: tagDrawer.entityID,
});

const closeTagDrawer = () => {
setTagDrawer({ ...tagDrawer, open: false });
};
Expand Down Expand Up @@ -68,7 +75,7 @@ export const CardView = (props: RenderLinodesProps) => {
<Grid className="m0" container style={{ width: '100%' }}>
{data.map((linode, idx: number) => (
<React.Fragment key={`linode-card-${idx}`}>
<StyledSummaryGrid xs={12} data-qa-linode-card={linode.id}>
<StyledSummaryGrid data-qa-linode-card={linode.id} xs={12}>
<LinodeEntityDetail
handlers={{
onOpenDeleteDialog: () =>
Expand Down Expand Up @@ -96,7 +103,7 @@ export const CardView = (props: RenderLinodesProps) => {
))}
</Grid>
<TagDrawer
entityID={tagDrawer.entityID}
disabled={isLinodesGrantReadOnly}
entityLabel={tagDrawer.entityLabel}
onClose={closeTagDrawer}
open={tagDrawer.open}
Expand All @@ -123,7 +130,7 @@ const StyledSummaryGrid = styled(Grid, { label: 'StyledSummaryGrid' })(
},
backgroundColor: theme.palette.background.paper,
marginBottom: 20,
paddingTop: 0, // from .py0 css class
paddingBottom: 0,
paddingTop: 0, // from .py0 css class
})
);
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export const SummaryPanel = () => {
</StyledTitle>
<TagsPanel
disabled={isNodeBalancerReadOnly}
entityId={nodebalancer.id}
tags={nodebalancer?.tags}
updateTags={(tags) => updateNodeBalancer({ tags })}
/>
Expand Down
Loading