Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support navigation back to feature list page by link #577

Merged
merged 8 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions ui/src/components/featureList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import { Link, useNavigate, useSearchParams } from "react-router-dom";
import { DownOutlined } from "@ant-design/icons";
import {
Button,
Expand All @@ -14,7 +14,12 @@ import {
import { Feature } from "../models/model";
import { fetchProjects, fetchFeatures } from "../api";

const FeatureList = () => {
type Props = {
preProject: string;
preKeyword: string;
blrchen marked this conversation as resolved.
Show resolved Hide resolved
};

const FeatureList = ({ preProject, preKeyword }: Props) => {
const navigate = useNavigate();
const columns = [
{
Expand Down Expand Up @@ -171,9 +176,10 @@ const FeatureList = () => {
const [page, setPage] = useState(1);
const [loading, setLoading] = useState(false);
const [tableData, setTableData] = useState<Feature[]>();
const [query, setQuery] = useState<string>("");
const [query, setQuery] = useState<string>(preKeyword);
const [projects, setProjects] = useState<any>([]);
const [project, setProject] = useState<string>("");
const [project, setProject] = useState<string>(preProject);
const [, setURLSearchParams] = useSearchParams();

const fetchData = useCallback(
async (project) => {
Expand All @@ -182,8 +188,12 @@ const FeatureList = () => {
setPage(page);
setTableData(result);
setLoading(false);
setURLSearchParams({
project: project,
keyword: query,
});
},
[page, query]
[page, query, setURLSearchParams]
);

const loadProjects = useCallback(async () => {
Expand All @@ -196,6 +206,12 @@ const FeatureList = () => {
loadProjects();
}, [loadProjects]);

useEffect(() => {
if (preProject) {
fetchData(preProject);
}
}, [preProject, fetchData]);

const onProjectChange = async (value: string) => {
setProject(value);
fetchData(value);
Expand Down Expand Up @@ -233,6 +249,7 @@ const FeatureList = () => {
></Select>
</Form.Item>
<Input
value={query}
placeholder="keyword"
style={{ width: "10%", marginLeft: "5px" }}
onChange={(e) => onKeywordChange(e.target.value)}
Expand Down
3 changes: 3 additions & 0 deletions ui/src/pages/feature/featureDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ const FeatureDetails = () => {
} else {
return (
<>
<Button type="link" onClick={() => navigate(-1)}>
feature list {">"}
</Button>
<Card>
<Title level={3}>{data.attributes.name}</Title>
<div>
Expand Down
8 changes: 5 additions & 3 deletions ui/src/pages/feature/features.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import { Button, Card, Space, Typography } from "antd";
import { useNavigate } from "react-router-dom";
import { useNavigate, useSearchParams } from "react-router-dom";
import FeatureList from "../../components/featureList";

const { Title } = Typography;
Expand All @@ -10,6 +9,9 @@ const Features = () => {
const onCreateFeatureClick = () => {
navigate("/new-feature");
};
const [searchParams] = useSearchParams();
const preProject = (searchParams.get("project") as string) ?? "";
blrchen marked this conversation as resolved.
Show resolved Hide resolved
const preKeyword = (searchParams.get("keyword") as string) ?? "";

return (
<div className="page">
Expand All @@ -28,7 +30,7 @@ const Features = () => {
+ Create Feature
</Button>
</Space>
<FeatureList />
<FeatureList preProject={preProject} preKeyword={preKeyword} />
</Card>
</div>
);
Expand Down