Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

refactoring: expose post status as string (#540)

Guilherme Oenning932cd5f7aa90
diff --git a/app/handlers/apiv1/post_test.go b/app/handlers/apiv1/post_test.go
index 098a26e1c..d5f4dd5fb 100644
--- a/app/handlers/apiv1/post_test.go
+++ b/app/handlers/apiv1/post_test.go
@@ -142,7 +142,7 @@ func TestSetResponseHandler(t *testing.T) {
OnTenant(mock.DemoTenant).
AsUser(mock.JonSnow).
AddParam("number", post.ID).
- ExecutePost(apiv1.SetResponse(), fmt.Sprintf(`{ "status": %d, "text": "Done!" }`, models.PostCompleted))
+ ExecutePost(apiv1.SetResponse(), fmt.Sprintf(`{ "status": "%s", "text": "Done!" }`, models.PostCompleted.Name()))
post, _ = services.Posts.GetByNumber(post.Number)
@@ -165,7 +165,7 @@ func TestSetResponseHandler_Unauthorized(t *testing.T) {
OnTenant(mock.DemoTenant).
AsUser(mock.AryaStark).
AddParam("number", post.ID).
- ExecutePost(apiv1.SetResponse(), fmt.Sprintf(`{ "status": %d, "text": "Done!" }`, models.PostCompleted))
+ ExecutePost(apiv1.SetResponse(), fmt.Sprintf(`{ "status": "%s", "text": "Done!" }`, models.PostCompleted.Name()))
post, _ = services.Posts.GetByNumber(post.Number)
@@ -182,7 +182,7 @@ func TestSetResponseHandler_Duplicate(t *testing.T) {
post1, _ := services.Posts.Add("The Post #1", "The Description #1")
post2, _ := services.Posts.Add("The Post #2", "The Description #2")
- body := fmt.Sprintf(`{ "status": %d, "originalNumber": %d }`, models.PostDuplicate, post2.Number)
+ body := fmt.Sprintf(`{ "status": "%s", "originalNumber": %d }`, models.PostDuplicate.Name(), post2.Number)
code, _ := server.
OnTenant(mock.DemoTenant).
AsUser(mock.JonSnow).
@@ -205,7 +205,7 @@ func TestSetResponseHandler_Duplicate_NotFound(t *testing.T) {
services.SetCurrentUser(mock.AryaStark)
post1, _ := services.Posts.Add("The Post #1", "The Description #1")
- body := fmt.Sprintf(`{ "status": %d, "originalNumber": 9999 }`, models.PostDuplicate)
+ body := fmt.Sprintf(`{ "status": "%s", "originalNumber": 9999 }`, models.PostDuplicate.Name())
code, _ := server.
OnTenant(mock.DemoTenant).
AsUser(mock.JonSnow).
@@ -223,7 +223,7 @@ func TestSetResponseHandler_Duplicate_Itself(t *testing.T) {
services.SetCurrentUser(mock.AryaStark)
post, _ := services.Posts.Add("The Post #1", "The Description #1")
- body := fmt.Sprintf(`{ "status": %d, "originalNumber": %d }`, models.PostDuplicate, post.Number)
+ body := fmt.Sprintf(`{ "status": "%s", "originalNumber": %d }`, models.PostDuplicate.Name(), post.Number)
code, _ := server.
OnTenant(mock.DemoTenant).
AsUser(mock.JonSnow).
diff --git a/app/models/feedback.go b/app/models/feedback.go
index 5663e436d..ec4d5d774 100644
--- a/app/models/feedback.go
+++ b/app/models/feedback.go
@@ -17,8 +17,8 @@ type Post struct {
HasVoted bool `json:"hasVoted"`
TotalVotes int `json:"totalVotes"`
TotalComments int `json:"totalComments"`
- Status int `json:"status"`
- Response *PostResponse `json:"response"`
+ Status PostStatus `json:"status"`
+ Response *PostResponse `json:"response,omitempty"`
Tags []string `json:"tags"`
}
@@ -61,10 +61,10 @@ type EditComment struct {
// SetResponse represents the action to update an post response
type SetResponse struct {
- Number int `route:"number"`
- Status int `json:"status"`
- Text string `json:"text"`
- OriginalNumber int `json:"originalNumber"`
+ Number int `route:"number"`
+ Status PostStatus `json:"status"`
+ Text string `json:"text"`
+ OriginalNumber int `json:"originalNumber"`
}
//PostResponse is a staff response to a given post
@@ -77,10 +77,10 @@ type PostResponse struct {
//OriginalPost holds details of the original post of a duplicate
type OriginalPost struct {
- Number int `json:"number"`
- Title string `json:"title"`
- Slug string `json:"slug"`
- Status int `json:"status"`
+ Number int `json:"number"`
+ Title string `json:"title"`
+ Slug string `json:"slug"`
+ Status PostStatus `json:"status"`
}
//Comment represents an user comment on an post
@@ -121,43 +121,63 @@ type AssignUnassignTag struct {
Number int `route:"number"`
}
+//PostStatus is the status of a given post
+type PostStatus int
+
var (
//PostOpen is the default status
- PostOpen = 0
+ PostOpen PostStatus
//PostStarted is used when the post has been accepted and work is in progress
- PostStarted = 1
+ PostStarted PostStatus = 1
//PostCompleted is used when the post has been accepted and already implemented
- PostCompleted = 2
+ PostCompleted PostStatus = 2
//PostDeclined is used when organizers decide to decline an post
- PostDeclined = 3
+ PostDeclined PostStatus = 3
//PostPlanned is used when organizers have accepted an post and it's on the roadmap
- PostPlanned = 4
+ PostPlanned PostStatus = 4
//PostDuplicate is used when the post has already been posted before
- PostDuplicate = 5
+ PostDuplicate PostStatus = 5
//PostDeleted is used when the post is completely removed from the site and should never be shown again
- PostDeleted = 6
+ PostDeleted PostStatus = 6
)
+var postStatusIDs = map[PostStatus]string{
+ PostOpen: "open",
+ PostStarted: "started",
+ PostCompleted: "completed",
+ PostDeclined: "declined",
+ PostPlanned: "planned",
+ PostDuplicate: "duplicate",
+ PostDeleted: "deleted",
+}
+
+var postStatusNames = map[string]PostStatus{
+ "open": PostOpen,
+ "started": PostStarted,
+ "completed": PostCompleted,
+ "declined": PostDeclined,
+ "planned": PostPlanned,
+ "duplicate": PostDuplicate,
+ "deleted": PostDeleted,
+}
+
+// MarshalText returns the Text version of the post status
+func (status PostStatus) MarshalText() ([]byte, error) {
+ return []byte(postStatusIDs[status]), nil
+}
+
+// UnmarshalText parse string into a post status
+func (status *PostStatus) UnmarshalText(text []byte) error {
+ *status = postStatusNames[string(text)]
+ return nil
+}
-// GetPostStatusName returns the name of a post status
-func GetPostStatusName(status int) string {
- switch status {
- case PostOpen:
- return "Open"
- case PostStarted:
- return "Started"
- case PostCompleted:
- return "Completed"
- case PostDeclined:
- return "Declined"
- case PostPlanned:
- return "Planned"
- case PostDuplicate:
- return "Duplicate"
- case PostDeleted:
- return "Deleted"
- default:
- return "Unknown"
+// Name returns the name of a post status
+func (status PostStatus) Name() string {
+ name, ok := postStatusIDs[status]
+ if ok {
+ return name
}
+ return "Unknown"
}
var (
diff --git a/app/models/identity.go b/app/models/identity.go
index 53b051fc0..c48c77082 100644
--- a/app/models/identity.go
+++ b/app/models/identity.go
@@ -1,7 +1,6 @@
package models
import (
- "fmt"
"time"
"github.com/getfider/fider/app/pkg/jwt"
@@ -78,14 +77,14 @@ var roleNames = map[string]Role{
"administrator": RoleAdministrator,
}
-// MarshalJSON returns the JSON version of the role
-func (role Role) MarshalJSON() ([]byte, error) {
- return []byte(fmt.Sprintf(`"%s"`, roleIDs[role])), nil
+// MarshalText returns the Text version of the post status
+func (role Role) MarshalText() ([]byte, error) {
+ return []byte(roleIDs[role]), nil
}
-// UnmarshalString parse string into a role
-func (role *Role) UnmarshalString(s string) error {
- *role = roleNames[s]
+// UnmarshalText parse string into a post status
+func (role *Role) UnmarshalText(text []byte) error {
+ *role = roleNames[string(text)]
return nil
}
diff --git a/app/pkg/csv/csv.go b/app/pkg/csv/csv.go
index 0eb10721a..f9e00bd4c 100644
--- a/app/pkg/csv/csv.go
+++ b/app/pkg/csv/csv.go
@@ -62,7 +62,7 @@ func FromPosts(posts []*models.Post) ([]byte, error) {
post.User.Name,
strconv.Itoa(post.TotalVotes),
strconv.Itoa(post.TotalComments),
- models.GetPostStatusName(post.Status),
+ post.Status.Name(),
respondedBy,
respondedAt,
response,
diff --git a/app/pkg/csv/testdata/more-posts.csv b/app/pkg/csv/testdata/more-posts.csv
index b789b011d..9a5404a47 100755
--- a/app/pkg/csv/testdata/more-posts.csv
+++ b/app/pkg/csv/testdata/more-posts.csv
@@ -1,4 +1,4 @@
number,title,description,created_at,created_by,total_votes,total_comments,status,responded_by,responded_at,response,original_number,original_title,tags
-10,Go is fast,Very tiny description,2018-03-23T19:33:22Z,Faceless,4,2,Declined,John Snow,2018-04-04T19:48:10Z,Nothing we need to do,,,"easy, ignored"
-15,Go is great,,2018-02-21T15:51:35Z,Someone else,4,2,Open,,,,,,
-20,Go is easy,,2018-01-12T01:46:59Z,Faceless,4,2,Duplicate,Arya Stark,2018-03-17T10:15:42Z,This has already been suggested,99,Go is very easy,"this-tag-has,comma"
+10,Go is fast,Very tiny description,2018-03-23T19:33:22Z,Faceless,4,2,declined,John Snow,2018-04-04T19:48:10Z,Nothing we need to do,,,"easy, ignored"
+15,Go is great,,2018-02-21T15:51:35Z,Someone else,4,2,open,,,,,,
+20,Go is easy,,2018-01-12T01:46:59Z,Faceless,4,2,duplicate,Arya Stark,2018-03-17T10:15:42Z,This has already been suggested,99,Go is very easy,"this-tag-has,comma"
diff --git a/app/pkg/csv/testdata/one-post.csv b/app/pkg/csv/testdata/one-post.csv
index b782067bc..4b1eb5379 100755
--- a/app/pkg/csv/testdata/one-post.csv
+++ b/app/pkg/csv/testdata/one-post.csv
@@ -1,2 +1,2 @@
number,title,description,created_at,created_by,total_votes,total_comments,status,responded_by,responded_at,response,original_number,original_title,tags
-10,Go is fast,Very tiny description,2018-03-23T19:33:22Z,Faceless,4,2,Declined,John Snow,2018-04-04T19:48:10Z,Nothing we need to do,,,"easy, ignored"
+10,Go is fast,Very tiny description,2018-03-23T19:33:22Z,Faceless,4,2,declined,John Snow,2018-04-04T19:48:10Z,Nothing we need to do,,,"easy, ignored"
diff --git a/app/pkg/web/binder.go b/app/pkg/web/binder.go
index 59a097ae6..db3f1fed4 100644
--- a/app/pkg/web/binder.go
+++ b/app/pkg/web/binder.go
@@ -61,9 +61,10 @@ func (b *DefaultBinder) bindRoute(idx int, target reflect.Value, targetType refl
value, err := strconv.ParseInt(params[name], 10, 64)
if err != nil {
obj := reflect.New(field.Type())
- m := obj.MethodByName("UnmarshalString")
+ m := obj.MethodByName("UnmarshalText")
if m.IsValid() {
- r := m.Call([]reflect.Value{reflect.ValueOf(params[name])})
+ b := []byte(params[name])
+ r := m.Call([]reflect.Value{reflect.ValueOf(b)})
if r[0].IsNil() {
field.Set(obj.Elem())
}
diff --git a/app/pkg/web/binder_test.go b/app/pkg/web/binder_test.go
index 5b8d07191..e310f70bb 100644
--- a/app/pkg/web/binder_test.go
+++ b/app/pkg/web/binder_test.go
@@ -195,8 +195,8 @@ type pizza struct {
TheSize64 Size64 `route:"size64"`
}
-func (p *Size) UnmarshalString(s string) error {
- if s == "large" {
+func (p *Size) UnmarshalText(s []byte) error {
+ if string(s) == "large" {
*p = Large
} else {
*p = Small
diff --git a/app/storage/inmemory/post.go b/app/storage/inmemory/post.go
index e7737d3cb..fb9f65cb2 100644
--- a/app/storage/inmemory/post.go
+++ b/app/storage/inmemory/post.go
@@ -84,8 +84,8 @@ func (s *PostStorage) GetAll() ([]*models.Post, error) {
}
// CountPerStatus returns total number of posts per status
-func (s *PostStorage) CountPerStatus() (map[int]int, error) {
- return make(map[int]int, 0), nil
+func (s *PostStorage) CountPerStatus() (map[models.PostStatus]int, error) {
+ return make(map[models.PostStatus]int, 0), nil
}
// Search existing posts based on input
@@ -173,7 +173,7 @@ func (s *PostStorage) RemoveVote(post *models.Post, user *models.User) error {
}
// SetResponse changes current post response
-func (s *PostStorage) SetResponse(post *models.Post, text string, status int) error {
+func (s *PostStorage) SetResponse(post *models.Post, text string, status models.PostStatus) error {
for i, storedPost := range s.posts {
if storedPost.Number == post.Number {
if status == models.PostDeleted {
diff --git a/app/storage/postgres/common.go b/app/storage/postgres/common.go
index 41307ad68..a29b0136b 100644
--- a/app/storage/postgres/common.go
+++ b/app/storage/postgres/common.go
@@ -16,12 +16,12 @@ func ToTSQuery(input string) string {
return strings.Join(strings.Fields(input), "|")
}
-func getFilterData(filter string) (string, []int, string) {
+func getFilterData(filter string) (string, []models.PostStatus, string) {
var (
condition string
sort string
)
- statuses := []int{
+ statuses := []models.PostStatus{
models.PostOpen,
models.PostStarted,
models.PostPlanned,
@@ -38,19 +38,19 @@ func getFilterData(filter string) (string, []int, string) {
sort = "comments"
case "planned":
sort = "response_date"
- statuses = []int{models.PostPlanned}
+ statuses = []models.PostStatus{models.PostPlanned}
case "started":
sort = "response_date"
- statuses = []int{models.PostStarted}
+ statuses = []models.PostStatus{models.PostStarted}
case "completed":
sort = "response_date"
- statuses = []int{models.PostCompleted}
+ statuses = []models.PostStatus{models.PostCompleted}
case "declined":
sort = "response_date"
- statuses = []int{models.PostDeclined}
+ statuses = []models.PostStatus{models.PostDeclined}
case "all":
sort = "id"
- statuses = []int{
+ statuses = []models.PostStatus{
models.PostOpen,
models.PostStarted,
models.PostPlanned,
diff --git a/app/storage/postgres/post.go b/app/storage/postgres/post.go
index dd3bdca87..81c1a9cbe 100644
--- a/app/storage/postgres/post.go
+++ b/app/storage/postgres/post.go
@@ -49,7 +49,7 @@ func (i *dbPost) toModel() *models.Post {
HasVoted: i.HasVoted,
TotalVotes: i.TotalVotes,
TotalComments: i.TotalComments,
- Status: i.Status,
+ Status: models.PostStatus(i.Status),
User: i.User.toModel(),
Tags: i.Tags,
}
@@ -65,7 +65,7 @@ func (i *dbPost) toModel() *models.Post {
Number: int(i.OriginalNumber.Int64),
Slug: i.OriginalSlug.String,
Title: i.OriginalTitle.String,
- Status: int(i.OriginalStatus.Int64),
+ Status: models.PostStatus(i.OriginalStatus.Int64),
}
}
}
@@ -96,8 +96,8 @@ func (c *dbComment) toModel() *models.Comment {
}
type dbStatusCount struct {
- Status int `db:"status"`
- Count int `db:"count"`
+ Status models.PostStatus `db:"status"`
+ Count int `db:"count"`
}
// PostStorage contains read and write operations for posts
@@ -195,7 +195,7 @@ var (
ON agg_c.post_id = p.id
LEFT JOIN agg_votes agg_s
ON agg_s.post_id = p.id
- WHERE p.status != ` + strconv.Itoa(models.PostDeleted) + ` AND %s
+ WHERE p.status != ` + strconv.Itoa(int(models.PostDeleted)) + ` AND %s
GROUP BY p.id, u.id, r.id, d.id, agg_s.all, agg_c.all, agg_c.recent, agg_s.recent`
)
@@ -258,13 +258,13 @@ func (s *PostStorage) GetAll() ([]*models.Post, error) {
}
// CountPerStatus returns total number of posts per status
-func (s *PostStorage) CountPerStatus() (map[int]int, error) {
+func (s *PostStorage) CountPerStatus() (map[models.PostStatus]int, error) {
stats := []*dbStatusCount{}
err := s.trx.Select(&stats, "SELECT status, COUNT(*) AS count FROM posts WHERE tenant_id = $1 GROUP BY status", s.tenant.ID)
if err != nil {
return nil, errors.Wrap(err, "failed to count posts per status")
}
- result := make(map[int]int, len(stats))
+ result := make(map[models.PostStatus]int, len(stats))
for _, v := range stats {
result[v.Status] = v.Count
}
@@ -293,7 +293,7 @@ func (s *PostStorage) Search(query, filter, limit string, tags []string) ([]*mod
ORDER BY %s DESC
LIMIT %s
`, innerQuery, scoreField, scoreField, limit)
- err = s.trx.Select(&posts, sql, s.tenant.ID, pq.Array([]int{
+ err = s.trx.Select(&posts, sql, s.tenant.ID, pq.Array([]models.PostStatus{
models.PostOpen,
models.PostStarted,
models.PostPlanned,
@@ -604,7 +604,7 @@ func (s *PostStorage) GetActiveSubscribers(number int, channel models.Notificati
}
// SetResponse changes current post response
-func (s *PostStorage) SetResponse(post *models.Post, text string, status int) error {
+func (s *PostStorage) SetResponse(post *models.Post, text string, status models.PostStatus) error {
if status == models.PostDuplicate {
return errors.New("Use MarkAsDuplicate to change an post status to Duplicate")
}
diff --git a/app/storage/storage.go b/app/storage/storage.go
index bdcbf4cae..a8366d296 100644
--- a/app/storage/storage.go
+++ b/app/storage/storage.go
@@ -21,7 +21,7 @@ type Post interface {
GetCommentsByPost(post *models.Post) ([]*models.Comment, error)
Search(query, filter, limit string, tags []string) ([]*models.Post, error)
GetAll() ([]*models.Post, error)
- CountPerStatus() (map[int]int, error)
+ CountPerStatus() (map[models.PostStatus]int, error)
Add(title, description string) (*models.Post, error)
Update(post *models.Post, title, description string) (*models.Post, error)
AddComment(post *models.Post, content string) (int, error)
@@ -32,7 +32,7 @@ type Post interface {
AddSubscriber(post *models.Post, user *models.User) error
RemoveSubscriber(post *models.Post, user *models.User) error
GetActiveSubscribers(number int, channel models.NotificationChannel, event models.NotificationEvent) ([]*models.User, error)
- SetResponse(post *models.Post, text string, status int) error
+ SetResponse(post *models.Post, text string, status models.PostStatus) error
MarkAsDuplicate(post *models.Post, original *models.Post) error
IsReferenced(post *models.Post) (bool, error)
VotedBy() ([]int, error)
diff --git a/app/tasks/tasks.go b/app/tasks/tasks.go
index 1f81b5ab7..f50e32c4c 100644
--- a/app/tasks/tasks.go
+++ b/app/tasks/tasks.go
@@ -159,7 +159,7 @@ func NotifyAboutNewComment(post *models.Post, comment *models.NewComment) worker
}
//NotifyAboutStatusChange sends a notification (web and email) to subscribers
-func NotifyAboutStatusChange(post *models.Post, prevStatus int) worker.Task {
+func NotifyAboutStatusChange(post *models.Post, prevStatus models.PostStatus) worker.Task {
return describe("Notify about post status change", func(c *worker.Context) error {
//Don't notify if previous status is the same
if prevStatus == post.Status {
@@ -172,7 +172,7 @@ func NotifyAboutStatusChange(post *models.Post, prevStatus int) worker.Task {
return c.Failure(err)
}
- title := fmt.Sprintf("**%s** changed status of **%s** to **%s**", c.User().Name, post.Title, models.GetPostStatusName(post.Status))
+ title := fmt.Sprintf("**%s** changed status of **%s** to **%s**", c.User().Name, post.Title, post.Status.Name())
link := fmt.Sprintf("/posts/%d/%s", post.Number, post.Slug)
for _, user := range users {
if user.ID != c.User().ID {
@@ -209,7 +209,7 @@ func NotifyAboutStatusChange(post *models.Post, prevStatus int) worker.Task {
"postLink": linkWithText(fmt.Sprintf("#%d", post.Number), c.BaseURL(), "/posts/%d/%s", post.Number, post.Slug),
"tenantName": c.Tenant().Name,
"content": markdown.Parse(post.Response.Text),
- "status": models.GetPostStatusName(post.Status),
+ "status": post.Status.Name(),
"duplicate": duplicate,
"view": linkWithText("View it on your browser", c.BaseURL(), "/posts/%d/%s", post.Number, post.Slug),
"unsubscribe": linkWithText("unsubscribe from it", c.BaseURL(), "/posts/%d/%s", post.Number, post.Slug),
diff --git a/app/tasks/tasks_test.go b/app/tasks/tasks_test.go
index a21902a4b..69d25fb8a 100644
--- a/app/tasks/tasks_test.go
+++ b/app/tasks/tasks_test.go
@@ -238,7 +238,7 @@ func TestNotifyAboutStatusChangeTask(t *testing.T) {
"tenantName": "Demonstration",
"content": template.HTML("<p>Planned for next release.</p>"),
"duplicate": template.HTML(""),
- "status": "Planned",
+ "status": "planned",
"view": template.HTML("<a href='http://domain.com/posts/1/add-support-for-typescript'>View it on your browser</a>"),
"change": template.HTML("<a href='http://domain.com/settings'>change your notification settings</a>"),
"unsubscribe": template.HTML("<a href='http://domain.com/posts/1/add-support-for-typescript'>unsubscribe from it</a>"),
@@ -259,7 +259,7 @@ func TestNotifyAboutStatusChangeTask(t *testing.T) {
Expect(notifications[0].CreatedAt).TemporarilySimilar(time.Now(), 5*time.Second)
Expect(notifications[0].Link).Equals("/posts/1/add-support-for-typescript")
Expect(notifications[0].Read).IsFalse()
- Expect(notifications[0].Title).Equals("**Jon Snow** changed status of **Add support for TypeScript** to **Planned**")
+ Expect(notifications[0].Title).Equals("**Jon Snow** changed status of **Add support for TypeScript** to **planned**")
}
func TestNotifyAboutStatusChangeTask_Duplicate(t *testing.T) {
@@ -290,7 +290,7 @@ func TestNotifyAboutStatusChangeTask_Duplicate(t *testing.T) {
"tenantName": "Demonstration",
"content": template.HTML(""),
"duplicate": template.HTML("<a href='http://domain.com/posts/1/add-support-for-typescript'>Add support for TypeScript</a>"),
- "status": "Duplicate",
+ "status": "duplicate",
"view": template.HTML("<a href='http://domain.com/posts/2/i-need-typescript'>View it on your browser</a>"),
"change": template.HTML("<a href='http://domain.com/settings'>change your notification settings</a>"),
"unsubscribe": template.HTML("<a href='http://domain.com/posts/2/i-need-typescript'>unsubscribe from it</a>"),
@@ -311,7 +311,7 @@ func TestNotifyAboutStatusChangeTask_Duplicate(t *testing.T) {
Expect(notifications[0].CreatedAt).TemporarilySimilar(time.Now(), 5*time.Second)
Expect(notifications[0].Link).Equals("/posts/2/i-need-typescript")
Expect(notifications[0].Read).IsFalse()
- Expect(notifications[0].Title).Equals("**Jon Snow** changed status of **I need TypeScript** to **Duplicate**")
+ Expect(notifications[0].Title).Equals("**Jon Snow** changed status of **I need TypeScript** to **duplicate**")
}
func TestSendInvites(t *testing.T) {
diff --git a/public/components/ShowPostResponse.tsx b/public/components/ShowPostResponse.tsx
index 032ebc020..52ef473cf 100644
--- a/public/components/ShowPostResponse.tsx
+++ b/public/components/ShowPostResponse.tsx
@@ -9,7 +9,7 @@ interface ShowPostStatusProps {
}
export const ShowPostStatus = (props: ShowPostStatusProps) => {
- return <span className={`status-label status-${props.status.slug}`}>{props.status.title}</span>;
+ return <span className={`status-label status-${props.status.value}`}>{props.status.title}</span>;
};
const DuplicateDetails = (props: PostResponseProps): JSX.Element | null => {
@@ -31,7 +31,7 @@ const DuplicateDetails = (props: PostResponseProps): JSX.Element | null => {
};
interface PostResponseProps {
- status: number;
+ status: string;
response: PostResponse | null;
}
diff --git a/public/models/post.ts b/public/models/post.ts
index 1d16211e2..06074fe37 100644
--- a/public/models/post.ts
+++ b/public/models/post.ts
@@ -7,7 +7,7 @@ export interface Post {
title: string;
description: string;
createdAt: string;
- status: number;
+ status: string;
user: User;
hasVoted: boolean;
response: PostResponse | null;
@@ -18,23 +18,22 @@ export interface Post {
export class PostStatus {
constructor(
- public value: number,
public title: string,
- public slug: string,
+ public value: string,
public show: boolean,
public closed: boolean,
public filterable: boolean
) {}
- public static Open = new PostStatus(0, "Open", "open", false, false, false);
- public static Planned = new PostStatus(4, "Planned", "planned", true, false, true);
- public static Started = new PostStatus(1, "Started", "started", true, false, true);
- public static Completed = new PostStatus(2, "Completed", "completed", true, true, true);
- public static Declined = new PostStatus(3, "Declined", "declined", true, true, true);
- public static Duplicate = new PostStatus(5, "Duplicate", "duplicate", true, true, false);
- public static Deleted = new PostStatus(6, "Deleted", "deleted", false, true, false);
+ public static Open = new PostStatus("Open", "open", false, false, false);
+ public static Planned = new PostStatus("Planned", "planned", true, false, true);
+ public static Started = new PostStatus("Started", "started", true, false, true);
+ public static Completed = new PostStatus("Completed", "completed", true, true, true);
+ public static Declined = new PostStatus("Declined", "declined", true, true, true);
+ public static Duplicate = new PostStatus("Duplicate", "duplicate", true, true, false);
+ public static Deleted = new PostStatus("Deleted", "deleted", false, true, false);
- public static Get(value: number): PostStatus {
+ public static Get(value: string): PostStatus {
for (const status of PostStatus.All) {
if (status.value === value) {
return status;
@@ -61,7 +60,7 @@ export interface PostResponse {
number: number;
title: string;
slug: string;
- status: number;
+ status: string;
};
}
diff --git a/public/pages/Home/components/PostFilter.tsx b/public/pages/Home/components/PostFilter.tsx
index 57bd9ed21..9ff9f2171 100644
--- a/public/pages/Home/components/PostFilter.tsx
+++ b/public/pages/Home/components/PostFilter.tsx
@@ -33,7 +33,7 @@ export class PostFilter extends React.Component<PostFilterProps, {}> {
PostStatus.All.filter(s => s.filterable && this.props.countPerStatus[s.value]).forEach(s => {
options.push({
text: s.title.toLowerCase(),
- value: s.slug,
+ value: s.value,
content: (
<span>
{s.title} <a className="counter">{this.props.countPerStatus[s.value]}</a>
diff --git a/public/pages/ShowPost/components/PostSearch.tsx b/public/pages/ShowPost/components/PostSearch.tsx
index c75bd18de..99c28cf8b 100644
--- a/public/pages/ShowPost/components/PostSearch.tsx
+++ b/public/pages/ShowPost/components/PostSearch.tsx
@@ -59,7 +59,7 @@ export class PostSearch extends React.Component<PostSearchProps, PostSearchState
<i className="caret up icon" />
{i.totalVotes}
</span>
- <span className={`status-label status-${status.slug}`}>{status.title}</span>
+ <span className={`status-label status-${status.value}`}>{status.title}</span>
{i.title}
</>
)
diff --git a/public/pages/ShowPost/components/ResponseForm.tsx b/public/pages/ShowPost/components/ResponseForm.tsx
index 6abc1f7f1..632f4dd17 100644
--- a/public/pages/ShowPost/components/ResponseForm.tsx
+++ b/public/pages/ShowPost/components/ResponseForm.tsx
@@ -12,7 +12,7 @@ interface ResponseFormProps {
interface ResponseFormState {
showModal: boolean;
- status: number;
+ status: string;
text: string;
originalNumber: number;
error?: Failure;
@@ -51,7 +51,7 @@ export class ResponseForm extends React.Component<ResponseFormProps, ResponseFor
private setStatus = (opt?: SelectOption) => {
if (opt) {
- this.setState({ status: parseInt(opt.value, 10) });
+ this.setState({ status: opt.value });
}
};
diff --git a/public/services/actions/post.ts b/public/services/actions/post.ts
index 3709e2508..fd1b80576 100644
--- a/public/services/actions/post.ts
+++ b/public/services/actions/post.ts
@@ -58,7 +58,7 @@ export const updateComment = async (postNumber: number, commentID: number, conte
};
interface SetResponseInput {
- status: number;
+ status: string;
text: string;
originalNumber: number;
}