Skip to content

Commit

Permalink
doc reviewer dashboard - sort wrt Due Date Issue Resolved . Moved fun…
Browse files Browse the repository at this point in the history
…ctionality to algolia (#37)
  • Loading branch information
soujash-mandal authored Jul 25, 2023
1 parent 80e4853 commit 872bc6b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 64 deletions.
94 changes: 93 additions & 1 deletion pkg/algolia/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Client struct {
// by descending modified time.
DocsModifiedTimeDesc *search.Index

DocsDueDateAsc *search.Index

// Drafts is an Algolia index for storing metadata for draft documents.
Drafts *search.Index

Expand Down Expand Up @@ -143,6 +145,7 @@ func New(cfg *Config) (*Client, error) {
cfg.DocsIndexName+"_createdTime_asc",
cfg.DocsIndexName+"_createdTime_desc",
cfg.DocsIndexName+"_modifiedTime_desc",
cfg.DocsIndexName+"_dueDate_asc",
),
})
if err != nil {
Expand All @@ -153,11 +156,14 @@ func New(cfg *Config) (*Client, error) {
c.DocsCreatedTimeAsc = a.InitIndex(cfg.DocsIndexName + "_createdTime_asc")
c.DocsCreatedTimeDesc = a.InitIndex(cfg.DocsIndexName + "_createdTime_desc")
c.DocsModifiedTimeDesc = a.InitIndex(cfg.DocsIndexName + "_modifiedTime_desc")
err = configureReplicaIndexes(
c.DocsDueDateAsc = a.InitIndex(cfg.DocsIndexName + "_dueDate_asc")

err = configureDocsReplicaIndexes(
cfg.DocsIndexName,
c.DocsCreatedTimeAsc,
c.DocsCreatedTimeDesc,
c.DocsModifiedTimeDesc,
c.DocsDueDateAsc,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -224,6 +230,7 @@ func configureReplicaIndexes(
createdTimeAscIndex *search.Index,
createdTimeDescIndex *search.Index,
modifiedTimeDescIndex *search.Index,

) error {
// Configure the createdTime_asc replica for index.
_, err := createdTimeAscIndex.SetSettings(search.Settings{
Expand Down Expand Up @@ -284,6 +291,90 @@ func configureReplicaIndexes(
return nil
}

func configureDocsReplicaIndexes(
indexName string,
createdTimeAscIndex *search.Index,
createdTimeDescIndex *search.Index,
modifiedTimeDescIndex *search.Index,
dueDateAscIndex *search.Index,
) error {
// Configure the createdTime_asc replica for index.
_, err := createdTimeAscIndex.SetSettings(search.Settings{
AttributesForFaceting: opt.AttributesForFaceting(
"contributors",
"docType",
"owners",
"product",
"status",
),

Ranking: opt.Ranking(
"asc(createdTime)",
),
})
if err != nil {
return fmt.Errorf(
"error setting settings for the %s createdTime_asc standard replica: %w",
indexName, err)
}

// Configure the createdTime_desc replica for index.
_, err = createdTimeDescIndex.SetSettings(search.Settings{
AttributesForFaceting: opt.AttributesForFaceting(
"contributors",
"docType",
"owners",
"product",
"status",
),

Ranking: opt.Ranking(
"desc(createdTime)",
),
})
if err != nil {
return fmt.Errorf(
"error setting settings for the %s createdTime_desc standard replica: %w",
indexName, err)
}

// Configure the modifiedTime_desc replica for index.
_, err = modifiedTimeDescIndex.SetSettings(search.Settings{
AttributesForFaceting: opt.AttributesForFaceting(
"status",
),

Ranking: opt.Ranking(
"desc(modifiedTime)",
),
})
if err != nil {
return fmt.Errorf(
"error setting settings for the %s modifiedTime_desc standard replica: %w",
indexName, err)
}

// Configure the dueDate_asc replica for index.
_, err = dueDateAscIndex.SetSettings(search.Settings{
AttributesForFaceting: opt.AttributesForFaceting(
"reviewers",
"reviewedBy",
"appCreated",
"status",
),
Ranking: opt.Ranking(
"asc(dueDate)",
),
})
if err != nil {
return fmt.Errorf(
"error setting settings for the %s modifiedTime_desc standard replica: %w",
indexName, err)
}

return nil
}

// NewSearchClient returns a new Algolia client for searching indices.
func NewSearchClient(cfg *Config) (*Client, error) {
if err := validate(cfg); err != nil {
Expand All @@ -299,6 +390,7 @@ func NewSearchClient(cfg *Config) (*Client, error) {
c.DocsCreatedTimeAsc = a.InitIndex(cfg.DocsIndexName + "_createdTime_asc")
c.DocsCreatedTimeDesc = a.InitIndex(cfg.DocsIndexName + "_createdTime_desc")
c.DocsModifiedTimeDesc = a.InitIndex(cfg.DocsIndexName + "_modifiedTime_desc")
c.DocsDueDateAsc = a.InitIndex(cfg.DocsIndexName + "_dueDate_asc")
c.Drafts = a.InitIndex(cfg.DraftsIndexName)
c.DraftsCreatedTimeAsc = a.InitIndex(cfg.DraftsIndexName + "_createdTime_asc")
c.DraftsCreatedTimeDesc = a.InitIndex(cfg.DraftsIndexName + "_createdTime_desc")
Expand Down
27 changes: 2 additions & 25 deletions web/app/routes/authenticated/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export default class DashboardRoute extends Route {
const userInfo = this.authenticatedUser.info;

const docsWaitingForReview = this.algolia.searchIndex
.perform(this.configSvc.config.algolia_docs_index_name, "", {
.perform(this.configSvc.config.algolia_docs_index_name+"_dueDate_asc","", {
filters:
`reviewers:'${userInfo.email}'` +
` AND NOT reviewedBy:'${userInfo.email}'` +
" AND appCreated:true" +
" AND status:In-Review",
hitsPerPage: 1000,
hitsPerPage: 4,
})
.then((result) => {
// Add modifiedAgo for each doc.
Expand Down Expand Up @@ -80,29 +80,6 @@ export default class DashboardRoute extends Route {
}
}



docsWaitingForReview._result = docsWaitingForReview._result.sort((a, b) => {
// Use optional chaining to access the 'dueDate' property safely
const dueDateA = a.dueDate?.toString()||"";
const dueDateB = b.dueDate?.toString()||"";

// Check if 'dueDate' property exists in both 'a' and 'b'
if (dueDateA && dueDateB) {
return dueDateA.localeCompare(dueDateB);
} else if (dueDateA) {
// If 'dueDate' exists in 'a' but not in 'b', consider 'a' to come before 'b'
return -1;
} else if (dueDateB) {

// If 'dueDate' exists in 'b' but not in 'a', consider 'b' to come before 'a'
return 1;
} else {
// If 'dueDate' doesn't exist in both 'a' and 'b', maintain their original order
return 0;
}
});

return RSVP.hash({
docsWaitingForReview: docsWaitingForReview,
});
Expand Down
41 changes: 3 additions & 38 deletions web/app/routes/authenticated/waiting-for-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default class WaitingForMeRoute extends Route {
@service algolia;
@service("config") configSvc;
@service("fetch") fetchSvc;
@service("recently-viewed-docs") recentDocs;
@service session;
@service authenticatedUser;

Expand Down Expand Up @@ -36,9 +35,9 @@ export default class WaitingForMeRoute extends Route {
}

const userInfo = this.authenticatedUser.info;

const searchIndex=this.configSvc.config.algolia_docs_index_name + "_dueDate_asc";
const docsWaitingForReview = this.algolia.searchIndex
.perform(this.configSvc.config.algolia_docs_index_name, "", {
.perform(searchIndex, "", {
filters:
`reviewers:'${userInfo.email}'` +
` AND NOT reviewedBy:'${userInfo.email}'` +
Expand Down Expand Up @@ -69,13 +68,11 @@ export default class WaitingForMeRoute extends Route {
});

const docsReviewed = this.algolia.searchIndex
.perform(this.configSvc.config.algolia_docs_index_name, "", {
.perform(searchIndex, "", {
filters:
`reviewers:'${userInfo.email}'` +
` AND reviewedBy:'${userInfo.email}'` +
" AND appCreated:true",
// +
// " AND status:In-Review",
hitsPerPage: 1000,
})
.then((result) => {
Expand All @@ -100,38 +97,6 @@ export default class WaitingForMeRoute extends Route {
return result.hits;
});

await this.recentDocs.fetchAll.perform();
if (this.recentDocs.all === null) {
try {
await this.recentDocs.fetchAll.perform();
} catch {
/**
* This tells our template to show the error state.
*/
this.recentDocs.all = null;
}
}

docsWaitingForReview._result = docsWaitingForReview._result.sort((a, b) => {

// Use optional chaining to access the 'dueDate' property safely
const dueDateA = a.dueDate?.toString()||"";
const dueDateB = b.dueDate?.toString()||"";

// Check if 'dueDate' property exists in both 'a' and 'b'
if (dueDateA && dueDateB) {
return dueDateA.localeCompare(dueDateB);
} else if (dueDateA) {
// If 'dueDate' exists in 'a' but not in 'b', consider 'a' to come before 'b'
return -1;
} else if (dueDateB) {
// If 'dueDate' exists in 'b' but not in 'a', consider 'b' to come before 'a'
return 1;
} else {
// If 'dueDate' doesn't exist in both 'a' and 'b', maintain their original order
return 0;
}
});

return RSVP.hash({
docsWaitingForReview: docsWaitingForReview,
Expand Down

0 comments on commit 872bc6b

Please sign in to comment.