Skip to content

Commit

Permalink
Merge pull request #4095 from specify/issue-4094
Browse files Browse the repository at this point in the history
Add a basic view btn to the report dialog
  • Loading branch information
CarolineDenis authored Oct 12, 2023
2 parents 817b153 + 876a142 commit 9fe891a
Showing 1 changed file with 47 additions and 31 deletions.
78 changes: 47 additions & 31 deletions specifyweb/frontend/js_src/lib/components/Reports/Parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { State } from 'typesafe-reducer';
import { useId } from '../../hooks/useId';
import { useLiveState } from '../../hooks/useLiveState';
import { commonText } from '../../localization/common';
import { preferencesText } from '../../localization/preferences';
import { reportsText } from '../../localization/report';
import type { IR, RA } from '../../utils/types';
import { replaceItem, replaceKey } from '../../utils/utils';
Expand All @@ -15,6 +16,7 @@ import type { SerializedResource } from '../DataModel/helperTypes';
import { getModelById } from '../DataModel/schema';
import type { SpQuery } from '../DataModel/types';
import { Dialog } from '../Molecules/Dialog';
import { IsQueryBasicContext, useQueryViewPref } from '../QueryBuilder/Context';
import { QueryFields } from '../QueryBuilder/Fields';
import type { QueryField } from '../QueryBuilder/helpers';
import { parseQueryFields, unParseQueryFields } from '../QueryBuilder/helpers';
Expand Down Expand Up @@ -66,6 +68,8 @@ export function QueryParametersDialog({
)
);

const [isBasic, setIsBasic] = useQueryViewPref(query.id);

return state.type === 'Running' ? (
<RunReport
definition={definition}
Expand All @@ -84,41 +88,53 @@ export function QueryParametersDialog({
}
dimensionsKey="ReportParameters"
header={query.name ?? reportsText.reports()}
headerButtons={
<>
<span className="-ml-2 flex-1" />
<Button.Small onClick={() => setIsBasic(!isBasic)}>
{isBasic
? preferencesText.detailedView()
: preferencesText.basicView()}
</Button.Small>
</>
}
icon={<span className="text-blue-500">{icons.documentReport}</span>}
onClose={handleClose}
>
<Form
id={id('form')}
onSubmit={(): void =>
setState({
type: 'Running',
query: replaceKey(
query,
'fields',
unParseQueryFields(model.name, fields)
),
})
}
>
<QueryFields
baseTableName={model.name}
enforceLengthLimit={false}
fields={fields}
getMappedFields={() => []}
openedElement={undefined}
showHiddenFields={false}
onChangeField={(line, field): void =>
setFields(replaceItem(fields, line, field))
<IsQueryBasicContext.Provider value={isBasic}>
<Form
id={id('form')}
onSubmit={(): void =>
setState({
type: 'Running',
query: replaceKey(
query,
'fields',
unParseQueryFields(model.name, fields)
),
})
}
onClose={undefined}
onLineFocus={undefined}
onLineMove={undefined}
onMappingChange={undefined}
onOpen={undefined}
onOpenMap={undefined}
onRemoveField={undefined}
/>
</Form>
>
<QueryFields
baseTableName={model.name}
enforceLengthLimit={false}
fields={fields}
getMappedFields={() => []}
openedElement={undefined}
showHiddenFields={false}
onChangeField={(line, field): void =>
setFields(replaceItem(fields, line, field))
}
onClose={undefined}
onLineFocus={undefined}
onLineMove={undefined}
onMappingChange={undefined}
onOpen={undefined}
onOpenMap={undefined}
onRemoveField={undefined}
/>
</Form>
</IsQueryBasicContext.Provider>
</Dialog>
);
}

0 comments on commit 9fe891a

Please sign in to comment.