| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import React, { Component, useContext, useEffect } from "react";
- import styled from "styled-components";
- import { Context } from "shared/Context";
- import ResourceTab from "./ResourceTab";
- import SaveButton from "./SaveButton";
- import { baseApi } from "shared/baseApi";
- import { readableDate } from "shared/string_utils";
- type Props = {
- resource: any;
- button: any;
- handleClick?: () => void;
- selected?: boolean;
- isLast?: boolean;
- roundAllCorners?: boolean;
- };
- const ExpandableResource: React.FC<Props> = (props) => {
- const { resource, button } = props;
- const { currentCluster, currentProject } = useContext(Context);
- const onSave = () => {
- const projID = currentProject.id;
- const clusterID = currentCluster.id;
- const config = button.actions[0].delete.context.config;
- // TODO: construct the endpoint scope, right now we're just using release scope
- const uri = `/api/projects/${projID}/clusters/${clusterID}/namespaces/${resource.metadata.namespace}${button.actions[0].delete.relative_uri}`;
- // compute the endpoint using button and target context
- baseApi<
- {
- name: string;
- namespace: string;
- group: string;
- version: string;
- resource: string;
- },
- {}
- >("DELETE", uri)(
- "<token>",
- {
- name: resource.metadata.name,
- namespace: resource.metadata.namespace,
- group: config.group,
- version: config.version,
- resource: config.resource,
- },
- {}
- )
- .then((res) => {})
- .catch((err) => { console.log(err); });
- };
- return (
- <ResourceTab
- label={resource.label}
- name={resource.name}
- status={{ label: resource.status }}
- >
- <ExpandedWrapper>
- <StatusSection>
- <StatusHeader>
- <Status>
- <Key>Status:</Key> {resource.status}
- </Status>
- <Timestamp>Updated {readableDate(resource.timestamp)}</Timestamp>
- </StatusHeader>
- {resource.message}
- </StatusSection>
- {Object.keys(resource.data).map((key: string, i: number) => {
- return (
- <Pair key={i}>
- <Key>{key}:</Key>
- {resource.data[key]}
- </Pair>
- );
- })}
- {button && (
- <StyledSaveButton
- onClick={onSave}
- clearPosition={true}
- text={button.name}
- helper={button.description}
- statusPosition={"right"}
- className="expanded-save-button"
- />
- )}
- </ExpandedWrapper>
- </ResourceTab>
- );
- };
- export default ExpandableResource;
- const Timestamp = styled.div`
- font-size: 12px;
- color: #ffffff44;
- `;
- const StatusHeader = styled.div`
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 20px;
- `;
- const Status = styled.div`
- display: flex;
- align-items: center;
- color: #aaaabb;
- `;
- const StatusSection = styled.div`
- border-radius: 8px;
- background: #ffffff11;
- font-size: 13px;
- padding: 20px 20px 25px;
- `;
- const ExpandedWrapper = styled.div`
- padding: 20px 20px 25px;
- `;
- const Pair = styled.div`
- margin-top: 20px;
- font-size: 13px;
- padding: 0 5px;
- color: #aaaabb;
- display: flex;
- align-items: center;
- `;
- const Key = styled.div`
- font-weight: bold;
- color: #ffffff;
- margin-right: 8px;
- `;
- const StyledSaveButton = styled(SaveButton)`
- margin-top: 20px;
- `;
|