Skip to content

Commit

Permalink
feat(profiles) link to instance list with profile filter applied WD-3874
Browse files Browse the repository at this point in the history
  • Loading branch information
lorumic authored and edlerd committed May 23, 2023
1 parent ebeaabf commit c49f136
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 43 deletions.
23 changes: 22 additions & 1 deletion src/pages/instances/InstanceSearchFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from "react";
import React, { FC, useEffect } from "react";
import { LxdInstance, LxdInstanceStatus } from "types/instance";
import {
InstanceFilters,
Expand All @@ -11,13 +11,24 @@ import {
SearchAndFilterData,
SearchAndFilterChip,
} from "@canonical/react-components/dist/components/SearchAndFilter/types";
import { useLocation } from "react-router-dom";

interface ProfileFilterState {
state?: {
appliedProfile: string;
};
}

interface Props {
instances: LxdInstance[];
setFilters: (newFilters: InstanceFilters) => void;
}

const InstanceSearchFilter: FC<Props> = ({ instances, setFilters }) => {
const { state } = useLocation() as ProfileFilterState;

useEffect(() => window.history.replaceState({}, ""), [state]);

const profileSet = [
...new Set(instances.flatMap((instance) => instance.profiles)),
];
Expand Down Expand Up @@ -68,6 +79,16 @@ const InstanceSearchFilter: FC<Props> = ({ instances, setFilters }) => {
return (
<div className="search-wrapper margin-right u-no-margin--bottom">
<SearchAndFilter
existingSearchData={
state?.appliedProfile
? [
{
lead: "profile",
value: state.appliedProfile,
},
]
: undefined
}
filterPanelData={searchAndFilterData}
returnSearchData={onSearchDataChange}
/>
Expand Down
1 change: 0 additions & 1 deletion src/pages/profiles/ProfileDetailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ const ProfileDetailPanel: FC = () => {
profile={profile}
project={projectName}
headingClassName="u-text--muted"
alignRight
/>
) : (
<tr>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/profiles/ProfileInstances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ interface Props {
profile: LxdProfile;
project: string;
headingClassName?: string;
alignRight?: boolean;
}

const ProfileInstances: FC<Props> = ({
profile,
project,
headingClassName,
alignRight,
}) => {
const isDefaultProject = project === "default";

Expand Down Expand Up @@ -59,13 +57,15 @@ const ProfileInstances: FC<Props> = ({

return isDefaultProject ? (
<ProfileUsedByDefaultProject
profile={profile.name}
affectedProjects={affectedProjects}
headingClassName={headingClassName}
/>
) : (
<ProfileUsedByRegularProject
profile={profile.name}
project={project}
usedByInstances={usedByInstances}
alignRight={alignRight}
/>
);
};
Expand Down
18 changes: 6 additions & 12 deletions src/pages/profiles/ProfileUsedByDefaultProject.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { FC } from "react";
import { LxdUsedBy } from "util/usedBy";
import ExpandableList from "components/ExpandableList";
import InstanceLink from "pages/instances/InstanceLink";
import ViewProfileInstancesBtn from "./actions/ViewProfileInstancesBtn";

interface Props {
profile: string;
affectedProjects?: {
name: string;
instances: LxdUsedBy[];
Expand All @@ -12,6 +12,7 @@ interface Props {
}

const ProfileUsedByDefaultProject: FC<Props> = ({
profile,
affectedProjects,
headingClassName,
}) => {
Expand All @@ -32,16 +33,9 @@ const ProfileUsedByDefaultProject: FC<Props> = ({
<i className="u-text--muted no-instances">No instances</i>
)}
{project.instances.length > 0 && (
<ExpandableList
items={project.instances.map((instance) => (
<div
key={instance.name}
className="u-truncate list-item"
title={instance.name}
>
<InstanceLink instance={instance} />
</div>
))}
<ViewProfileInstancesBtn
profile={profile}
project={project.name}
/>
)}
</td>
Expand Down
24 changes: 6 additions & 18 deletions src/pages/profiles/ProfileUsedByRegularProject.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
import React, { FC } from "react";
import { LxdUsedBy } from "util/usedBy";
import ExpandableList from "components/ExpandableList";
import InstanceLink from "pages/instances/InstanceLink";
import ViewProfileInstancesBtn from "./actions/ViewProfileInstancesBtn";

interface Props {
profile: string;
project: string;
usedByInstances: LxdUsedBy[];
alignRight?: boolean;
}

const ProfileUsedByRegularProject: FC<Props> = ({
profile,
project,
usedByInstances,
alignRight = false,
}) => {
return (
<>
{usedByInstances.length > 0 && (
<tr>
{alignRight && <th />}
<td>
<div className="list-wrapper">
<ExpandableList
items={usedByInstances.map((instance) => (
<div
key={instance.name}
className="u-truncate list-item non-default-project-item"
title={instance.name}
>
<InstanceLink instance={instance} />
</div>
))}
/>
</div>
<ViewProfileInstancesBtn profile={profile} project={project} />
</td>
</tr>
)}
Expand Down
31 changes: 31 additions & 0 deletions src/pages/profiles/actions/ViewProfileInstancesBtn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { FC } from "react";
import { useNavigate } from "react-router-dom";
import { Button } from "@canonical/react-components";

interface Props {
profile: string;
project: string;
}

const ViewProfileInstancesBtn: FC<Props> = ({ profile, project }) => {
const navigate = useNavigate();

return (
<Button
appearance="link"
className="u-no-margin u-no-padding"
small
onClick={() => {
navigate(`/ui/${project}/instances`, {
state: {
appliedProfile: profile,
},
});
}}
>
Go to instances
</Button>
);
};

export default ViewProfileInstancesBtn;
8 changes: 0 additions & 8 deletions src/sass/_profile_used_by_default_project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,4 @@
margin-right: $sph--small;
}
}

.list-item {
padding-bottom: $spv--small;
}

.p-button--link {
padding: $spv--small 0;
}
}

0 comments on commit c49f136

Please sign in to comment.