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

add file type filter chip #7602

Merged
merged 5 commits into from
Nov 13, 2023
Merged

add file type filter chip #7602

merged 5 commits into from
Nov 13, 2023

Conversation

2403905
Copy link
Contributor

@2403905 2403905 commented Oct 27, 2023

Description

Related Issue

Motivation and Context

How Has This Been Tested?

  • test environment: local.
    The request example
curl --location --request REPORT 'https://:9200/remote.php/dav/spaces/admin/' \
--header 'Content-Type: application/xml' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--data '<?xml version="1.0"?>
<oc:search-files  xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
    <d:prop>
        <oc:permissions />
        <oc:favorite />
        <oc:fileid />
        <oc:file-parent />
        <oc:name />
        <oc:owner-id />
        <oc:owner-display-name />
        <oc:shareid />
        <oc:shareroot />
        <oc:share-types />
        <oc:privatelink />
        <d:getcontentlength />
        <oc:size />
        <d:getlastmodified />
        <d:getetag />
        <d:getcontenttype />
        <d:resourcetype />
        <oc:downloadURL />
        <oc:tags />
    </d:prop>
    <oc:search>
        <oc:pattern>mimetype:pdf</oc:pattern>
        <oc:limit>8</oc:limit>
    </oc:search>
</oc:search-files>'

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

@2403905 2403905 requested a review from fschade October 30, 2023 13:09
@2403905 2403905 force-pushed the issue-7432 branch 3 times, most recently from b63e5d7 to dc81e6a Compare October 30, 2023 14:21
@2403905 2403905 marked this pull request as ready for review October 30, 2023 14:21
@fschade
Copy link
Contributor

fschade commented Nov 7, 2023

the tests fail locally, let me know if i can help

@2403905 2403905 force-pushed the issue-7432 branch 3 times, most recently from efab378 to d829aef Compare November 8, 2023 14:59
@2403905 2403905 force-pushed the issue-7432 branch 2 times, most recently from f50f4a6 to 263b6d8 Compare November 8, 2023 20:44
@2403905 2403905 force-pushed the issue-7432 branch 2 times, most recently from 0ab54b5 to a408cbf Compare November 9, 2023 14:21
@2403905 2403905 force-pushed the issue-7432 branch 3 times, most recently from 7800dcb to defdcaa Compare November 10, 2023 11:32
@2403905 2403905 requested a review from fschade November 13, 2023 08:31
@lookacat lookacat requested a review from kulmann November 13, 2023 09:36
@lookacat
Copy link
Contributor

from testing it on web i can say it works perfect, just cant approve the PR because i think someone from the ocis team has more knowledge of the topic

Comment on lines 244 to 259
if left, ok := ln.(*bleveQuery.DisjunctionQuery); ok {
// if both are DisjunctionQuery then merge
if right, ok := rn.(*bleveQuery.DisjunctionQuery); ok {
left.AddQuery(right.Disjuncts...)
return left
}
left.AddQuery(rn)
return left
}
if _, ok := ln.(*bleveQuery.ConjunctionQuery); !ok {
if right, ok := rn.(*bleveQuery.DisjunctionQuery); ok {
left := bleveQuery.NewDisjunctionQuery([]bleveQuery.Query{ln})
left.AddQuery(right.Disjuncts...)
return left
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are type asserting ln and rn multiple times here. Can't we solve that with a typeswitch? Like

right, ok := rn.(*bleveQuery.DisjunctionQuery)
switch left := ln.(type) {
default:
    if ok {
        left := bleveQuery.NewDisjunctionQuery([]bleveQuery.Query{ln})
        left.AddQuery(right.Disjuncts...)
        return left
    }
    fallthrough
case *bleveQuery.ConjunctionQuery:
    return bleveQuery.NewDisjunctionQuery([]bleveQuery.Query{ln, rn})
case *bleveQuery.DisjunctionQuery:
    if ok {
        left.AddQuery(right.Disjunkts)
    } else {
        left.AddQuery(rn)
   }
   return left	
}

Or similar. But we want to make the type assertions only once

Copy link
Contributor Author

@2403905 2403905 Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallthrough doesn't work in this way.
I can rewrite but It became badly readable, sounds to me

		right, ok := rn.(*bleveQuery.DisjunctionQuery)
		switch left := ln.(type) {
		case *bleveQuery.DisjunctionQuery:
			if ok {
				left.AddQuery(right.Disjuncts...)
			} else {
				left.AddQuery(rn)
			}
			return left
		case *bleveQuery.ConjunctionQuery:
			return bleveQuery.NewDisjunctionQuery([]bleveQuery.Query{ln, rn})
		default:
			if ok {
				left := bleveQuery.NewDisjunctionQuery([]bleveQuery.Query{ln})
				left.AddQuery(right.Disjuncts...)
				return left
			} else {
				return bleveQuery.NewDisjunctionQuery([]bleveQuery.Query{ln, rn})
			}
		}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo better readable than the double type assertion. If you ask me I'd go with second solution. But up to you in the end...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could skip the last else though 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reworked

@2403905 2403905 requested a review from kobergj November 13, 2023 15:19
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

53.5% 53.5% Coverage
0.0% 0.0% Duplication

@2403905 2403905 merged commit 7ab553e into owncloud:master Nov 13, 2023
2 checks passed
ownclouders pushed a commit that referenced this pull request Nov 13, 2023
* add file type filter chip

* changed the keyword

* use reva issue-7432-replace

* changed the filter name. fix types

* rework mapBinary

---------

Co-authored-by: Roman Perekhod <rperekhod@owncloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants