Skip to content

Commit

Permalink
filter previews from app instances when getting base (#4680)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored May 22, 2024
1 parent a9b13a6 commit 62bad5b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Image from "components/porter/Image";
import SearchBar from "components/porter/SearchBar";
import Spacer from "components/porter/Spacer";
import Text from "components/porter/Text";
import { useDeploymentTargetList } from "lib/hooks/useDeploymentTarget";
import { useAppInstances } from "lib/hooks/useLatestAppRevisions";
import { useTemplateEnvs } from "lib/hooks/useTemplateEnvs";

Expand All @@ -29,23 +30,28 @@ export const ConfigurableAppList: React.FC = () => {
projectId: currentProject?.id ?? 0,
clusterId: currentCluster?.id ?? 0,
});
const { deploymentTargetList } = useDeploymentTargetList({ preview: false });

const { environments, status } = useTemplateEnvs();

const envsWithExistingAppInstance = useMemo(() => {
return environments
.map((env) => {
const existingAppInstance = appInstances.find(
(inst) => inst.name === env.name
);

return {
...env,
existingAppInstance,
};
})
.filter((ev) => ev.name.includes(searchValue));
}, [environments, appInstances, searchValue]);
const filteredEnvs = useMemo(() => {
const activeAppInstances = appInstances.filter((ai) =>
deploymentTargetList.some((dt) => dt.id === ai.deployment_target.id)
);

const withBaseAppInstance = environments.map((env) => {
const existingAppInstance = activeAppInstances.find(
(ai) => ai.name === env.name
);

return {
...env,
existingAppInstance,
};
});

return withBaseAppInstance;
}, [environments, deploymentTargetList, searchValue]);

if (status === "loading") {
return <Loading offset="-150px" />;
Expand Down Expand Up @@ -101,7 +107,7 @@ export const ConfigurableAppList: React.FC = () => {
</Container>
<Spacer y={1} />
<List>
{envsWithExistingAppInstance.map((ev) => (
{filteredEnvs.map((ev) => (
<ConfigurableAppRow
key={ev.name}
setEditingApp={() => {
Expand Down

0 comments on commit 62bad5b

Please sign in to comment.