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

Sent status request to the backend #1066

Merged
merged 7 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
79 changes: 73 additions & 6 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,21 +437,54 @@ func (db database) GetUserBountiesCount(personKey string, tabType string) int64
return count
}

func (db database) GetBountiesCount() int64 {
func (db database) GetBountiesCount(r *http.Request) int64 {
keys := r.URL.Query()
open := keys.Get("Open")
assingned := keys.Get("Assigned")
paid := keys.Get("Paid")
openQuery := ""
assignedQuery := ""
paidQuery := ""

if open != "" && open == "true" {
openQuery = "AND assignee = ''"
assignedQuery = ""
}
if assingned != "" && assingned == "true" {
if open != "" && open == "true" {
assignedQuery = "OR assignee != ''"
} else {
assignedQuery = "AND assignee != ''"
}
}
if paid != "" && paid == "true" {
paidQuery = "AND paid = true"
}

var count int64
db.db.Model(&Bounty{}).Where("show != ?", false).Count(&count)

query := "SELECT COUNT(*) FROM bounty WHERE show != false"
allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery
db.db.Raw(allQuery).Scan(&count)
return count
}

func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []Bounty {
keys := r.URL.Query()
tags := keys.Get("tags") // this is a string of tags separated by commas
offset, limit, sortBy, direction, search := utils.GetPaginationParams(r)
open := keys.Get("Open")
assingned := keys.Get("Assigned")
paid := keys.Get("Paid")
ms := []Bounty{}

orderQuery := ""
limitQuery := ""
searchQuery := ""
openQuery := ""
assignedQuery := ""
paidQuery := ""

if sortBy != "" && direction != "" {
orderQuery = "ORDER BY " + sortBy + " " + direction
} else {
Expand All @@ -463,10 +496,24 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B
if search != "" {
searchQuery = fmt.Sprintf("WHERE LOWER(title) LIKE %s", "'%"+search+"%'")
}
if open != "" && open == "true" {
openQuery = "AND assignee = ''"
assignedQuery = ""
}
if assingned != "" && assingned == "true" {
if open != "" && open == "true" {
assignedQuery = "OR assignee != ''"
} else {
assignedQuery = "AND assignee != ''"
}
}
if paid != "" && paid == "true" {
paidQuery = "AND paid = true"
}

rawQuery := `SELECT * FROM bounty WHERE org_uuid = '` + org_uuid + `'`

theQuery := db.db.Raw(rawQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery)
query := `SELECT * FROM bounty WHERE org_uuid = '` + org_uuid + `'`
allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery
theQuery := db.db.Raw(allQuery)

if tags != "" {
// pull out the tags and add them in here
Expand Down Expand Up @@ -514,12 +561,18 @@ func (db database) GetAllBounties(r *http.Request) []Bounty {
keys := r.URL.Query()
tags := keys.Get("tags") // this is a string of tags separated by commas
offset, limit, sortBy, direction, search := utils.GetPaginationParams(r)
open := keys.Get("Open")
assingned := keys.Get("Assigned")
paid := keys.Get("Paid")

ms := []Bounty{}

orderQuery := ""
limitQuery := ""
searchQuery := ""
openQuery := ""
assignedQuery := ""
paidQuery := ""

if sortBy != "" && direction != "" {
orderQuery = "ORDER BY " + sortBy + " " + direction
Expand All @@ -532,10 +585,24 @@ func (db database) GetAllBounties(r *http.Request) []Bounty {
if search != "" {
searchQuery = fmt.Sprintf("AND LOWER(title) LIKE %s", "'%"+search+"%'")
}
if open != "" && open == "true" {
openQuery = "AND assignee = ''"
assignedQuery = ""
}
if assingned != "" && assingned == "true" {
if open != "" && open == "true" {
assignedQuery = "OR assignee != ''"
} else {
assignedQuery = "AND assignee != ''"
}
}
if paid != "" && paid == "true" {
paidQuery = "AND paid = true"
}

query := "SELECT * FROM public.bounty WHERE show != false"

allQuery := query + " " + searchQuery + " " + orderQuery + " " + limitQuery
allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery

theQuery := db.db.Raw(allQuery)

Expand Down
2 changes: 0 additions & 2 deletions db/db_codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ func TestCodeGet(t *testing.T) {
defer db.Close()

gorm.Open("postgres", db)

rows := sqlmock.NewRows([]string{"connection_string", "date_created", "is_used", "date_created"}).AddRow(code.ID, code.ConnectionString, code.IsUsed, code.DateCreated)

mock.ExpectQuery(regexp.QuoteMeta(
`SELECT connection_string, date_created FROM connectioncodes WHERE is_used = ? ORDER BY id DESC LIMIT 1`)).
WithArgs(false).
Expand Down
6 changes: 0 additions & 6 deletions db/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ func TestSetCache(t *testing.T) {
var value = "Trial"

InitCache()

Store.SetCache(key, value)

cacheValue, err := Store.GetCache(key)

if err != nil {
Expand All @@ -30,7 +28,6 @@ func TestDeleteCache(t *testing.T) {
InitCache()

Store.SetCache(key, value)

cacheValue, err := Store.GetCache(key)

if err != nil {
Expand All @@ -42,7 +39,6 @@ func TestDeleteCache(t *testing.T) {
}

Store.DeleteCache(key)

_, errD := Store.GetCache(key)

if errD == nil {
Expand All @@ -60,9 +56,7 @@ func TestSetLnCache(t *testing.T) {
}

InitCache()

Store.SetLnCache(key, value)

cacheValue, err := Store.GetLnCache(key)

if err != nil {
Expand Down
1 change: 0 additions & 1 deletion frontend/app/src/pages/tickets/TicketModalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const TicketModalPage = observer(({ setConnectPerson }: Props) => {
const [isDeleted, setisDeleted] = useState(false);

const isMobile = useIsMobile();
const { uuid } = useParams<{ uuid: string }>();

const search = useMemo(() => {
const s = new URLSearchParams(location.search);
Expand Down
47 changes: 42 additions & 5 deletions frontend/app/src/pages/tickets/Tickets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@ import { observer } from 'mobx-react-lite';
import FirstTimeScreen from 'people/main/FirstTimeScreen';
import BountyHeader from 'people/widgetViews/BountyHeader';
import WidgetSwitchViewer from 'people/widgetViews/WidgetSwitchViewer';
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { useHistory } from 'react-router';
import { queryLimit } from 'store/main';
import { colors } from '../../config/colors';
import { useIsMobile } from '../../hooks';
import { useStores } from '../../store';
import { Body, Backdrop } from './style';

// avoid hook within callback warning by renaming hooks

function BodyComponent() {
const { main, ui } = useStores();
const [loading, setLoading] = useState(true);
const [showDropdown, setShowDropdown] = useState(false);
const selectedWidget = 'wanted';
const [scrollValue, setScrollValue] = useState<boolean>(false);
const [checkboxIdToSelectedMap, setCheckboxIdToSelectedMap] = useState({});
const [checkboxIdToSelectedMap, setCheckboxIdToSelectedMap] = useState({
Open: true,
Assigned: false,
Paid: false
});
const [checkboxIdToSelectedMapLanguage, setCheckboxIdToSelectedMapLanguage] = useState({});
const [page, setPage] = useState<number>(1);
const [currentItems, setCurrentItems] = useState<number>(queryLimit);
const [totalBounties, setTotalBounties] = useState(0);

const color = colors['light'];

Expand All @@ -31,10 +38,10 @@ function BodyComponent() {
await main.getOpenGithubIssues();
await main.getBadgeList();
await main.getPeople();
await main.getPeopleBounties({ page: 1, resetPage: true });
await main.getPeopleBounties({ page: 1, resetPage: true, ...checkboxIdToSelectedMap });
setLoading(false);
})();
}, [main]);
}, [main, checkboxIdToSelectedMap]);

useEffect(() => {
setCheckboxIdToSelectedMap({
Expand All @@ -50,6 +57,22 @@ function BodyComponent() {
}
}, [main, ui.meInfo]);

const getTotalBounties = useCallback(
async (statusData: any) => {
const totalBounties = await main.getTotalBountyCount(
statusData.Open,
statusData.Assigned,
statusData.Paid
);
setTotalBounties(totalBounties);
},
[main]
);

useEffect(() => {
getTotalBounties(checkboxIdToSelectedMap);
}, [getTotalBounties]);

const onChangeStatus = (optionId: any) => {
const newCheckboxIdToSelectedMap = {
...checkboxIdToSelectedMap,
Expand All @@ -58,6 +81,10 @@ function BodyComponent() {
}
};
setCheckboxIdToSelectedMap(newCheckboxIdToSelectedMap);
getTotalBounties(newCheckboxIdToSelectedMap);
// set data to default
setCurrentItems(queryLimit);
setPage(1);
};

const onChangeLanguage = (optionId: any) => {
Expand Down Expand Up @@ -129,6 +156,11 @@ function BodyComponent() {
fromBountyPage={true}
selectedWidget={selectedWidget}
loading={loading}
totalBounties={totalBounties}
currentItems={currentItems}
setCurrentItems={setCurrentItems}
page={page}
setPage={setPage}
/>
</div>

Expand Down Expand Up @@ -191,6 +223,11 @@ function BodyComponent() {
fromBountyPage={true}
selectedWidget={selectedWidget}
loading={loading}
totalBounties={totalBounties}
currentItems={currentItems}
setCurrentItems={setCurrentItems}
page={page}
setPage={setPage}
/>
</div>
</div>
Expand Down
Loading
Loading