ExpandableResource.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import React, { Component, useContext, useEffect } from "react";
  2. import styled from "styled-components";
  3. import { Context } from "shared/Context";
  4. import ResourceTab from "./ResourceTab";
  5. import SaveButton from "./SaveButton";
  6. import { baseApi } from "shared/baseApi";
  7. import { readableDate } from "shared/string_utils";
  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) => { console.log(err); });
  48. };
  49. return (
  50. <ResourceTab
  51. label={resource.label}
  52. name={resource.name}
  53. status={{ label: resource.status }}
  54. >
  55. <ExpandedWrapper>
  56. <StatusSection>
  57. <StatusHeader>
  58. <Status>
  59. <Key>Status:</Key> {resource.status}
  60. </Status>
  61. <Timestamp>Updated {readableDate(resource.timestamp)}</Timestamp>
  62. </StatusHeader>
  63. {resource.message}
  64. </StatusSection>
  65. {Object.keys(resource.data).map((key: string, i: number) => {
  66. return (
  67. <Pair key={i}>
  68. <Key>{key}:</Key>
  69. {resource.data[key]}
  70. </Pair>
  71. );
  72. })}
  73. {button && (
  74. <StyledSaveButton
  75. onClick={onSave}
  76. clearPosition={true}
  77. text={button.name}
  78. helper={button.description}
  79. statusPosition={"right"}
  80. className="expanded-save-button"
  81. />
  82. )}
  83. </ExpandedWrapper>
  84. </ResourceTab>
  85. );
  86. };
  87. export default ExpandableResource;
  88. const Timestamp = styled.div`
  89. font-size: 12px;
  90. color: #ffffff44;
  91. `;
  92. const StatusHeader = styled.div`
  93. display: flex;
  94. align-items: center;
  95. justify-content: space-between;
  96. margin-bottom: 20px;
  97. `;
  98. const Status = styled.div`
  99. display: flex;
  100. align-items: center;
  101. color: #aaaabb;
  102. `;
  103. const StatusSection = styled.div`
  104. border-radius: 8px;
  105. background: #ffffff11;
  106. font-size: 13px;
  107. padding: 20px 20px 25px;
  108. `;
  109. const ExpandedWrapper = styled.div`
  110. padding: 20px 20px 25px;
  111. `;
  112. const Pair = styled.div`
  113. margin-top: 20px;
  114. font-size: 13px;
  115. padding: 0 5px;
  116. color: #aaaabb;
  117. display: flex;
  118. align-items: center;
  119. `;
  120. const Key = styled.div`
  121. font-weight: bold;
  122. color: #ffffff;
  123. margin-right: 8px;
  124. `;
  125. const StyledSaveButton = styled(SaveButton)`
  126. margin-top: 20px;
  127. `;