Skip to content

Commit

Permalink
chore(3838): adjust filter behaviours
Browse files Browse the repository at this point in the history
  • Loading branch information
junminahn committed Sep 27, 2024
1 parent 43cef79 commit 97aadff
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { IS_PROD } from '@/config';
import createClientPage from '@/core/client-page';
import { getPrivateCloudProject } from '@/services/backend/private-cloud/products';
import { usePrivateProductState } from '@/states/global';
import { resetState as resetRequestsState } from './requests/state';

const pathParamSchema = z.object({
licencePlate: z.string(),
Expand All @@ -36,6 +37,7 @@ export default privateCloudProductLayout(({ pathParams, queryParams, session, ch

useEffect(() => {
privateState.currentProduct = currentProduct;
resetRequestsState();
}, [currentProduct]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { proxy, useSnapshot } from 'valtio';
import { proxy } from 'valtio';
import { deepClone } from 'valtio/utils';
import { requestSortsInProduct } from '@/constants';
import { PrivateCloudRequestSearchBody } from '@/validation-schemas/private-cloud';

export const pageState = proxy<PrivateCloudRequestSearchBody>({
const initialValue = {
search: '',
page: 1,
pageSize: 10,
Expand All @@ -14,4 +15,21 @@ export const pageState = proxy<PrivateCloudRequestSearchBody>({
sortValue: requestSortsInProduct[0].label,
sortKey: requestSortsInProduct[0].sortKey,
sortOrder: requestSortsInProduct[0].sortOrder,
});
};

export const pageState = proxy<PrivateCloudRequestSearchBody>(deepClone(initialValue));

export function resetState() {
const resetObj = deepClone(initialValue);
pageState.search = resetObj.search;
pageState.page = resetObj.page;
pageState.pageSize = resetObj.pageSize;
pageState.ministries = resetObj.ministries;
pageState.clusters = resetObj.clusters;
pageState.temporary = resetObj.temporary;
pageState.status = resetObj.status;
pageState.types = resetObj.types;
pageState.sortValue = resetObj.sortValue;
pageState.sortKey = resetObj.sortKey;
pageState.sortOrder = resetObj.sortOrder;
}
11 changes: 7 additions & 4 deletions app/app/private-cloud/products/all/state.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Prisma, ProjectStatus } from '@prisma/client';
import { proxy, useSnapshot } from 'valtio';
import { ProjectStatus } from '@prisma/client';
import { proxy } from 'valtio';
import { deepClone } from 'valtio/utils';
import { productSorts } from '@/constants';
import { PrivateCloudProductSearchBody } from '@/validation-schemas/private-cloud';

export const pageState = proxy<PrivateCloudProductSearchBody>({
const initialValue = {
search: '',
page: 1,
pageSize: 10,
Expand All @@ -14,4 +15,6 @@ export const pageState = proxy<PrivateCloudProductSearchBody>({
sortValue: productSorts[0].label,
sortKey: productSorts[0].sortKey,
sortOrder: productSorts[0].sortOrder,
});
};

export const pageState = proxy<PrivateCloudProductSearchBody>(deepClone(initialValue));
3 changes: 2 additions & 1 deletion app/app/private-cloud/requests/all/state.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DecisionStatus } from '@prisma/client';
import { proxy, useSnapshot } from 'valtio';
import { requestSorts } from '@/constants';
import { PrivateCloudRequestSearchBody } from '@/validation-schemas/private-cloud';
Expand All @@ -9,7 +10,7 @@ export const pageState = proxy<PrivateCloudRequestSearchBody>({
ministries: [],
clusters: [],
temporary: [],
status: [],
status: [DecisionStatus.PENDING],
types: [],
sortValue: requestSorts[0].label,
sortKey: requestSorts[0].sortKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Tabs, { ITab } from '@/components/generic/tabs/BasicTabs';
import createClientPage from '@/core/client-page';
import { getPublicCloudProject } from '@/services/backend/public-cloud/products';
import { publicProductState } from '@/states/global';
import { resetState as resetRequestsState } from './requests/state';

const pathParamSchema = z.object({
licencePlate: z.string(),
Expand All @@ -31,6 +32,7 @@ export default publicCloudProductSecurityACS(({ pathParams, queryParams, session

useEffect(() => {
publicProductState.currentProduct = currentProduct;
resetRequestsState();
}, [currentProduct]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { proxy, useSnapshot } from 'valtio';
import { proxy } from 'valtio';
import { deepClone } from 'valtio/utils';
import { requestSorts } from '@/constants';
import { PublicCloudRequestSearchBody } from '@/validation-schemas/public-cloud';

export const pageState = proxy<PublicCloudRequestSearchBody>({
const initialValue = {
search: '',
page: 1,
pageSize: 10,
Expand All @@ -13,4 +14,20 @@ export const pageState = proxy<PublicCloudRequestSearchBody>({
sortValue: requestSorts[0].label,
sortKey: requestSorts[0].sortKey,
sortOrder: requestSorts[0].sortOrder,
});
};

export const pageState = proxy<PublicCloudRequestSearchBody>(deepClone(initialValue));

export function resetState() {
const resetObj = deepClone(initialValue);
pageState.search = resetObj.search;
pageState.page = resetObj.page;
pageState.pageSize = resetObj.pageSize;
pageState.ministries = resetObj.ministries;
pageState.providers = resetObj.providers;
pageState.status = resetObj.status;
pageState.types = resetObj.types;
pageState.sortValue = resetObj.sortValue;
pageState.sortKey = resetObj.sortKey;
pageState.sortOrder = resetObj.sortOrder;
}
11 changes: 7 additions & 4 deletions app/app/public-cloud/products/all/state.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Prisma, ProjectStatus } from '@prisma/client';
import { proxy, useSnapshot } from 'valtio';
import { ProjectStatus } from '@prisma/client';
import { proxy } from 'valtio';
import { deepClone } from 'valtio/utils';
import { productSorts } from '@/constants';
import { PublicCloudProductSearchBody } from '@/validation-schemas/public-cloud';

export const pageState = proxy<PublicCloudProductSearchBody>({
const initialValue = {
search: '',
page: 1,
pageSize: 10,
Expand All @@ -13,4 +14,6 @@ export const pageState = proxy<PublicCloudProductSearchBody>({
sortValue: productSorts[0].label,
sortKey: productSorts[0].sortKey,
sortOrder: productSorts[0].sortOrder,
});
};

export const pageState = proxy<PublicCloudProductSearchBody>(deepClone(initialValue));
3 changes: 2 additions & 1 deletion app/app/public-cloud/requests/all/state.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DecisionStatus } from '@prisma/client';
import { proxy, useSnapshot } from 'valtio';
import { requestSorts } from '@/constants';
import { PublicCloudRequestSearchBody } from '@/validation-schemas/public-cloud';
Expand All @@ -8,7 +9,7 @@ export const pageState = proxy<PublicCloudRequestSearchBody>({
pageSize: 10,
ministries: [],
providers: [],
status: [],
status: [DecisionStatus.PENDING],
types: [],
sortValue: requestSorts[0].label,
sortKey: requestSorts[0].sortKey,
Expand Down
42 changes: 21 additions & 21 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 97aadff

Please sign in to comment.