Skip to content

Commit

Permalink
Ext/servicenow (#15612)
Browse files Browse the repository at this point in the history
* Update servicenow extension

- Merge branch \'contributions/merge-1732386826459466000\'
- Pull contributions
- Merge branch \'contributions/merge-1732386638586856000\'
- Pull contributions
- Update CHANGELOG.md
- Merge branch \'contributions/merge-1732386407934031000\'
- Pull contributions
- Updated dependencies
- Updated dependencies
- Updated README and CHANGELOG
- Added new screenshots
- Limited and full options
- Allow to manage favorites from different places
- Improved confirmation messages when deleting
- Minor fixes
- Corrected usage of mutate and revalidate
- Update SearchList.tsx
- Used mutate and /api/now/batch to delete history records
- Improved shortcuts
- Fixed favorites with mutation
- Moved selectedInstance to hook
- New feature: Remove from favorites
- Improved tags and added accessory for modules count in Navigator
- Added filter by groups to navigation menu
- Small bugs fixed
- Replaced table API calls by now/ui
- Created hook for favorites and added it to SearchResultItem
- Show favorites on Navigation Menu
- Fixed favorites in Navigation History
- Show favorites in Navigation History
- Added Explore Favorites Command
- Improved visualization of NavigationHistory
- Added command Explore Navigation Menu
- Use Section Subtitle in Search Results
- Added Explore Navigation History command
- Added Documate icon and updated default one
- Fixed update set filename and readme

* Minor fixes

* Add slash to URL when needed

* Update CHANGELOG.md and optimise images

* Fixed issue with different formats in dates

* Update CHANGELOG.md

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: raycastbot <[email protected]>
  • Loading branch information
robertoalvarezalonso and raycastbot authored Dec 2, 2024
1 parent 3175e5a commit 887fbef
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 29 deletions.
5 changes: 5 additions & 0 deletions extensions/servicenow/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Search Documate Changelog

## [Navigation History Command Fix] - 2024-12-02

- Fixed an issue with the Explore Navigation History command that was failing when the instance had a different date format from the Out-of-the-Box (OOTB) format.
- Applied minor fixes and aesthetic improvements for a smoother user experience.

## [New Commands] - 2024-11-25

- Added the **Manage Favorites** command to manage your favorite items and groups.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function NavigationHistoryFull() {
(options) => {
const terms = searchTerm.split(" ");
const query = terms.map((t) => `^titleLIKE${t}^ORdescriptionLIKE${t}^ORurlLIKE${t}`).join("");
return `${instanceUrl}/api/now/table/sys_ui_navigator_history?sysparm_query=${query}^userDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORDERBYDESCsys_created_on&sysparm_fields=title,description,url,sys_created_on,sys_id&sysparm_display_value=true&sysparm_limit=100&sysparm_offset=${options.page * 100}`;
return `${instanceUrl}/api/now/table/sys_ui_navigator_history?sysparm_query=${query}^userDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORDERBYDESCsys_created_on&sysparm_fields=title,description,url,sys_created_on,sys_id&sysparm_limit=100&sysparm_offset=${options.page * 100}`;
},
{
headers: {
Expand Down Expand Up @@ -139,7 +139,10 @@ export default function NavigationHistoryFull() {
const accessories: List.Item.Accessory[] = [
{
icon: Icon.Calendar,
tooltip: format(historyEntry.sys_created_on || "", "EEEE d MMMM yyyy 'at' HH:mm"),
tooltip: format(
new Date(historyEntry.sys_created_on + " UTC") || "",
"EEEE d MMMM yyyy 'at' HH:mm",
),
},
{
icon: Icon.Link,
Expand Down
4 changes: 2 additions & 2 deletions extensions/servicenow/src/components/ResultDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function ResultDetail({ result, fields }: { result: Record; field
<Detail.Metadata.Label
key={field.name}
title={field.label}
text={fieldData ? format(new Date(fieldData.display), "dd MMM yyyy") : ""}
text={fieldData ? format(new Date(fieldData.value + " UTC"), "dd MMM yyyy") : ""}
/>
);

Expand All @@ -51,7 +51,7 @@ export default function ResultDetail({ result, fields }: { result: Record; field
<Detail.Metadata.Label
key={field.name}
title={field.label}
text={fieldData ? format(new Date(fieldData.display), "dd MMM yyyy HH:mm") : ""}
text={fieldData ? format(new Date(fieldData.value + " UTC"), "dd MMM yyyy HH:mm") : ""}
/>
);

Expand Down
6 changes: 3 additions & 3 deletions extensions/servicenow/src/components/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ export default function SearchList() {
_updateHistory(
request,
{
before: `Removing ${title} from favorites`,
success: `${title} removed from favorites`,
failure: "Failed removing favorite",
before: `Removing ${title} from history`,
success: `${title} removed from history`,
failure: "Failed removing item from history",
},
updateData,
);
Expand Down
62 changes: 43 additions & 19 deletions extensions/servicenow/src/hooks/useInstances.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from "react";

import { useCachedState } from "@raycast/utils";
import { LocalStorage } from "@raycast/api";
import { LocalStorage, showToast, Toast } from "@raycast/api";

import fetch from "node-fetch";

Expand Down Expand Up @@ -47,29 +47,53 @@ export default function useInstances() {
}

useEffect(() => {
const fetchUserId = async () => {
if (!selectedInstance) {
return "";
}
if (!selectedInstance) {
return;
}

const fetchUserId = async () => {
const { name: instanceName = "", username = "", password = "" } = selectedInstance;
const response = await fetch(
`https://${instanceName}.service-now.com/api/now/table/sys_user?sysparm_query=user_name=${username}`,
{
method: "GET",
headers: {
Authorization: `Basic ${Buffer.from(username + ":" + password).toString("base64")}`,

try {
const response = await fetch(
`https://${instanceName}.service-now.com/api/now/table/sys_user?sysparm_query=user_name=${username}`,
{
method: "GET",
headers: {
Authorization: `Basic ${Buffer.from(username + ":" + password).toString("base64")}`,
},
},
},
);
if (!response.ok) {
return "";
}
);

const jsonData = (await response.json()) as { result: { sys_id: string }[] };
return jsonData.result[0].sys_id;
const jsonData = (await response.json()) as {
result?: { sys_id: string }[];
error?: { message: string };
};

if (!jsonData.result) {
showToast({
style: Toast.Style.Failure,
title: `Could not connect to ${instanceName}`,
message: jsonData.error?.message,
});

return "";
}

return jsonData.result[0].sys_id;
} catch (error) {
console.error(error);

showToast({
style: Toast.Style.Failure,
title: `Could not connect to ${instanceName}`,
message: error instanceof Error ? error.message : "",
});
}
};
fetchUserId().then((userId) => setUserId(userId));
fetchUserId().then((userId) => {
if (userId) setUserId(userId);
});
}, [selectedInstance]);

return {
Expand Down
6 changes: 3 additions & 3 deletions extensions/servicenow/src/utils/getSectionTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ TimeAgo.addDefaultLocale(en);
const timeAgo = new TimeAgo("en-US");

export const getSectionTitle = (dateTime: string) => {
const creationDate = new Date(dateTime);
const diffInMinutes = differenceInMinutes(new Date(), creationDate);
const utcDate = new Date(dateTime + " UTC");
const diffInMinutes = differenceInMinutes(new Date(), utcDate);

if (diffInMinutes < 1) {
return "Just now";
Expand All @@ -28,6 +28,6 @@ export const getSectionTitle = (dateTime: string) => {
} else if (diffInMinutes < 60) {
return "50 minutes ago";
} else {
return timeAgo.format(creationDate);
return timeAgo.format(utcDate);
}
};

0 comments on commit 887fbef

Please sign in to comment.