Skip to content
Open
18 changes: 10 additions & 8 deletions scripts/type-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,11 @@ function recordNonNull(
hits: NonNullHit[],
sourceFile: ts.SourceFile,
node: ts.Node,
kind: NonNullHit['kind'],
codeNode?: ts.Node
kind: NonNullHit['kind']
) {
const pos = ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));
const relPath = path.relative(process.cwd(), sourceFile.fileName);
const code = textPreview((codeNode ?? node).getText(sourceFile));
const code = textPreview(node.getText(sourceFile));
hits.push({
file: relPath,
line: pos.line + 1,
Expand All @@ -224,12 +223,11 @@ function recordTypeAssertion(
sourceFile: ts.SourceFile,
node: ts.Node,
kind: TypeAssertionHit['kind'],
targetType: string,
codeNode?: ts.Node
targetType: string
) {
const pos = ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));
const relPath = path.relative(process.cwd(), sourceFile.fileName);
const code = textPreview((codeNode ?? node).getText(sourceFile));
const code = textPreview(node.getText(sourceFile));
hits.push({
file: relPath,
line: pos.line + 1,
Expand All @@ -240,9 +238,13 @@ function recordTypeAssertion(
});
}

function textPreview(s: string, max = 80) {
const TEXT_PREVIEW_MAX_LENGTH = 80;

function textPreview(s: string) {
const one = s.replace(/\s+/g, ' ').trim();
return one.length <= max ? one : one.slice(0, max - 1) + '…';
return one.length <= TEXT_PREVIEW_MAX_LENGTH
? one
: one.slice(0, TEXT_PREVIEW_MAX_LENGTH - 1) + '…';
}

function countBindingPatternElements(
Expand Down
2 changes: 1 addition & 1 deletion static/app/actionCreators/dashboards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {getResultsLimit} from 'sentry/views/dashboards/widgetBuilder/utils';
export function fetchDashboards(
api: Client,
orgSlug: string,
query?: {filter?: DashboardFilter; sort?: string}
query?: {filter?: DashboardFilter}
) {
const promise: Promise<DashboardListItem[]> = api.requestPromise(
`/organizations/${orgSlug}/dashboards/`,
Expand Down
4 changes: 1 addition & 3 deletions static/app/actionCreators/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,13 @@ type FetchIssueTagValuesParameters = {
organization: Organization;
tagKey: string;
cursor?: QueryParamValue;
environment?: string[];
sort?: string | string[];
};

export function issueTagValuesApiOptions({
organization,
groupId,
tagKey,
environment,
sort,
cursor,
}: FetchIssueTagValuesParameters) {
Expand All @@ -223,7 +221,7 @@ export function issueTagValuesApiOptions({
issueId: groupId,
key: tagKey,
},
query: {environment, sort, cursor},
query: {sort, cursor},
staleTime: 0,
}
),
Expand Down
12 changes: 2 additions & 10 deletions static/app/actionCreators/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import type {Location, Query} from 'history';
import {openModal} from 'sentry/actionCreators/modal';
import {ContextPickerModalContainer as ContextPickerModal} from 'sentry/components/contextPickerModal';
import {ProjectsStore} from 'sentry/stores/projectsStore';
import type {ApiQueryKey} from 'sentry/utils/api/apiQueryKey';
import {replaceRouterParams} from 'sentry/utils/replaceRouterParams';
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';
import type {ReactRouter3Navigate} from 'sentry/utils/useNavigate';

export function navigateTo(
to: string | {pathname: string; query?: Query},
navigate: ReactRouter3Navigate,
location: Location | undefined,
configQueryKey?: ApiQueryKey
location: Location | undefined
) {
let pathname: string;
if (typeof to === 'string') {
Expand All @@ -31,12 +29,7 @@ export function navigateTo(
typeof comingFromProjectId === 'string' ? comingFromProjectId : undefined
);

if (
needOrg ||
needTeam ||
(needProject && (needProjectId || !projectById)) ||
configQueryKey
) {
if (needOrg || needTeam || (needProject && (needProjectId || !projectById))) {
openModal(
modalProps => (
<ContextPickerModal
Expand All @@ -45,7 +38,6 @@ export function navigateTo(
needOrg={needOrg}
needProject={needProject}
needTeam={needTeam}
configQueryKey={configQueryKey}
onFinish={path => {
modalProps.closeModal();
return window.setTimeout(() => navigate(normalizeUrl(path)), 0);
Expand Down
12 changes: 1 addition & 11 deletions static/app/actionCreators/organizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {GuideStore} from 'sentry/stores/guideStore';
import {OrganizationsStore} from 'sentry/stores/organizationsStore';
import {OrganizationStore} from 'sentry/stores/organizationStore';
import {ProjectsStore} from 'sentry/stores/projectsStore';
import {TeamStore} from 'sentry/stores/teamStore';
import type {Organization} from 'sentry/types/organization';
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';

Expand Down Expand Up @@ -175,11 +174,6 @@ type FetchOrganizationDetailsParams = {
*/
loadProjects?: boolean;

/**
* Should load teams in TeamStore?
*/
loadTeam?: boolean;

/**
* Should set as active organization?
*/
Expand All @@ -188,7 +182,7 @@ type FetchOrganizationDetailsParams = {
export async function fetchOrganizationDetails(
api: Client,
orgId: string,
{setActive, loadProjects, loadTeam}: FetchOrganizationDetailsParams
{setActive, loadProjects}: FetchOrganizationDetailsParams
) {
const data = await api.requestPromise(`/organizations/${orgId}/`, {
query: {
Expand All @@ -200,10 +194,6 @@ export async function fetchOrganizationDetails(
setActiveOrganization(data);
}

if (loadTeam) {
TeamStore.loadInitialData(data.teams, false, null);
}

if (loadProjects) {
ProjectsStore.loadInitialData(data.projects || []);
}
Expand Down
23 changes: 4 additions & 19 deletions static/app/actionCreators/prompts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ type PromptCheckParams = {
*/
feature: string | string[];
organization: OrganizationSummary;
/**
* The numeric project ID as a string
*/
projectId?: string;
};

type PromptCheckHookParams = {
Expand Down Expand Up @@ -101,7 +97,6 @@ export async function promptsCheck(
): Promise<PromptData> {
const query = {
feature: params.feature,
...(params.projectId === undefined ? {} : {project_id: params.projectId}),
};
const url = `/organizations/${params.organization.slug}/prompts-activity/`;
const response: PromptResponse = await api.requestPromise(url, {
Expand Down Expand Up @@ -150,7 +145,6 @@ function usePromptsCheck(
export function usePrompts({
features,
organization,
projectId,
daysToSnooze,
options,
isDismissed = promptIsDismissed,
Expand All @@ -160,10 +154,9 @@ export function usePrompts({
daysToSnooze?: number;
isDismissed?: (prompt: PromptData, daysToSnooze?: number) => boolean;
options?: Partial<UseApiQueryOptions<PromptResponse>>;
projectId?: string;
}) {
const api = useApi({persistInFlight: true});
const prompts = usePromptsCheck({feature: features, organization, projectId}, options);
const prompts = usePromptsCheck({feature: features, organization}, options);
const queryClient = useQueryClient();
const isPromptDismissed = useMemo(() => {
if (prompts.isSuccess) {
Expand All @@ -186,7 +179,6 @@ export function usePrompts({
}
promptsUpdate(api, {
organization,
projectId,
feature,
status: 'dismissed',
});
Expand All @@ -198,7 +190,6 @@ export function usePrompts({
makePromptsCheckQueryKey({
organization,
feature: features,
projectId,
}),
existingData => {
const dismissedTs = Date.now() / 1000;
Expand All @@ -209,7 +200,7 @@ export function usePrompts({
}
);
},
[api, organization, projectId, queryClient, features]
[api, organization, queryClient, features]
);

const snoozePrompt = useCallback(
Expand All @@ -219,7 +210,6 @@ export function usePrompts({
}
promptsUpdate(api, {
organization,
projectId,
feature,
status: 'snoozed',
});
Expand All @@ -231,7 +221,6 @@ export function usePrompts({
makePromptsCheckQueryKey({
organization,
feature: features,
projectId,
}),
existingData => {
const snoozedTs = Date.now() / 1000;
Expand All @@ -242,7 +231,7 @@ export function usePrompts({
}
);
},
[api, organization, projectId, queryClient, features]
[api, organization, queryClient, features]
);

const showPrompt = useCallback(
Expand All @@ -252,7 +241,6 @@ export function usePrompts({
}
promptsUpdate(api, {
organization,
projectId,
feature,
status: 'visible',
});
Expand All @@ -264,7 +252,6 @@ export function usePrompts({
makePromptsCheckQueryKey({
organization,
feature: features,
projectId,
}),
existingData => {
return {
Expand All @@ -274,7 +261,7 @@ export function usePrompts({
}
);
},
[api, organization, projectId, queryClient, features]
[api, organization, queryClient, features]
);

return {
Expand Down Expand Up @@ -423,12 +410,10 @@ export async function batchedPromptsCheck<T extends readonly string[]>(
features: T,
params: {
organization: OrganizationSummary;
projectId?: string;
}
): Promise<Record<T[number], PromptData>> {
const query = {
feature: features,
...(params.projectId === undefined ? {} : {project_id: params.projectId}),
};
const url = `/organizations/${params.organization.slug}/prompts-activity/`;
const response: PromptResponse = await api.requestPromise(url, {
Expand Down
7 changes: 1 addition & 6 deletions static/app/actionCreators/savedSearches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,19 @@ function recentSearchesApiOptions({
namespace,
orgSlug,
savedSearchType,
query,
}: {
limit: number;
orgSlug: string;
savedSearchType: SavedSearchType | null;
namespace?: string;
query?: string;
}) {
return {
...apiOptions.as<RecentSearch[]>()(
'/organizations/$organizationIdOrSlug/recent-searches/',
{
path: savedSearchType === null ? skipToken : {organizationIdOrSlug: orgSlug},
query: {
query: encodeNamespacedRecentSearch(namespace, query),
query: encodeNamespacedRecentSearch(namespace),
type: savedSearchType,
limit,
},
Expand All @@ -120,15 +118,13 @@ type RecentSearchesQueryOptions = Omit<

export function useFetchRecentSearches(
{
query,
savedSearchType,
limit = MAX_AUTOCOMPLETE_RECENT_SEARCHES,
namespace,
}: {
savedSearchType: SavedSearchType | null;
limit?: number;
namespace?: string;
query?: string;
},
options: RecentSearchesQueryOptions = {}
) {
Expand All @@ -139,7 +135,6 @@ export function useFetchRecentSearches(
limit,
namespace,
orgSlug: organization.slug,
query,
savedSearchType,
}),
...options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export function ChoiceMapperTable({
* Transform choice tuples from the backend config into Select options.
*/
function transformMappedChoices(
selector?: {choices?: Array<[string, string]>; placeholder?: string} | unknown
selector?: {choices?: Array<[string, string]>} | unknown
): Array<{label: string; value: string}> {
if (!selector || typeof selector !== 'object') {
return [];
Expand Down
22 changes: 11 additions & 11 deletions static/app/components/core/chat/thinkingBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@ import {IconSeer} from 'sentry/icons';
import {getDuration} from 'sentry/utils/duration/getDuration';
import {SECOND} from 'sentry/utils/formatters';

const ELAPSED_TIME_TICK_INTERVAL_MS = 100;
Comment thread
TkDodo marked this conversation as resolved.

/**
* Returns elapsed ms between `startTime` and `endTime`.
* While `endTime` is undefined, ticks every `intervalMs` to keep the value live.
* While `endTime` is undefined, ticks every ELAPSED_TIME_TICK_INTERVAL_MS to keep the value live.
*/
function useElapsedTime(
startTime: Date,
endTime: Date | undefined,
intervalMs = 100
): number {
function useElapsedTime(startTime: Date, endTime: Date | undefined): number {
const [now, setNow] = useState(() => new Date());

useEffect(() => {
if (endTime) {
return;
}
const id = setInterval(() => setNow(new Date()), intervalMs);
const id = setInterval(() => setNow(new Date()), ELAPSED_TIME_TICK_INTERVAL_MS);
return () => clearInterval(id);
}, [endTime, intervalMs]);
}, [endTime]);

return (endTime ?? now).getTime() - startTime.getTime();
}
Expand All @@ -37,13 +35,15 @@ function useElapsedTime(
* in even thirds so they fit the reserved space and never shift layout as the
* count changes. Decorative — hidden from AT.
*/
function AnimatedEllipsis({intervalMs = 400}: {intervalMs?: number}) {
const ELLIPSIS_TICK_INTERVAL_MS = 400;

function AnimatedEllipsis() {
const [count, setCount] = useState(1);

useEffect(() => {
const id = setInterval(() => setCount(c => (c % 3) + 1), intervalMs);
const id = setInterval(() => setCount(c => (c % 3) + 1), ELLIPSIS_TICK_INTERVAL_MS);
return () => clearInterval(id);
}, [intervalMs]);
}, []);

return (
<span
Expand Down
Loading
Loading