Skip to content

Commit

Permalink
[UI] Add edit option to resources that have create template in annota…
Browse files Browse the repository at this point in the history
…tion (#2846)

* Add edit option to resources that have create template in anno - WIP

* Move edit option to resource details page

* Refactor edit in details

* Extract custom actions component

* Remove edit from core details table

* Remove edit from core details table - updated

* Fix some errors

* Add custom actions to the details page

* Add custom actions to the details page - updated

* Add actions type and move edit button

* Add actions type and move edit button - updated

* Lint
  • Loading branch information
AlinaGoaga authored and foot committed Oct 14, 2022
1 parent 9b6a249 commit 3cb0ee0
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 9 deletions.
11 changes: 10 additions & 1 deletion ui/components/AutomationDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useToggleSuspend } from "../hooks/flux";
import { Kind } from "../lib/api/core/types.pb";
import { Automation } from "../lib/objects";
import Button from "./Button";
import CustomActions from "./CustomActions";
import DependenciesView from "./DependenciesView";
import EventsTable from "./EventsTable";
import Flex from "./Flex";
Expand All @@ -28,9 +29,16 @@ type Props = {
className?: string;
info: InfoField[];
customTabs?: Array<routeTab>;
customActions?: JSX.Element[];
};

function AutomationDetail({ automation, className, info, customTabs }: Props) {
function AutomationDetail({
automation,
className,
info,
customTabs,
customActions,
}: Props) {
const { path } = useRouteMatch();
const { setNodeYaml, appState } = React.useContext(AppContext);
const nodeYaml = appState.nodeYaml;
Expand Down Expand Up @@ -152,6 +160,7 @@ function AutomationDetail({ automation, className, info, customTabs }: Props) {
>
{automation.suspended ? "Resume" : "Suspend"}
</Button>
<CustomActions actions={customActions} />
</Flex>

<SubRouterTabs rootPath={`${path}/details`}>
Expand Down
4 changes: 3 additions & 1 deletion ui/components/BucketDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { InfoField } from "./InfoList";
type Props = {
className?: string;
bucket: Bucket;
customActions?: JSX.Element[];
};

function BucketDetail({ className, bucket }: Props) {
function BucketDetail({ className, bucket, customActions }: Props) {
const { data } = useFeatureFlags();
const flags = data?.flags || {};

Expand All @@ -32,6 +33,7 @@ function BucketDetail({ className, bucket }: Props) {
className={className}
type={Kind.Bucket}
source={bucket}
customActions={customActions}
info={[
["Type", Kind.Bucket],
["Endpoint", bucket.endpoint],
Expand Down
17 changes: 17 additions & 0 deletions ui/components/CustomActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from "react";
import Spacer from "./Spacer";

function CustomActions({ actions }: { actions: JSX.Element[] }) {
return actions?.length > 0 ? (
<>
{actions?.map((action, index) => (
<React.Fragment key={index}>
<Spacer padding="xs" />
{action}
</React.Fragment>
))}
</>
) : null;
}

export default CustomActions;
8 changes: 7 additions & 1 deletion ui/components/GitRepositoryDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import { InfoField } from "./InfoList";
type Props = {
className?: string;
gitRepository: GitRepository;
customActions?: JSX.Element[];
};

function GitRepositoryDetail({ className, gitRepository }: Props) {
function GitRepositoryDetail({
className,
gitRepository,
customActions,
}: Props) {
const { data } = useFeatureFlags();
const flags = data?.flags || {};

Expand All @@ -32,6 +37,7 @@ function GitRepositoryDetail({ className, gitRepository }: Props) {
className={className}
type={Kind.GitRepository}
source={gitRepository}
customActions={customActions}
info={[
["Type", Kind.GitRepository],
[
Expand Down
4 changes: 3 additions & 1 deletion ui/components/HelmChartDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { InfoField } from "./InfoList";
type Props = {
className?: string;
helmChart: HelmChart;
customActions?: JSX.Element[];
};

function HelmChartDetail({ className, helmChart }: Props) {
function HelmChartDetail({ className, helmChart, customActions }: Props) {
const { data } = useFeatureFlags();
const flags = data?.flags || {};

Expand All @@ -31,6 +32,7 @@ function HelmChartDetail({ className, helmChart }: Props) {
type={Kind.HelmChart}
className={className}
source={helmChart}
customActions={customActions}
info={[
["Type", Kind.HelmChart],
["Chart", helmChart.chart],
Expand Down
9 changes: 8 additions & 1 deletion ui/components/HelmReleaseDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Props = {
helmRelease?: HelmRelease;
className?: string;
customTabs?: Array<routeTab>;
customActions?: JSX.Element[];
};

function helmChartLink(helmRelease: HelmRelease) {
Expand Down Expand Up @@ -49,7 +50,12 @@ function helmChartLink(helmRelease: HelmRelease) {
);
}

function HelmReleaseDetail({ helmRelease, className, customTabs }: Props) {
function HelmReleaseDetail({
helmRelease,
className,
customTabs,
customActions,
}: Props) {
const { data } = useFeatureFlags();
const flags = data?.flags || {};

Expand All @@ -67,6 +73,7 @@ function HelmReleaseDetail({ helmRelease, className, customTabs }: Props) {
className={className}
automation={helmRelease}
customTabs={customTabs}
customActions={customActions}
info={[
["Source", helmChartLink(helmRelease)],
["Chart", helmRelease?.helmChart.chart],
Expand Down
8 changes: 7 additions & 1 deletion ui/components/HelmRepositoryDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import Timestamp from "./Timestamp";
type Props = {
className?: string;
helmRepository: HelmRepository;
customActions?: JSX.Element[];
};

function HelmRepositoryDetail({ className, helmRepository }: Props) {
function HelmRepositoryDetail({
className,
helmRepository,
customActions,
}: Props) {
const { data } = useFeatureFlags();
const flags = data?.flags || {};

Expand All @@ -32,6 +37,7 @@ function HelmRepositoryDetail({ className, helmRepository }: Props) {
className={className}
type={Kind.HelmRepository}
source={helmRepository}
customActions={customActions}
info={[
["Type", Kind.HelmRepository],
["Repository Type", helmRepository.repositoryType.toLowerCase()],
Expand Down
9 changes: 8 additions & 1 deletion ui/components/KustomizationDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ type Props = {
kustomization?: Kustomization;
className?: string;
customTabs?: Array<routeTab>;
customActions?: JSX.Element[];
};

function KustomizationDetail({ kustomization, className, customTabs }: Props) {
function KustomizationDetail({
kustomization,
className,
customTabs,
customActions,
}: Props) {
const { data } = useFeatureFlags();
const flags = data?.flags || {};

Expand All @@ -42,6 +48,7 @@ function KustomizationDetail({ kustomization, className, customTabs }: Props) {
className={className}
customTabs={customTabs}
automation={kustomization}
customActions={customActions}
info={[
[
"Source",
Expand Down
9 changes: 8 additions & 1 deletion ui/components/OCIRepositoryDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import Interval from "./Interval";
import Link from "./Link";
import SourceDetail from "./SourceDetail";
import Timestamp from "./Timestamp";

type Props = {
className?: string;
ociRepository: OCIRepository;
customActions?: JSX.Element[];
};

function OCIRepositoryDetail({ className, ociRepository }: Props) {
function OCIRepositoryDetail({
className,
ociRepository,
customActions,
}: Props) {
const { data } = useFeatureFlags();
const flags = data?.flags || {};

Expand All @@ -31,6 +37,7 @@ function OCIRepositoryDetail({ className, ociRepository }: Props) {
className={className}
type={Kind.OCIRepository}
source={ociRepository}
customActions={customActions}
info={[
["Type", Kind.OCIRepository],
["URL", <Link href={ociRepository.url}>{ociRepository.url}</Link>],
Expand Down
5 changes: 4 additions & 1 deletion ui/components/SourceDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { HelmRelease, Source } from "../lib/objects";
import { getSourceRefForAutomation } from "../lib/utils";
import AutomationsTable from "./AutomationsTable";
import Button from "./Button";
import CustomActions from "./CustomActions";
import EventsTable from "./EventsTable";
import Flex from "./Flex";
import InfoList, { InfoField } from "./InfoList";
Expand All @@ -27,9 +28,10 @@ type Props = {
children?: JSX.Element;
source: Source;
info: InfoField[];
customActions?: JSX.Element[];
};

function SourceDetail({ className, source, info, type }: Props) {
function SourceDetail({ className, source, info, type, customActions }: Props) {
const { data: automations, isLoading: automationsLoading } =
useListAutomations();
const { path } = useRouteMatch();
Expand Down Expand Up @@ -107,6 +109,7 @@ function SourceDetail({ className, source, info, type }: Props) {
>
{source?.suspended ? "Resume" : "Suspend"}
</Button>
<CustomActions actions={customActions} />
</Flex>

<SubRouterTabs rootPath={`${path}/details`}>
Expand Down

0 comments on commit 3cb0ee0

Please sign in to comment.