ExpandableResource.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import React, { Component, useContext, useEffect } from "react";
  2. import styled from "styled-components";
  3. import { baseApi } from "shared/baseApi";
  4. import { Context } from "shared/Context";
  5. import { readableDate } from "shared/string_utils";
  6. import ResourceTab from "./ResourceTab";
  7. import SaveButton from "./SaveButton";
  8. type Props = {
  9. resource: any;
  10. button: any;
  11. handleClick?: () => void;
  12. selected?: boolean;
  13. isLast?: boolean;
  14. roundAllCorners?: boolean;
  15. };
  16. const ExpandableResource: React.FC<Props> = (props) => {
  17. const { resource, button } = props;
  18. const { currentCluster, currentProject } = useContext(Context);
  19. const onSave = () => {
  20. const projID = currentProject.id;
  21. const clusterID = currentCluster.id;
  22. const config = button.actions[0].delete.context.config;
  23. // TODO: construct the endpoint scope, right now we're just using release scope
  24. const uri = `/api/projects/${projID}/clusters/${clusterID}/namespaces/${resource.metadata.namespace}${button.actions[0].delete.relative_uri}`;
  25. // compute the endpoint using button and target context
  26. baseApi<
  27. {
  28. name: string;
  29. namespace: string;
  30. group: string;
  31. version: string;
  32. resource: string;
  33. },
  34. {}
  35. >("DELETE", uri)(
  36. "<token>",
  37. {
  38. name: resource.metadata.name,
  39. namespace: resource.metadata.namespace,
  40. group: config.group,
  41. version: config.version,
  42. resource: config.resource,
  43. },
  44. {}
  45. )
  46. .then((res) => {})
  47. .catch((err) => {
  48. console.log(err);
  49. });
  50. };
  51. return (
  52. <ResourceTab
  53. label={resource.label}
  54. name={resource.name}
  55. status={{ label: resource.status }}
  56. >
  57. <ExpandedWrapper>
  58. <StatusSection>
  59. <StatusHeader>
  60. <Status>
  61. <Key>Status:</Key> {resource.status}
  62. </Status>
  63. <Timestamp>Updated {readableDate(resource.timestamp)}</Timestamp>
  64. </StatusHeader>
  65. {resource.message}
  66. </StatusSection>
  67. {Object.keys(resource.data).map((key: string, i: number) => {
  68. return (
  69. <Pair key={i}>
  70. <Key>{key}:</Key>
  71. {resource.data[key]}
  72. </Pair>
  73. );
  74. })}
  75. {button && (
  76. <StyledSaveButton
  77. onClick={onSave}
  78. clearPosition={true}
  79. text={button.name}
  80. helper={button.description}
  81. statusPosition={"right"}
  82. className="expanded-save-button"
  83. />
  84. )}
  85. </ExpandedWrapper>
  86. </ResourceTab>
  87. );
  88. };
  89. export default ExpandableResource;
  90. const Timestamp = styled.div`
  91. font-size: 12px;
  92. color: #ffffff44;
  93. `;
  94. const StatusHeader = styled.div`
  95. display: flex;
  96. align-items: center;
  97. justify-content: space-between;
  98. margin-bottom: 20px;
  99. `;
  100. const Status = styled.div`
  101. display: flex;
  102. align-items: center;
  103. color: #aaaabb;
  104. `;
  105. const StatusSection = styled.div`
  106. border-radius: 8px;
  107. background: #ffffff11;
  108. font-size: 13px;
  109. padding: 20px 20px 25px;
  110. `;
  111. const ExpandedWrapper = styled.div`
  112. padding: 20px 20px 25px;
  113. `;
  114. const Pair = styled.div`
  115. margin-top: 20px;
  116. font-size: 13px;
  117. padding: 0 5px;
  118. color: #aaaabb;
  119. display: flex;
  120. align-items: center;
  121. `;
  122. const Key = styled.div`
  123. font-weight: bold;
  124. color: #ffffff;
  125. margin-right: 8px;
  126. `;
  127. const StyledSaveButton = styled(SaveButton)`
  128. margin-top: 20px;
  129. `;