[WEB-1255] chore: necessary changes for advanced views (#4955)

* make necessary changes for advanced views

* fix update view access methods
This commit is contained in:
rahulramesha 2024-06-27 18:42:07 +05:30 committed by GitHub
parent dbd7756163
commit 1f9f821543
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 65 additions and 8 deletions

View file

@ -36,7 +36,7 @@ export type TViewFilterProps = {
created_at?: string[] | null;
owned_by?: string[] | null;
favorites?: boolean;
accessTypes?: EViewAccess[];
view_type?: EViewAccess[];
};
export type TViewFilters = {

View file

@ -9,9 +9,10 @@ import { Breadcrumbs, PhotoFilterIcon, Button } from "@plane/ui";
// components
import { BreadcrumbLink, Logo } from "@/components/common";
import { ViewListHeader } from "@/components/views";
import { ViewAppliedFiltersList } from "@/components/views/filters/applied-filters";
import { ViewAppliedFiltersList } from "@/components/views/applied-filters";
// constants
import { EUserProjectRoles } from "@/constants/project";
import { EViewAccess } from "@/constants/views";
// helpers
import { calculateTotalFilters } from "@/helpers/filter.helper";
// hooks
@ -29,7 +30,7 @@ export const ProjectViewsHeader = observer(() => {
const { filters, updateFilters, clearAllFilters } = useProjectView();
const handleRemoveFilter = useCallback(
(key: keyof TViewFilterProps, value: string | null) => {
(key: keyof TViewFilterProps, value: string | EViewAccess | null) => {
let newValues = filters.filters?.[key];
if (key === "favorites") {

View file

@ -0,0 +1,46 @@
import { observer } from "mobx-react";
// icons
import { X } from "lucide-react";
// constants
import { EViewAccess, VIEW_ACCESS_SPECIFIERS } from "@/constants/views";
// helpers
type Props = {
editable: boolean | undefined;
handleRemove: (val: EViewAccess) => void;
values: EViewAccess[];
};
export const AppliedAccessFilters: React.FC<Props> = observer((props) => {
const { editable, handleRemove, values } = props;
const getAccessLabel = (val: EViewAccess) => {
const value = VIEW_ACCESS_SPECIFIERS.find((option) => option.key === val);
return value?.label;
};
return (
<>
{values.map((access) => {
const label = getAccessLabel(access);
if (!label) return null;
return (
<div key={access} className="flex items-center gap-1 rounded bg-custom-background-80 p-1 text-xs">
<span className="normal-case">{label}</span>
{editable && (
<button
type="button"
className="grid place-items-center text-custom-text-300 hover:text-custom-text-200"
onClick={() => handleRemove(access)}
>
<X size={10} strokeWidth={2} />
</button>
)}
</div>
);
})}
</>
);
});

View file

@ -0,0 +1 @@
export * from "./root";

View file

@ -2,19 +2,23 @@ import { X } from "lucide-react";
import { TViewFilterProps } from "@plane/types";
// components
import { AppliedDateFilters, AppliedMembersFilters } from "@/components/common/applied-filters";
// constants
import { EViewAccess } from "@/constants/views";
// helpers
import { replaceUnderscoreIfSnakeCase } from "@/helpers/string.helper";
import { AppliedAccessFilters } from "./access";
// types
type Props = {
appliedFilters: TViewFilterProps;
handleClearAllFilters: () => void;
handleRemoveFilter: (key: keyof TViewFilterProps, value: string | null) => void;
handleRemoveFilter: (key: keyof TViewFilterProps, value: string | EViewAccess | null) => void;
alwaysAllowEditing?: boolean;
};
const MEMBERS_FILTERS = ["owned_by"];
const DATE_FILTERS = ["created_at"];
const VIEW_ACCESS_FILTERS = ["view_type"];
export const ViewAppliedFiltersList: React.FC<Props> = (props) => {
const { appliedFilters, handleClearAllFilters, handleRemoveFilter, alwaysAllowEditing } = props;
@ -39,6 +43,13 @@ export const ViewAppliedFiltersList: React.FC<Props> = (props) => {
>
<div className="flex flex-wrap items-center gap-1.5">
<span className="text-xs text-custom-text-300">{replaceUnderscoreIfSnakeCase(filterKey)}</span>
{VIEW_ACCESS_FILTERS.includes(filterKey) && (
<AppliedAccessFilters
editable={isEditingAllowed}
handleRemove={(val) => handleRemoveFilter(filterKey, val)}
values={Array.isArray(value) ? (value as EViewAccess[]) : []}
/>
)}
{DATE_FILTERS.includes(filterKey) && (
<AppliedDateFilters
editable={isEditingAllowed}

View file

@ -277,7 +277,6 @@ export class GlobalViewStore implements IGlobalViewStore {
const currentView = this.getViewDetailsById(viewId);
const currentAccess = currentView?.access;
try {
if (currentAccess === access) return;
runInAction(() => {
set(this.globalViewMap, [viewId, "access"], access);
});

View file

@ -313,7 +313,6 @@ export class ProjectViewStore implements IProjectViewStore {
const currentView = this.getViewById(viewId);
const currentAccess = currentView?.access;
try {
if (currentAccess === access) return;
runInAction(() => {
set(this.viewMap, [viewId, "access"], access);
});

View file

@ -54,8 +54,8 @@ export const shouldFilterView = (view: IProjectView, filters: TViewFilterProps |
});
}
if (filterKey === "accessTypes" && filters?.accessTypes && filters?.accessTypes?.length > 0) {
fallsInFilters = filters.accessTypes.includes(view.access);
if (filterKey === "view_type" && filters?.view_type && filters?.view_type?.length > 0) {
fallsInFilters = filters.view_type.includes(view.access);
}
});