Skip to content

Commit

Permalink
init front-end series query
Browse files Browse the repository at this point in the history
  • Loading branch information
acwhite211 committed Jan 29, 2025
1 parent c50e1d5 commit f173ac2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe('serializeResource', () => {
remarks: null,
searchSynonymy: null,
selectDistinct: null,
selectSeries: null,
smushed: null,
specifyUser: null,
sqlStr: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5291,6 +5291,7 @@ export type SpQuery = {
readonly remarks: string | null;
readonly searchSynonymy: boolean | null;
readonly selectDistinct: boolean | null;
readonly selectSeries: boolean | null;
readonly smushed: boolean | null;
readonly sqlStr: string | null;
readonly timestampCreated: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ overrideAjax(
resource_uri: undefined,
searchsynonymy: null,
selectdistinct: false,
selectseries: false,
smushed: null,
specifyuser: '/api/specify/specifyuser/2/',
sqlstr: null,
Expand Down
13 changes: 13 additions & 0 deletions specifyweb/frontend/js_src/lib/components/QueryBuilder/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function QueryToolbar({
showHiddenFields,
tableName,
isDistinct,
isSeries,
showSeries,
onToggleHidden: handleToggleHidden,
onToggleDistinct: handleToggleDistinct,
onRunCountOnly: handleRunCountOnly,
Expand All @@ -21,6 +23,8 @@ export function QueryToolbar({
readonly showHiddenFields: boolean;
readonly tableName: keyof Tables;
readonly isDistinct: boolean;
readonly isSeries: boolean;
readonly showSeries: boolean;
readonly onToggleHidden: (value: boolean) => void;
readonly onToggleDistinct: () => void;
readonly onRunCountOnly: () => void;
Expand All @@ -38,6 +42,15 @@ export function QueryToolbar({
<span className="-ml-2 flex-1" />
{hasPermission('/querybuilder/query', 'execute') && (
<>
{showSeries && (
<Label.Inline>
<Input.Checkbox
checked={isSeries}
onChange={handleToggleSeries}
/>
{queryText.series()}
</Label.Inline>
)}
{/*
* Query Distinct for trees is disabled because of
* https://github.com/specify/specify7/pull/1019#issuecomment-973525594
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function Wrapped({
readonly onChange?: (props: {
readonly fields: RA<SerializedResource<SpQueryField>>;
readonly isDistinct: boolean | null;
readonly isSeries: boolean | null;
}) => void;
}): JSX.Element {
const [query, setQuery] = useResource(queryResource);
Expand Down Expand Up @@ -157,8 +158,9 @@ function Wrapped({
handleChange?.({
fields: unParseQueryFields(state.baseTableName, state.fields),
isDistinct: query.selectDistinct,
isSeries: query.selectSeries,
});
}, [state, query.selectDistinct]);
}, [state, query.selectDistinct, query.selectSeries]);

/**
* If tried to save a query, enforce the field length limit for the
Expand Down Expand Up @@ -296,6 +298,10 @@ function Wrapped({
undefined
);

const showSeries =
table.name === 'CollectionObject' &&
state.fields.some((field) => field.mappingPath[0] === 'catalogNumber');

return treeRanksLoaded ? (
<ReadOnlyContext.Provider value={isReadOnly}>
<IsQueryBasicContext.Provider value={isBasic}>
Expand Down Expand Up @@ -556,6 +562,8 @@ function Wrapped({
/>
<QueryToolbar
isDistinct={query.selectDistinct ?? false}
isSeries={query.selectSeries ?? false}
showSeries={showSeries}
showHiddenFields={showHiddenFields}
tableName={table.name}
onRunCountOnly={(): void => runQuery('count')}
Expand All @@ -570,6 +578,12 @@ function Wrapped({
selectDistinct: !(query.selectDistinct ?? false),
})
}
onToggleSeries={(): void =>
setQuery({
...query,
selectSeries: !(query.selectSeries ?? false),
})
}
onToggleHidden={setShowHiddenFields}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function createQuery(
query.set('contextName', table.name);
query.set('contextTableId', table.tableId);
query.set('selectDistinct', false);
query.set('selectSeries', false);
query.set('countOnly', false);
query.set('formatAuditRecIds', false);
query.set('specifyUser', userInformation.resource_uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function makeComboBoxQuery({
query.set('contextName', table.name);
query.set('contextTableId', table.tableId);
query.set('selectDistinct', false);
query.set('selectSeries', false);
query.set('countOnly', false);
query.set('specifyUser', userInformation.resource_uri);
query.set('isFavorite', false);
Expand Down
3 changes: 3 additions & 0 deletions specifyweb/frontend/js_src/lib/localization/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ export const queryText = createDictionary({
'uk-ua': 'Виразний',
'de-ch': 'Unterscheidbar',
},
series: {
'en-us': 'Series',
},
createCsv: {
'en-us': 'Create CSV',
'ru-ru': 'Создать CSV-файл',
Expand Down

0 comments on commit f173ac2

Please sign in to comment.