Skip to content

Commit 913d866

Browse files
Merge pull request #2797 from specify/issue-2420
Make interaction table's name dynamic
2 parents a755f02 + 85c1d1a commit 913d866

File tree

5 files changed

+100
-102
lines changed

5 files changed

+100
-102
lines changed

specifyweb/frontend/js_src/lib/components/FormCommands/ShowTransactions.tsx

+22-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useAsyncState } from '../../hooks/useAsyncState';
1515
import { AnySchema } from '../DataModel/helperTypes';
1616
import { Preparation } from '../DataModel/types';
1717
import { interactionsText } from '../../localization/interactions';
18+
import { schema } from '../DataModel/schema';
1819

1920
function List({
2021
resources,
@@ -104,27 +105,44 @@ export function ShowLoansCommand({
104105
header={commonText.transactions()}
105106
onClose={handleClose}
106107
>
107-
<H3>{interactionsText.openLoans()}</H3>
108+
<H3>
109+
{interactionsText.openLoans({
110+
loanTable: schema.models.Loan.label,
111+
})}
112+
</H3>
108113
<List
109114
displayFieldName="loanNumber"
110115
fieldName="loan"
111116
resources={data.openLoans ?? []}
112117
/>
113-
<H3>{interactionsText.resolvedLoans()}</H3>
118+
<H3>
119+
{interactionsText.resolvedLoans({
120+
loanTable: schema.models.Loan.label,
121+
})}
122+
</H3>
114123
<List
115124
displayFieldName="loanNumber"
116125
fieldName="loan"
117126
resources={data.resolvedLoans ?? []}
118127
/>
119-
<H3>{interactionsText.gifts()}</H3>
128+
<H3>
129+
{interactionsText.gifts({
130+
giftTable: schema.models.Gift.label,
131+
})}
132+
</H3>
120133
<List
121134
displayFieldName="giftNumber"
122135
fieldName="gift"
123136
resources={data.gifts ?? []}
124137
/>
125138
{Array.isArray(data.exchanges) && data.exchanges.length > 0 && (
126139
<>
127-
<H3>{interactionsText.exchanges()}</H3>
140+
<H3>
141+
{interactionsText.exchanges({
142+
exhangeInTable: schema.models.ExchangeIn.label,
143+
exhangeOutTable: schema.models.ExchangeOut.label,
144+
})}
145+
</H3>
128146
<List
129147
displayFieldName="exchangeOutNumber"
130148
fieldName="exchange"

specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
resolveParser,
5050
} from '../../utils/parser/definitions';
5151
import { interactionsText } from '../../localization/interactions';
52+
import { schema } from '../DataModel/schema';
5253

5354
export function InteractionDialog({
5455
recordSetsPromise,
@@ -197,10 +198,15 @@ export function InteractionDialog({
197198
return state.type === 'LoanReturnDoneState' ? (
198199
<Dialog
199200
buttons={commonText.close()}
200-
header={interactionsText.returnedPreparations()}
201+
header={interactionsText.returnedPreparations({
202+
tablePreparation: schema.models.Preparation.label,
203+
})}
201204
onClose={handleClose}
202205
>
203-
{interactionsText.returnedAndSaved({ count: state.result })}
206+
{interactionsText.returnedAndSaved({
207+
count: state.result,
208+
tablePreparation: schema.models.Preparation.label,
209+
})}
204210
</Dialog>
205211
) : state.type === 'PreparationSelectState' &&
206212
Object.keys(state.problems).length === 0 ? (

specifyweb/frontend/js_src/lib/components/Interactions/InteractionsDialog.tsx

+32-14
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,37 @@ const supportedActions = [
8888
/**
8989
* Remap Specify 6 UI localization strings to Specify 7 UI localization strings
9090
*/
91-
const stringLocalization = {
92-
RET_LOAN: interactionsText.returnLoan(),
91+
const stringLocalization = f.store(() => ({
92+
RET_LOAN: interactionsText.returnLoan({
93+
tableLoan: schema.models.Loan.label,
94+
}),
9395
PRINT_INVOICE: interactionsText.printInvoice(),
94-
LOAN_NO_PRP: interactionsText.loanWithoutPreparation(),
96+
LOAN_NO_PRP: interactionsText.loanWithoutPreparation({
97+
tableLoan: schema.models.Loan.label,
98+
tablePreparation: schema.models.Preparation.label,
99+
}),
95100
'InteractionsTask.LN_NO_PREP':
96-
interactionsText.loanWithoutPreparationDescription(),
97-
'InteractionsTask.NEW_LN': interactionsText.createLoan(),
98-
'InteractionsTask.EDT_LN': interactionsText.editLoan(),
99-
'InteractionsTask.NEW_GFT': interactionsText.createdGift(),
100-
'InteractionsTask.EDT_GFT': interactionsText.editGift(),
101-
'InteractionsTask.CRE_IR': interactionsText.createInformationRequest(),
101+
interactionsText.loanWithoutPreparationDescription({
102+
tableLoan: schema.models.Loan.label,
103+
tablePreparation: schema.models.Preparation.label,
104+
}),
105+
'InteractionsTask.NEW_LN': interactionsText.createLoan({
106+
tableLoan: schema.models.Loan.label,
107+
}),
108+
'InteractionsTask.EDT_LN': interactionsText.editLoan({
109+
tableLoan: schema.models.Loan.label,
110+
}),
111+
'InteractionsTask.NEW_GFT': interactionsText.createdGift({
112+
tableGift: schema.models.Gift.label,
113+
}),
114+
'InteractionsTask.EDT_GFT': interactionsText.editGift({
115+
tableGift: schema.models.Gift.label,
116+
}),
117+
'InteractionsTask.CRE_IR': interactionsText.createInformationRequest({
118+
tableInformationRequest: schema.models.InfoRequest.label,
119+
}),
102120
'InteractionsTask.PRT_INV': interactionsText.printInvoice(),
103-
};
121+
}));
104122

105123
export type InteractionEntry = {
106124
readonly action: typeof supportedActions[number] | undefined;
@@ -240,8 +258,8 @@ function Interactions({
240258
key={index}
241259
title={
242260
typeof tooltip === 'string'
243-
? stringLocalization[
244-
tooltip as keyof typeof stringLocalization
261+
? stringLocalization()[
262+
tooltip as keyof ReturnType<typeof stringLocalization>
245263
] ?? tooltip
246264
: undefined
247265
}
@@ -265,8 +283,8 @@ function Interactions({
265283
<TableIcon label={false} name={icon} />
266284
))}
267285
{typeof label === 'string'
268-
? stringLocalization[
269-
label as keyof typeof stringLocalization
286+
? stringLocalization()[
287+
label as keyof ReturnType<typeof stringLocalization>
270288
] ?? label
271289
: typeof table === 'string'
272290
? getModel(table)?.label

specifyweb/frontend/js_src/lib/components/QueryBuilder/LoanReturn.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ export function QueryLoanReturn({
146146
})
147147
}
148148
>
149-
{interactionsText.returnLoan()}
149+
{interactionsText.returnLoan({
150+
tableLoan: schema.models.Loan.label,
151+
})}
150152
</QueryButton>
151153
{state.type === 'Dialog' && Array.isArray(toReturn) ? (
152154
<Dialog

specifyweb/frontend/js_src/lib/localization/interactions.ts

+35-81
Original file line numberDiff line numberDiff line change
@@ -188,39 +188,27 @@ export const interactionsText = createDictionary({
188188
},
189189
prepReturnFormatter: {
190190
comment: 'Used to format preparations in the prep return dialog',
191-
'en-us': '{tableName:string}: {resource: string}',
192-
'ru-ru': '{tableName:string}: {resource: string}',
193-
'es-es': '{tableName:string}: {resource: string}',
194-
'fr-fr': '{tableName : chaîne} : {ressource : chaîne}',
195-
'uk-ua': '{tableName:string}: {ресурс: string}',
191+
'en-us': '{tableName:string}: {resource:string}',
192+
'ru-ru': '{tableName:string}: {resource:string}',
193+
'es-es': '{tableName:string}: {resource:string}',
194+
'fr-fr': '{tableName:chaîne}: {ressource:chaîne}',
195+
'uk-ua': '{tableName:string}: {resource:string}',
196196
},
197197
resolvedLoans: {
198-
'en-us': 'Resolved Loans',
199-
'ru-ru': 'Решение Заемы',
200-
'es-es': 'Préstamos Resueltos',
201-
'fr-fr': 'Prêts résolus',
202-
'uk-ua': 'Вирішені позики',
198+
comment: 'Example: Resolved Loan records',
199+
'en-us': 'Resolved {loanTable:string} records',
203200
},
204201
openLoans: {
205-
'en-us': 'Open Loans',
206-
'ru-ru': 'Открытые займы',
207-
'es-es': 'Préstamos abiertos',
208-
'fr-fr': 'Prêts ouverts',
209-
'uk-ua': 'Відкриті кредити',
202+
comment: 'Example: Open Loan records',
203+
'en-us': 'Open {loanTable:string} records',
210204
},
211205
gifts: {
212-
'en-us': 'Gifts',
213-
'ru-ru': 'Подарки',
214-
'es-es': 'Regalos',
215-
'fr-fr': 'Cadeaux',
216-
'uk-ua': 'Подарунки',
217-
},
218-
exchanges: {
219-
'en-us': 'Exchanges',
220-
'ru-ru': 'Обмены',
221-
'es-es': 'Intercambios',
222-
'fr-fr': 'Échanges',
223-
'uk-ua': 'Обміни',
206+
comment: 'Example: Gift records',
207+
'en-us': '{giftTable:string} records',
208+
},
209+
exchanges: {
210+
comment: 'Example: Exchange In / Exchnage Out records',
211+
'en-us': '{exhangeInTable:string} / {exhangeOutTable:string} records',
224212
},
225213
unCataloged: {
226214
'en-us': 'uncataloged',
@@ -230,23 +218,13 @@ export const interactionsText = createDictionary({
230218
'uk-ua': 'некаталогований',
231219
},
232220
returnedPreparations: {
233-
'en-us': 'Returned Preparations',
234-
'ru-ru': 'Возвращенные препараты',
235-
'es-es': 'Preparaciones devueltas',
236-
'fr-fr': 'Préparations retournées',
237-
'uk-ua': 'Повернені препарати',
221+
comment: 'Example: Preparation records',
222+
'en-us': 'Returned {tablePreparation:string} records',
238223
},
239224
returnedAndSaved: {
225+
comment: 'Example: 2 Preparation records have been returned and saved',
240226
'en-us':
241-
'{count:number|formatted} preparations have been returned and saved.',
242-
'ru-ru': '{count:number|formatted} препарата возвращены и сохранены.',
243-
'es-es':
244-
'{count:number|formatted} los preparativos se han devuelto y guardado.',
245-
'fr-fr': `
246-
Les préparations {count:number|formatted} ont été renvoyées et
247-
enregistrées.
248-
`,
249-
'uk-ua': 'Препарати {count:number|formatted} повернуто та збережено.',
227+
'{count:number|formatted} {tablePreparation:string} records have been returned and saved',
250228
},
251229
deselectAll: {
252230
'en-us': 'Deselect all',
@@ -270,11 +248,8 @@ export const interactionsText = createDictionary({
270248
'uk-ua': 'Недоступний',
271249
},
272250
returnLoan: {
273-
'en-us': 'Return Loan',
274-
'ru-ru': 'Возврат Заема',
275-
'es-es': 'Préstamo de devolución',
276-
'fr-fr': 'Prêt de retour',
277-
'uk-ua': 'Повернення кредиту',
251+
comment: 'Example: Return Loan records',
252+
'en-us': 'Return {tableLoan:string} records',
278253
},
279254
printInvoice: {
280255
'en-us': 'Print Invoice',
@@ -284,52 +259,31 @@ export const interactionsText = createDictionary({
284259
'uk-ua': 'Роздрукувати рахунок-фактуру',
285260
},
286261
loanWithoutPreparation: {
287-
'en-us': 'Loan w/o Preps',
288-
'ru-ru': 'Заем без Препаратов',
289-
'es-es': 'Préstamo sin preparación',
290-
'fr-fr': 'Prêt sans préparation',
291-
'uk-ua': 'Позика без підготовки',
262+
comment: 'Example: Loan records w/o Preparation records',
263+
'en-us': '{tableLoan:string} w/o {tablePreparation:string} records',
292264
},
293265
loanWithoutPreparationDescription: {
294-
'en-us': 'Create a loan with no preparations',
295-
'ru-ru': 'Создать Заем без препаратов',
296-
'es-es': 'Crear un préstamo sin preparativos',
297-
'fr-fr': 'Créer un prêt sans préparation',
298-
'uk-ua': 'Оформіть позику без підготовки',
266+
comment: 'Example: Create a Loan records with no Preparation records',
267+
'en-us': 'Create a {tableLoan:string} with no {tablePreparation:string} records',
299268
},
300269
createLoan: {
301-
'en-us': 'Create a Loan',
302-
'ru-ru': 'Создать Заем',
303-
'es-es': 'Crear un préstamo',
304-
'fr-fr': 'Créer un prêt',
305-
'uk-ua': 'Створіть позику',
270+
comment: 'Example: Create a Loan',
271+
'en-us': 'Create a {tableLoan:string}',
306272
},
307273
editLoan: {
308-
'en-us': 'Edit Loan',
309-
'ru-ru': 'Редактировать Заем',
310-
'es-es': 'Editar préstamo',
311-
'fr-fr': 'Modifier le prêt',
312-
'uk-ua': 'Редагувати кредит',
274+
comment: 'Example: Edit a Loan',
275+
'en-us': 'Edit {tableLoan:string}',
313276
},
314277
createdGift: {
315-
'en-us': 'Create a Gift',
316-
'ru-ru': 'Создать Дар',
317-
'es-es': 'Crear un regalo',
318-
'fr-fr': 'Créer un cadeau',
319-
'uk-ua': 'Створіть подарунок',
278+
comment: 'Example: Create a Gift',
279+
'en-us': 'Create a {tableGift:string}',
320280
},
321281
editGift: {
322-
'en-us': 'Edit Gift',
323-
'ru-ru': 'Редактировать Дар',
324-
'es-es': 'Editar regalo',
325-
'fr-fr': 'Modifier le cadeau',
326-
'uk-ua': 'Редагувати подарунок',
282+
comment: 'Example: Edit a Gift',
283+
'en-us': 'Edit {tableGift:string}',
327284
},
328285
createInformationRequest: {
329-
'en-us': 'Create Information Request',
330-
'ru-ru': 'Создать Экспресс Запрос',
331-
'es-es': 'Crear solicitud de información',
332-
'fr-fr': "Créer une demande d'informations",
333-
'uk-ua': 'Створити інформаційний запит',
286+
comment: 'Example: Create a Infrormation Request',
287+
'en-us': 'Create {tableInformationRequest:string}',
334288
},
335289
} as const);

0 commit comments

Comments
 (0)