Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5398 use store pref to hide extra columns #5407

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Types from '@openmsupply-client/common';
import { GraphQLClient, RequestOptions } from 'graphql-request';
import gql from 'graphql-tag';
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
export type UserStoreNodeFragment = { __typename: 'UserStoreNode', code: string, id: string, nameId: string, name: string, storeMode: Types.StoreModeNodeType, createdDate?: string | null, homeCurrencyCode?: string | null, isDisabled: boolean, preferences: { __typename: 'StorePreferenceNode', id: string, responseRequisitionRequiresAuthorisation: boolean, requestRequisitionRequiresAuthorisation: boolean, packToOne: boolean, omProgramModule: boolean, vaccineModule: boolean, issueInForeignCurrency: boolean, monthlyConsumptionLookBackPeriod: number, monthsLeadTime: number, monthsOverstock: number, monthsUnderstock: number, monthsItemsExpire: number, stocktakeFrequency: number } };
export type UserStoreNodeFragment = { __typename: 'UserStoreNode', code: string, id: string, nameId: string, name: string, storeMode: Types.StoreModeNodeType, createdDate?: string | null, homeCurrencyCode?: string | null, isDisabled: boolean, preferences: { __typename: 'StorePreferenceNode', id: string, responseRequisitionRequiresAuthorisation: boolean, requestRequisitionRequiresAuthorisation: boolean, packToOne: boolean, omProgramModule: boolean, vaccineModule: boolean, issueInForeignCurrency: boolean, monthlyConsumptionLookBackPeriod: number, monthsLeadTime: number, monthsOverstock: number, monthsUnderstock: number, monthsItemsExpire: number, stocktakeFrequency: number, extraFieldsInRequisition: boolean } };

export type AuthTokenQueryVariables = Types.Exact<{
username: Types.Scalars['String']['input'];
Expand All @@ -16,7 +16,7 @@ export type AuthTokenQuery = { __typename: 'Queries', authToken: { __typename: '
export type MeQueryVariables = Types.Exact<{ [key: string]: never; }>;


export type MeQuery = { __typename: 'Queries', me: { __typename: 'UserNode', email?: string | null, language: Types.LanguageType, username: string, userId: string, firstName?: string | null, lastName?: string | null, phoneNumber?: string | null, jobTitle?: string | null, defaultStore?: { __typename: 'UserStoreNode', code: string, id: string, nameId: string, name: string, storeMode: Types.StoreModeNodeType, createdDate?: string | null, homeCurrencyCode?: string | null, isDisabled: boolean, preferences: { __typename: 'StorePreferenceNode', id: string, responseRequisitionRequiresAuthorisation: boolean, requestRequisitionRequiresAuthorisation: boolean, packToOne: boolean, omProgramModule: boolean, vaccineModule: boolean, issueInForeignCurrency: boolean, monthlyConsumptionLookBackPeriod: number, monthsLeadTime: number, monthsOverstock: number, monthsUnderstock: number, monthsItemsExpire: number, stocktakeFrequency: number } } | null, stores: { __typename: 'UserStoreConnector', totalCount: number, nodes: Array<{ __typename: 'UserStoreNode', code: string, id: string, nameId: string, name: string, storeMode: Types.StoreModeNodeType, createdDate?: string | null, homeCurrencyCode?: string | null, isDisabled: boolean, preferences: { __typename: 'StorePreferenceNode', id: string, responseRequisitionRequiresAuthorisation: boolean, requestRequisitionRequiresAuthorisation: boolean, packToOne: boolean, omProgramModule: boolean, vaccineModule: boolean, issueInForeignCurrency: boolean, monthlyConsumptionLookBackPeriod: number, monthsLeadTime: number, monthsOverstock: number, monthsUnderstock: number, monthsItemsExpire: number, stocktakeFrequency: number } }> } } };
export type MeQuery = { __typename: 'Queries', me: { __typename: 'UserNode', email?: string | null, language: Types.LanguageType, username: string, userId: string, firstName?: string | null, lastName?: string | null, phoneNumber?: string | null, jobTitle?: string | null, defaultStore?: { __typename: 'UserStoreNode', code: string, id: string, nameId: string, name: string, storeMode: Types.StoreModeNodeType, createdDate?: string | null, homeCurrencyCode?: string | null, isDisabled: boolean, preferences: { __typename: 'StorePreferenceNode', id: string, responseRequisitionRequiresAuthorisation: boolean, requestRequisitionRequiresAuthorisation: boolean, packToOne: boolean, omProgramModule: boolean, vaccineModule: boolean, issueInForeignCurrency: boolean, monthlyConsumptionLookBackPeriod: number, monthsLeadTime: number, monthsOverstock: number, monthsUnderstock: number, monthsItemsExpire: number, stocktakeFrequency: number, extraFieldsInRequisition: boolean } } | null, stores: { __typename: 'UserStoreConnector', totalCount: number, nodes: Array<{ __typename: 'UserStoreNode', code: string, id: string, nameId: string, name: string, storeMode: Types.StoreModeNodeType, createdDate?: string | null, homeCurrencyCode?: string | null, isDisabled: boolean, preferences: { __typename: 'StorePreferenceNode', id: string, responseRequisitionRequiresAuthorisation: boolean, requestRequisitionRequiresAuthorisation: boolean, packToOne: boolean, omProgramModule: boolean, vaccineModule: boolean, issueInForeignCurrency: boolean, monthlyConsumptionLookBackPeriod: number, monthsLeadTime: number, monthsOverstock: number, monthsUnderstock: number, monthsItemsExpire: number, stocktakeFrequency: number, extraFieldsInRequisition: boolean } }> } } };

export type IsCentralServerQueryVariables = Types.Exact<{ [key: string]: never; }>;

Expand Down Expand Up @@ -75,6 +75,7 @@ export const UserStoreNodeFragmentDoc = gql`
monthsUnderstock
monthsItemsExpire
stocktakeFrequency
extraFieldsInRequisition
}
createdDate
homeCurrencyCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fragment UserStoreNode on UserStoreNode {
monthsUnderstock
monthsItemsExpire
stocktakeFrequency
extraFieldsInRequisition
}
createdDate
homeCurrencyCode
Expand Down
104 changes: 103 additions & 1 deletion client/packages/common/src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,45 @@ export type InboundInvoiceCounts = {
notDelivered: Scalars['Int']['output'];
};

export type IndicatorColumnNode = {
__typename: 'IndicatorColumnNode';
columnNumber: Scalars['Int']['output'];
name: Scalars['String']['output'];
value?: Maybe<IndicatorValueNode>;
valueType: IndicatorValueTypeNode;
};


export type IndicatorColumnNodeValueArgs = {
customerNameLinkId: Scalars['String']['input'];
periodId: Scalars['String']['input'];
storeId: Scalars['String']['input'];
};

export type IndicatorLineNode = {
__typename: 'IndicatorLineNode';
columns: Array<IndicatorColumnNode>;
line: IndicatorLineRowNode;
};

export type IndicatorLineRowNode = {
__typename: 'IndicatorLineRowNode';
code: Scalars['String']['output'];
lineNumber: Scalars['Int']['output'];
name: Scalars['String']['output'];
};

export type IndicatorValueNode = {
__typename: 'IndicatorValueNode';
id: Scalars['String']['output'];
value: Scalars['String']['output'];
};

export enum IndicatorValueTypeNode {
Number = 'NUMBER',
String = 'STRING'
}

export type InitialisationStatusNode = {
__typename: 'InitialisationStatusNode';
siteName?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -4048,6 +4087,7 @@ export type Mutations = {
updateInboundShipment: UpdateInboundShipmentResponse;
updateInboundShipmentLine: UpdateInboundShipmentLineResponse;
updateInboundShipmentServiceLine: UpdateInboundShipmentServiceLineResponse;
updateIndicatorValue: UpdateIndicatorValueResponse;
updateLabelPrinterSettings: UpdateLabelPrinterSettingsResponse;
updateLocation: UpdateLocationResponse;
updateLogLevel: UpsertLogLevelResponse;
Expand Down Expand Up @@ -4566,6 +4606,12 @@ export type MutationsUpdateInboundShipmentServiceLineArgs = {
};


export type MutationsUpdateIndicatorValueArgs = {
input: UpdateIndicatorValueInput;
storeId: Scalars['String']['input'];
};


export type MutationsUpdateLabelPrinterSettingsArgs = {
input: LabelPrinterSettingsInput;
};
Expand Down Expand Up @@ -5400,6 +5446,37 @@ export type ProgramFilterInput = {
name?: InputMaybe<StringFilterInput>;
};

export type ProgramIndicatorConnector = {
__typename: 'ProgramIndicatorConnector';
nodes: Array<ProgramIndicatorNode>;
totalCount: Scalars['Int']['output'];
};

export type ProgramIndicatorFilterInput = {
id?: InputMaybe<EqualFilterStringInput>;
programId?: InputMaybe<EqualFilterStringInput>;
};

export type ProgramIndicatorNode = {
__typename: 'ProgramIndicatorNode';
code?: Maybe<Scalars['String']['output']>;
id: Scalars['String']['output'];
lineAndColumns: Array<IndicatorLineNode>;
program: ProgramNode;
};

export type ProgramIndicatorResponse = ProgramIndicatorConnector;

export enum ProgramIndicatorSortFieldInput {
Code = 'code',
ProgramId = 'programId'
}

export type ProgramIndicatorSortInput = {
desc?: InputMaybe<Scalars['Boolean']['input']>;
key: ProgramIndicatorSortFieldInput;
};

export type ProgramNode = {
__typename: 'ProgramNode';
id: Scalars['String']['output'];
Expand Down Expand Up @@ -5564,6 +5641,7 @@ export type Queries = {
plugins: Array<PluginNode>;
programEnrolments: ProgramEnrolmentResponse;
programEvents: ProgramEventResponse;
programIndicators: ProgramIndicatorResponse;
programs: ProgramsResponse;
rAndRForm: RnRFormResponse;
rAndRForms: RnRFormsResponse;
Expand Down Expand Up @@ -6054,6 +6132,13 @@ export type QueriesProgramEventsArgs = {
};


export type QueriesProgramIndicatorsArgs = {
filter?: InputMaybe<ProgramIndicatorFilterInput>;
sort?: InputMaybe<ProgramIndicatorSortInput>;
storeId: Scalars['String']['input'];
};


export type QueriesProgramsArgs = {
filter?: InputMaybe<ProgramFilterInput>;
page?: InputMaybe<PaginationInput>;
Expand Down Expand Up @@ -6341,7 +6426,7 @@ export type RecordBelongsToAnotherStore = DeleteAssetErrorInterface & DeleteAsse
description: Scalars['String']['output'];
};

export type RecordNotFound = AddFromMasterListErrorInterface & AddToInboundShipmentFromMasterListErrorInterface & AddToOutboundShipmentFromMasterListErrorInterface & AllocateOutboundShipmentUnallocatedLineErrorInterface & CreateRequisitionShipmentErrorInterface & DeleteAssetCatalogueItemErrorInterface & DeleteAssetErrorInterface & DeleteAssetLogReasonErrorInterface & DeleteCustomerReturnErrorInterface & DeleteErrorInterface & DeleteInboundShipmentErrorInterface & DeleteInboundShipmentLineErrorInterface & DeleteInboundShipmentServiceLineErrorInterface & DeleteLocationErrorInterface & DeleteOutboundShipmentLineErrorInterface & DeleteOutboundShipmentServiceLineErrorInterface & DeleteOutboundShipmentUnallocatedLineErrorInterface & DeletePrescriptionErrorInterface & DeletePrescriptionLineErrorInterface & DeleteRequestRequisitionErrorInterface & DeleteRequestRequisitionLineErrorInterface & DeleteResponseRequisitionErrorInterface & DeleteResponseRequisitionLineErrorInterface & DeleteSupplierReturnErrorInterface & DeleteVaccineCourseErrorInterface & NodeErrorInterface & RequisitionLineChartErrorInterface & RequisitionLineStatsErrorInterface & ScannedDataParseErrorInterface & SupplyRequestedQuantityErrorInterface & UpdateAssetErrorInterface & UpdateErrorInterface & UpdateInboundShipmentErrorInterface & UpdateInboundShipmentLineErrorInterface & UpdateInboundShipmentServiceLineErrorInterface & UpdateLocationErrorInterface & UpdateNameErrorInterface & UpdateNamePropertiesErrorInterface & UpdateOutboundShipmentLineErrorInterface & UpdateOutboundShipmentServiceLineErrorInterface & UpdateOutboundShipmentUnallocatedLineErrorInterface & UpdatePrescriptionErrorInterface & UpdatePrescriptionLineErrorInterface & UpdateRequestRequisitionErrorInterface & UpdateRequestRequisitionLineErrorInterface & UpdateResponseRequisitionErrorInterface & UpdateResponseRequisitionLineErrorInterface & UpdateReturnOtherPartyErrorInterface & UpdateSensorErrorInterface & UpdateStockLineErrorInterface & UseSuggestedQuantityErrorInterface & {
export type RecordNotFound = AddFromMasterListErrorInterface & AddToInboundShipmentFromMasterListErrorInterface & AddToOutboundShipmentFromMasterListErrorInterface & AllocateOutboundShipmentUnallocatedLineErrorInterface & CreateRequisitionShipmentErrorInterface & DeleteAssetCatalogueItemErrorInterface & DeleteAssetErrorInterface & DeleteAssetLogReasonErrorInterface & DeleteCustomerReturnErrorInterface & DeleteErrorInterface & DeleteInboundShipmentErrorInterface & DeleteInboundShipmentLineErrorInterface & DeleteInboundShipmentServiceLineErrorInterface & DeleteLocationErrorInterface & DeleteOutboundShipmentLineErrorInterface & DeleteOutboundShipmentServiceLineErrorInterface & DeleteOutboundShipmentUnallocatedLineErrorInterface & DeletePrescriptionErrorInterface & DeletePrescriptionLineErrorInterface & DeleteRequestRequisitionErrorInterface & DeleteRequestRequisitionLineErrorInterface & DeleteResponseRequisitionErrorInterface & DeleteResponseRequisitionLineErrorInterface & DeleteSupplierReturnErrorInterface & DeleteVaccineCourseErrorInterface & NodeErrorInterface & RequisitionLineChartErrorInterface & RequisitionLineStatsErrorInterface & ScannedDataParseErrorInterface & SupplyRequestedQuantityErrorInterface & UpdateAssetErrorInterface & UpdateErrorInterface & UpdateInboundShipmentErrorInterface & UpdateInboundShipmentLineErrorInterface & UpdateInboundShipmentServiceLineErrorInterface & UpdateIndicatorValueErrorInterface & UpdateLocationErrorInterface & UpdateNameErrorInterface & UpdateNamePropertiesErrorInterface & UpdateOutboundShipmentLineErrorInterface & UpdateOutboundShipmentServiceLineErrorInterface & UpdateOutboundShipmentUnallocatedLineErrorInterface & UpdatePrescriptionErrorInterface & UpdatePrescriptionLineErrorInterface & UpdateRequestRequisitionErrorInterface & UpdateRequestRequisitionLineErrorInterface & UpdateResponseRequisitionErrorInterface & UpdateResponseRequisitionLineErrorInterface & UpdateReturnOtherPartyErrorInterface & UpdateSensorErrorInterface & UpdateStockLineErrorInterface & UseSuggestedQuantityErrorInterface & {
__typename: 'RecordNotFound';
description: Scalars['String']['output'];
};
Expand Down Expand Up @@ -7240,6 +7325,7 @@ export type StoreNodeNameArgs = {

export type StorePreferenceNode = {
__typename: 'StorePreferenceNode';
extraFieldsInRequisition: Scalars['Boolean']['output'];
id: Scalars['String']['output'];
issueInForeignCurrency: Scalars['Boolean']['output'];
monthlyConsumptionLookBackPeriod: Scalars['Float']['output'];
Expand Down Expand Up @@ -7843,6 +7929,22 @@ export enum UpdateInboundShipmentStatusInput {
Verified = 'VERIFIED'
}

export type UpdateIndicatorValueError = {
__typename: 'UpdateIndicatorValueError';
error: UpdateIndicatorValueErrorInterface;
};

export type UpdateIndicatorValueErrorInterface = {
description: Scalars['String']['output'];
};

export type UpdateIndicatorValueInput = {
id: Scalars['String']['input'];
value: Scalars['String']['input'];
};

export type UpdateIndicatorValueResponse = IndicatorValueNode | UpdateIndicatorValueError;

export type UpdateLabelPrinterSettingsError = {
__typename: 'UpdateLabelPrinterSettingsError';
error: Scalars['String']['output'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Popover,
ReasonOptionNodeType,
TextArea,
useAuthContext,
useToggle,
} from '@openmsupply-client/common';
import { useResponse } from '../../api';
Expand Down Expand Up @@ -49,6 +50,7 @@ export const ResponseLineEdit = ({
isProgram,
}: ResponseLineEditProps) => {
const t = useTranslation();
const { store } = useAuthContext();
const { isOn: ourStats, toggle: toggleOurStats } = useToggle();
const { isOn: theirStats, toggle: toggleTheirStats } = useToggle();
const { data } = useResponse.line.stats(draft?.id);
Expand Down Expand Up @@ -107,7 +109,7 @@ export const ResponseLineEdit = ({
sx={{ marginBottom: 1 }}
/>
)}
{isProgram && (
{isProgram && store?.preferences.extraFieldsInRequisition && (
<>
<InputWithLabelRow
Input={
Expand Down Expand Up @@ -204,7 +206,7 @@ export const ResponseLineEdit = ({
label={t('label.amc')}
sx={{ marginBottom: 1 }}
/>
{isProgram && (
{isProgram && store?.preferences.extraFieldsInRequisition && (
<InputWithLabelRow
Input={
<NumericTextInput
Expand Down Expand Up @@ -281,7 +283,7 @@ export const ResponseLineEdit = ({
)}
</Box>
</Box>
{isProgram && (
{isProgram && store?.preferences.extraFieldsInRequisition && (
<InputWithLabelRow
Input={
<NumericTextInput
Expand Down Expand Up @@ -384,7 +386,7 @@ export const ResponseLineEdit = ({
)}
</Box>
</Box>
{isProgram && (
{isProgram && store?.preferences.extraFieldsInRequisition && (
<InputWithLabelRow
Input={
<ReasonOptionsSearchInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useUrlQueryParams,
ColumnDescription,
TooltipTextCell,
useAuthContext,
} from '@openmsupply-client/common';
import { ResponseLineFragment, useResponse } from './../api';
import { PackQuantityCell } from '@openmsupply-client/system';
Expand All @@ -16,6 +17,7 @@ export const useResponseColumns = () => {
updateSortQuery,
queryParams: { sortBy },
} = useUrlQueryParams({ initialSort: { key: 'itemName', dir: 'asc' } });
const { store } = useAuthContext();
const { isRemoteAuthorisation } = useResponse.utils.isRemoteAuthorisation();
const { programName } = useResponse.document.fields(['programName']);

Expand Down Expand Up @@ -71,7 +73,7 @@ export const useResponseColumns = () => {
accessor: ({ rowData }) => rowData.availableStockOnHand,
});
}
if (programName) {
if (programName && store?.preferences?.extraFieldsInRequisition) {
columnDefinitions.push(
// TODO: Global pref to show/hide the next columns
{
Expand Down Expand Up @@ -234,7 +236,7 @@ export const useResponseColumns = () => {
]);

// TODO: Global pref to show/hide column
if (programName) {
if (programName && store?.preferences?.extraFieldsInRequisition) {
columnDefinitions.push({
key: 'reason',
label: 'label.reason',
Expand Down
4 changes: 4 additions & 0 deletions server/graphql/types/src/types/store_preference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ impl StorePreferenceNode {
pub async fn stocktake_frequency(&self) -> &f64 {
&self.store_preference.stocktake_frequency
}

pub async fn extra_fields_in_requisition(&self) -> &bool {
&self.store_preference.extra_fields_in_requisition
}
}

impl StorePreferenceNode {
Expand Down
2 changes: 2 additions & 0 deletions server/repository/src/db_diesel/store_preference_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ table! {
months_understock -> Double,
months_items_expire -> Double,
stocktake_frequency -> Double,
extra_fields_in_requisition -> Bool,
}
}

Expand Down Expand Up @@ -60,6 +61,7 @@ pub struct StorePreferenceRow {
pub months_understock: f64,
pub months_items_expire: f64,
pub stocktake_frequency: f64,
pub extra_fields_in_requisition: bool,
}

pub struct StorePreferenceRowRepository<'a> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::migrations::*;

pub(crate) struct Migrate;

impl MigrationFragment for Migrate {
fn identifier(&self) -> &'static str {
"add_store_pref_use_extra_fields"
}

fn migrate(&self, connection: &StorageConnection) -> anyhow::Result<()> {
sql!(
connection,
r#"
ALTER TABLE store_preference ADD extra_fields_in_requisition BOOLEAN NOT NULL DEFAULT FALSE;
"#
)?;

Ok(())
}
}
2 changes: 2 additions & 0 deletions server/repository/src/migrations/v2_04_00/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod add_expected_lifespan_to_assets;
mod add_item_variant_id_to_stock_line_and_invoice_line;
mod add_manual_requisition_line_fields;
mod add_reason_option_table;
mod add_store_pref_use_extra_fields;
mod add_unserviceable_status_to_asset_status_enum;
mod delete_pack_variant;
mod indicator_line_column_create_tables;
Expand Down Expand Up @@ -42,6 +43,7 @@ impl Migration for V2_04_00 {
Box::new(indicator_value_create_table::Migrate),
Box::new(add_bundled_item_table::Migrate),
Box::new(add_demographic_indicator_types_to_activity_log::Migrate),
Box::new(add_store_pref_use_extra_fields::Migrate),
]
}
}
Expand Down
Loading
Loading