|
@@ -7,8 +7,10 @@ import { ClusterType } from "shared/types";
|
|
|
|
|
|
|
|
import EnvGroup from "./EnvGroup";
|
|
import EnvGroup from "./EnvGroup";
|
|
|
import Loading from "components/Loading";
|
|
import Loading from "components/Loading";
|
|
|
|
|
+import { getQueryParam, pushQueryParams } from "shared/routing";
|
|
|
|
|
+import { RouteComponentProps, withRouter } from "react-router";
|
|
|
|
|
|
|
|
-type PropsType = {
|
|
|
|
|
|
|
+type PropsType = RouteComponentProps & {
|
|
|
currentCluster: ClusterType;
|
|
currentCluster: ClusterType;
|
|
|
namespace: string;
|
|
namespace: string;
|
|
|
sortType: string;
|
|
sortType: string;
|
|
@@ -27,51 +29,70 @@ const dummyEnvGroups = [
|
|
|
{ name: "backend-production", last_updated: "7", namespace: "default" },
|
|
{ name: "backend-production", last_updated: "7", namespace: "default" },
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
-export default class EnvGroupList extends Component<PropsType, StateType> {
|
|
|
|
|
|
|
+class EnvGroupList extends Component<PropsType, StateType> {
|
|
|
state = {
|
|
state = {
|
|
|
envGroups: [] as any[],
|
|
envGroups: [] as any[],
|
|
|
loading: false,
|
|
loading: false,
|
|
|
error: false,
|
|
error: false,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- updateEnvGroups = () => {
|
|
|
|
|
- api
|
|
|
|
|
- .listEnvGroups(
|
|
|
|
|
- "<token>",
|
|
|
|
|
- {},
|
|
|
|
|
- {
|
|
|
|
|
- id: this.context.currentProject.id,
|
|
|
|
|
- namespace: this.props.namespace,
|
|
|
|
|
- cluster_id: this.props.currentCluster.id,
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- .then((res) => {
|
|
|
|
|
- let sortedGroups = res?.data;
|
|
|
|
|
- switch (this.props.sortType) {
|
|
|
|
|
- case "Oldest":
|
|
|
|
|
- sortedGroups.sort((a: any, b: any) =>
|
|
|
|
|
- Date.parse(a.created_at) > Date.parse(b.created_at) ? 1 : -1
|
|
|
|
|
- );
|
|
|
|
|
- break;
|
|
|
|
|
- case "Alphabetical":
|
|
|
|
|
- sortedGroups.sort((a: any, b: any) => (a.name > b.name ? 1 : -1));
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- sortedGroups.sort((a: any, b: any) =>
|
|
|
|
|
- Date.parse(a.created_at) > Date.parse(b.created_at) ? -1 : 1
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- this.setState({ envGroups: sortedGroups, loading: false });
|
|
|
|
|
- })
|
|
|
|
|
- .catch((err) => {
|
|
|
|
|
- console.log(err);
|
|
|
|
|
- this.setState({ loading: false, error: true });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ updateEnvGroups = async () => {
|
|
|
|
|
+ const { currentCluster, namespace, sortType } = this.props;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const envGroups = await api
|
|
|
|
|
+ .listEnvGroups(
|
|
|
|
|
+ "<token>",
|
|
|
|
|
+ {},
|
|
|
|
|
+ {
|
|
|
|
|
+ id: this.context.currentProject.id,
|
|
|
|
|
+ namespace: this.props.namespace,
|
|
|
|
|
+ cluster_id: this.props.currentCluster.id,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ .then((res) => res.data);
|
|
|
|
|
+
|
|
|
|
|
+ let sortedGroups = envGroups;
|
|
|
|
|
+ switch (this.props.sortType) {
|
|
|
|
|
+ case "Oldest":
|
|
|
|
|
+ sortedGroups.sort((a: any, b: any) =>
|
|
|
|
|
+ Date.parse(a.created_at) > Date.parse(b.created_at) ? 1 : -1
|
|
|
|
|
+ );
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "Alphabetical":
|
|
|
|
|
+ sortedGroups.sort((a: any, b: any) => (a.name > b.name ? 1 : -1));
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ sortedGroups.sort((a: any, b: any) =>
|
|
|
|
|
+ Date.parse(a.created_at) > Date.parse(b.created_at) ? -1 : 1
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return sortedGroups;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.log(error);
|
|
|
|
|
+ this.setState({ loading: false, error: true });
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
this.setState({ loading: true });
|
|
this.setState({ loading: true });
|
|
|
- this.updateEnvGroups();
|
|
|
|
|
|
|
+ this.updateEnvGroups().then((envGroups) => {
|
|
|
|
|
+ const selectedEnvGroup = getQueryParam(this.props, "selected_env_group");
|
|
|
|
|
+
|
|
|
|
|
+ if (selectedEnvGroup) {
|
|
|
|
|
+ // find env group by selectedEnvGroup
|
|
|
|
|
+ const envGroup = envGroups.find(
|
|
|
|
|
+ (envGroup: any) => envGroup.name === selectedEnvGroup
|
|
|
|
|
+ );
|
|
|
|
|
+ if (envGroup) {
|
|
|
|
|
+ this.props.setExpandedEnvGroup(envGroup);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pushQueryParams(this.props, {}, ["selected_env_group"]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ this.setState({ envGroups, loading: false });
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps: PropsType) {
|
|
componentDidUpdate(prevProps: PropsType) {
|
|
@@ -82,10 +103,32 @@ export default class EnvGroupList extends Component<PropsType, StateType> {
|
|
|
prevProps.sortType !== this.props.sortType
|
|
prevProps.sortType !== this.props.sortType
|
|
|
) {
|
|
) {
|
|
|
(this.props.namespace || this.props.namespace === "") &&
|
|
(this.props.namespace || this.props.namespace === "") &&
|
|
|
- this.updateEnvGroups();
|
|
|
|
|
|
|
+ this.updateEnvGroups().then((envGroups) => {
|
|
|
|
|
+ const selectedEnvGroup = getQueryParam(
|
|
|
|
|
+ this.props,
|
|
|
|
|
+ "selected_env_group"
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ this.setState({ envGroups, loading: false });
|
|
|
|
|
+
|
|
|
|
|
+ if (selectedEnvGroup) {
|
|
|
|
|
+ // find env group by selectedEnvGroup
|
|
|
|
|
+ const envGroup = envGroups.find(
|
|
|
|
|
+ (envGroup: any) => envGroup.name === selectedEnvGroup
|
|
|
|
|
+ );
|
|
|
|
|
+ if (envGroup) {
|
|
|
|
|
+ this.props.setExpandedEnvGroup(envGroup);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ handleExpand = (envGroup: any) => {
|
|
|
|
|
+ pushQueryParams(this.props, { selected_env_group: envGroup.name }, []);
|
|
|
|
|
+ this.props.setExpandedEnvGroup(envGroup);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
renderEnvGroupList = () => {
|
|
renderEnvGroupList = () => {
|
|
|
let { loading, error, envGroups } = this.state;
|
|
let { loading, error, envGroups } = this.state;
|
|
|
|
|
|
|
@@ -115,7 +158,7 @@ export default class EnvGroupList extends Component<PropsType, StateType> {
|
|
|
<EnvGroup
|
|
<EnvGroup
|
|
|
key={i}
|
|
key={i}
|
|
|
envGroup={envGroup}
|
|
envGroup={envGroup}
|
|
|
- setExpanded={() => this.props.setExpandedEnvGroup(envGroup)}
|
|
|
|
|
|
|
+ setExpanded={() => this.handleExpand(envGroup)}
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
@@ -128,6 +171,8 @@ export default class EnvGroupList extends Component<PropsType, StateType> {
|
|
|
|
|
|
|
|
EnvGroupList.contextType = Context;
|
|
EnvGroupList.contextType = Context;
|
|
|
|
|
|
|
|
|
|
+export default withRouter(EnvGroupList);
|
|
|
|
|
+
|
|
|
const Placeholder = styled.div`
|
|
const Placeholder = styled.div`
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
display: flex;
|
|
display: flex;
|