Skip to content

Commit 3f27478

Browse files
committed
revert changes to stoprint
1 parent 0fd0e38 commit 3f27478

File tree

10 files changed

+53
-93
lines changed

10 files changed

+53
-93
lines changed

modules/app-config/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ export type {AppConfigKey, FeatureFlagType} from './types'
88
export const AppConfig = async (): Promise<FeatureFlagType[]> => {
99
return [
1010
{
11-
configKey: AppConfigKey.MockStoprintData,
12-
group: AppConfigGroupKey.stoprint,
13-
title: 'Use mock data',
14-
active: await getFeatureFlag(AppConfigKey.MockStoprintData),
11+
configKey: AppConfigKey.TestDataKey,
12+
group: AppConfigGroupKey.test,
13+
title: 'Test config key',
14+
active: await getFeatureFlag(AppConfigKey.TestDataKey),
1515
},
1616
]
1717
}
@@ -30,5 +30,5 @@ const useFeature = (featureKey: AppConfigKey): boolean => {
3030
}
3131

3232
// exported feature flags
33-
export const useMockedStoprint = (): boolean =>
34-
useFeature(AppConfigKey.MockStoprintData)
33+
export const useTestFeature = (): boolean =>
34+
useFeature(AppConfigKey.TestDataKey)

modules/app-config/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ export interface FeatureFlagType {
66
}
77

88
export enum AppConfigKey {
9-
MockStoprintData = 'MockStoprintData',
9+
TestDataKey = 'TestData',
1010
}
1111

1212
export enum AppConfigGroupKey {
13-
stoprint = 'stoPrint',
13+
test = 'test',
1414
}

source/lib/stoprint/__mocks__/api.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,32 @@ function papercut<T>(mockData: T): Promise<T> {
2323
export function logIn(
2424
credentials: SharedWebCredentials,
2525
now: number = new Date().getTime(),
26-
useMockPrintData = true,
2726
): Promise<void> {
2827
return Promise.resolve()
2928
}
3029

31-
export const fetchJobs = (
32-
username: string,
33-
useMockPrintData = true,
34-
): Promise<PrintJobsResponse> => Promise.resolve(mockJobs)
30+
export const fetchJobs = (username: string): Promise<PrintJobsResponse> =>
31+
Promise.resolve(mockJobs)
3532

3633
export const fetchAllPrinters = (
3734
username: string,
38-
useMockPrintData = true,
3935
): Promise<AllPrintersResponse> => Promise.resolve(mockAllPrinters)
4036

4137
export const fetchRecentPrinters = (
4238
username: string,
43-
useMockPrintData = true,
4439
): Promise<RecentPopularPrintersResponse> => Promise.resolve(mockRecent)
4540

4641
export const heldJobsAvailableAtPrinterForUser = (
4742
printerName: string,
4843
username: string,
49-
useMockPrintData = true,
5044
): Promise<HeldJobsResponse> => Promise.resolve(mockHeldJobs)
5145

5246
export const releasePrintJobToPrinterForUser = ({
5347
jobId,
5448
printerName,
5549
username,
56-
useMockPrintData = true,
5750
}: {
5851
jobId: string
5952
printerName: string
6053
username: string
61-
useMockPrintData: boolean
6254
}): Promise<ReleaseResponse> => Promise.resolve(mockRelease)

source/lib/stoprint/api.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
logIn as mockLogIn,
99
releasePrintJobToPrinterForUser as mockReleasePrintJobToPrinterForUser,
1010
} from './__mocks__/api'
11+
import {isStoprintMocked} from '../../lib/stoprint'
1112

1213
import type {
1314
AllPrintersResponse,
@@ -30,12 +31,11 @@ export async function logIn(
3031
credentials: SharedWebCredentials,
3132
options: Options,
3233
now: number = new Date().getTime(),
33-
useMockPrintData = false,
3434
): Promise<void> {
3535
let {username, password} = credentials
3636

37-
if (useMockPrintData) {
38-
return mockLogIn(credentials, now, useMockPrintData)
37+
if (isStoprintMocked) {
38+
return mockLogIn(credentials, now)
3939
}
4040

4141
const result = (await papercutApi
@@ -57,9 +57,8 @@ export async function logIn(
5757
export async function fetchJobs(
5858
username: string,
5959
options: Options,
60-
useMockPrintData = false,
6160
): Promise<PrintJobsResponse> {
62-
if (useMockPrintData) {
61+
if (isStoprintMocked) {
6362
return mockFetchJobs(username)
6463
}
6564

@@ -71,9 +70,8 @@ export async function fetchJobs(
7170
export async function fetchAllPrinters(
7271
username: string,
7372
options: Options,
74-
useMockPrintData = false,
7573
): Promise<AllPrintersResponse> {
76-
if (useMockPrintData) {
74+
if (isStoprintMocked) {
7775
return mockFetchAllPrinters(username)
7876
}
7977

@@ -88,9 +86,8 @@ export async function fetchAllPrinters(
8886
export async function fetchRecentPrinters(
8987
username: string,
9088
options: Options,
91-
useMockPrintData = false,
9289
): Promise<RecentPopularPrintersResponse> {
93-
if (useMockPrintData) {
90+
if (isStoprintMocked) {
9491
return mockFetchRecentPrinters(username)
9592
}
9693

@@ -102,14 +99,7 @@ export async function fetchRecentPrinters(
10299
.json()) as RecentPopularPrintersResponse
103100
}
104101

105-
export async function fetchColorPrinters(
106-
options: Options,
107-
useMockPrintData = false,
108-
): Promise<string[]> {
109-
if (useMockPrintData) {
110-
return ['mfc-rml-4-disco', 'mfc-toh101']
111-
}
112-
102+
export async function fetchColorPrinters(options: Options): Promise<string[]> {
113103
let response = (await client
114104
.get('color-printers', options)
115105
.json()) as ColorPrintersResponse
@@ -120,10 +110,9 @@ export async function heldJobsAvailableAtPrinterForUser(
120110
printerName: string,
121111
username: string,
122112
options: Options,
123-
useMockPrintData = false,
124113
): Promise<HeldJobsResponse> {
125114
// https://PAPERCUT_API.stolaf.edu/rpc/api/rest/internal/mobilerelease/api/held-jobs/?username=rives&printerName=printers%5Cmfc-it
126-
if (useMockPrintData) {
115+
if (isStoprintMocked) {
127116
return mockHeldJobsAvailableAtPrinterForUser(printerName, username)
128117
}
129118

@@ -162,9 +151,8 @@ type PrintJobReleaseArgs = {
162151
export async function releasePrintJobToPrinterForUser(
163152
{jobId, printerName, username}: PrintJobReleaseArgs,
164153
options: Options,
165-
useMockPrintData = false,
166154
): Promise<ReleaseResponse> {
167-
if (useMockPrintData) {
155+
if (isStoprintMocked) {
168156
return mockReleasePrintJobToPrinterForUser({jobId, printerName, username})
169157
}
170158

source/lib/stoprint/debug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const isStoprintMocked = false

source/lib/stoprint/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export type {
1313
HeldJobsResponse,
1414
} from './types'
1515
export {showGeneralError} from './errors'
16+
export {isStoprintMocked} from './debug'

source/views/stoprint/print-jobs.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import * as React from 'react'
22
import {timezone} from '@frogpond/constants'
33
import {Platform, SectionList} from 'react-native'
44
import type {PrintJob} from '../../lib/stoprint'
5-
import {STOPRINT_HELP_PAGE} from '../../lib/stoprint'
6-
import {useMockedStoprint} from '@frogpond/app-config'
5+
import {STOPRINT_HELP_PAGE, isStoprintMocked} from '../../lib/stoprint'
76
import {
87
Detail,
98
ListRow,
@@ -20,6 +19,7 @@ import sortBy from 'lodash/sortBy'
2019
import {getTimeRemaining} from './lib'
2120
import {NativeStackNavigationOptions} from '@react-navigation/native-stack'
2221
import {useNavigation} from '@react-navigation/native'
22+
import {DebugNoticeButton} from '@frogpond/navigation-buttons'
2323
import {useMomentTimer} from '@frogpond/timer'
2424
import {usePrintJobs} from './query'
2525
import {useHasCredentials} from '../../lib/login'
@@ -38,8 +38,6 @@ export const PrintJobsView = (): JSX.Element => {
3838
isRefetching: jobsRefetching,
3939
} = usePrintJobs()
4040

41-
const useMockPrintData = useMockedStoprint()
42-
4341
let navigation = useNavigation()
4442
let openSettings = () => navigation.navigate('Settings')
4543

@@ -55,7 +53,7 @@ export const PrintJobsView = (): JSX.Element => {
5553
return <LoadingView text="Loading…" />
5654
}
5755

58-
if (!hasCredentials && !useMockPrintData) {
56+
if (!hasCredentials && !isStoprintMocked) {
5957
return (
6058
<StoPrintNoticeView
6159
buttonText="Open Settings"
@@ -136,4 +134,5 @@ export const PrintJobsView = (): JSX.Element => {
136134

137135
export const NavigationOptions: NativeStackNavigationOptions = {
138136
title: 'Print Jobs',
137+
headerRight: () => <DebugNoticeButton shouldShow={isStoprintMocked} />,
139138
}

source/views/stoprint/print-release.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ import {
77
cancelPrintJobForUser,
88
releasePrintJobToPrinterForUser,
99
} from '../../lib/stoprint/api'
10-
import {showGeneralError, type Printer, type PrintJob} from '../../lib/stoprint'
10+
import {
11+
isStoprintMocked,
12+
showGeneralError,
13+
type Printer,
14+
type PrintJob,
15+
} from '../../lib/stoprint'
1116
import {NativeStackNavigationOptions} from '@react-navigation/native-stack'
1217
import {RouteProp, useNavigation, useRoute} from '@react-navigation/native'
1318
import {RootStackParamList} from '../../navigation/types'
19+
import {DebugNoticeButton} from '@frogpond/navigation-buttons'
1420
import {useHeldJobs} from './query'
1521
import {useMutation} from '@tanstack/react-query'
1622
import {useUsername} from '../../lib/login'
@@ -211,4 +217,5 @@ export const PrintJobReleaseView = (): JSX.Element => {
211217

212218
export const NavigationOptions: NativeStackNavigationOptions = {
213219
title: 'Release job',
220+
headerRight: () => <DebugNoticeButton shouldShow={isStoprintMocked} />,
214221
}

source/views/stoprint/printers.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react'
22
import {SectionList, StyleSheet} from 'react-native'
33
import type {Printer} from '../../lib/stoprint'
4+
import {isStoprintMocked} from '../../lib/stoprint'
45
import {
56
Detail,
67
ListRow,
@@ -9,6 +10,7 @@ import {
910
Title,
1011
} from '@frogpond/lists'
1112
import {LoadingView} from '@frogpond/notice'
13+
import {DebugNoticeButton} from '@frogpond/navigation-buttons'
1214
import groupBy from 'lodash/groupBy'
1315
import {StoPrintErrorView} from './components/error'
1416
import {NativeStackNavigationOptions} from '@react-navigation/native-stack'
@@ -157,4 +159,5 @@ export const PrinterListView = (): JSX.Element => {
157159

158160
export const NavigationOptions: NativeStackNavigationOptions = {
159161
title: 'Select Printer',
162+
headerRight: () => <DebugNoticeButton shouldShow={isStoprintMocked} />,
160163
}

source/views/stoprint/query.ts

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {useQuery, UseQueryResult} from '@tanstack/react-query'
22
import {useUsername} from '../../lib/login'
3-
import {useMockedStoprint} from '@frogpond/app-config'
43
import {
54
fetchAllPrinters,
65
fetchColorPrinters,
@@ -16,52 +15,37 @@ import {
1615
} from '../../lib/stoprint/types'
1716

1817
export const keys = {
19-
jobs: (username: string, useMockPrintData: boolean) =>
20-
['printing', 'jobs', 'all', username, useMockPrintData] as const,
18+
jobs: (username: string) => ['printing', 'jobs', 'all', username] as const,
2119
heldJobs: ({
2220
username,
2321
printerName,
24-
useMockPrintData,
2522
}: {
2623
username: string
2724
printerName: string
28-
useMockPrintData: boolean
29-
}) =>
30-
[
31-
'printing',
32-
'jobs',
33-
'held',
34-
username,
35-
printerName,
36-
useMockPrintData,
37-
] as const,
38-
printers: (username: string, useMockPrintData: boolean) =>
39-
['printing', 'printers', username, useMockPrintData] as const,
25+
}) => ['printing', 'jobs', 'held', username, printerName] as const,
26+
printers: (username: string) => ['printing', 'printers', username] as const,
4027
recentPrinters: (username: string) =>
4128
['printing', 'printers', 'recent', username] as const,
42-
colorPrinters: ['printing', 'printers', 'color', useMockedStoprint] as const,
29+
colorPrinters: ['printing', 'printers', 'color'] as const,
4330
}
4431

4532
export function usePrintJobs(): UseQueryResult<PrintJobsResponse, unknown> {
4633
let {data: username = ''} = useUsername()
47-
const useMockPrintData = useMockedStoprint()
4834

4935
return useQuery({
50-
queryKey: keys.jobs(username, useMockPrintData),
51-
enabled: Boolean(username) || useMockPrintData,
52-
queryFn: ({signal}) => fetchJobs(username, {signal}, useMockPrintData),
36+
queryKey: keys.jobs(username),
37+
enabled: Boolean(username),
38+
queryFn: ({signal}) => fetchJobs(username, {signal}),
5339
})
5440
}
5541

5642
export function useAllPrinters(): UseQueryResult<AllPrintersResponse, unknown> {
5743
let {data: username = ''} = useUsername()
58-
const useMockPrintData = useMockedStoprint()
5944

6045
return useQuery({
61-
queryKey: keys.printers(username, useMockPrintData),
62-
enabled: Boolean(username) || useMockPrintData,
63-
queryFn: ({signal}) =>
64-
fetchAllPrinters(username, {signal}, useMockPrintData),
46+
queryKey: keys.printers(username),
47+
enabled: Boolean(username),
48+
queryFn: ({signal}) => fetchAllPrinters(username, {signal}),
6549
})
6650
}
6751

@@ -70,47 +54,32 @@ export function useRecentPrinters(): UseQueryResult<
7054
unknown
7155
> {
7256
let {data: username = ''} = useUsername()
73-
const useMockPrintData = useMockedStoprint()
7457

7558
return useQuery({
76-
queryKey: keys.printers(username, useMockPrintData),
77-
enabled: Boolean(username) || useMockPrintData,
78-
queryFn: ({signal}) =>
79-
fetchRecentPrinters(username, {signal}, useMockPrintData),
59+
queryKey: keys.printers(username),
60+
enabled: Boolean(username),
61+
queryFn: ({signal}) => fetchRecentPrinters(username, {signal}),
8062
})
8163
}
8264

8365
export function useColorPrinters(): UseQueryResult<string[], unknown> {
84-
const useMockPrintData = useMockedStoprint()
85-
8666
return useQuery({
8767
queryKey: keys.colorPrinters,
88-
queryFn: ({signal}) => fetchColorPrinters({signal}, useMockPrintData),
68+
queryFn: ({signal}) => fetchColorPrinters({signal}),
8969
})
9070
}
9171

9272
export function useHeldJobs(
9373
printerName: string | undefined,
9474
): UseQueryResult<HeldJobsResponse, unknown> {
9575
let {data: username = ''} = useUsername()
96-
const useMockPrintData = useMockedStoprint()
9776

9877
let usablePrinterName = printerName || 'undefined'
9978

10079
return useQuery({
101-
enabled:
102-
(Boolean(username) && printerName !== undefined) || useMockPrintData,
103-
queryKey: keys.heldJobs({
104-
username,
105-
printerName: usablePrinterName,
106-
useMockPrintData,
107-
}),
80+
enabled: Boolean(username) && printerName !== undefined,
81+
queryKey: keys.heldJobs({username, printerName: usablePrinterName}),
10882
queryFn: ({signal}) =>
109-
heldJobsAvailableAtPrinterForUser(
110-
usablePrinterName,
111-
username,
112-
{signal},
113-
useMockPrintData,
114-
),
83+
heldJobsAvailableAtPrinterForUser(usablePrinterName, username, {signal}),
11584
})
11685
}

0 commit comments

Comments
 (0)